May i know is there are way to create function at the fly. Meanings that create a control loop flow script to create unique function name.
Example as below (But this doesn't works)
foreach( ele list( list("funcA" funcB") list("funC" "funcD"))
newFunctionName = stringToSymbol(strcat( car(ele) cadr(ele) ))
(defun newFunctionName args
(printf "Hello World - %L\n" args))
My intention is to create a function at the fly.Any idea? Is this possible?
foreach( ele list( list("funcA" "funcB") list("funC" "funcD")) newFunctionName = stringToSymbol(strcat( car(ele) cadr(ele) )) putd(newFunctionName lambda((args) printf("Hello World - %L\n" args) ) ))
Hello World - "test"
However, I would say that creating functions on the fly is something that is even more powerful in SKILL++ mode, because that supports the concept of "closures". For example (either type toplevel('ils) and then type this in the CIW, or put in a file with a ".ils" suffix):
defun(CCFmakeCounter (@key (init 0) (step 1)) lambda(() init=init+step))
c1=CCFmakeCounter()c2=CCFmakeCounter(?init 4 ?step 3)
c1() => 1c1() => 2c2() => 7c2() => 10c1() => 3
This concept is covered in more detail in the SKILL documentation. The idea is that CCFmakeCounter() is returning a function object with the specific environment containing the arguments that were passed in (it's the same function object, but the environment changes in essence). In SKILL++ mode functions are variables, so you can much more easily pass around function objects without needing to use funcall or apply to call them.
Thanks Adrew for the solution and great sharing. I should start learning SKILL++ now.