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

chained function application giving strange results #839

Closed
miguel-negrao opened this issue May 6, 2013 · 3 comments
Closed

chained function application giving strange results #839

miguel-negrao opened this issue May 6, 2013 · 3 comments
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library"

Comments

@miguel-negrao
Copy link
Member

When using a lot of nested function application sclang starts giving strange results when a variable is declared in one of the first blocks and then it is used further down the chain.

Example:

(
f = { |x,g|
    g.()
};
f.(2,{ var abc = "this"; 
    f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{f.(2,{ f.(2, { "abc is %".format(abc).postln; 3})})})})})})})})})})})})})})})
)

should print 'abc is this' but prints 'abc is 2'. With FPLib I manage to get even stranger results:

(
Some(1) >>= {|x| var abc = 3; Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|
    Some(1) >>= {|x| Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|
        Some(1)>>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x|Some(1) >>= {|x| "abc: %".format(abc).postln; Some(2) }}}}}}}}}}}}}}}}}}}}}}
)

result:
abc: emacs
Some(2)
abc: a Function
Some(2)
abc: nil
Some(2)
abc: 0
Some(2)
abc: SystemClock
Some(2)
abc: true
Some(2)
abc: true
Some(2)
abc: a Function
Some(2)
abc: true
Some(2)
abc: SystemClock
Some(2)
@telephon
Copy link
Member

Just for reference, here is the case that does not fail, when the function has only one argument:

(
f = { |g|
g.()
};
f.({ var abc = "this";
f.(f.(f.(f.(f.(f.(f.(f.(f.(f.(f.(f.(f.(f.({ "abc is %".format(abc).postln; 3}))))))))))))))
})
)

@telephon
Copy link
Member

It seems to have to do with the compiler rather than being an issue with the function stack?

This works:

(
f = { |x,g|
g.()
};

z = { |func, n, func2|
if(n < 1, func2, { func.(2, { z.(func, n - 1, func2) }) });
};
);

(
var abc = "this";
z.(f, 10, { "abc is %".format(abc).postln; 3 } ).value;
)

@muellmusik
Copy link
Contributor

Fixed with PR #1054.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library"
Projects
None yet
Development

No branches or pull requests

3 participants