Skip to content

Instantly share code, notes, and snippets.

@Ke-
Last active June 8, 2016 10:12
Show Gist options
  • Save Ke-/6bd80bf81517fe496920c268ffa63a91 to your computer and use it in GitHub Desktop.
Save Ke-/6bd80bf81517fe496920c268ffa63a91 to your computer and use it in GitHub Desktop.
// Thread objects to store data
! ::global_store_00->istype ? define global_store_00 => thread {parent map public oncreate => ..oncreate}
! ::global_store_01->istype ? define global_store_01 => thread {parent map public oncreate => ..oncreate}
! ::global_store_02->istype ? define global_store_02 => thread {parent map public oncreate => ..oncreate}
! ::global_store_03->istype ? define global_store_03 => thread {parent map public oncreate => ..oncreate}
! ::global_store_04->istype ? define global_store_04 => thread {parent map public oncreate => ..oncreate}
// Establish store to use
define global_store(name::string) => {
match(#name->hash->abs % 5) => {
case(0) return global_store_00
case(1) return global_store_01
case(2) return global_store_02
case(3) return global_store_03
case(4) return global_store_04
}
}
define global(name::string) => global_store(#name)->find(#name)
define global=(value::any,name::string) => global_store(#name)->insert(#name = #value)
define global(pair::pair) => global_store(#pair->name)->insert(#pair->name = #pair->value)
// Test it
/*
global('test1') = 'abc.1'
global('test2' = 'abc.2')
global('test1') '\n'
global('test2') '\n'
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment