Arc Forumnew | comments | leaders | submitlogin
Lists as hash keys
2 points by ekiru 5837 days ago | 2 comments
How can one use a list as a key to a hash? I'm new to arc, and I'm working on an implementation of multimethods(I'm aware that there is already one on Anarki, but I thought it would be an interesting thing to do). My multiple dispatch idea was to use a table with lists of argument types as the key. However, I can't figure out how to get using lists as hash keys to work.

For example:

(= foo (obj '(int int) +))

(foo '(int int))

returns nil. I want it to return +. Is there any way to make that happen with Arc hash tables?



2 points by CatDancer 5836 days ago | link

obj quotes your key arguments for you (that's the job of obj), so what you want is:

  arc> (= foo (obj (int int) +))
  #hash(((int int . nil) . #<procedure:...t/git/arc/ac.scm:602:9>))
  arc> (foo '(int int))
  #<procedure:...t/git/arc/ac.scm:602:9>
Saying (obj '(int int) ...) will use (quote (int int)) as the key.

Also, there is a bug in arc2 with using lists as keys in a table, to be fixed in the next Arc release. (See http://arclanguage.org/item?id=9151)

-----

1 point by pg 5836 days ago | link

This is a bug that's fixed in the next release.

-----