| kind | = | "Dict" |
A dictionary is a collection of mappings from one object to another object. The default Dict implementation will use hashing for this.
- +(...)
- ==(other)
- ===(other)
- ?&(...)
- ?|(...)
- [](...)
- []=(key, value)
- addKeysAndValues(keys, values)
- at(key)
- each([indexOrArgOrCode] nil, [argOrCode] nil, [code] nil)
- empty?()
- hash()
- inspect()
- key?(key)
- keys()
- merge(+pairsAndDicts, +:keywordPairs)
- mergeWith(...)
- notice()
- seq()
- size()
- withDefault(defaultValue)
nil
[ show source ]
method(other,
if(self same?(
{}),
Reflector other:mimics?(cell(:other),
{}),
bind(rescue(Condition Error, fn(c, false)),
self ==(
other))))
if this dict is non-empty, returns the result of evaluating the argument, otherwise returns the dict
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
unless(empty?,
call argAt(0),
self),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
if this dict is empty, returns the result of evaluating the argument, otherwise returns the dict
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
if(empty?,
call argAt(0),
self),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
takes two arguments, the key of the element to set and the value to set it too. returns the value set
zips the keys and the values together into this dict. note that neither keys nor values need to be lists. you can use anything that is iterable with index.
[ show source ]
method(keys, values,
keys each(i, k,
self [](k) = values [](i))
self)
takes one argument, the key of the element to return. if the key doesn't map to anything in the dict, returns the default value
takes either one or two or three arguments. if one argument is given, it should be a message chain that will be sent to each object in the dict. the result will be thrown away. if two arguments are given, the first is an unevaluated name that will be set to each of the entries in the dict in succession, and then the second argument will be evaluated in a scope with that argument in it. if three arguments is given, the first one is an unevaluated name that will be set to the index of each element, and the other two arguments are the name of the argument for the value, and the actual code. the code will evaluate in a lexical context, and if the argument name is available outside the context, it will be shadowed. the method will return the dict. the entries yielded will be mimics of Pair.
creates a new Dict from the arguments provided, combined with the values in the receiver. the arguments provided will override those in the receiver. the rules for arguments are the same as for dict, except that dicts can also be provided. all positional arguments will be added before the keyword arguments.
merges this dictionary with the first argument using different strategies defined by the second to fourth arguments
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
other = call argAt(
0)
self merge(other),
argCount ==(
2),
other = call argAt(
0)
theCode = call arguments [](
1)
theCode = theCode deepCopy
rhsName = genSym
theCode last <<(message(rhsName))
combined = {}
other each(kv,
if(self key?(kv key),
call ground cell(rhsName) = kv value
combined [](kv key) = theCode evaluateOn(call ground, self [](kv key)),
combined [](kv key) = kv value))
self merge(combined),
argCount ==(
3),
other = call argAt(
0)
lhsName = call arguments [](
1)
theCode = call arguments [](
2)
theCode = theCode deepCopy
rhsName = genSym
theCode last <<(message(rhsName))
combined = {}
other each(kv,
if(self key?(kv key),
call ground cell(lhsName) = self [](kv key)
call ground cell(rhsName) = kv value
combined [](kv key) = theCode evaluateOn(call ground),
combined [](kv key) = kv value))
self merge(combined),
argCount ==(
4),
other = call argAt(
0)
lhsName = call arguments [](
1)
rhsName = call arguments [](
2)
theCode = call arguments [](
3)
lexicalCode = LexicalBlock createFrom(list(lhsName, rhsName, theCode), call ground)
combined = {}
other each(kv,
if(self key?(kv key),
combined [](kv key) = lexicalCode(self [](kv key), kv value),
combined [](kv key) = kv value))
self merge(combined)
,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)