Paul Gauthier asked:
> How can I know is a potential new symbol exist without
> creating it as a symbol ?
Performance questions aside, this works:
symcut =. ]`((<@#~ [: +./\. ' '&~:)"1)`(<;._1)@.([: (*>:)/ 1 2 >
L. , [EMAIL PROTECTED])
allsyms =. 5 s: _6 s: [: i. 0 s: 0:
syme =: (symcut e. allsyms) f.
For example:
syme <'bob'
0
s:<'bob'
`bob
syme <'bob'
1
syme ' now is the time'
0 0 0 0
s: ' now time'
`now `time
syme ' now is the time'
1 0 0 1
A more efficient implementation would avoid manifesting the entire symbol
table, but that would require significant research.
I don't feel the inclination at the moment, but if I did, I'd start with
http://www.jsoftware.com/help/dictionary/dsco.htm (to try
to deduce what how s: is implemented under the covers), http://www.google.com
(to find literature relevant to the inferred
algorithm) and http://www.jsoftware.com/jwiki/Essays/Huffman_Coding (to
understand how "trees" can be efficiently decoded with J).
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm