Arc Forumnew | comments | leaders | submitlogin
Arc History: use of exclamation ssyntax
5 points by akkartik 2506 days ago | 2 comments
I've been looking for any description of ssyntax that explains why we use a!b to mean (a 'b). Anybody know what the earliest mention of this is? I can't see it anywhere in the sources, or in pg's submissions. So I'm not sure how I even know this :)


5 points by zck 2506 days ago | link

I'm not sure where I read this, but the explanation is this:

Using this obj:

  arc> (= h (obj 1 2 three 4))
  #hash((1 . 2) (three . 4))
We can access the key 1 with dot ssyntax:

  arc> h.1
  2
If we have a variable bound to 'three, we can use it the same way:

  arc> (let val 'three h.val)
  4
But if we don't, and want to use the quoted literal 'three with ssyntax, we can't, because it errors:

  arc> h.'three
  Error: "Bad ssyntax h."
  arc> three
So the ssyntax for this takes the two characters that don't map cleanly (the .' in the middle of h.'three), and pushes them into the closest character. .' becomes !

  arc> h!three
  4
Looking around, I can't find where I read this either. I'm 90% sure this came from pg, and not from my brain, but that is distinctly not 100%.

-----

4 points by shader 2506 days ago | link

I'm having a hard time finding any documentation on ssyntax either. Must have been in some early forum posts... But your understanding is the same as mine.

For a little more background, the "." symbol is traditional Lisp syntax for a single cons cell. So (1 . 2) is a cons cell with car containing 1 and cdr containing 2. This is in contrast to the list '(1 2), which expands to two cons cells: (1 . (2 . nil)).

Cons cell notation is often used for pairs, such as k/v pairs in a hash table, since you don't need the ability to append additional content.

pg added "a.b" as "symbol syntax" to arc to provide shorthand for (a b), which is a very common pattern - calling a single argument function, looking something up in a table, etc. Furthermore, it chains, so "a.b.c" expands to ((a b) c) - the pattern you would want if you were going to look something up in a nested set of objects.

And as zck points out, symbols (quoted names) are very common keys for object, since they are perfect for literal names. In fact, that's precisely how templates are used to make something analogous to classes in arc.

https://arclanguage.github.io/ref/template.html

(and yes, you two probably know this, but hopefully it's useful for somebody)

I'll keep looking for explanations of ssyntax though.

-----