Arc Forumnew | comments | leaders | submitlogin
2 points by conanite 5487 days ago | link | parent

Could you show us an example of code that calls "while"? I'm not sure it's quite exactly correct to say a velcro can take "unevaluated code" as an argument; it looks more like it takes a closure (you seem to say so yourself); and perhaps Eight syntax is such that closures are completely transparent and require no extra decoration. The magic of course is dealing with variable capture.

For example, an Eight-like 'while in arc could look like this:

  (def while (test body)
    (when (test) (body) (while test body)))
invoked thusly displays 10 9 8 ... 1:

  (let n 10
    (while (fn () (> n 0))
           (fn () (prn n) (-- n))))
I'm guessing Eight allows you write the above without the (fn () ), like this:

  (let n 10
    (while (> n 0) (prn n) (-- n)))
Am I close? I like the idea of a syntax for making closures more transparent; arc's [ ... _ ...] helps, as do macros.

As for the question of whether Eight is compilable, I don't see why not; an arc compiler needs to look at expressions to see if the car refers to a macro; an Eight compiler could look at the car of each expression to see if it refers to a "velcro", in which case it should wrap the relevant invocation parameters in a closure-creation instruction, instead of wrapping them in a nested invocation instruction.



1 point by diiq 5487 days ago | link

Right, so the major difference between a traditional closure and a closure in Eight is that a closure in Eight still looks and acts just like a list. I can do this:

     (def foo ('bar)
        (print (car bar)))

     (foo (+ 2 3))
And what would be printed is:

+

Which is not useful, but it's how you'd expect a macro to work. But in Arc, once you've wrapped something in (fn) to make a closure, it becomes inaccessible; I can't do:

    (pr (car (fn () (+ 2 3))))
EDIT: I didn't answer the question.

    (set! a 10)
    (while (> a 3) (print "hello") (set! a (- a 1)))
Which outputs:

hellohellohellohellohellohellohello()

[Warning to those you want to try this in the Eight interpreter, - and + are not implemented yet, use 'minus' and 'plus']

-----