[Openmcl-devel] function self reference

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Wed Apr 22 04:55:09 PDT 2015


Hi

Thank you for your rapid reply

I am defining a library of primitives for a lazy language (with evaluation
under lambda)

I am using the following code to define a primitive with 2 number operands:

(defmacro defop2 (op)

  `(setf (gethash ',op *prim*)

         (labels ((f (closure)

                    (if (null closure)

                        (function f)

                        (let ((r1 (ev (car closure) (cdr closure) nil)))

                          (labels ((g (closure)

                                     (if (null closure)

                                         (function g)

                                         (let ((r2 (ev (car closure) (cdr
closure) nil)))

                                           (if (and (numberp r1) (numberp
r2))

                                               (,op r1 r2)

                                               `((,',op ,r1) ,r2))))))

                            (function g)

                            )))))

           (function f))))

I was thinking that maybe there is a better way without using LABELS


Kind regards

Taoufik

On Wed, Apr 22, 2015 at 1:15 PM, Stas Boukarev <stassats at gmail.com> wrote:

> Taoufik Dachraoui <dachraoui.taoufik at gmail.com> writes:
>
> > Hi
> >
> > is it possible to reference a function inside its body
> >
> > I would like to have something equivalent to the following without using
> > eval:
> >
> > *(funcall (funcall (funcall #1=(lambda (n) (if (= n 0) (eval '#1#)
> > #2=(lambda (m) (if (= m 0) (eval '#2#) (+ n m))))) 0) 3) 5)*
> >
> LABELS
>
> --
> With best regards, Stas.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20150422/f3da6da0/attachment.htm>


More information about the Openmcl-devel mailing list