1. load
Searches dictionary stack for a key and returns its associated value.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
0 |
|
1.3. Description
load searches for key in each dictionary on the dictionary stack, starting with the topmost (current) dictionary.
-
If found: pushes the associated value
-
If not found: executes [
undefined] error
load looks up keys the same way the interpreter looks up executable names, but always pushes the value (never executes it).
1.5. Examples
/pi 3.14159 def
/pi load % Returns 3.14159
/avg { add 2 div } def
/avg load % Returns { add 2 div }, doesn't execute
/add load % Pushes add operator
add % Executes add operator
1.6. Common Use Cases
1.7. Common Pitfalls
Always Pushes Value - load never executes values, even executable ones.
|
/proc { 1 2 add } def
proc % Executes, pushes 3
/proc load % Pushes { 1 2 add }
Undefined Keys - If key not found, [undefined] error occurs.
|
/nonexistent load % Error: undefined
| Use where First - Check if key exists before loading: |
/key where {
/key load
} {
% Handle missing key
} ifelse
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Dictionary on stack has no-access attribute |
[ |
No operand on stack |
[ |
Operand wrong type |
[ |
Key not found in any dictionary on stack |
1.9. Implementation Notes
-
Searches dictionary stack top-down
-
Same lookup mechanism as interpreter uses
-
Fast operation (hash table lookup)
-
Does not create new objects (returns actual value)