Arc Forumnew | comments | leaders | submitlogin
1 point by stefano 5710 days ago | link | parent

I like the idea of using { and } for hash tables. But without taking {} (they could be useful in the future) we could use a syntax like #h(key val ...). E.g:

  #h(a 1 b 2)
instead of

  {a 1 b 2}


4 points by drcode 5710 days ago | link

In my own view, the payoff here isn't really enough relative to

  (obj a 1 b 2)

-----

3 points by Amferreira 5710 days ago | link

Yes, but then you can't print hash tables in a way that is also readable, and unambiguous with a list. Right now: arc> (= codes (obj "Boston" 'bos "San Francisco" 'sfo "Paris" 'cdg)) #hash(("Boston" . bos) ("Paris" . cdg) ("San Francisco" . sfo))

Could be: arc> (= codes {("Boston" 'bos) ("San Francisco" 'sfo) ("Paris" 'cdg)} {("Boston" 'bos) ("San Francisco" 'sfo) ("Paris" 'cdg)}

If the () are required or not is up for discussion, keys/values could be positional like obj.

Note that printing (obj a 1 b 2) as (obj a 1 b 2) is ambiguous with printing the list '(obj a 1 b 2)

-----

2 points by drcode 5710 days ago | link

I think you have a good point here. I'll have to think about this line of thinking some more.

-----

2 points by almkglor 5710 days ago | link

Doesn't mzscheme already properly support:

   #hash((a . 1) (b . 2))

?

-----

2 points by absz 5709 days ago | link

Yes, but Arc (or at least Anarki) does not:

  arc> #hash((a . 1) (b . 2))
  Error: "Type: unknown type #f"
We can, however, read it in, but this doesn't work either, since it creates immutable hash tables:

  arc> (= h (read "#hash((a . 1) (b . 2))"))
  #hash((b . 2) (a . 1))
  arc> h!b
  2
  arc> (= h!b 3)
  Error: "hash-table-put!: expects type <mutable hash-table> as 1st argument,
  given: #hash((b . 2) (a . 1)); other arguments were: b 3"
Fixing these would probably be worthwhile.

-----

1 point by stefano 5709 days ago | link

You're right! I didn't know it.

-----