Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I implement a function inside of a list?

4 views
Skip to first unread message

Sungwoo Lim

unread,
Jul 24, 2001, 5:09:58 AM7/24/01
to
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

Patrick W.

unread,
Jul 24, 2001, 5:59:32 AM7/24/01
to
Sungwoo Lim <sun...@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?

Kalle Olavi Niemitalo

unread,
Jul 24, 2001, 6:14:14 AM7/24/01
to
anap...@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).

Sungwoo Lim

unread,
Jul 24, 2001, 6:22:53 AM7/24/01
to
In article <87k80yw...@ivory.localhost>, Patrick W.

<anap...@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

Erik Naggum

unread,
Jul 24, 2001, 8:01:50 AM7/24/01
to
* Sungwoo Lim <sun...@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.

Sungwoo Lim

unread,
Jul 24, 2001, 8:49:14 AM7/24/01
to
In article <32049649...@naggum.net>, Erik Naggum <er...@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

Coby Beck

unread,
Jul 24, 2001, 12:44:46 PM7/24/01
to

"Sungwoo Lim" <sun...@cad.strath.ac.uk> wrote in message
news:240720011009588191%sun...@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")


Sungwoo Lim

unread,
Jul 24, 2001, 1:45:15 PM7/24/01
to
In article <2Ch77.54443$uo3.9...@typhoon.tampabay.rr.com>, Coby Beck
<cb...@mercury.bc.ca> wrote:

.

0 new messages