[<<][staapl][>>][..]
Fri May 23 13:11:54 CEST 2008

namespaces and parameterization

Instead of trying to use late binding, it might be more interesting to
use explicit parameterization where possible. This is one of the
problems with Brood 4 which caused a lot of pain. Let's fix that
first.

Taking the interpreter code as an example. What i'd like to do is to
make instantiation explicit:

: interpreter
    ' io make-interpreter compile ;


There's an interesting problem here with choice of words. Maybe here
'compile' should be used to indicate that there's an instantiation
going on. It's not always clear whether something is dynamic or
static. There's a difference between:


    : interpreter int-body ;

and

    ` interpreter create-interpreter

The latter is preferred. It is more general. But is not possible in
the current implementation. Labels can be defined, but they are only
for annotation, and visible AFTER compilation.

Can this be simplified?
What is desired is something like

    ` bla

Where at that moment the current context has a macro called bla, which
is not yet associated to any code. So how to associate a macro to
code?

Maybe instead of mapping Forth code directly to 'define' it should be
mapped to a 2-step procedure of undefined macro creation + single
assignment.

I'm touching some core of reflection here.. Something that doesn't
really work well together with the way the Purrr language is layed
out. There's no problem with doing this in s-expression syntax, but
expressing this in Forth syntax is not so easy..

Let's see.. Quick hacking it:

      \ create the macros
      declare read
      declare write

      \ define them
      ' read ' write make-io!

But, this requires make-io! to have side-effects + read and write not
to appear in any code before make-io! is executed. That is definitely
not desirable: it would be back to the old imperative style.

So, what about using this as the primary syntax:

    [ 2 3 4 ] define bla

And writing ':' as a substitution macro?


Continuing the random walk. It is possible to do something like:

    : read   io 2nd ;
    : write  io 1st ;

But that's exactly the thing that's not flexible enough when a lot of
macros need to be created. Is it really a good idea to try to solve
this in Forth syntax, since it obviously has some shortcomings..

It looks like the only way to solve this is to use 'parsing word'
preprocessors. Maybe the goal is here to figure out a way to create
such substitution macros in .f files? It's certainly possible to
create scheme files which have the 3 levels:

       - parsing words (bound to scheme level 1)
       - macros (scheme level 0)
       - forth words: consequence of hitting 'compile'

The problem really is how to map the scheme s-expression flexibility
to Forth code. Can't be done?

This is a dead end..

Solve it with substitutions and be done with it?

((io read write) (:macro read io drop compile
                  :macro write swap drop compile))



[Reply][About]
[<<][staapl][>>][..]