Excuse me, could anyone explain to me the following two line of codes?
(let ((New-sol (append solution (car Rest)))))
is this statement meaning that New-sol = solution + (car Rest) ?
(cond
((and (OK (transpose-word New-sol))
(equal level word-length)
(print New-sol)))
does it mean that if both statements (OK(transpose-word New-sol) and
(equal level world-length are true, then do (print New-sol)? and what
is keyword "and" doing here?? please help me out, thanks in advance!!
Mike Chu <······@hotmail.com> writes:
> Excuse me, could anyone explain to me the following two line of codes?
> (let ((New-sol (append solution (car Rest)))))
> is this statement meaning that New-sol = solution + (car Rest) ?
(car rest) will get you the first element of rest.
(append solution (car rest)) is suspicious. Without seeing your
program it's hard to know for sure, but my bet is that you are missing
a call to LIST here. Append takes two lists, not a list and an element.
(append '(a b c) '(d e f)) => (a b c d e f)
If x contains (d e f), then
(append '(a b c) (car x))
will signal an error. But doing
(append '(a b c) (list (car x)))
should fix it, returning (a b c d).
> (cond
> ((and (OK (transpose-word New-sol))
> (equal level word-length)
> (print New-sol)))
> does it mean that if both statements (OK(transpose-word New-sol) and
> (equal level world-length are true, then do (print New-sol)? and what
> is keyword "and" doing here?? please help me out, thanks in advance!!
You have parens misbalanced (and there's one missing). It looks like OK
is a function, so (OK (transpose-word New-sol)) is probably an attempt
to transpose something and then to check the result using some function
called OK. The AND should have parens around the various things
being anded. Probably you should have
(cond ((and (OK (transpose-word New-sol))
(equal level word-length))
(print New-sol)))
This would make the AND take two tests and then print be what happens
on success.
It's conventional, by the way, to indent this as I've done, showing
the arguments to AND vertically arranged underneath one another
so that you don't have to count parens.
Mike Chu <······@hotmail.com> writes:
> Excuse me, could anyone explain to me the following two line of codes?
> (let ((New-sol (append solution (car Rest)))))
> is this statement meaning that New-sol = solution + (car Rest) ?
More or less. It means that between
(let ((New-sol (append solution (car Rest))))
and
)
the variable has that value. (Provided you take "+" to mean "append"!)
> (cond
> ((and (OK (transpose-word New-sol))
> (equal level word-length)
> (print New-sol)))
> does it mean that if both statements (OK(transpose-word New-sol) and
> (equal level world-length) are true, then do (print New-sol)?
It would mean that if the parentheses were placed correctly,
which they aren't. :-)
> and what
> is keyword "and" doing here?? please help me out, thanks in advance!!
It means "and". As in "both", in your paraphrase above.
--
Gareth McCaughan Dept. of Pure Mathematics & Mathematical Statistics,
·····@dpmms.cam.ac.uk Cambridge University, England.