Skip to content

Instantly share code, notes, and snippets.

@basp1
Last active August 29, 2015 14:21
Show Gist options
  • Save basp1/7f42fbe22372b41309af to your computer and use it in GitHub Desktop.
Save basp1/7f42fbe22372b41309af to your computer and use it in GitHub Desktop.
dummy key-value list in J language
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