zegl/tre

feature: First class functions

zegl opened this issue · 5 comments

zegl commented
  • Assign a func to a variable
  • Execute func from variable
  • Clojures (variables outside the func are available inside the func)

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 commented

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()
}

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 commented

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.

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!)