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

global Func objects #876

Closed
AlasdairWJ opened this Issue Apr 26, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@AlasdairWJ

AlasdairWJ commented Apr 26, 2015

It seems rock doesn't recognize globally declared function objects.

myFunc: Func(Int)
myFunc_imp: func (i: Int) {
    "%d" printfln(i)
}
main: func {
    myFunc = myFunc_imp
    myFunc(10)
}

The compiler throws a 'No such function' error on myFunc(10). This also fails:

other := func {
    "Hi!" println()
}   
main: func {
    other()
}

but can however, be worked around like this:

f := myFunc
f(10)
g := other
g()

zhaihj added a commit to zhaihj/rock that referenced this issue Apr 27, 2015

@fasterthanlime

This comment has been minimized.

Collaborator

fasterthanlime commented Jul 8, 2015

My version of the test, using string interpolation & more importantly, making sure closures still work in that context:

x := 2

myFunc: Func (Int)

myFunc_imp := func (i: Int) {
    "i = #{i}" println()
    x = 4
}

main: func {
    myFunc = myFunc_imp
    "before, x = #{x}" println()
    myFunc(10)
    "after, x = #{x}" println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment