RosettaCodeData/Task/Associative-array-Creation/Phixmonti/associative-array-creation.phixmonti

35 lines
574 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
include ..\Utilitys.pmt
def getd /# dict key -- dict data #/
swap 1 get rot find nip
dup if
swap 2 get rot get nip
else
drop "Unfound"
endif
enddef
def setd /# dict ( key data ) -- dict #/
1 get var ikey
2 get var idata
drop
1 get ikey find var p drop
p if
2 get idata p set 2 set
else
2 get idata 0 put 2 set
1 get ikey 0 put 1 set
endif
enddef
( ( ) ( ) )
( 1 "one" ) setd
( "two" 2 ) setd
( PI PI ) setd
1 getd print nl
"two" getd print nl
PI getd tostr print nl
3 getd print