Ah thanks for pointing out the problems. I had quite a hard time finding the
bug in my little "i learn jess now"-programm but your explanations make
things much clearer now!

Thanks a ton!


Ernest Friedman-Hill wrote:
> 
> 
> On Mar 26, 2007, at 3:17 PM, spielc wrote:
> 
>>
>> Hello everybody!
>>
>> Assume i have the following function:
>>
>>    (deffunction my_member (?val ?list)
>>      "implementation for member-predicate in jess"
>>      (
>>         (printout t (length$ (list ?list) ))
>>         ;(foreach ?element ?tail (printout t ?element))
>>     ))
>> I tried to call the function using Jess70p1 like this:
>>
>> 1. (my_member 3 (list 1 2 3 4))
>> Result: (my_member 3 (list 1 2 3 4))
>> Jess reported an error in routine call
>>         while executing (call (printout t (length$ (list ?list))))
>>         while executing deffunction my_member
>>         while executing (my_member 3 (list 1 2 3 4)).
>>   Message: Not enough arguments . <= Hmm okey what function did  
>> ACTUALLY
>> fail? length$, list, printout?
> 
> 
> The function definition is broken; there's an extra set of  
> parentheses around the function calls in the body. Jess interprets  
> this as one big function call. The return value of "(printout t  
> (length$ (list ?list)) crlf)" is the functor, and that "foreach" call  
> would be an argument if it weren't commented out. Jess sees that the  
> functor is a function call, so it inserts "call" as the real functor  
> (this is explained in the manual. Therefore you get the "(call  
> (printout t (length$ (list ?list))))" mentioned in the stack trace.  
> But "call" wants two arguments, at least: the object to call a method  
> on, and the name of the method. You've only supplied one argument to  
> "call" here, so "call" fails, and reports (as you can probably guess,  
> "Not enough arguments." The stack trace tells you exactly which  
> function failed and reported "not enough arguments", but because of  
> the computer-sciency name and because you didn't write it explicitly,  
> this wasn't obvious before; hope it is now.
> 
> There's another problem with the function, although not one you'd  
> notice without my pointing it out: the "list" function turns a bunch  
> of arguments into a list. Once a variable points to a list, it's a  
> list -- there's no need to call "list" again. So a proper, complete  
> definition would be
> 
> (deffunction my_member (?val ?list)
>       "implementation for member-predicate in jess"
>          (printout t (length$ ?list)))
> 
>>
>>  (my_member 3 (list 1 2 3 4))
> 
> When fixed, this is a perfectly fine way to call the function.
> 
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Advanced Software Research          Phone: (925) 294-2154
> Sandia National Labs                FAX:   (925) 294-2234
> PO Box 969, MS 9012                 [EMAIL PROTECTED]
> Livermore, CA 94550                 http://www.jessrules.com
> 
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-correctly-call-a-function-which-has-a-list-as-parameter-tf3468987.html#a9688451
Sent from the Jess mailing list archive at Nabble.com.

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to