Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 4474 days ago | link | parent

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.