[Openmcl-devel] macros

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Sun May 24 10:49:34 PDT 2015


Hi

In the pattern matcher I wrote I tried to add a setter for the defined
variables in the pattern; after a lot of work I've got the following
implementation (close to it):

(let ((acc-x) (prev-x) (x 5))

  (flet (((setf foox) (value x) (funcall x value)))

    (macrolet ((it (x)

                 (let ((xacc (intern (format nil "ACC-~A" (symbol-name x))))

                       (xprev (intern (format nil "PREV-~A" (symbol-name
x)))))

                   `(foox (cond

                           ((null ,xacc) (lambda (v) (setf ,x v)))

                           ((eq ,xacc 'car) (lambda (v) (setf (car ,xprev)
v)))

                           (t (lambda (v) (setf (cdr ,xprev) v))))))))

      (setf (it x) 3) x)))

PS: I cannot use (setf x y) instead of (setf (it x) y) because the
variables x, y are defined within the match macro: (let ((x) (y)) ...)

I spent a lot of time figuring out this solution, but I am wondering if
there is a better implementation.

Example of usage:

*? (let ((a '(1 (2 3)))) (match a ((1 (?x ?y)) (setf (it x) y) a)))*

(1 (3 3))

Kind regards

Taoufik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20150524/75dab52b/attachment.htm>


More information about the Openmcl-devel mailing list