How can I implement a function inside of a list?
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.lisp
From:
Sungwoo Lim <sung... @cad.strath.ac.uk>
Date: Tue, 24 Jul 2001 10:09:58 +0100
Local: Tues, Jul 24 2001 5:09 am
Subject: How can I implement a function inside of a list?
Hello, Suppose, I have a function TEST as below.
(defun test (i) (loop for j from 0 to (- i 1) do (print j)))
And, suppose I got a list as below.
3 > (list 'test 10) (TEST 10) 3 >
How can I get the result of the TEST function from the above list directly?
Thanks in advance,
Sungwoo
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
anapra... @yahoo.com.au (Patrick W.)
Date: 24 Jul 2001 19:59:32 +1000
Local: Tues, Jul 24 2001 5:59 am
Subject: Re: How can I implement a function inside of a list?
Sungwoo Lim <sung
... @cad.strath.ac.uk> writes:
> Hello,
> Suppose, I have a function TEST as below.
> (defun test (i) > (loop for j from 0 to (- i 1) > do (print j)))
> And, suppose I got a list as below.
> 3 > (list 'test 10) > (TEST 10) > 3 >
(apply #'funcall (list 'test 10)) Is that what you meant?
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
Kalle Olavi Niemitalo <k... @iki.fi>
Date: 24 Jul 2001 13:14:14 +0300
Local: Tues, Jul 24 2001 6:14 am
Subject: Re: How can I implement a function inside of a list?
anapra
... @yahoo.com.au (Patrick W.) writes:
> (apply #'funcall (list 'test 10))
Which one is clearer, that or (apply (car list) (cdr list)) (assuming LIST is such a list)? Your version is a little shorter, but it has kind of a double indirection. Note to OP: If the list were '(test foo), then the argument to function TEST would be the symbol FOO and not the value of the variable FOO; but you can use (list 'test foo).
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
Sungwoo Lim <sung... @cad.strath.ac.uk>
Date: Tue, 24 Jul 2001 11:22:53 +0100
Local: Tues, Jul 24 2001 6:22 am
Subject: Re: How can I implement a function inside of a list?
In article <87k80ywsu3.... @ivory.localhost>, Patrick W.
<anapra
... @yahoo.com.au> wrote:
> (apply #'funcall (list 'test 10))
> Is that what you meant?
Yes, that's kind of what I mean, however, I put the wrong example. Sorry. Actually, I am trying to implement following DEFDIAGRAM. ;------------------------- ; Line-drawing labeling ; in Paradiams of Artificial Interlligence programming, chapter 17. ; (defdiagram cube2 (a W e b c) (b L d a) (c Y a d f) (d W b g c) (e L a f) (f W g e c) (g L f d))
(defmacro defdiagram (name &rest vertex-descriptors) `(put-diagram ',name (construct-diagram (check-diagram ',vertex-descriptors)))) ;----------
I got a label list of a cube by some calculations as below,
((a Y b c d) (b W g e a) (c W e f a) (d W f g a) (e L c b) (f L d c) (g L b d))
and wanted put into the (defdiagram shape ) like the above example. But (apply #'funcall ) doesn't works for this case...
> Error: #<Compiled-function DEFDIAGRAM Macroexpander #xCDB2BD6> can't be FUNCALLed or APPLYed. > While executing: "Unknown"
Also, it seems I cannot put the list element into defdiagram directly... I tried some other experiments, and failed as ;------------------------- (setf dlist (list '(a W e b c) '(b L d a) '(c Y a d f) '(d W b g c) '(e L a f) '(f W g e c) '(g L f d))) (defdiagram cube (first dlist) (second dlist) (third dlist) (fourth dlist) (fifth dlist) (sixth dlist) (seventh dlist)) ; dumb... ;-------------------------
Any ideas to implement this macro with a provided list plz? Thanks alot,
Sungwoo
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
Erik Naggum <e... @naggum.net>
Date: Tue, 24 Jul 2001 12:01:50 GMT
Local: Tues, Jul 24 2001 8:01 am
Subject: Re: How can I implement a function inside of a list?
* Sungwoo Lim <sung... @cad.strath.ac.uk>
> I got a label list of a cube by some calculations as below,
> ((a Y b c d) (b W g e a) (c W e f a) (d W f g a) (e L c b) (f L d c) (g > L b d))
> and wanted put into the (defdiagram shape) like the above example. > But (apply #'funcall) doesn't works for this case...
This is the closest to what the Lisp environment will do if you type it in like you seem to want to do: (eval (list* 'defdiagram 'cube <list>))
You will hear a lot of whining from people who think eval is evil. Ignore them for now.
However, the macro is actually pretty well-behaved, so you can easily do
(put-diagrem 'cube (construct-diagram (check-diagram <list>)))
which should produce the desired results.
#:Erik -- There is nothing in this message that under normal circumstances should cause Barry Margolin to announce his moral superiority over others, but one never knows how he needs to behave to maintain his belief in it.
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
Sungwoo Lim <sung... @cad.strath.ac.uk>
Date: Tue, 24 Jul 2001 13:49:14 +0100
Local: Tues, Jul 24 2001 8:49 am
Subject: Re: How can I implement a function inside of a list?
In article <3204964907881... @naggum.net>, Erik Naggum <e... @naggum.net> wrote:
> This is the closest to what the Lisp environment will do if you type it
> in like you seem to want to do:
> (eval (list* 'defdiagram 'cube <list>))
> You will hear a lot of whining from people who think eval is evil. > Ignore them for now.
> However, the macro is actually pretty well-behaved, so you can easily do
> (put-diagrem 'cube (construct-diagram (check-diagram <list>)))
> which should produce the desired results.
> #:Erik
Both works very well. Thanks alot. =0) Sungwoo
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
"Coby Beck" <cb... @mercury.bc.ca>
Date: Tue, 24 Jul 2001 16:44:46 GMT
Local: Tues, Jul 24 2001 12:44 pm
Subject: Re: How can I implement a function inside of a list?
"Sungwoo Lim" <sung
... @cad.strath.ac.uk> wrote in message
news:240720011009588191%sungwoo@cad.strath.ac.uk ...
> Hello,
> Suppose, I have a function TEST as below.
> (defun test (i) > (loop for j from 0 to (- i 1) > do (print j)))
[off topic] (- i 1) ==> (1- i)
(loop for j from 0 to (1- i)) ==> (loop for j below i)
just FYI...
Coby
-- (remove #\space "coby . beck @ opentechgroup . com")
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.lisp
From:
Sungwoo Lim <sung... @cad.strath.ac.uk>
Date: Tue, 24 Jul 2001 18:45:15 +0100
Local: Tues, Jul 24 2001 1:45 pm
Subject: Thanx. =) (no content)
In article <2Ch77.54443$uo3.9715... @typhoon.tampabay.rr.com>, Coby Beck
<cb
... @mercury.bc.ca> wrote:
.
You must
Sign in before you can post messages.
You do not have the permission required to post.