Re: Macro Question: Paraphrasing
- From: M Jared Finder <jared@xxxxxxxxxxx>
- Date: Tue, 15 Nov 2005 23:03:01 -0800
I'm replying to your reply out of order. I think my reasoning is clearer in this order. Just giving a heads up...
Jack wrote:
MJF wrote:
If you did want to have your language have it's own grammar, the easiest way would be to write a macro WITH-ENGLISH-GRAMMAR that processes all its subforms and rearranges it to look like normal Lisp.
Aha! So you admit that I can tailor Lisp to suit my needs. Thanks for the 411, but I had already pinned that donkey's tail.
I'll admit it, I didn't put much effort into my original post. I'll put more effort into this one.
What I was trying to say is that you won't be able to define macros TO and BE that would rearrange (move-object (to destination) (from source)) to (move-object source destination). You can't do this because macros have no access to the super-form they are in. Instead, you will need to put some macro around all the forms that need to be processed, and use a code walker to process each subform, a la
(with-english-grammar (move-object (to destination) (from source)))
The with-english-grammar macro has access to the super-form of
(from source) and (to destination) and can make the necesarray modifications.
Keyword arguments and the package system should be enough, though.
Enforcing English grammar rules in a programming language is (usually) bad. The programming language has its own grammar rules that are simpler and much more consistent than natural language. Just look at how easy it is to understand LOOP.
Your somewhat twisted reasoning amuses me, especially considering the text you chose to quote. From the original post onward, I've tried to elucidate that I would like to add to the language for my own viewing pleasure. Far from enforcing English grammar rules on Lisp, these ideas entail adding context to arbitrary ordering and paraphrasing awkward expressions. That doesn't seem like too tall an order.
Lisp already has a construct that serves exactly that purpose -- keyword arguments. Combined with the package system, you can define your own version of any existing function or macro:
(defpackage :cl-keyworded (:use) ;not using COMMON-LISP! (:export setf let))
(in-package :cl-keyworded)
(cl:defmacro setf (cl:&rest args)
`(cl:setf
,@(cl:loop :for cons :on args :by #'cl:cdddr
:do (cl:assert (cl:eq (cl:second cons) :to))
:collect (cl:first cons) :collect (cl:third cons))))(cl:defmacro let (bindings cl:&body body)
`(cl:let ,(cl:loop :for (symbol cl:&key be) :in bindings
:collect (cl:list symbol be))
,@body))Now you can use cl-keyworded:setf and cl-keyworded:let instead of cl:setf and cl:let. The paraphrase macro is similarly simple:
(defmacro paraphrase ((old-name &rest old-args)
(new-name &rest new-args))
`(defun ,new-name ,new-args
(,old-name ,@(paraphrase-lambda-list-args old-args))))where paraphrase-lambda-list-args is a function that returns a list that could get called.
I still don't think this is a good idea. If you break the existing convention, other people will find it harder to help you, since they won't understand why let and setf are taking keyword arguments.
LOOP is quite brilliant. It allows the formation of compact compound-very-complex sentences. The variable clauses resemble [potentially compound] dependent clauses, and the main clause represents the [potentially compound] independent clause(s). It mimics English grammar very nicely, though I might improve the punctuation.
And I could not disagree with you more. LOOP is *the* worst construct in the Common Lisp language, because it disregards everything that's good about computer programming. Worse still, because LOOP's syntax is completely different from *the rest of Lisp*, I don't get autocompletion, indenting, or any other computer assistance. So I have to parse its meaning, token by token, by hand.
You consider that "quite brilliant"?
-- MJF .
- Follow-Ups:
- Re: Macro Question: Paraphrasing
- From: Thomas A. Russ
- Re: Macro Question: Paraphrasing
- From: Jack
- Re: Macro Question: Paraphrasing
- From: Jack
- Re: Macro Question: Paraphrasing
- References:
- Macro Question: Paraphrasing
- From: Jack
- Re: Macro Question: Paraphrasing
- From: M Jared Finder
- Re: Macro Question: Paraphrasing
- From: Jack
- Macro Question: Paraphrasing
- Prev by Date: Re: Why Lisp for web applications?
- Next by Date: Re: Macro Question: Paraphrasing
- Previous by thread: Re: Macro Question: Paraphrasing
- Next by thread: Re: Macro Question: Paraphrasing
- Index(es):
Relevant Pages
|