NewLisp function with a variable number or arguments?

Pondering the philosophy behind the language
Locked
Sunburned Surveyor
Posts: 28
Joined: Thu Jan 13, 2005 12:42 am
Location: California
Contact:

NewLisp function with a variable number or arguments?

Post by Sunburned Surveyor »

Is it possible to have a custom function defined in newLisp that accepts a variable number of arguments?

For example, could I have the "doThis" function accept an integer named "number1" and a string named "text" or just two integers, "number1" and "number2"? How would I do this? Can you do it by just specifying all parameters in the define statement for the function, and then if the values are not used they are passed as nil?

Thanks,

The Sunburned Surveyor

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Yes,

... and you can also go the other way around: specifiying more parameters than specified in the function definition. Those then would be shown by the function (args), which will return a list of all parameters passed but not defined.

Lutz

Ps: read the manual for all of this

statik
Posts: 58
Joined: Thu Apr 14, 2005 1:12 am

Post by statik »

You are able to, like Lutz said, define a function without arguments. This, I suppose, would be usefull if you were dynamically creating functions where the number of arguments could be any amount. By using (args), you could get everything.

Code: Select all

newLISP v.8.6.0 on OSX, execute 'newlisp -h' for more info.

> (define (myfunc) (println (args)))
(lambda () (println (args)))
> (myfunc "one" "two" "three")
("one" "two" "three")
("one" "two" "three")
>
-statik

Locked