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
Closed

global Func objects #876

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

Comments

@AlasdairWJ
Copy link

@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()
horasal added a commit to horasal/rock that referenced this issue Apr 27, 2015
@fasterthanlime
Copy link
Collaborator

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

Loading

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

Successfully merging a pull request may close this issue.

None yet
2 participants