From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: How the backquote and the comma really work? Date: Sun, 12 Jul 2015 21:55:54 +0200 Message-ID: <87mvz1b16h.fsf@mbork.pl> References: <87vbebg1fs.fsf@mbork.pl> <87r3ozy9pf.fsf@web.de> <87si9ffys0.fsf@mbork.pl> <87d20jbqbj.fsf@web.de> <87pp4jfx9y.fsf@mbork.pl> <87615sxn1a.fsf@mbork.pl> <87zj318j7z.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1436730987 30770 80.91.229.3 (12 Jul 2015 19:56:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Jul 2015 19:56:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 12 21:56:20 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZENMK-0003L0-M1 for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Jul 2015 21:56:20 +0200 Original-Received: from localhost ([::1]:51801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZENMJ-0001BA-VG for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Jul 2015 15:56:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZENM9-0001B5-AO for help-gnu-emacs@gnu.org; Sun, 12 Jul 2015 15:56:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZENM6-0004CD-3o for help-gnu-emacs@gnu.org; Sun, 12 Jul 2015 15:56:09 -0400 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:42457) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZENM5-0004Bl-Nd for help-gnu-emacs@gnu.org; Sun, 12 Jul 2015 15:56:06 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id C813E4FA048 for ; Sun, 12 Jul 2015 21:56:02 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZX8OjvZREK2Y for ; Sun, 12 Jul 2015 21:56:00 +0200 (CEST) Original-Received: from localhost (unknown [109.232.24.146]) by mail.mojserwer.eu (Postfix) with ESMTPSA id A0B724FA03B for ; Sun, 12 Jul 2015 21:55:59 +0200 (CEST) In-reply-to: <87zj318j7z.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:5e00:2:52::8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:105661 Archived-At: On 2015-07-12, at 17:54, Michael Heerdegen wro= te: > 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=E2=80=99ll try to study its code. > Dunno if your interpreter will support macros. If not, you could handl= e > backquote directly in your interpreter. No, I don't want to support macros =E2=80=93 too much work and little ben= efit, 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=E2=80=99ll add their definition= s directly, or drop them altogether. I=E2=80=99ll see. I=E2=80=99m rather= not going to publish this code on Melpa or anything like that; it=E2=80=99ll quite pro= bably 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 =E2=80=93 I=E2=80=99m working on lexical binding, an= d hopefully I=E2=80=99ll 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=E2=80=99s 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 =E2=80=93 I haven=E2=80=99= 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=E2=80=99m not satisfied with the =E2= =80=9CI kind of understand this... I guess=E2=80=9D situation =E2=80=93 if I can=E2=80= =99t implement it, I don=E2=80=99t understand it. (Unfortunately, the converse need not be = true; I might be lucky and implement it without a full understanding, too...) And I=E2=80=99m really determined to understand this stuff well enough to= be able to teach it to others. > Regards, > > Michael. Thanks for kind words. Stay tuned! --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University