From: Sungwoo Lim
Subject: How can I implement a function inside of a list?
Date: 
Message-ID: <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)))

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

From: Coby Beck
Subject: Re: How can I implement a function inside of a list?
Date: 
Message-ID: <2Ch77.54443$uo3.9715430@typhoon.tampabay.rr.com>
"Sungwoo Lim" <·······@cad.strath.ac.uk> wrote in message
·······························@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")
From: Sungwoo Lim
Subject: Thanx. =) (no content)
Date: 
Message-ID: <240720011845159083%sungwoo@cad.strath.ac.uk>
In article <·······················@typhoon.tampabay.rr.com>, Coby Beck
<·····@mercury.bc.ca> wrote:

.
From: Patrick W.
Subject: Re: How can I implement a function inside of a list?
Date: 
Message-ID: <87k80ywsu3.fsf@ivory.localhost>
Sungwoo Lim <·······@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?
From: Sungwoo Lim
Subject: Re: How can I implement a function inside of a list?
Date: 
Message-ID: <240720011122531720%sungwoo@cad.strath.ac.uk>
In article <··············@ivory.localhost>, Patrick W.
<·········@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
From: Erik Naggum
Subject: Re: How can I implement a function inside of a list?
Date: 
Message-ID: <3204964907881721@naggum.net>
* Sungwoo Lim <·······@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.
From: Sungwoo Lim
Subject: Re: How can I implement a function inside of a list?
Date: 
Message-ID: <240720011349140610%sungwoo@cad.strath.ac.uk>
In article <················@naggum.net>, Erik Naggum <····@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
From: Kalle Olavi Niemitalo
Subject: Re: How can I implement a function inside of a list?
Date: 
Message-ID: <iznae1uzlah.fsf@stekt34.oulu.fi>
·········@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).