Hi again,
the following function
(defun left (state)
(let ((pos (element-index state '0))))
(cond
((equal '0 pos) nil)
((equal '3 pos) nil)
((equal '6 pos) nil)
(t swap state (- pos 1) pos)
)
)
produces the error message mentioned in the subject.
The function element-index itself works fine.
Can anyone give me a hint?
Thanks a lot,
Christian
P.S. Every other comment is highly appreciated, too. I'm just giving
myself a Lisp crash course...
Christian Soltenborn wrote:
> Hi again,
>
> the following function
>
> (defun left (state)
> (let ((pos (element-index state '0)))) ;; extra paren?
> (cond
> ((equal '0 pos) nil)
> ((equal '3 pos) nil)
> ((equal '6 pos) nil)
> (t swap state (- pos 1) pos) ;; this line looks funky
> )
> )
>
> produces the error message mentioned in the subject.
>
> The function element-index itself works fine.
>
> Can anyone give me a hint?
>
> Thanks a lot,
> Christian
>
> P.S. Every other comment is highly appreciated, too. I'm just giving
> myself a Lisp crash course...
Your parentheses are off.
Suggestion: if you don't already have one, get an editor that is (or can
be made to be) Lisp-aware.
[Hint: the bindings in a `let' form only exist within the `let' form.]
[Hint 2: As, by your indentation style, you're from the C* world, your
problem is roughly analogous to (we'll assume C++ for the moment):
for (int i = 0; i < n; i++);
{
// whatever code goes here, involving `i'
}]
HTH,
--ag
--
Artie Gold -- Austin, Texas
"Yeah. It's an urban legend. But it's a *great* urban legend!"
Artie Gold <·········@austin.rr.com> writes:
> [Hint 2: As, by your indentation style, you're from the C* world, your
> problem is roughly analogous to (we'll assume C++ for the moment):
> for (int i = 0; i < n; i++);
For the record, this code is valid in C99.
gcc -std=gnu99
--
jan
jan wrote:
> Artie Gold <·········@austin.rr.com> writes:
>
>
>>[Hint 2: As, by your indentation style, you're from the C* world, your
>>problem is roughly analogous to (we'll assume C++ for the moment):
>> for (int i = 0; i < n; i++);
>
>
> For the record, this code is valid in C99.
...and, of course, equally useless!! ;-)
>
> gcc -std=gnu99
>
Cheers,
--ag
--
Artie Gold -- Austin, Texas
"Yeah. It's an urban legend. But it's a *great* urban legend!"
From: Joe Marshall
Subject: Re: Hint for "EVAL: variable pos has no value"
Date:
Message-ID: <y8r86hdi.fsf@comcast.net>
Christian Soltenborn <···················@webmail.de> writes:
> Hi again,
>
> the following function
>
> (defun left (state)
> (let ((pos (element-index state '0))))
> (cond
> ((equal '0 pos) nil)
> ((equal '3 pos) nil)
> ((equal '6 pos) nil)
> (t swap state (- pos 1) pos)
> )
> )
>
> produces the error message mentioned in the subject.
>
> The function element-index itself works fine.
>
> Can anyone give me a hint?
Scope. The COND isn't `in' the LET.
Compare it to this:
> (defun left (state)
> (let ((pos (element-index state 0)))
> (cond ((= pos 0) nil)
> ((= pos 3) nil)
> ((= pos 6) nil)
> (t (swap state (- pos 1) pos)))))
--
~jrm