| kind | = | "Arity" |
Arity provides information about the arguments needed to activate a value.
- apply(...)
- applyOn(...)
- arguments(message, context: nil, signalErrors: false)
- asText()
- from(+[arguments])
- fromArgumentsCode(argumentsCode)
- keywords()
- krest()
- max()
- min()
- optional()
- positionals(includeOptionals true)
- required()
- rest()
- satisfied?(...)
- satisfiedOn?(...)
- takeEverything?()
- takeKeyword?(keyword)
- takeNothing?()
Invoke arguments with this message without evaluating them
[ show source ]
macro( arguments(call message) )
First argument must be an evaluated value, rest is the message arguments. arguments will be evaluated on the first argument.
[ show source ]
macro(
on = call argAt(0)
msg = call arguments rest inject('(apply), m, a, m <<(a))
arguments(msg, context: on)
)
Obtain arguments from message according to this arity. If a context is given, the arguments will be evaluated on context. This method returns an Arguments object, see its documentation for available cells. If the message arguments contain an splatted argument and no context is given, an Condition Error Invocation NotSpreadable condition will be signaled.
[ show source ]
method(message, context: nil, signalErrors: false,
req = required
o = Arguments mimic(message arguments)
o given = message arguments
arg = nil
signalError = fn(+(r), +:(k),
if(signalErrors,
error!(*(r), *(k), message: message, context: context,
receiver: self, given: arg, info: o)))
addKeyword = fn(key, value,
cond(
takeNothing?, o extraKeywords [](key) = value,
takeEverything?, o krest [](key) = value,
keywords include?(key), o keywords [](key) = value,
krest, o krest [](key) = value,
o extraKeywords [](key) = value))
addPositional = fn(value,
cond(
takeNothing?, o extraPositional <<(value),
takeEverything?, o rest <<(value),
o positional length <(positionals(true) length), o positional <<(value),
rest, o rest <<(value),
o extraPositional <<(value)))
message arguments each(arg,
cond(
arg keyword?,
name = :(arg name asText [](0 ..(-(2))))
arg = if(context, arg next evaluateOn(context), arg next)
addKeyword(name, arg),
arg name ==(:("*")) &&(arg arguments length ==(1)),
arg = arg arguments first
if(context,
arg = arg evaluateOn(context)
case(arg
List,
arg each(a, addPositional(a))
Dict,
arg each(p, addKeyword(p key, p value))
o notSpreadable <<(arg)
signalError(Condition Error Invocation NotSpreadable)),
o notSpreadable <<(arg)
signalError(Condition Error Invocation NotSpreadable)),
arg = if(context, arg evaluateOn(context), arg)
addPositional(arg)
))
if(o positional length <(min),
o missing = required [](o positional length ..(-(1)))
o order = -(1) *((o missing length))
signalError(Condition Error Invocation TooFewArguments, howMany: o missing length),
if((o extraPositional length) +((o extraKeywords size)) >(0),
o order = (o extraPositional length) +((o extraKeywords size))
if(o extraPositional empty?,
signalError(Condition Error Invocation MismatchedKeywords, howMany: o extraKeywords size),
signalError(Condition Error Invocation TooManyArguments, howMany: o order)),
o order = 0))
o
)
Create an Arity object from the given messages. The list of unevaluated messages given to this method will be used as if they were the arguments part of a DefaultMethod definition.
nil
[ show source ]
method(argumentsCode,
case(argumentsCode,
or(nil, ""), taking:nothing,
"...", taking:everything,
msg = Message fromText("from(#{argumentsCode})")
if(msg next, error!("Invalid argumentsCode: " +(argumentsCode)))
msg sendTo(self))
)
Return the maximum number of positional arguments. A negative value indicates rest positional arguments.
[ show source ]
method(
cond(takeNothing?, 0,
takeEverything?, -(1),
rest, -(1) *((positionals(true) length +(1))),
positionals(true) length)
)
Return the minimun number of positional arguments
[ show source ]
method( positionals(false) length)
Return the names of optional positional arguments.
[ show source ]
method( positionals(true) -(positionals(false)))
Return true if this arity takes everything. As is the case for macros or created from argumentsCode ... , it's also the arity needed to activate a non-activatable value
[ show source ]
method( self ==(taking:everything))
Return true if this arity takes nothing. For things that take no arguments at all.
[ show source ]
method( self ==(taking:nothing))