Re: Macro Question: Paraphrasing



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
.



Relevant Pages

  • Re: Programming By The Seat Of Your Pants
    ... the only way I'm going to learn Lisp ... was Python, a better scripting language. ... Not much in the way of libraries. ... then add a macro layer that allows you to write things the way you want to ...
    (comp.lang.lisp)
  • Re: A "killer" macro
    ... could be included as a feature in another language, ... The "killer" macro, in CL ... of the functional features of Lisp. ... When confronted by fellow programmers with the question "so why is ...
    (comp.lang.lisp)
  • Re: Python gets macros - now XML does too
    ... > I think the main advantage: You use Lisp within a Lisp macro to generate ... > generation part in another language than the description to generate the ... MetaL compiler flow module provides support for level 0 (macro ... Despite currently I only use PHP because I only develop Web ...
    (comp.lang.lisp)
  • Re: What you can do with macros in Lisp
    ... > Imagine you have a language with a CASE expression. ... > equivalent to writing a macro system...) ... as explained in Paul Graham's "On Lisp" in his extended coverage ... macro calls by function calls encapsulating the bodies in closure ...
    (comp.lang.lisp)
  • Re: ILC2005: McCarthy denounces Common Lisp, "Lisp", XML, and Rahul
    ... >> the language should be available to users. ... In the design of Common Lisp, I asked Dave Moon (one of the architects ... Now, there are good kinds of low-level, like the way that floats are ...
    (comp.lang.lisp)