Jump to content

Associative array/Iteration: Difference between revisions

Line 2,579:
<lang Phixmonti>include ..\Utilitys.pmt
 
def getd /# dict key -- dict data #/
( ( ) ( ) ) var dictionary
dictionaryswap 1 get nip swaprot find nip
dup if
dictionaryswap 2 get nip swaprot get nip
else
drop "Unfound"
endif
enddef
 
 
def setd /# dict ( key data ) -- dict #/
def setd
1 get var ikey
2 get var idata
drop
dictionary 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
var dictionary
enddef
 
def getd /# key -- data #/
dictionary 1 get nip swap find nip
dup if
dictionary 2 get nip swap get nip
else
drop "Unfound"
endif
enddef
 
def pair /# dict n -- dict ( k d ) #/
1 over 2 tolist var ikey
2 swap 2 tolist var idata
dictionary ikey sget
swap idata sget niprot swap
2 tolist
enddef
 
def scandict /# dict n -- dict ( ) #/
var dictionaryn
dictionary 1 get len nip nip
for
pair
over 0 !=n if overn get nip endif
print nl
endfor
drop
enddef
 
def pairs /# dict -- dict ( ) #/
0 scandict
enddef
Line 2,635 ⟶ 2,634:
 
/# ---------- MAIN ---------- #/
 
( ( ) ( ) ) var dictionary
 
( "one" 1 ) setd
Line 2,642 ⟶ 2,643:
pairs nl
keys nl
values</lang>
</lang>
 
=={{header|PHP}}==
672

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.