From: Jayanth V. Rajan
Subject: fexprs
Date: 
Message-ID: <6s4143$g1p@news.microsoft.com>
How does one write a function in Common Lisp that does not evaluate its
arguments? I am trying to model an Franz Lisp fexpr.

E-mail to ········@microsoft.com.

From: Donald Fisk
Subject: Re: fexprs
Date: 
Message-ID: <35E5944D.30E18368@bt-sys.spamblock.bt.co.uk>
Jayanth V. Rajan wrote:
> How does one write a function in Common Lisp that does not evaluate its
> arguments? I am trying to model an Franz Lisp fexpr.

I'd do it using defmacro.

Example:

: (defmacro foo (x y)
    (print x)
    (print y)
    nil)
FOO
: (foo a b)

A 
B 
NIL
: 

> E-mail to ········@microsoft.com.

-- 
Le Hibou (mo bheachd fhe/in: my own opinion)
"it's just that in C++ and the like, you don't trust _anybody_,
and in CLOS you basically trust everybody.  the practical result
is that thieves and bums use C++ and nice people use CLOS."
	-- Erik Naggum
From: Tim Bradshaw
Subject: Re: fexprs
Date: 
Message-ID: <ey367fe9uu2.fsf@todday.aiai.ed.ac.uk>
* Donald Fisk wrote:
> I'd do it using defmacro.

> Example:

> : (defmacro foo (x y)
>     (print x)
>     (print y)
>     nil)

This is wrong, or at least it almost certainly is not what was
expected!  You need a macro which expands into something that quotes
its arguments:

(defmacro fibly (x)
  `(list (quote ,x) (quote ,x)))

Then (fibly y) expands to (list 'y 'y).

--tim
From: Jeff Dalton
Subject: Re: fexprs
Date: 
Message-ID: <x2ogt4hqll.fsf@gairsay.aiai.ed.ac.uk>
Re: Franz Lisp fexprs in Common Lisp.

You can't quite do what you can in Franz, because Common Lisp
uses lexical scoping by default while Franz does that only in
compiled code.  So something like the following is about
as close as you can get.  If defines a macro that calls a
function.  The function gets all of the (unevaluated) args
in a list, which is how Franz fexprs work.

(defmacro define-fexpr (name (var) &body forms)
  (let ((fn-name
	 (intern (concatenate 'string (string name) "-FUNCTION")
		 (symbol-package name))))
    `(progn
       (defun ,fn-name (,var)
	 ,@forms)
       (defmacro ,name (&rest ,var)
	 `(,',fn-name ',,var)))))


And then:

>(macroexpand-1 '(define-fexpr f (args) (print args) nil))
(progn
  (defun f-function (args) (print args) nil)
  (defmacro f (&rest args) (list 'f-function (list 'quote args))))
t

>(eval *)
f

>(f this is an example)

(this is an example) 
nil

-- jeff
From: Stig Hemmer
Subject: Re: fexprs
Date: 
Message-ID: <ekvaf4q8g0y.fsf@gnoll.pvv.ntnu.no>
"Jayanth V. Rajan" <········@microsoft.com> writes:
> How does one write a function in Common Lisp that does not evaluate its
> arguments? I am trying to model an Franz Lisp fexpr.

(defmacro)

E.g.

(defmacro quoted-list (&rest params)
   (cons 'quote (list params)))

QUOTED-LIST

(quoted-list a b c d)

(A B C D)

For more useful examples, read this news group for a while.  
Macros abound.

By the way, the above is not how I would normally have written this
macro.  I would rather have written:

(defmacro quoted-list (&rest params)
   `',params)

but I wasn't sure if you knew the backquote notation.  Learn
backquotes if you haven't already.  They are very useful, especially
in connection with macros.

Stig Hemmer.