← Back to context

Comment by DeusExMachina

15 years ago

Does anybody care to explain the strange indentation I see in the Arc code? I know Lisp a little (mostly Clojure), but I don't get the indentation of the code at the bottom of the algorithm where it looks like it's branching in two parts. Is this peculiar to Arc? Or to other Lisps as well?

That's because of the way Arc does if-expressions. In Scheme and Common Lisp, you have two conditional forms: 'if and 'cond. 'if takes three arguments (or two, with an implied nil, in CL), and is analogous to an if-then-else in other languages:

    > (if #t 'then 'else)
    then
    > (if #f 'then 'else)
    else

'cond, in contrast, takes as many branches as you like, but they're parenthesized like so:

    > (cond (#f 'a) 
            (#t (display "I can have a body here!\n")
                'b)
            (#t 'c))
    I can have a body here!
    b

In arc, there's just 'if, which is like 'cond with a lot of implicit parenthesization and else-branches:

    arc> (if t 'then 'else)
    then
    arc> (if nil 'then)         ; if no else-branch is given, nil is implied
    nil
    arc> (if nil 'a
             t   (do (prn "'do is like Scheme's 'begin or CL's 'progn.")
                     'b)
             'else)
    'do is like Scheme's 'begin or CL's 'progn.
    b

I've barely looked at Arc[1] but as far as I remember, the if macro/special form allows an arbitrary number of argument forms, a bit like a combination of Clojure/CL's if and cond:

  (if
    cond1  expr1
    cond2  expr2
    ..     ..
    condN  exprN
           else-expr)

With an even number of arguments, there is no else-expr (the same as CL/Clojure cond).

The indentation is probably to distinguish between condition and conditional expression - the second column is what could be evaluated and returned from the whole expression.

[1] I too use Clojure

Doesn't stray that much from clojure, so I think it's a lisp thing. To keep bindings in clojure with different length names more readable, people tend to indent like this:

    (let [really-long-name l
          score            (get-score x)
          position         (get-pos) x)
          test             test]
         (...
                ....)))))

Sort of the same effect in the arc snippet in OP.