Last active
August 29, 2015 14:21
-
-
Save basp1/7f42fbe22372b41309af to your computer and use it in GitHub Desktop.
dummy key-value list in J language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cocurrent 'H' | |
fst =: [: > 0&{ | |
snd =: [: > 1&{ | |
nop =: ''"_ | |
pos =: 1: i.~ [: ; (([: # ]) = [: +/ (] = [: fst [) :: 0:) each | |
add =: ;~ | |
unsafe_get =: [: snd ([: > [) {~ pos | |
get =: (unsafe_get <) :: nop | |
unsafe_set =: 4 : '(<y) (x pos <fst y) } x' | |
set =: unsafe_set :: add | |
cocurrent 'base' | |
NB. usage example | |
NB. h =: ('two' ; 2) ; ('zero' ; 0) ; (<'one' ; 1) | |
NB. h get 'one' | |
NB. 1 | |
NB. $h =: h set ('one';111) | |
NB. 3 | |
NB. h get 'one' | |
NB. 111 | |
NB. $h =: h set ('five';5) | |
NB. 4 | |
NB. h get 'five' | |
NB. 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment