From: Joe Corneli
Subject: access argument list from within function?
Date: 
Message-ID: <21bcb4c2.0405051902.24b08925@posting.google.com>
Is there a LISP equivalent to Bash's ··@'?

I would like to include something like (mapcar (lambda...) arglist) in
my function.  But it turns out that, at least in CLISP, `arglist' is a
function that is supposed to be called with some function as its
argument.

I tried

(defun taco (a)
  (arglist 'taco))

but then (taco t) evaluates to (#:ARG0) -- whereas I would have liked
to see (t).

From: Matthew Danish
Subject: Re: access argument list from within function?
Date: 
Message-ID: <20040506032719.GI25328@mapcar.org>
On Wed, May 05, 2004 at 08:02:14PM -0700, Joe Corneli wrote:
> Is there a LISP equivalent to Bash's ··@'?
> 
> I would like to include something like (mapcar (lambda...) arglist) in
> my function.  But it turns out that, at least in CLISP, `arglist' is a
> function that is supposed to be called with some function as its
> argument.
> 
> I tried
> 
> (defun taco (a)
>   (arglist 'taco))
> 
> but then (taco t) evaluates to (#:ARG0) -- whereas I would have liked
> to see (t).

Hmm, well that's an interesting function in CLISP.  But I disgress.
What you want is very simple to do in any Common Lisp:

(defun taco (&rest fillings)
  (mapc #'(lambda (filling)   ;; MAPC is used purely for side-effects here
            (write-line filling))
        fillings))

or maybe even

(defun taco (&rest fillings)
  (format t "Your taco has ~{~A~^, ~} in it.~%" fillings))

[3]> (taco "beef" "cheese" "salsa")
Your taco has beef, cheese, salsa in it.

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Tim Bradshaw
Subject: Re: access argument list from within function?
Date: 
Message-ID: <ey3llk63syy.fsf@cley.com>
* Joe Corneli wrote:
> Is there a LISP equivalent to Bash's ··@'?

&REST, I think.  You can fairly easily get both the whole arglist and
specific arguments by something like:

(defmacro ·······@ (fn arglist &body code)
  ;; Explicitly binds ·@ to the whole arglist
  `(defun ,fn (&rest ·@)
     (apply (lambda ,arglist ,@code) ·@)))

(·······@ foo (&key (x 1))
  (print x)
  (print ·@))

--tim
From: Marco Antoniotti
Subject: Re: access argument list from within function?
Date: 
Message-ID: <QKrmc.153$a5.43111@typhoon.nyu.edu>
Joe Corneli wrote:

> Is there a LISP equivalent to Bash's ··@'?
> 
> I would like to include something like (mapcar (lambda...) arglist) in
> my function.  But it turns out that, at least in CLISP, `arglist' is a
> function that is supposed to be called with some function as its
> argument.
> 
> I tried
> 
> (defun taco (a)
>   (arglist 'taco))
> 
> but then (taco t) evaluates to (#:ARG0) -- whereas I would have liked
> to see (t).


Nope.  There isn't anything in the standard that does that.  Your 
implementation may have something implementation dependent.

You could use &rest arguments to do what you want.  That is not general, 
but it may suite your needs

	(defun foo (&rest arglist)
	   (mapcar (lambda (a) ...) arglist))

Cheers
--
Marco
From: Frode Vatvedt Fjeld
Subject: Re: access argument list from within function?
Date: 
Message-ID: <2hr7tx3a81.fsf@vserver.cs.uit.no>
········@math.utexas.edu (Joe Corneli) writes:

> Is there a LISP equivalent to Bash's ··@'?

Yes, there is the &rest lambda-list keyword.

  (defun taco (&rest ·@)
    (warn "Taco with ~S" ·@))

If you for some reason want an automagic variable, say ·@, you can
write your own defun, like so:

  (defmacro defbashfun (name lambda &body body)
    `(defun ,name (&rest ·@)
       (apply (lambda ,lambda ,@body) ·@)))

and you'll be able to say

  (defbashfun taco (x y)
    (warn "taco with ~$" ·@)
    (+ x y))

-- 
Frode Vatvedt Fjeld
From: Marco Antoniotti
Subject: Re: access argument list from within function?
Date: 
Message-ID: <Yzumc.155$a5.46325@typhoon.nyu.edu>
Frode Vatvedt Fjeld wrote:
> ········@math.utexas.edu (Joe Corneli) writes:
> 
> 
>>Is there a LISP equivalent to Bash's ··@'?
> 
> 
> Yes, there is the &rest lambda-list keyword.
> 
>   (defun taco (&rest ·@)
>     (warn "Taco with ~S" ·@))
> 
> If you for some reason want an automagic variable, say ·@, you can
> write your own defun, like so:
> 
>   (defmacro defbashfun (name lambda &body body)
>     `(defun ,name (&rest ·@)
>        (apply (lambda ,lambda ,@body) ·@)))
> 
> and you'll be able to say
> 
>   (defbashfun taco (x y)
>     (warn "taco with ~$" ·@)
>     (+ x y))
> 

Yes, but....

	(defbashfun taco (x &optional foo &rest bar &key (baz 42))
	   (warn "taco with ~S." ·@)
	   ...)

will most likely barf.

The following may work

(defmacro defbashfun (name lambda-list &body body)
   (let ((fn (gentemp "BASHFUN-")))
     `(progn
        (setf (symbol-function ',name)
              (lambda (&rest ·@)
                (flet ((,fn ,lambda-list ,@body))
                  (apply #',fn ·@))))
        ',name)))


Cheers
--
Marco
From: Peter Seibel
Subject: Re: access argument list from within function?
Date: 
Message-ID: <m37jvjzyld.fsf@javamonkey.com>
Marco Antoniotti <·······@cs.nyu.edu> writes:

> Frode Vatvedt Fjeld wrote:
>> ········@math.utexas.edu (Joe Corneli) writes:
>>
>>>Is there a LISP equivalent to Bash's ··@'?
>> Yes, there is the &rest lambda-list keyword.
>>   (defun taco (&rest ·@)
>>     (warn "Taco with ~S" ·@))
>> If you for some reason want an automagic variable, say ·@, you can
>> write your own defun, like so:
>>   (defmacro defbashfun (name lambda &body body)
>>     `(defun ,name (&rest ·@)
>>        (apply (lambda ,lambda ,@body) ·@)))
>> and you'll be able to say
>>   (defbashfun taco (x y)
>>     (warn "taco with ~$" ·@)
>>     (+ x y))
>>
>
> Yes, but....
>
> 	(defbashfun taco (x &optional foo &rest bar &key (baz 42))
> 	   (warn "taco with ~S." ·@)
> 	   ...)
>
> will most likely barf.
>
> The following may work
>
> (defmacro defbashfun (name lambda-list &body body)
>    (let ((fn (gentemp "BASHFUN-")))
>      `(progn
>         (setf (symbol-function ',name)
>               (lambda (&rest ·@)
>                 (flet ((,fn ,lambda-list ,@body))
>                   (apply #',fn ·@))))
>         ',name)))


How about:

  (defmacro defbashfun (name lambda-list &body body)
    `(defun ,name (&rest ·@)
       (destructuring-bind ,lambda-list ·@
         ,@body)))


-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp