Arc Forumnew | comments | leaders | submitlogin
1 point by almkglor 6037 days ago | link | parent

You know, what I'm really thinking is that placing the annotations in the argslist looks horrible. The body itself is not bad, but the argslist is really, really horrible.

How about this instead:

  (mac while (cond . body)
    (w/hof ( () ,cond
             () ,@body)
      ((afn ()
         (when (cond)
           (body)
           (self))))))
Where w/hof expands to:

  (do
    ; inefficient since we set it everytime the macro is called, but...
    (set gs42 ; set so it won't say "redefined"
      (fn (cond body)
        ((afn ()
           (when (cond)
             (body)
             (self))))))
    `(gs42 (fn () ,cond) (fn () ,@body)))
The above strikes me as being easier to implement.

Of course unfortunately it won't work properly for variable capture.

Edit: Hmm, maybe it'll actually be able to support some variable capture:

  (mac awhile (v cond . body)
    (w/hof ( ()   ,cond
             (,v) ,@body)
      ((afn ()
         (let tmp (cond)
           (when tmp
             (body tmp)
             (self)))))))
HOF-style anaphora:

  (mac afn (params . body)
    (w/hof ( (self ,@params) ,@body )
      (let self nil
        (= self
           (fn rest
             (apply body self rest)))
        self)))


1 point by rkts 6037 days ago | link

Well, we can cut down on the parentheses in the parameter list. This looks ok to me:

  (defho while ([test] . [f])
    ...)

  (defho awhen (x . [f it])
    ...)
As to w/hof, it may be easier to implement, but it seems kind of hard to use.

-----

1 point by almkglor 6037 days ago | link

> As to w/hof, it may be easier to implement, but it seems kind of hard to use.

Then perhaps you can define 'defho in terms of 'mac and 'w/hof, maybe? The Arc solution: throw more macros at it.

Regarding (x . [f it]) :

In canonical arc2, [f it] is (fn (_) (f it)), so (x . [f it]) becomes (x fn (_) (f it)) . In Anarki, [f it] is (make-br-fn (f it)), so (x . [f it]) becomes (x make-br-fn (f it))

This makes the use of [] problematical.

'w/hof is trivially implementable, 'defho much less so due to the syntax.

w/hof is also more general, at the expense of being more talkative.

In fact it might be better to do things this way:

  (mac while (cond . body)
    (w/hof (cond (fn () ,cond)
            body (fn () ,@body))
      ((afn ()
         (when (cond)
           (body)
           (self))))))
This allows a few shortcuts in anaphora:

  (mac aif (cond then (o else))
    (w/hof (cond ,cond
            then (fn (it) ,then)
            else (fn () ,else))
      (if cond
          (then cond)
          (else))))

-----

1 point by rkts 6036 days ago | link

> 'w/hof is trivially implementable, 'defho much less so due to the syntax.

Oh. I haven't bothered to learn how to hack the syntax in Arc, so I'll take your word on that.

-----