On Mar 28, 2007, at 7:00 AM, spielc wrote:
Hello everybody!
Sorry that i'm asking so much (in you eyes probably stupid)
questions, but
i'm trying to learn jess as i need it for my diploma thesis.
No problem. Everybody is a beginner at the beginning.
(
bind ?revplan (list)
return (length$ ?revplan)
)
These three strangely formatted (for Jess) lines form the body of
your function. The formatting makes it look as though there are two
function calls here, but again, there's just one at the top level, a
call to "bind" with 4 arguments: ?revplan, (list), return, and
"(length$ ?revplan)". The first parenthesis opens a function call,
and it's not closed until the matching close parenthesis is seen,
which is the one at the end. "bind", like many Jess functions, will
simply ignore extra arguments beyond the two it expects, so
everything from "return" on has no effect. The "()" you're seeing is
the value of the "bind" function call. If a deffunction included no
"return", then the value of a call to the deffunction is the value of
the last expression evaluated, which here is "()".
A function call in a C-like language looks like F(X, Y, Z) . The
equivalent in Jess looks like (F X Y Z) . If you try to put
parentheses around the arguments, or use parentheses for grouping, or
if you omit the parentheses around a function call, or any other
variations, then you'll get either syntax errors or unexpected behavior.
I tried every
combination of brackets i could think of
Since you're a student, this is perhaps a good teaching opportunity.
A good software developer will *never* do this. Andy Hunt and Dave
Thomas call this "Programming by Coincidence." The problem with
trying everything until something works is that then you have code
which *seems* to do the right thing, but which you don't really
understand. When it comes time to change it, it might break in
unexpected ways, and you won't know what to do, since you never
understood it in the first place. Instead, take the time to
understand *why* something works, or doesn't. You've done the right
thing by coming here to ask questions!
You might want to have a look at an introductory Lisp text, just to
firm up your understanding of the basic syntax of Lisp-like languages
like Jess.
---------------------------------------------------------
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]
--------------------------------------------------------------------