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

feature: First class functions #36

Open
2 of 3 tasks
zegl opened this issue Feb 6, 2018 · 5 comments
Open
2 of 3 tasks

feature: First class functions #36

zegl opened this issue Feb 6, 2018 · 5 comments
Labels

Comments

@zegl
Copy link
Owner

zegl commented Feb 6, 2018

  • Assign a func to a variable
  • Execute func from variable
  • Clojures (variables outside the func are available inside the func)
@zegl zegl added the feature label Feb 6, 2018
zegl added a commit that referenced this issue Dec 1, 2018
zegl added a commit that referenced this issue Dec 1, 2018
zegl added a commit that referenced this issue Dec 1, 2018
zegl added a commit that referenced this issue Dec 2, 2018
@prologic
Copy link
Contributor

Variables outside the func are available inside the func

Do you mean that closures are currently not supported? I also noticed that you cannot assign a module-scoped variable either; the compilation ends with a nill pointer exception.

@zegl
Copy link
Owner Author

zegl commented Nov 15, 2019

Do you mean that closures are currently not supported?

Yes, exactly. The compilation of the following program will fail:

package main

import "external"

func main() {
	foo := 100
	fn := func() {
		external.Printf("foo = %d\n", foo) // error: use of undefined value '%foo-1'
	}
	fn()
}

@prologic
Copy link
Contributor

Got it! Any plans to implement Closures soon? :) I'd have a crack at it myself but I'm still learning the in/outs of LLVM :/ I certainl yknow how to implement Closures as I've done in monkey-lang and mio-lang

@zegl
Copy link
Owner Author

zegl commented Nov 15, 2019

I'd really like to implement closures one day, I've never implemented it in a language, so it should be a fun challenge! Inspiration to work on tre usually comes back when the winter arrives in the northern hemisphere, so I'll probably start hacking on this project again soon.

@prologic
Copy link
Contributor

That timing might work out in that case :) I won't put up a PR to give you a chance to hack and learn! I need to go learn LLVM anyway so I'm using your project tre as a basis to learn from (tinygo is a bit much of a codebase to learn from!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants