Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 4747 days ago | link | parent

I was playing around with the idea and thought of an alternative syntax:

  (with hash
     ..)
I even came up with a kinda icky implementation in wart:

  mac with(vars . body) :case (~cons? vars)
    `(with ,(collect:each (k v) eval.vars
              yield.k
              yield.v)
       ,@body)
Pros: it's shorter to use because I don't need to repeat the keys.

Cons: it only works with syms. You can't eval an expr that returns a hash. It replaces the runtime check you're concerned about with that super ugly eval-inside-unquote. You can't import just a few of the keys so it feels a little like 'using namespace std' in C++ -- you may not know what vars you're going to get, and you may end up overriding bindings.

Perhaps I should just make it a new term. That would address the first limitation:

  (w/bindings hash
    ..)
Meh, I'm not sure how I feel about this.


1 point by rocketnia 4747 days ago | link

You're not going to be able to use (with hash ...) with a local variable 'hash unless you have at least one of these:

- Fexprs. An fexpr implementation of 'with can use the complete value of 'hash as it determines how to treat the unparsed body.

- Static typing with record types, so that a macro can use the type of 'hash as it determines how to treat the unparsed body.

- Some variant of JavaScript-style scope chain semantics, in the sense that a bare variable reference means (or can mean) a field lookup in general. IMO, this would be the most straightforward to add to an Arc-3.1-like compiler, since it's a matter of compiling foo to (scope 'foo), (with foo ...) to (let ((scope (shadow (scope 'foo) scope))) ...), and other scope-related things in their own analogous ways.

- Something else I haven't thought of. :)

-----