Re: Is there a trick so macrolet can't refer to itself?
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Sat, 19 Aug 2006 12:17:37 +0200
howard yeh wrote:
What's wrong with something like this?
(defclass parser () ())
(defclass list-parser ()
((elements :accessor list-elements :initarg :elements)))
(defclass vector-parser ()
((elements :accessor vector-elements :initarg :elements)
(index :accessor vector-index :initarg 0)))
(defgeneric current (parser))
(defgeneric end? (parser))
(defgeneric next (parser))
(defmethod current ((parser list-parser))
(first (list-elements parser)))
(defmethod end? ((parser list-parser))
(null (list-elements parser)))
(defmethod next ((parser list-parser))
(pop (list-elements parser)))
(defmethod current ((parser vector-parser))
(svref (vector-elements parser) (vector-index parser)))
(defmethod end? ((parser vector-parser))
(>= (vector-index parser) (length (vector-elements parser))))
(defmethod next ((parser vector-parser))
(incf (vector-index parser)))
...
(and ...
(if (and (end? parser) (eql (current parser) x))
...
(next parser))
...)
I guess that's good. What do you think of the code described
in the paper? I know it's supposed to be "bad" style.
But it's good in a tortured way.
With modern computing power, Henry Baker's approach
is probably a gratuitous exercise in macro-enabled efficiency,
as the overhead of method dispatching may be ignored.
I hesitate to judge Henry Baker's coding style because I haven't studied the paper in detail and don't completely understand its goals. One of the advantages he mentions is that his abstractions allow for several different implementations, and maybe that's indeed where macros help in his case - indeed, syntactic abstractions potentially gives you more freedom in this respect than functional abstractions. (I am referring to the third advantage he mentions in his conclusions.)
However, when skimming through his code, I see some macros that could have been implemented as functions as well, so I am at least skeptical.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.
- Follow-Ups:
- Re: Is there a trick so macrolet can't refer to itself?
- From: Rob Warnock
- Re: Is there a trick so macrolet can't refer to itself?
- References:
- Is there a trick so macrolet can't refer to itself?
- From: howard yeh
- Re: Is there a trick so macrolet can't refer to itself?
- From: Pascal Costanza
- Re: Is there a trick so macrolet can't refer to itself?
- From: howard yeh
- Re: Is there a trick so macrolet can't refer to itself?
- From: Pascal Costanza
- Re: Is there a trick so macrolet can't refer to itself?
- From: howard yeh
- Is there a trick so macrolet can't refer to itself?
- Prev by Date: Re: cliki.net is again down, and so ASDF-INSTALL doesn't work
- Next by Date: Re: The Weakness of Lisp
- Previous by thread: Re: Is there a trick so macrolet can't refer to itself?
- Next by thread: Re: Is there a trick so macrolet can't refer to itself?
- Index(es):
Relevant Pages
|