help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How the backquote and the comma really work?


From: Michael Heerdegen
Subject: Re: How the backquote and the comma really work?
Date: Sun, 12 Jul 2015 17:54:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Hi Marcin,

sorry for the late reply.

> So here's my humble attempt at the reader itself.  It does nothing
> with ticks, backticks and commas -- AFAIUC, it shouldn't be done at
> this level anyway -- it just translates them to special forms (quote
> ...), (quasi-quote ...)  and (unquote ...).

Yes, that's the right approach.  You could of course translate into the
symbols named "'", "`" and "," instead, like the Lisp reader does, but
that's a detail.  In Elisp, these aren't special forms.  They could be
in your interpreter, of course.

> Do I get it correctly that it's the eval function which should handle
> these?

In Elisp, it's not directly handled by eval, since handling the
backquote mechanism is not hardcoded.  Instead, backquote is
a macro written in Lisp.

Dunno if your interpreter will support macros.  If not, you could handle
backquote directly in your interpreter.

> (require 'anaphora)                   ; we'll use acase

It would be good if you could drop this dependence.  This would spare
people from trying your code from installing additional stuff.

> (defun mci/next-token () ...

> (defun mci/read () ...

> (defun mci/read-list-contents () ...

That looks already very promising!

I never tried to write a Lisp reader in Elisp, but the general approach
seems to be appropriate (others might be able to give more and better
comments -- Drew, Stefan, Lars, ... - anyone?).

There is a problem though when the read expression is nested.  I tried
to `mci/read' this string for example:

  "(defun fac (x) (if (< 2 x) 1 (* x (fac (1- x)))))"

and got

  (defun fac :open-paren x)

as result.  If you Edebug your functions, you can see what goes wrong.
Please tell me if you need more hints...

I guess you already know that you have not chosen the easiest way to
understand backquote.  Anyway, you learn a lot of stuff with your
approach.  Looking forward the next version!


Regards,

Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]