Arc Forumnew | comments | leaders | submitlogin
Why "!"?
2 points by garply 5315 days ago | 8 comments
When getting hash vals, I find the "!" a bit harsh on the eyes. Could we possibly use "." instead? It appears "." has a different use, but I can't figure out what it is. E.g.,

(= a {a 1 b 3}) ; using aw's {} syntax for objs

a.a => nil

a.b => Error: "reference to undefined identifier: _b"

Could someone please enlighten me as to what the period is doing there?



5 points by garply 5314 days ago | link

Thanks for the responses guys! I get it now. Actually, it's kind of clever:

. + ' => !

I think I read somewhere that some old typewriters saved key space by using that eliminating the exclamation point and forcing typists to use that combo.

Still, it seems kind of hard for me to scan it as two separate components: my brain parses "foo!bar" quite differently than "foo.bar" - I guess it'll become more natural with time.

-----

5 points by evanrmurphy 5314 days ago | link

As the next installment in our "A confession of stupidity" series [1], I never realized that before. :) Turns out that superimposing chars on top of each other to make other chars is an addictive game, though. Here are a few I came up with:

  |S => $
  :, => ;
  ++++ or //= => #
  o/o => %
  ao or aO => @
  \S => &
  -x or -X => *
  |_ => L
  /-\ => A
  |3 => B
  ][ => I
  |-| => H
  C- => G
  |= => F
  |^^| => M or m
  |< => K
  |? or |> => P
  |o => b
  |) => D
  -/_ => z
  O, => Q
  -| => +
  |\| => N
  bP => B
Unfortunately, few if any of these could be useful for Arc.

  .' => !
is really kind of a gem.

[1] http://arclanguage.org/item?id=11556

-----

3 points by shader 5312 days ago | link

I wish we weren't so dependent on Scheme's reader, so that ssyntaxes could be "first class".

I.e., what if instead of being forced to use foo!bar, you could use foo.'bar .

Right now, you can't do that, because scheme's reader turns it into two expressions "foo." and 'bar, before it even gets sent to the ssyntax parser. If we had our own reader, we could use syntax in more situations, like foo."bar", foo.(bar), etc.

I wonder if aw's parser combinator library would be good for that, or do we need to write something specifically for this?

-----

1 point by aw 5312 days ago | link

That's precisely the purpose of my Scheme/Arc parser (scheme-parser0.arc at http://awwx.ws/hundred-year-parser) -- use that as a starting point, and implement whatever parser you want. It doesn't handle incremental parsing yet though, so it isn't a drop in replacement for "read" now.

-----

2 points by evanrmurphy 5315 days ago | link

In your table, both the keys are symbols, which need the quote for reference. You can use dot ssyntax to retrieve vals for any keys that are numbers (since numbers don't need quote):

  arc> (= a (obj 1 "one" 2 "two"))
  #hash((1 . "one") (2 . "two"))
  arc> a.1
  "one"
  arc> a.2
  "two"
For keys of other types that don't need quote, like char and string, you can't use dot ssyntax directly:

  arc> (= a (obj #\a "char a" "b" "string b"))
  #hash((#\a . "char a") ("b" . "string b"))
  arc> a.#\a
  Error: "UNKNOWN::0: read: bad syntax `#a'"
  arc> a."b"
  Error: "Bad ssyntax a."
  arc> "b"

But you can use it if you go through a variable:

  arc> (let ch #\a
         a.ch)
  "char a"
  arc> (let s "b"
         a.s)
  "string b"

-----

3 points by akkartik 5315 days ago | link

  a.b <=> (a b)
  a!b <=> (a 'b)
I'm not sure how a.a is working for you above.

  (= a (obj a 1 b 3))
  a.a ; Error: "reference to undefined identifier: _a"

-----

3 points by evanrmurphy 5315 days ago | link

I get the same result as garply:

  arc> (= a (obj a 1 b 3))
  #hash((b . 3) (a . 1))
  arc> a.a
  nil
For me, a.x appears to return nil for any bound x, else it returns the error:

  arc> a.x
  Error: "reference to undefined identifier: _x"
  arc> (let x 'foo
         a.x)
  nil
Maybe an Anarki patch is responsible for the difference?

-----

1 point by thaddeus 5315 days ago | link

The period is resolving a bound variable. In your first case a.a happens to work since 'a happens to already be bound.

To use the period for b:

  arc> (let x 'b a.x)
  1
[edit - oops I see there's already a good reply]

-----