I want to a skill function that can return multiple values.
Could anybody please tell how it can be done.
Looks like you might be used to Perl, but one way to do this in SKILL is to return a list of values, but you would have to assign them to variables outside of the function call in a more manual way. Here's a brief outline:
procedure(skillfunction(x y z)
let( (ret1 ret2)
;; do some function on these parameters
ret1 = x + 2*y
ret2 = y - z
;; this next line is the return value of the function
retlist = skillfunction(10 20 5)
a = car(retlist)
b = cadr(retlist)
Something like that. Function arguments are separated by whitespace. If you have more than a couple of variables then you might consider a more general approach, for example using a table structure for storage in named slots.
Hopefully this is helpful to you.
Returning multiple values as a list is a clean way to do this, but you can also use the destructuringBind function (new in IC615) to destructure the list contents and assign to variables (local to the scope of the destructuringBind function). This example uses the function that Lawrence wrote above to illustrate this:
destructuringBind((a b) skillfunction(10 20 5) printf("a=%L b=%L\n" a b))
You can use this with other interesting list structures - for example, imagine that you have an instance id from the database - you can do:
area=destructuringBind(((llx lly) (urx ury)) instId~>bBox ; compute the area of the bBox (urx-llx)*(ury-lly))
Cool, eh? (OK, so I'm easily impressed)
Thanks for the sharing.
Dear Lawrence & Andrew,
Thanks a lot.
Andrew: It is really nice. But is this feature available in IC5141.
In IC5141 you could use the following for the simple (non-nested list) case:
(defmacro CCFsimpleMultiAssign (listOfVars listValue @rest body) `(apply (lambda ,listOfVars ,@body) ,listValue) )
and then use CCFsimpleMultiAssign instead of destructuringBind in my first example. This won't work for the second bBox example - it would need a more complex macro (I threw the above together pretty quickly).