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
SYSTEM::%EXPAND-FOR:element should be a lambda expression
-
- Posts: 447
- Joined: Sat Jun 28, 2008 7:49 am
- Location: Austin, TX
- Contact:
Re: SYSTEM::%EXPAND-FOR:element should be a lambda expression
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:
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:
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:
In Lisp, you write:
Thus, I think you want:
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:
BTW, you should really use idiomatic indentation and paren placement. While
might be good C style, it's horrible Lisp style. Please place all closing parentheses on the same line as the last form.
Code: Select all
(list (1.0 0 0))
Code: Select all
(list 1.0 0 0)
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);
Code: Select all
(list 1.0 0 0)
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)))
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)))
Code: Select all
int foo(int bar)
{
while (1) {
do_something();
}
}
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Re: SYSTEM::%EXPAND-FOR:element should be a lambda expression
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
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
-
- Posts: 447
- Joined: Sat Jun 28, 2008 7:49 am
- Location: Austin, TX
- Contact:
Re: SYSTEM::%EXPAND-FOR:element should be a lambda expression
No problem. I went through the same sorts of issues when I first learned Lisp, coming from a C/C++/Java background.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/