> From: Christoph Reck [mailto:[EMAIL PROTECTED]]
> 
> 
> > > -0, I can very well imagine VMs updating the parent 
> context (more below).
> > > Whereas the tools and defaults set up as a base context should be
> > read-only.
> > 
> > Are we talking about the same thing?
> 
> don't know? Jose gave the example:
> > > > #macro(m1 $p1)
> > > > #local($a)
> > > >  $set( $a = $p1 )
> > > >  $set( $appVar = $a + $a )
> > > > #end
> 

Just to elaborate on my example to avoid confusion. The macro is trying to
modify the context "appVar" entry with the value of its parameter doubled.
I am just trying to do it so the macro repeats the macro parameter twice.
The implementation tries to avoid re-evaluating the expression by using
a local variable which will disapear at the end of the macro.

> >[snip]
> > > Singleton pattern with a private constructor:
> 
> Jose's example is not serialization safe, equals() will not work:
> > > >  public static final Object NULL = new Object();

Equality works fine! Object defines equality to be true only when the two
references are the same (same Object). So NULL.equals(NULL) is true.

Is there a need for the values in the Context to be serializable?
I have not seen such a requirement before. In any case, you would need more
that just defining a class for this to work. You need to implement the
serialization function so that when the value is reloaded you put in the
context the correct constant since the constant NULL is per ClassLoader.

> 
> That's why I provided an example of a *real* singleton in Java.
> 
I do not remember all the methods for *real* singletons required for 
serialization to work. But I really did not pay that much attention.

> >[snip]
> > The local/end thing will be fixed soon w/o new directives 
> (I hope:)  There
> > are a couple of related issues I want to knock off in one 
> fell swoop.
> 
> I'm eager to find out how you will do it. See my note on this in the
> "Context chaining examples" post.
> I guess it could be what Jose once posted (within the VM rendering):
>   1. save the arguments that match ones in the current context, 
>   2. evaluate the passes parameters and put them into context
>      (this would also avoid multiple evaluation of passed parameters)
>   3. render the macro
>   4. restore the saved arguments
> 
I think this behavior as the common way to dealt with macros was rejected.

That is why I introduced #local directive in my example. As used in the
example, we could implement this directive without usage of new Context
implementations. All you need to do is for the directive when rendering to
do the following:

   1. Look in the context for a variable of the same name as the one used
      in #local and save it on the execution stack.
   2. Set the variable in the Context to NULL (the constant).
   3. Render the block
   4. On exit, set the variable in the context to the original value
      (or remove it from the Context if it was not defined before).

This is a very simple implementation, that should work just fine. Allows for
modification of Context since Chaining is not used, and it only relies on
the NULL constant.

Jose Alberto

Reply via email to