Arc Forumnew | comments | leaders | submitlogin
Two Design Questions About the Arc Language
2 points by TMO 4475 days ago | 2 comments
(1) PG mentions that `=' and `def' are two functions that don't evaluate all of their arguments. However, I don't think this needs to be the case for `=' and `def'. You could have

    (= 'foo 13)

    (def 'average '(x y)
        '(/ (+ x y) 2))
Is there a deeper reason for these irregularities, or is it just convenience?

(2) Why are lists compared via `iso' but strings are compared via `is'? Is it because strings are a symbol but lists aren't?



2 points by rocketnia 4474 days ago | link

Both '= and 'def can modify a variable in the caller's local scope. This is something a normal function can't do.

  (def my-len (lst)
    
    ; Introduce a local variable `n'.
    (let n 0
      
      (each element lst
        
        ; Modify that variable.
        (= n (+ 1 n)))
      
      n))
(Technically 'def only seems to be intended for the global scope. It prints a warning when the global variable is already bound, even if it actually modifies a local variable.)

---

"Is there a deeper reason for these irregularities, or is it just convenience?"

The syntax of languages like Arc, Lisp and Scheme is actually a bit more irregular than it looks: The code (a b c) usually means to do a function call, but this isn't true if "a" is the name of a special form or a macro. Special forms are how the language provides structured syntaxes other than function calls. Macros are user-defined special-form-like syntaxes that specify a way to translate ("macroexpand") their syntax into some already-supported code.

In Arc, both '= and 'def are macros provided with the language. They act as shorthand for using Arc's 'assign special form.

Kernel is a different kind of language. It goes back to lisp's roots a little, and lets users define syntaxes based on a way to interpret them at run time. Since the user can write their interpretation code however they want to, it's challenging to predict what these programs will do until they execute, which is why nobody (I think) has managed to write a good optimizing compiler for Kernel.

---

"Why are lists compared via `iso' but strings are compared via `is'?"

This is a very irregular part of Arc. You can compare lists using either operator, but 'iso does a deep comparison and 'is compares by reference. However, 'is actually special-cases strings and compares them by their contents, just like 'iso.

I think this choice was made because strings aren't usually modified. Arc lets you mutate a string if you really want to, but it's not a very commonly used feature.

---

"Is it because strings are a symbol but lists aren't?"

Technically, string and symbol are separate data types.

Technically, the empty list (nil) is a symbol. :)

If your point is that Arc's strings are interned like symbols, that's probably not true, since they're mutable. It's really an awkward special case in the language.

-----

2 points by akkartik 4475 days ago | link

(1) Yes this has occurred to me as well. I think it's pretty much just convenience. Though languages like Kernel and even Common Lisp (with constant need to quote or function-quote) reduce that inconvenience anyway.

Even if you choose to quote names in definers, you still need some irregularity in evaluation policies to build short-circuiting or/and.

(2) Arc is built on racket, and strings in racket (and other schemes?) are interned and so fast to compare just by their address. Lisp choose not to intern strings.

I tend to avoid these complexities and just use 'iso' everywhere. (My language has only an equivalent of iso: https://github.com/akkartik/wart/blob/955497c1ca/045check.wa...)

Past discussions: http://arclanguage.org/item?id=248, http://www.arclanguage.org/item?id=16304

-----