| | |
Lisp help - is this function right?
![]() |
•
•
Join Date: May 2005
Posts: 18
Reputation:
Solved Threads: 0
Hello,
the listp function doesn't apply the full "list" rules.
Example
(cons 1 ( cons 2 3 ))
Isn't a list as the definition goes:
* either an empty list (nil)
* or a cons cell that has a list for a cdr
altough listp yelds true to that "list"
So I'm writing a function that will do the full thing
This is correct for the following examples
(cons 1 ( cons 2 ( cons 3 ( cons 4 5 ))))
returns nil
(cons 1 (cons 2 3))
returns nul
(cons 1 ( cons 2 ( cons 3 ( cons 4 nil ))))
returns t
(1 2)
returns t
It seams ok. Is it?
Thamls.
the listp function doesn't apply the full "list" rules.
Example
(cons 1 ( cons 2 3 ))
Isn't a list as the definition goes:
* either an empty list (nil)
* or a cons cell that has a list for a cdr
altough listp yelds true to that "list"
So I'm writing a function that will do the full thing
(defun isList (list)
(if (null list)
t
(if (not (consp list ))
nil
(and t (isList (cdr list))))))This is correct for the following examples
(cons 1 ( cons 2 ( cons 3 ( cons 4 5 ))))
returns nil
(cons 1 (cons 2 3))
returns nul
(cons 1 ( cons 2 ( cons 3 ( cons 4 nil ))))
returns t
(1 2)
returns t
It seams ok. Is it?
Thamls.
It looks like a fine implementation of the behavior of the Scheme function, LIST?. I don't know why you'd use
However, Common Lisp (I'll assume that's the variant you're using, since you didn't specify) has a different meaning for listp.
(and t (isList (cdr list))) when that means the same thing as (isList (cdr list)).However, Common Lisp (I'll assume that's the variant you're using, since you didn't specify) has a different meaning for listp.
•
•
•
•
Originally Posted by Common Lisp the Language, 2nd Edition
listp object
listp is true if its argument is a cons or the empty list (), and otherwise is false. It does not check for whether the list is a ``true list'' (one terminated by nil) or a ``dotted list'' (one terminated by a non-null atom).
All my posts may be redistributed under the GNU Free Documentation License.
![]() |
Similar Threads
- Lisp load function in windows (Computer Science)
- Lisp Load Function (Computer Science)
- Object Oriented Programming (Computer Science)
- Lisp Programming defparameter (Computer Science)
- Lisp lambda problem (Legacy and Other Languages)
- LISP:i changed the load function accidently...HELP (Computer Science)
- Anyone know pure LISP? (Legacy and Other Languages)
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: First time using awk, I have a couple questions
- Next Thread: Ruby Language
| Thread Tools | Search this Thread |






