[Jprogramming] Symbol exist ?

Dan Bron j at bron.us
Sat Sep 29 02:43:37 HKT 2007


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. , #@$)
	   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



More information about the Programming mailing list