From: Pascal J. Bourguignon on
Spiros Bousbouras <spibou(a)gmail.com> writes:

> I'm trying to construct a macro called memory.


(defparameter *cell* 0)
(define-symbol-macro cell *cell*)
(defmacro memory (&rest body)
`(let ((*cell* (1+ *cell*)))
,@body)))


C/USER[100]> (memory
(format t "CELL has value ~a~%" cell)
(memory (format t "CELL has value ~a~%" cell))
(format t "CELL has value ~a~%" cell))
CELL has value 1
CELL has value 2
CELL has value 1
NIL


--
__Pascal Bourguignon__
From: Kaz Kylheku on
On 2009-11-07, Spiros Bousbouras <spibou(a)gmail.com> wrote:
> It would be convenient if Lisp had some kind of minimal-compile
> function ...

Indeed, it would help a certain troll in another thread to have a fraction of a
valid point.
From: Spiros Bousbouras on

On 7 Nov, 18:41, p...(a)informatimago.com (Pascal J. Bourguignon) wrote:
> Spiros Bousbouras <spi...(a)gmail.com> writes:
> > I'm trying to construct a macro called memory.
>
> (defparameter *cell* 0)
> (define-symbol-macro cell *cell*)
> (defmacro memory (&rest body)
> `(let ((*cell* (1+ *cell*)))
> ,@body)))

This is a good approximation to what I asked for. The following is
even better:

(defparameter b 0)
(defmacro memory (&rest body)
`(let ((b (1+ b)))
(symbol-macrolet ((cell b))
,@body)))

It makes cell only available within body not everywhere. A difference
from my vision is that in the code above cell expands to a variable
instead of a numerical constant but that's fairly unimportant. I'm a
bit more annoyed by the fact that your solution also exposes an
implementation detail to the world. I would prefer a 100% clean
solution like what we would have if memory were a function when we
would use closures.

--
Who's your mama ?
From: Spiros Bousbouras on

On 7 Nov, 18:53, Kaz Kylheku <kkylh...(a)gmail.com> wrote:
>
> Why does cell have to be a symbol macro? How about simply generating:
>
> (let ((cell (1+ cell)) ...)
>
> Take advantage of the LET scoping rule which allows you to shadow an outer
> variable, but use its avlue to initialize the shadowing one.

It doesn't have to be a symbol macro. The point of the exercise is to
investigate methods by which different invocations of the same macro
can share information. Many of the technical details are unimportant.
Having said that , it would be nice to have a way for this sharing of
information to happen through objects only the macro knows about.

> You just need to bootstrap this somehow for the outermost invocation. Here is
> where a symbol macro comes in: a global one made with define-symbol-macro,
> to avoid introducing cell as a dynamic variable.

It would be good if this bootstrapping could be done through the
macro
definition itself.

--
To have absolutely if l' this large Mister is loved!
Translation on 2-11-2009 by
http://uk.babelfish.yahoo.com/translate_txt of
"A posséder absolument si l'on aime ce grand monsieur!
From: Madhu on
* Kaz Kylheku <20091107104314.867(a)gmail.com> :
Wrote on Sat, 7 Nov 2009 18:44:28 +0000 (UTC):

| On 2009-11-07, Spiros Bousbouras <spibou(a)gmail.com> wrote:
|> It would be convenient if Lisp had some kind of minimal-compile
|> function ...
|
| Indeed, it would help a certain troll in another thread to have a
| fraction of a valid point.

Assuming you are baiting me here by calling me a troll, I think you are
rather sore for pointing out you had no clue what minimal compilation
was and its implications to symbol macro-expansion

--
Madhu

 |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: Lisp sucks!
Next: grabbing key presses