Arc Forumnew | comments | leaders | submitlogin
First Class Special Forms?
8 points by mecon 5907 days ago | 11 comments
Special forms should be indistinguishable from macros -- in arc this means that Special Forms should be first class.


1 point by vsingh 5907 days ago | link

Macros are source-code transformers. How is 'if' a macro?

-----

1 point by greatness 5906 days ago | link

IF is a macro because you don't always want to evaluate all of it's arguments...

-----

3 points by kens 5906 days ago | link

I don't want to be pedantic, but 'if' is a special form and not a macro:

  arc> if
  Error: "reference to undefined identifier: _if"
  arc> and
  #3(tagged mac #<procedure>)
It's the basis for other "partial evaluation" macros.

My foundation documentation (http://arcfn.com/foundation-doc.html) lists the special forms.

-----

2 points by greatness 5905 days ago | link

err, I was refering to the way it executed. I believe On Lisp implemented an if macro.

-----

2 points by Darmani 5904 days ago | link

A conditional such as if can only be implemented as a macro if it expands to another conditional such as cond, which must be implemented as a special form.

In Arc, if is just a special form.

-----

3 points by absz 5904 days ago | link

I think the logic is to make if a "primitive macro," the way + is a primitive function. Just as you can't define + in terms of Arc functions, you can't define if in terms of Arc macros. Nevertheless, (isa + 'fn), and so the thinking is that (isa if 'mac) makes sense.

There are valid reasons not to do things this way, of course. For instance, what's so powerful about macros is that they literally expand into a code tree, which (as you observed) if can't do. For that reason, why not have (isa if 'form) (or 'prim, or 'special, or something similarly descriptive)? Then you have first-class special forms without literally making them macros. This would be a big improvement over the current state of affairs:

  arc> (type if)
  Error: "reference to undefined identifier: _if"

.

-----

1 point by mecon 5904 days ago | link

That's what i meant.

-----

1 point by zxquarx 5904 days ago | link

If can be implemented as a primitive function instead of a special form given the fn operator. It could take three arguments: a condition, a then function, and an else function and then call the appropriate function. An example implementation is:

(def if2 (cond then else) (if cond (then) (else)))

If2 would be given as a primitive function and its implementation would be hidden like that of cons is. Given access to if2, a basic if construct is:

(mac basic-if (cond then (o else)) `(if2 ,cond (fn () ,then) (fn () ,else)))

This would make code walkers easier because they wouldn't have to know about as many special forms.

-----

1 point by mecon 5904 days ago | link

What I meant is to the user it of the code it should not be noticeable that the form that there using is a special form or a macro. I was thinking of a tag for special forms called sf. so if would return '#(tagged sf if)

-----

1 point by cooldude127 5906 days ago | link

how are they different now in any significant way?

-----

3 points by absz 5906 days ago | link

They're different because they don't actually exist. Observe:

  arc> def
  #3(tagged mac #<procedure>)
  arc> fn
  Error: "reference to undefined identifier: _fn"
Since def is a macro, we can use it anywhere we like. But since fn is not, we can only use it in the head of a list, and it can't be overridden. fn, if, etc. should be first class: if not macros, then (type fn) should be 'prim or some such thing.

-----