Arc Forumnew | comments | leaders | submitlogin
1 point by waterhouse 5222 days ago | link | parent

You may recall how I attempted to do something along these lines a long time ago (comment: http://www.arclanguage.org/item?id=11529). The part I got stuck on was using macros in the definitions (not expansions) of macros, or in the definitions of functions I intended to use at compile time; so, for example, if I wanted to define the macro "xloop" to implement the function "tuples" and use "tuples" to implement an "=" macro, then that would not work. (My comment gives a similar example with "my-if".)

At a glance, I'm not sure whether your approach offers any hope of getting around this difficulty. Does it?



1 point by aw 5222 days ago | link

Yes. (That's what I meant by "the helper functions can be defined with a plain 'define' instead having to use 'define-for-syntax'")

But it then doesn't work with modules for the same reason. So it's not a solution yet, it just pushes around what doesn't work from one place to another.

-----

1 point by aw 5222 days ago | link

Hmm, we should think about whether we'd want to use Racket modules anyway. Racket macros are more expressive (albeit harder to write) than Arc macros because they operate on syntax objects. But Racket modules don't seem very expressive to me: they aren't first class objects and they aren't parameterizable.

I'm guessing that a module system in the spirit of Arc would correspond more to Racket namespaces. Maybe I ought to be able to say something like:

  (module arc
    (load "foo.arc")
    (bar))
which creates a new namespace, populates it with values from the arc namespace, evaluates the expressions within that namespace, and returns the namespace. Or something like that.

-----

1 point by Pauan 5221 days ago | link

Which, incidentally, is already possible with namespaces + eval accepting a second parameter:

  (mac module (name . body)
    `(let ,name (new-namespace)
       (eval '(do ,@body) ,name)
       ,name))
Such a tiny change (namespaces + eval) has a lot of power, I think. Personally, I'd prefer this:

  (w/namespace (new-namespace)
    (load "foo.arc")
    (bar))
Because then you can do this:

  (import foo "foo.arc"
          bar "bar.arc")

  (w/namespace foo
    ...)

  (w/namespace bar
    (load ...)
    (load ...)
    ...)

  (w/namespace (current-namespace)
    ...)
  
  (w/namespace (current-environment)
    ...)

  (w/namespace (table)
    ...)
But it's not a big deal, since both `module` and `w/namespace` are easy to write as macros. So you can use whichever you want. :D

-----

1 point by aw 5221 days ago | link

So it's not a solution yet

On the other hand, if namespace modules do turn out to be a good idea, then it doesn't matter that it doesn't work with Racket modules :)

-----