Sam Steingold <s...@goems.com> writes: > while trying to implement an EL/CL compatibility package (a preliminary > version is available in elisp.lsp in > <http://www.goems.com/~sds/data/cllib.zip>), I encountered a problem: > apparently, the following (calendar.el in Emacs distribution):
> (defmacro calendar-for-loop (var from init to final do &rest body) > "Execute a for loop." > (` (let (( (, var) (1- (, init)) )) > (while (>= (, final) (setq (, var) (1+ (, var)))) > (,@ body)))))
> is correct in EL (but not in CL). obviously I have to redefine > backquote in the emacs-lisp package, but I don't know how to do this > easily (I am not particularly eager to re-invent the wheel).
> Any suggestions?
> [the obvious solution - load backquote.el - fails because the file > defines `backquote-unquote-symbol' to be ', and the reader chokes on > this]
> Thanks.
In the olden days (maclisp), pre-backquote, we used to do:
Don't know if that helps, but it's worth noticing that sometimes when technology runs awry, the underlying thing they're buying you sometimes isn't worth the fuss.
* Sam Steingold <s...@goems.com> | (defmacro calendar-for-loop (var from init to final do &rest body) | "Execute a for loop." | (` (let (( (, var) (1- (, init)) )) | (while (>= (, final) (setq (, var) (1+ (, var)))) | (,@ body))))) | | is correct in EL (but not in CL). obviously I have to redefine backquote | in the emacs-lisp package, but I don't know how to do this easily (I am | not particularly eager to re-invent the wheel). | | Any suggestions?
yes. don't bother. many things in Emacs Lisp should not be replicated. instead, fix the Emacs sources and submit them as patches.
Erik Naggum <e...@naggum.no> writes: > yes. don't bother. many things in Emacs Lisp should not be > replicated. instead, fix the Emacs sources and submit them as > patches.
A large amount of legacy Emacs code (both in the distribution and elsewhere on the net) uses "old-style" backquotes. If Sam's goal is to run such code unchanged, he will probably have to implement the backquote junk, somehow.
* Sam Steingold <s...@goems.com> | Note that it only works with Allegro CL with Erik's readtable fix, which | he did not post but sent me by private e-mail. I would appreciate if he | did post it for public consumption.
um, I'm not sure this is a good idea, but here goes:
excl: ;; compile and load this, do _not_ evaluate interpreted (loop ;; make the #\ reader fully ANSI CL compliant, ignore CLtL1. with readtables = (get-objects 11) for i from 1 to (aref readtables 0) for readtable = (aref readtables i) do (when (readtable-dispatch-tables readtable) (set-dispatch-macro-character #\# #\\ (named-function sharp-backslash (lambda (stream backslash font) (declare (ignore font)) (stream-unread-char backslash stream) (let* ((charstring (read-extended-token stream))) (unless *read-suppress* (or (if (= (length charstring) 1) (char charstring 0) (name-char charstring)) (internal-reader-error stream "Meaningless character name ~A" (string-upcase charstring))))))) readtable)))
this is deliberately Allegro CL-specific and hopefully won't work anywhere else. unsupported, copyrighted, no warranties kind of stuff, based on my understanding of source code licensed to supported customers, but not derived from which, etc, legal blah blah blah, sue Bill Gates if you have problems, and indemnify everybody else, OK? cancel? <click>
Sam Steingold <s...@goems.com> writes: > This does not work with CLISP because (probe-file "/etc/") signals an > error (file is not a directory). (a workaround is being worked on).
Incidentally, I see no reason for (probe-file "/etc/") to return anything useful in any conforming implementation. Directories are not required to be files. In some operating systems, they aren't files. That's not to say an implementation can't usefully define this behavior; I just wanted to be clear it's not something you should expect because of the standard... at least, not for any reason I can recall.
>> yes. don't bother. many things in Emacs Lisp should not be >> replicated. instead, fix the Emacs sources and submit them as >> patches.
> A large amount of legacy Emacs code (both in the distribution and > elsewhere on the net) uses "old-style" backquotes. If Sam's goal is > to run such code unchanged, he will probably have to implement the > backquote junk, somehow.
Wouldn't it be easier to implement the byte code interpreter and just run the .elc files instead?
* mike...@mikemac.com (Mike McDonald) | Wouldn't it be easier to implement the byte code interpreter and just run | the .elc files instead?
for this particular case, it would, but the byte code interpreter calls out to functions all the time, and you would need to implement almost everything anyway. the byte code is also more incompatible between the various versions of Emacs than the source is. not that it isn't a good idea, but it would probably cause a lot more work than you think to get it right everywhere.
Clearly, this rapidly becomes incomprehensible as the complexity of the backquoted form rises.
Modern Emacs Lisp readers have horrific kluges to recognise old-style backquoting; this also means that certain (admittedly obscure) usages of backquote will fail.
If I recall correctly, the ANSI CL spec suggests (but does not require) that implementations of the backquote reader try to be compatible with Scheme and other dialects, which provide macros (as opposed to reader macros) for doing some of the same things as CL backquote does.
For example, there should be macros named QUASIQUOTE, UNQUOTE and UNQUOTE-SPLICING. (If one wanted to provide similar utilities for other CL backquoting features that are not part of Scheme, one would also define something like "unquote-splicing!" and "quasivector".)
I don't know how many CL implementations do this, but if they support anything like this (even with different names,) then it should be pretty easy to support elisp quasiquoting macros within CL.
It is not clear to me whether one could then get away with either of: 1. globally replacing "(` " (with space) to "(quasiquote ", "(,@ " => "(unquote-splicing ", etc. 2. Hacking the ` reader to return the symbol QUASIQUOTE if the next character is a space, and similarly for , and ,@. This would allows .el files to be used directly, without modification. However, it might screw up .lisp files, so arrangements would have to made such that the modified readtable would be used only on .el files. Both of these depend on the assumption that "old style elisp backquoting" relied on whitespace to terminate the symbols named "`", "," and ",@".
If this concept is sound, I can donate some untested code to the cause. I have code for the next version of Eclipse that implements QUASIQUOTE, etc., macros, and coordinates them with the backquote reader macros. The code is about 4 screen fulls and is loosely based on appendix C in CLtL2. Contact me if you want it. Here's an overview:
;;; We process quasiquote forms at macroexpansion time, and backquote ;;; forms at read time. In either case, processing involves ;;; simplifiying the forms and transforming them to bq-xxx forms. The ;;; bq-xxx macros expand into xxx, but are recognized by the ;;; pretty-printer so that they can be printed using backquote ;;; characters. They also keep the simplifier from mistakenly ;;; simplifying user code.
> In article <36D2BC01.70862...@elwood.com>, > "Howard R. Stearns" <how...@elwood.com> writes: > > Could someone sumarize what the issue was with backquote. I don't know > > what is meant by "old style backquote".
> In older Emacs Lisp dialects, backquote, comma and comma-at are macros, > rather than being handled by the reader. This means that instead of
> Clearly, this rapidly becomes incomprehensible as the complexity of the > backquoted form rises.
> Modern Emacs Lisp readers have horrific kluges to recognise old-style > backquoting; this also means that certain (admittedly obscure) usages of > backquote will fail.
Another area where there exist major room for improvement in CL...
The syntax of Backquote is about as ugly as one can imagine. Unfortunately, backquote is almost always used when defining macros. And with the macro being one of the key strengths of lisp, we have the situation where a key strength of lisp uses one of the most bizarre and ugly syntactic constructs in the language. At least parenthesis have a form of beauty and functionality, but backquote is just plain ugly and bizzare.
So how about some suggestions on something different, something better. How about a straw man: Use [] to replace , and {} to replace ,@ i.e. `(zap ,foo ,@bar) ==> `(zap [foo] {bar})
> If I recall correctly, the ANSI CL spec suggests (but does not require) > that implementations of the backquote reader try to be compatible with > Scheme and other dialects, which provide macros (as opposed to reader > macros) for doing some of the same things as CL backquote does.
> For example, there should be macros named QUASIQUOTE, UNQUOTE and > UNQUOTE-SPLICING. (If one wanted to provide similar utilities for other > CL backquoting features that are not part of Scheme, one would also > define something like "unquote-splicing!" and "quasivector".)
> I don't know how many CL implementations do this, but if they support > anything like this (even with different names,) then it should be pretty > easy to support elisp quasiquoting macros within CL.
> It is not clear to me whether one could then get away with either of: > 1. globally replacing "(` " (with space) to "(quasiquote ", > "(,@ " => "(unquote-splicing ", etc. > 2. Hacking the ` reader to return the symbol QUASIQUOTE if the next > character is > a space, and similarly for , and ,@. This would allows .el files to > be used > directly, without modification. However, it might screw up .lisp > files, so > arrangements would have to made such that the modified readtable > would be used > only on .el files. > Both of these depend on the assumption that "old style elisp > backquoting" relied on whitespace to terminate the symbols named "`", > "," and ",@".
> If this concept is sound, I can donate some untested code to the cause. > I have code for the next version of Eclipse that implements QUASIQUOTE, > etc., macros, and coordinates them with the backquote reader macros. > The code is about 4 screen fulls and is loosely based on appendix C in > CLtL2. Contact me if you want it. Here's an overview:
> ;;; We process quasiquote forms at macroexpansion time, and backquote > ;;; forms at read time. In either case, processing involves > ;;; simplifiying the forms and transforming them to bq-xxx forms. The > ;;; bq-xxx macros expand into xxx, but are recognized by the > ;;; pretty-printer so that they can be printed using backquote > ;;; characters. They also keep the simplifier from mistakenly > ;;; simplifying user code.
> Aaron Crane wrote:
> > In article <36D2BC01.70862...@elwood.com>, > > "Howard R. Stearns" <how...@elwood.com> writes: > > > Could someone sumarize what the issue was with backquote. I don't know > > > what is meant by "old style backquote".
> > In older Emacs Lisp dialects, backquote, comma and comma-at are macros, > > rather than being handled by the reader. This means that instead of
> > Clearly, this rapidly becomes incomprehensible as the complexity of the > > backquoted form rises.
> > Modern Emacs Lisp readers have horrific kluges to recognise old-style > > backquoting; this also means that certain (admittedly obscure) usages of > > backquote will fail.
In article <36D45172.5EA34...@intellimarket.com>, Kelly Murray <k...@IntelliMarket.Com> writes:
> Another area where there exist major room > for improvement in CL...
> The syntax of Backquote is about as ugly as one can imagine. > Unfortunately, backquote is almost always used when > defining macros. And with the macro being one of the key > strengths of lisp, we have the situation where a key strength > of lisp uses one of the most bizarre and ugly syntactic constructs > in the language. At least parenthesis have a form of beauty > and functionality, but backquote is just plain ugly and bizzare.
> So how about some suggestions on something different, > something better. How about a straw man: > Use [] to replace , and {} to replace ,@ > i.e. `(zap ,foo ,@bar) ==> `(zap [foo] {bar})
Looks about as ugly and bizzare to me as the current syntax.
On Wed, 24 Feb 1999 11:22:26 -0800, Kelly Murray <k...@IntelliMarket.Com> wrote: > [SNIP backquote is ugly]
> i.e. `(zap ,foo ,@bar) ==> `(zap [foo] {bar})
[Coming from a lisp "dabbler"] I'd always thought ("always" is the last year that I've been toying with lisp) that the backquote syntax had a certain beauty to it. It's hard to describe but I felt that "," and ",@" painted the actual action into my editor. "," "nicked and opened" what followed and ",@" "nicked and unrolled" what followed.
Assuming your suggestion was serious (I've got this funny feeling I may have missed the joke in your post), why do you think the current syntax is ugly?
-- Take a look in Hagbard's World: | w3ng - The WWW Norton Guide reader. http://www.acemake.com/hagbard/ | eg - Norton Guide reader for Linux. http://www.hagbard.demon.co.uk/ | weg - Norton Guide reader for Windows. Free software, including........| dgscan - DGROUP scanner for Clipper.
davep.n...@hagbard.demon.co.uk (Dave Pearson) writes: > On Wed, 24 Feb 1999 11:22:26 -0800, Kelly Murray <k...@IntelliMarket.Com> wrote:
> > [SNIP backquote is ugly]
> > i.e. `(zap ,foo ,@bar) ==> `(zap [foo] {bar})
> [Coming from a lisp "dabbler"] I'd always thought ("always" is the last year > that I've been toying with lisp) that the backquote syntax had a certain > beauty to it. It's hard to describe but I felt that "," and ",@" painted the > actual action into my editor. "," "nicked and opened" what followed and ",@" > "nicked and unrolled" what followed.
> Assuming your suggestion was serious (I've got this funny feeling I may have > missed the joke in your post), why do you think the current syntax > is ugly?
it certainly looks weird.
where else do you find the comma attached to the *front* of anything?
i suppose you get used to it, but it is rather jarring to have your normal sense of where to put commas completely turned on its head.
-- J o h a n K u l l s t a m [kulls...@ne.mediaone.net] Don't Fear the Penguin!
>>>>> "JK" == Johan Kullstam <kulls...@ne.mediaone.net> writes:
[...] JK> where else do you find the comma attached to the *front* of JK> anything?
JK> i suppose you get used to it, but it is rather jarring to have JK> your normal sense of where to put commas completely turned on JK> its head.
How is this different than '+' in prefix? You get used to it in about a few hours, in my experience. I may be biased though, I already had decided that I loved lisp when I started using backquote and comma.
Kelly Murray wrote: > The syntax of Backquote is about as ugly as one can imagine. > Unfortunately, backquote is almost always used when > defining macros. And with the macro being one of the key > strengths of lisp, we have the situation where a key strength > of lisp uses one of the most bizarre and ugly syntactic constructs > in the language. At least parenthesis have a form of beauty > and functionality, but backquote is just plain ugly and bizzare.
> So how about some suggestions on something different, > something better. How about a straw man: > Use [] to replace , and {} to replace ,@ > i.e. `(zap ,foo ,@bar) ==> `(zap [foo] {bar})
First of all, you have a readability problem with this particular suggestion: I read your `(zap [foo] {bar}) first as `(zap [foo] (bar)), in other words, for anybody with less than perfect eyesight, () and {} are uncomfortably similar in some fonts.
The other problem I have with this is that this would add more parentheses to the program; as the most often heard complaint from newcomers is that all the parens make the language unreadable, adding more of them would be unlikely to help.
I find that I actually prefer Lisp's style of using no explicit end delimiter in quote etc.: saves me from all the problems with missing or misplaced end delimiters, the whitespace or parens ending the form are quite sufficient for my taste as end indicators.
I prefer the current backquote to your suggestion, I'd rather save the []{} for the user for any extension languages etc.
-- ________________________________________________________________ ^. Martti Halminen / \`. Design Power Europe Oy / \ `. Tekniikantie 12, FIN-02150 Espoo, Finland /\`. \ | Tel:+358 9 4354 2306, Fax:+358 9 455 8575 /__\|___\| Mailto:Martti.Halmi...@dpe.fi http://www.dpe.fi
* aaron.cr...@pobox.com (Aaron Crane) | Modern Emacs Lisp readers have horrific kluges to recognise old-style | backquoting; this also means that certain (admittedly obscure) usages of | backquote will fail.
this isn't quite true. the new-style backquoting is returned as old-style function calls with funny function names.
(car (read-from-string "`(a ,b ,@c)")) => (\` (a (\, b) (\,@ c)))
(the two values are returned as a cons.) moreover, ` is a macro:
In article <3128925742665...@naggum.no>, Erik Naggum <e...@naggum.no> wrote:
>* Johan Kullstam <kulls...@ne.mediaone.net> >| where else do you find the comma attached to the *front* of anything?
> what do you mean "comma"? don't you see it's a low quote?
Since the ordinary quote (') is sometimes called an "inverted comma," what could be more natural than un-inverting the comma in order to reverse the effect? This seems especially appropriate in constructs like ',item, where the item needs to be evaluated and then quoted.
>> where else do you find the comma attached to the *front* of anything?
>It's not a comma, it's a quote in the wrong place. (I bet this isn't >really why it's done like that, but...)
The idea is that the comma is the *opposite* of the backquote.
>(and what about colons on the front of keywords...)
Colons were already being used as package separators, so it was natural to adopt them as a keyword indicator as well. Putting them at the beginning was done by analogy with the way options are often specified to OS commands (e.g. -<keyword> on Multics, -<letter> on Unix, /<keyword> on ITS and most DEC OS's).
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
* Kelly Murray <k...@IntelliMarket.Com> | Another area where there exist major room for improvement in CL...
it doesn't appear that you want to use Common Lisp at all, but it also doesn't appear that you have any gripes more fundamental than syntactic aesthetics. what gives? this is a part of the language you can change at will, but there simply is no need to do this in Common Lisp.
speaking of which, I explained to the British guy sitting next to me on a recent transatlantic flight that I worked with Common Lisp. he in turn talked about his great hobby: ornithology, where "common" is a synonym for "garden", as in "garden variety". he thought it would have better acceptance if it was called "Garden Lisp". feel free to use it, Kelly.