Page 1 of 1

SYSTEM::%EXPAND-FOR:element should be a lambda expression

Posted: Wed Jul 01, 2009 9:28 am
by andy25
Hello everyone,
I am a new user and very new to Lisp. I would appreciate it if anyone could help me with this.

I have the following code:
"
(defun add-forec ( nexperts rand )

(list (
(make-ex (list (1.0 0 0)))
(make-ex (list (0 1.0 0)))
(make-ex (list (0 0 1.0)))
)))


(defun make-ex ( dist )
(make-instance 'lw-expert :weights dist) )"

as part as a larger piece of code (the rest works perfectly).
When i run it it gives me the following error:

SYSTEM::%EXPAND-FORM: (MAKE-EX (LIST ('1.0 '0 '0))) should be a lambda
expression


With the (little) lisp knowledge i have i know that lamdba expressions are ways of defining functions and recursion. They are passed as arguments and returned as results.

I have already tried treating the numbers as literals using ': (e.g.list ('1.0 '0 '0))

Could anyone tell me if i understood lambda expressions and maybe suggest what the problem may be??
Thank you very much,
Andy

Re: SYSTEM::%EXPAND-FOR:element should be a lambda expression

Posted: Wed Jul 01, 2009 3:58 pm
by findinglisp
Your problem is that you're calling LIST wrong. In several places, you are placing the arguments to LIST inside parentheses. For instance, you say:

Code: Select all

(list (1.0 0 0))
at a few places. When the system reaches "(1.0 0 0)" it thinks that's a function call. It's barfing because the thing after the parenthesis is not a function (1.0 isn't a function, it's a number). Instead, it should be:

Code: Select all

(list 1.0 0 0)
which will then return the list (1.0 0 0). (BTW, that's a float followed by two integers, if you care.)

Basically, it looks like you're a C programmer having trouble with the conversion to Lisp syntax. In C, you'd write:

Code: Select all

list(1.0, 0, 0);
In Lisp, you write:

Code: Select all

(list 1.0 0 0)
Thus, I think you want:

Code: Select all

(defun add-forec (nexperts rand)
    (list (make-ex (list 1.0 0 0))
          (make-ex (list 0 1.0 0))
          (make-ex (list 0 0 1.0)))
Also, realize that if your list just contains literals, there is really no point in calling LIST at all. You could do this more simply with a literal list using quote:

Code: Select all

(defun add-forec (nexperts rand)
    (list (make-ex '(1.0 0 0))
          (make-ex '(0 1.0 0))
          (make-ex '(0 0 1.0)))
BTW, you should really use idiomatic indentation and paren placement. While

Code: Select all

int foo(int bar)
{
    while (1) {
        do_something();
    }
}
might be good C style, it's horrible Lisp style. Please place all closing parentheses on the same line as the last form.

Re: SYSTEM::%EXPAND-FOR:element should be a lambda expression

Posted: Thu Jul 02, 2009 5:40 am
by andy25
To begin with, thank you very much for your help! it solved my problem.
You are very right, i am a c and java programmer and im having my first contact with LISP. I will try to follow your advice

Re: SYSTEM::%EXPAND-FOR:element should be a lambda expression

Posted: Thu Jul 02, 2009 8:21 am
by findinglisp
No problem. I went through the same sorts of issues when I first learned Lisp, coming from a C/C++/Java background. ;)