Re: possibly silly question re quoting of function arguments...
- From: Peter Seibel <peter@xxxxxxxxxxxxxxx>
- Date: Fri, 28 Apr 2006 15:00:14 GMT
"birlinn@xxxxxxxxx" <birlinn@xxxxxxxxx> writes:
Hi,
i'm writing my first lisp programme and am trying to work out how to do
this:
i have a bunch of variables that look like:
(defvar myvar-x1 nil
"1st x variable")
(defvar myvar-y1 nil
"1st y variable")
i want to be able to push and pop items onto & out of myvar-x1 etc.
i want a predicate function that tells me whether a given list is of x
or y (e.g. myvar-x1 or myvar-y1)
(defun dest-is-xvar-p (alist)
(if (eq alist myvar-x1)
't
'nil))
You can just write that:
(defun dest-is-xvar-p (alist)
(eq alist myvar-x1))
Though I subscribe to the school of thought that you should always use
EQL and never EQ. And a lisper is going to read alist as an
abbreviation for "association list" rather than "a list". But luckily
this isn't Scheme so we can use the 'list' as a variable name. So I'd
write it:
(defun dest-is-xvar-p (list)
(eql list myvar-x1))
such that:
(dest-is-xvar-p myvar-x1) ;; this doesn't work...
returns true.
What did you expect it to return. You asked, (eq myvar-x1 myvar-x1);
of course it's true.
i can't work out how to do this without quoting the argument to
dest-is-xvar-p:
(defun dest-is-xvar-p (alist)
(if (eq alist 'myvar-x1)
't
'nil))
(dest-is-xvar-p 'myvar-x1)
Doesn't this also return true? Now you're asking (eq 'myvar-x1
'myvar-x1) which is also true but for a different reason.
works, but i want to have a function which doesn't require me to
quote the argument.
can anyone suggest a simple lisp-ish way of doing this?
It's not clear what "this" is. Maybe you can step back and explain
what you're really trying to do.
-Peter
--
Peter Seibel * peter@xxxxxxxxxxxxxxx
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
.
- Follow-Ups:
- Re: possibly silly question re quoting of function arguments...
- From: birlinn@xxxxxxxxx
- Re: possibly silly question re quoting of function arguments...
- References:
- possibly silly question re quoting of function arguments...
- From: birlinn@xxxxxxxxx
- possibly silly question re quoting of function arguments...
- Prev by Date: possibly silly question re quoting of function arguments...
- Next by Date: Re: Xah's Edu Corner: Criticism vs Constructive Criticism
- Previous by thread: possibly silly question re quoting of function arguments...
- Next by thread: Re: possibly silly question re quoting of function arguments...
- Index(es):
Relevant Pages
|
|