Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 5129 days ago | link | parent

It's both a function and a special form. Yes, it's weird. Yes, I hope to change it.

I don't see how `if` could be implemented as a macro. Consider this case:

  (def foo (a) (if a 1 2))
The `if` form needs to be evaluated every time the foo function is run, and then return either 1 or 2, depending on what 'a is. Keep in mind this is Python, so I can't have `if` desugar to `cond`. :P

---

Yeah, that's what I was talking about: have `fn` be a fexpr that returns functions that are annotated with type 'fn. And since macros are just functions with type 'fn, that would mean that everything in PyArc boils down to fexprs.

I didn't realize that what I described was fexprs, but in hindsight I probably should have. I actually messed around with NewLisp for a bit; they use fexprs. I prefer Arc's macro system, since I don't think NewLisp has quasiquote/unquote, which made certain things more verbose than they should have been.

However, the ability to have everything desugar to fexprs is appealing, especially since I no longer need special forms hardcoded into eval. PyArc will still have normal functions and macros, of course. They'll just be fexprs underneath. :P



1 point by rocketnia 5129 days ago | link

Here's a version of 'if that depends only on a built-in function and a built-in macro:

  (def fn-if (condition then else)
    ((if condition then else)))
  
  (mac if body
    (whenlet (first . rest) body
      (iflet (then . elses) rest
        `(fn-if ,first (fn () ,then) (fn () (if ,@elses)))
        first)))
These implementations are just for demonstration, since they depend on 'if themselves.

-----

1 point by Pauan 5129 days ago | link

Huh, interesting. I think I'll implement it as a fexpr, though, both for consistency (with the other special forms) and simplicity.

-----

1 point by rocketnia 5129 days ago | link

Oops, no time to comment right now, but I figure I'll mention that I just finished ninja-editing that comment to put in links to PicoLisp and Eight.

-----