[kepler-dev] Fun with the Ptolemy II expression language
Tobin Fricke
tobin at splorg.org
Tue Aug 3 17:35:47 PDT 2004
The PtII expression language doesn't have 'currying':
>> adder = function(x,y) x+y
(function(x, y) (x+y))
>> adder(1)
Wrong number of arguments when applying function (function(x, y) (x+y))
But you can simulate it with functions that return functions:
>> adder = function(x) function(y) x+y
(function(x) (function(y) (x+y)))
>> adder(1)
(function(y) (1+y))
>> adder(1)(2)
3
Some methods supported by FunctionTokens:
>> adder = function(x,y) x+y
(function(x, y) (x+y))
>> adder.getNumberOfArguments
2
>> adder.apply({10,2})
12
>> adder.getType
object((function(a0:general, a1:general) general))
We can define our own 'apply' function:
>> apply = function(f:(function() general),args:{general}) f.apply(args)
(function(f:(function() general), args:{general}) f.apply(args))
>> adder
(function(x, y) (x+y))
>> apply(adder,{1,2})
3
Tobin
More information about the Kepler-dev
mailing list