Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions depending on other Functions #128

Open
Deleplace opened this issue May 12, 2019 · 2 comments
Open

Functions depending on other Functions #128

Deleplace opened this issue May 12, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@Deleplace
Copy link
Contributor

package main

import (
	"fmt"
)

func main() {
	a := myFloats{1.0, 2.0, 3.0}
	fmt.Println(a.First())
}

//go:generate pie myFloats.First
type myFloats []float64

yields

./myfloats_pie.go:5:11: ss.FirstOr undefined (type myFloats has no field or method FirstOr)

Currently, the developer hits this error and figures out they must explicitly ask for FirstOr:

//go:generate pie myFloats.First.FirstOr

It would be nice if Pie somehow knew it requires to generate FirstOras a dependency for First. I'm not saying this is trivial though, and also the inconvenience is minor.

@Deleplace
Copy link
Contributor Author

Generating all Pie functions with
//go:generate pie myType.*
seems to be the best choice in general.

My measurements confirm that the final compiled binary is not bigger when lots a unused functions are generated. Unused funcs are correctly discarded by the compiler.

@elliotchance elliotchance added the bug Something isn't working label May 12, 2019
@elliotchance
Copy link
Owner

Ah, that's a good catch. I have thought before about how to handle this because there are several other cases where some functions would be easier to implement if they could use other functions that may not be included.

One solution I can think of right now is to add dependencies when registering the functions:

// functions/main.go

{"First", "first.go", ForAll, []string{"FirstOr"}},

The pie command has to build a list of functions anyway (from CLI args), this shouldn't be too hard to merge with the existing list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants