From: Marcin Borkowski <mbork@mbork.pl>
To: help-gnu-emacs@gnu.org
Subject: Re: How the backquote and the comma really work?
Date: Sun, 12 Jul 2015 21:55:54 +0200 [thread overview]
Message-ID: <87mvz1b16h.fsf@mbork.pl> (raw)
In-Reply-To: <87zj318j7z.fsf@web.de>
On 2015-07-12, at 17:54, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Hi Marcin,
>
> sorry for the late reply.
It's fine, I'm working slowly on this anyway.
>> 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.
And they will be;-).
>> 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.
I see. I’ll try to study its code.
> Dunno if your interpreter will support macros. If not, you could handle
> backquote directly in your interpreter.
No, I don't want to support macros – too much work and little benefit,
I guess. Maybe some day. So all the \(quasi-\)?quoting will be handled
by eval, as special forms (as I said above).
>> (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.
Well, aif is also useful for me. Maybe I’ll add their definitions
directly, or drop them altogether. I’ll see. I’m rather not going to
publish this code on Melpa or anything like that; it’ll quite probably
appear on my blog, however. And if someone wants to dive deep enough in
Elisp to study an MCI, I guess installing one package is not too high
a hurdle.
>> (defun mci/next-token () ...
>
>> (defun mci/read () ...
>
>> (defun mci/read-list-contents () ...
>
> That looks already very promising!
Thanks! I already have a rudimentary mci/eval (not supporting variable
binding yet, however – I’m working on lexical binding, and hopefully
I’ll get closures then almost for free when implementing lambdas), and
mci/apply will come next. (One of the nice things when writing a Lisp
MCI is that you can use the standard eval or apply before you write your
own, and everything can work even before it’s finished;-).)
> 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...
Good catch, thanks. No need for edebug, I guess – I haven’t looked at
my code, but I guess I know the problem already. Stupid me.
> 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!
Not the easiest, but more thorough. I’m not satisfied with the “I kind
of understand this... I guess” situation – if I can’t implement it,
I don’t understand it. (Unfortunately, the converse need not be true;
I might be lucky and implement it without a full understanding, too...)
And I’m really determined to understand this stuff well enough to be
able to teach it to others.
> Regards,
>
> Michael.
Thanks for kind words. Stay tuned!
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
next prev parent reply other threads:[~2015-07-12 19:55 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-25 17:09 How the backquote and the comma really work? Marcin Borkowski
2015-06-25 17:33 ` Michael Heerdegen
2015-06-25 18:06 ` Marcin Borkowski
2015-06-25 18:22 ` Michael Heerdegen
2015-06-25 18:39 ` Marcin Borkowski
2015-06-25 18:44 ` Marcin Borkowski
2015-06-25 19:06 ` Michael Heerdegen
2015-07-10 11:36 ` Marcin Borkowski
2015-07-12 15:54 ` Michael Heerdegen
2015-07-12 19:55 ` Marcin Borkowski [this message]
2015-07-12 20:33 ` Marcin Borkowski
2015-07-14 18:17 ` Marcin Borkowski
2015-07-14 22:08 ` Emanuel Berg
2015-07-21 22:08 ` Michael Heerdegen
2015-07-24 13:01 ` Michael Heerdegen
2015-08-11 11:41 ` Marcin Borkowski
2015-08-12 15:29 ` Michael Heerdegen
[not found] ` <mailman.8207.1439393377.904.help-gnu-emacs@gnu.org>
2015-08-12 16:30 ` Pascal J. Bourguignon
2015-08-23 8:30 ` Marcin Borkowski
[not found] ` <mailman.110.1440318650.11330.help-gnu-emacs@gnu.org>
2015-08-23 16:46 ` Pascal J. Bourguignon
2015-07-21 21:54 ` Michael Heerdegen
2015-08-11 10:15 ` Marcin Borkowski
2015-08-11 17:20 ` Thorsten Jolitz
2015-08-12 15:01 ` Michael Heerdegen
2015-07-21 21:50 ` Michael Heerdegen
2015-06-25 18:10 ` Drew Adams
2015-06-25 18:40 ` Michael Heerdegen
2015-06-25 18:53 ` Marcin Borkowski
2015-06-25 19:39 ` Michael Heerdegen
2015-06-25 20:05 ` Drew Adams
2015-06-25 20:18 ` Marcin Borkowski
2015-06-25 20:37 ` Drew Adams
2015-06-25 23:55 ` Robert Thorpe
[not found] ` <mailman.5697.1435276533.904.help-gnu-emacs@gnu.org>
2015-06-26 1:41 ` Rusi
2015-06-26 14:24 ` Michael Heerdegen
[not found] ` <mailman.5716.1435328741.904.help-gnu-emacs@gnu.org>
2015-06-26 14:35 ` Rusi
2015-06-26 14:51 ` Michael Heerdegen
2015-06-25 18:46 ` Marcin Borkowski
2015-06-26 7:31 ` tomas
2015-06-26 13:48 ` Drew Adams
2015-06-26 14:06 ` tomas
2015-06-26 15:06 ` Emanuel Berg
2015-07-12 17:38 ` Vaidheeswaran C
[not found] <mailman.5657.1435252169.904.help-gnu-emacs@gnu.org>
2015-06-30 16:27 ` sokobania.01
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mvz1b16h.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.