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.
In reply to skillUser:
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)
In reply to Andrew Beckett:
Thanks for the sharing.
Dear Lawrence & Andrew,
Thanks a lot.
Andrew: It is really nice. But is this feature available in IC5141.
In reply to RFStuff:
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).
destructuringBind is wicked magic that should be studied in IC615. It is very useful, especially since you can return keyed values, optional values and @rest values.
Before IC615, you could return the values as a disembodied property list (DPL). It is a list of key value pairs that begins with a nil:
list( nil key1 "value1" key2 2.0 key3 list( "Value" "number" 3 ) )
myDPL = callingMyFunction(....)
myDPL->key1 => "value1"
myDPL->key2 => 2.0
myDPL->key3 => list("Value" "number" 3)
In reply to theopaone:
You know you are in trouble if you dream in SKILL.
In my last post, I made an error and realized it last night. The key values in a DPL must be symbols. In the example, they are variables and the code may fail but will definately not work the way it was written. The DPL should be written as:
list( nil 'key1 "value1" 'key2 2.0 'key3 list( "Value" "number" 3 ) )
The keys must be quoted to be symbols.