Go to the first, previous, next, last section, table of contents.


|ged

Function: |ged do{ [] key deflt -> [] val }
file: job.t
package: muf
status: alpha

Given key default value deflt, and a block interpreted as keyval pairs, |ged (GEt with Default) returns the value corresponding to key in the block, if present, else dflt.

[   :a 1   :b 2   :c 3   |
Stack: [ :a 1 :b 2 :c 3 |
:a 13 |ged
Stack: [ :a 1 :b 2 :c 3 | 1
pop :d 13 |ged
Stack: [ :a 1 :b 2 :c 3 | 13

This function is intended for functions which take a block of keyword-labelled arguments, some of which may be optionally omitted and which default to non-nil values:

: fn { [] -> }
   :key0 deflt0 |ged -> val0
   :key1 deflt1 |ged -> val1
   :key2 deflt2 |ged -> val2
   ...
   :keyN defltN |ged -> valN
   ]pop
   ( Stuff depending on val0..valN. )
;

Keywords are the recommended type of key, but any datatype may be used.

This type of parameter passing is not suitable for simple, efficiency-critical, commonly used functions, but is very suitable for obscure functions which take many parameters, some of little interest to many users, and especially if you'd like to maintain the option to add more parameters in future without breaking existing code.

See section |gep. See section |get. See section |dup. See section |dupNth.


Go to the first, previous, next, last section, table of contents.