June Kim wrote:
> Though symbols are implemented with hash tables
> internally, they can't function as a general dictionary.
Why not?
Here's an example of how I might implement a dictionary in J
using symbols:
coclass 'dictionary'
okchar=:~. (,toupper) '0123456789abcdefghijklmnopqrstuz'
ok=: ] [ [: assert [: *./ e.&okchar
intern=: [: ('z' , ok)&.> boxxopen
has=: _1 < [EMAIL PROTECTED]
set=: 4 :'(intern x)=: y'
get=: ".@>@intern
With this script loaded, I can do stuff like:
table=: conew 'dictionary'
has__table 'foo'
0
'foo' set__table i. 3
0 1 2
has__table 'foo'
1
get__table 'foo'
0 1 2
If you need a larger symbol domain, replace 'ok' with
a function which converts symbols to hexadecimal strings.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm