From: fisadev on
I'm learning Lisp, and just for fun I made a macro that allows you to
write inverted Lisp.
(I'm using Common Lisp)
Maybe it has a lot of errors, these are my first steps with Lisp. It
would be very usefull to me if you point me any errors, or if you have
any suggestions.

((defun rreverse (expr)
(if (listp expr)
`(,@(if (rest expr) (rreverse (rest expr))) ,(rreverse (first
expr)))
expr))

(defmacro psil (expr)
(rreverse expr))

Now I can write:
(psil ((x print) (5 x) dotimes))

And the expansion will be:
(dotimes (x 5) (print x))

Thanks for your time!
PS: I'm reading Peter Seibel's "Practical Common Lisp".
From: Tamas K Papp on
On Wed, 23 Jun 2010 08:31:28 -0700, fisadev wrote:

> I'm learning Lisp, and just for fun I made a macro that allows you to
> write inverted Lisp.
> (I'm using Common Lisp)
> Maybe it has a lot of errors, these are my first steps with Lisp. It
> would be very usefull to me if you point me any errors, or if you have
> any suggestions.
>
> ((defun rreverse (expr)
> (if (listp expr)
> `(,@(if (rest expr) (rreverse (rest expr))) ,(rreverse (first
> expr)))
> expr))
>
> (defmacro psil (expr)
> (rreverse expr))
>
> Now I can write:
> (psil ((x print) (5 x) dotimes))
>
> And the expansion will be:
> (dotimes (x 5) (print x))

It has no errors, you gave a nice recursive solution, both for walking
the tree and reversing each list.

You could also have used CL's library functions:

(defun rreverse (form)
(if (listp form)
(nreverse (mapcar #'rreverse form))
form))

Or, since CL lacks a reverse-map combo, write one yourself:

(defun rreverse (form)
(if (listp form)
(let (result)
(dolist (element form result)
(push (rreverse element) result)))
form))

But, unless speed is a concern, I wouldn't bother.

> PS: I'm reading Peter Seibel's "Practical Common Lisp".

Good choice.

Enjoy CL,

Tamas
From: fisadev on
On Jun 23, 1:04 pm, Tamas K Papp <tkp...(a)gmail.com> wrote:
> On Wed, 23 Jun 2010 08:31:28 -0700, fisadev wrote:
> > I'm learning Lisp, and just for fun I made a macro that allows you to
> > write inverted Lisp.
> > (I'm using Common Lisp)
> > Maybe it has a lot of errors, these are my first steps with Lisp. It
> > would be very usefull to me if you point me any errors, or if you have
> > any suggestions.
>
> > ((defun rreverse (expr)
> >   (if (listp expr)
> >     `(,@(if (rest expr) (rreverse (rest expr))) ,(rreverse (first
> > expr)))
> >     expr))
>
> > (defmacro psil (expr)
> >   (rreverse expr))
>
> > Now I can write:
> > (psil ((x print) (5 x) dotimes))
>
> > And the expansion will be:
> > (dotimes (x 5) (print x))
>
> It has no errors, you gave a nice recursive solution, both for walking
> the tree and reversing each list.
>
> You could also have used CL's library functions:
>
> (defun rreverse (form)
>   (if (listp form)
>       (nreverse (mapcar #'rreverse form))
>       form))
>
> Or, since CL lacks a reverse-map combo, write one yourself:
>
> (defun rreverse (form)
>   (if (listp form)
>       (let (result)
>         (dolist (element form result)
>           (push (rreverse element) result)))
>       form))
>
> But, unless speed is a concern, I wouldn't bother.
>
> > PS: I'm reading Peter Seibel's "Practical Common Lisp".
>
> Good choice.
>
> Enjoy CL,
>
> Tamas

Thanks!