Algebraic data types: Difference between revisions

m
Line 209:
''Symbols are a data type and are created by the verb s:. Symbols provide a mechanism for searching, sorting, and comparisons more efficient than alternative mechanisms such as boxed strings. Structural, selection, and relational verbs work on symbols. Arithmetic verbs do not work on symbols.''
 
The following code provides dictionary functionality using a red-black tree written in J without symbols.
 
<lang J>
Line 413:
load'rb.ijs'
NB. populate dictionary in random order with 999 key value pairs
insert@:(; 6j1&":)"0@:?~ 999
find 'the' NB. 'the' has no entry.
find 239 NB. entry 239 has the anticipated formatted string value.
Line 419:
find 823823 NB. also no such entry
NB.
NB. tree passes the "no consecutive red" and "same number of black"
check'' NB. nodes to (and including) NULL leaves.
check''
</lang>
 
Anonymous user