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

global Func objects #876

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

Comments

@AlasdairWJ
Copy link

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.

Copy link
Collaborator

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
Projects
None yet
2 participants
You can’t perform that action at this time.