|
|
> My problem seems to be that the formal parameters supplied to the function
> don't seem to be in scope for the expressions. It is as thought they were
> not declared.
They aren't. Commands beginning with # are evaluated at parse time in order
to get the tokens which are used to generate the objects they surround: in
this case, the function. So as the # commands are evaluated, the function
doesn't exist yet, and once the function is finished being created, the #
commands are already taken care of and are never seen again.
If you want to have an "if"-type structure within a function, you can use
the select() function (untested code):
#declare foo = function(a,b,c) {
select(a,
(a+1)+b+c, // if a >= 0
a+b+c // otherwise
)
}
See the documentation for more thorough information on select().
Also note that you can't define temporary variables within a function (that
is, there's no equivalent for #declare). You can, however, call other
functions and pass them whatever you want, which is often a decent
replacement:
#declare bar = function(a,b,c) {
a+b+c // or something more complicated
}
#declare foo = function(a,b,c) {
select(a, bar(a+1, b, c), bar(a, b, c))
}
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
|