Arity provides information about the arguments needed to activate a value.

Mimics
Inactive cells
Active cells
Specs
Arity Arguments
Arity take:everything
  • - should be the arity for ... argumentsCode [ show source ]
    Arity fromArgumentsCode("...") should ==(Arity taking:everything) 
    
    
  • - should be an Arity [ show source ]
    Arity taking:everything should mimic(Arity) 
    
    
  • - should not equal taking:nothing [ show source ]
    Arity taking:everything should not ==(Arity taking:nothing) 
    
    
  • - should not equal Arity [ show source ]
    Arity taking:nothing should not ==(Arity) 
    
    
Arity take:nothing
  • - should be the arity for empty argumentsCode [ show source ]
    Arity fromArgumentsCode("") should ==(Arity taking:nothing) 
    
    
  • - should be an Arity [ show source ]
    Arity taking:nothing should mimic(Arity) 
    
    
  • - should not equal taking:everything [ show source ]
    Arity taking:nothing should not ==(Arity taking:everything) 
    
    
  • - should not equal Arity [ show source ]
    Arity taking:nothing should not ==(Arity) 
    
    
Inactive cells (details)
kind = "Arity"
taking:everything = Arity_0x11B0F38A
taking:nothing = Arity_0x7844F218
Active cells (details)
apply(...)

Invoke arguments with this message without evaluating them

macro(
  arguments(call message) 
  )
Arity apply
  • - should not evaluate by default [ show source ]
    o = Origin mimic do(m = method(@ evaled = true)) 
    a = Arity from(n) apply(m) 
    a should mimic(Arity Arguments) 
    o cell?(:evaled) should be false 
    a order should ==(0) 
    
    
applyOn(...)

First argument must be an evaluated value, rest is the message arguments. arguments will be evaluated on the first argument.

macro(
  on = call argAt(0) 
  msg = call arguments rest inject('(apply), m, a, m <<(a)) 
  arguments(msg, context: on) 
  )
Arity applyOn
  • - should evaluate by default [ show source ]
    o = Origin mimic do(m = method(@ evaled = true)) 
    a = Arity from(n) applyOn(o, m) 
    a should mimic(Arity Arguments) 
    o cell?(:evaled) should be true 
    a order should ==(0) 
    
    
arguments(message, context: nil, signalErrors: false)

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.

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 
  )
Arity arguments
  • - should not signal errors by default, but just collect argument info [ show source ]
    a = Arity from(n) arguments('(foo(*([](1, 2))))) 
    a should mimic(Arity Arguments) 
    a notSpreadable should not be empty 
    
    
  • - should signal error when given an splat argument and not evaluating [ show source ]
    fn(
      Arity from(n) arguments('(foo(*([](1, 2)))), signalErrors: true) 
      ) should signal(Condition Error Invocation NotSpreadable) 
    
    
  • - should evaluate arguments if given a context [ show source ]
    o = Origin mimic do(m = method(22)) 
    a = Arity from(n) arguments('(foo(m)), context: o) 
    a should mimic(Arity Arguments) 
    a positional should ==([](22)) 
    
    
asText()

returns the text representation of this arity

Arity asText
  • - should return empty text for taking:nothing [ show source ]
    Arity taking:nothing asText should ==("")
    
  • - should return ... for taking:everything [ show source ]
    Arity taking:everything asText should ==("...")
    
  • - should return the argumentsCode for a simple arg [ show source ]
    Arity from(one) asText should ==("one") 
    
    
  • - should return the argumentsCode for a simple keyword [ show source ]
    Arity from(two: 2) asText should ==("two: 2") 
    
    
  • - should return the argumentsCode having rest arg [ show source ]
    Arity from(one, two: 2, +(rest)) asText should ==("one, two: 2, +rest") 
    
    
  • - should return the argumentsCode having krest arg [ show source ]
    Arity from(one, two: 2, +(rest), +:(krest)) asText should ==("one, two: 2, +rest, +:krest") 
    
    
from(+[arguments])

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.

Arity from
  • - should return an empty arity if given no arguments [ show source ]
    Arity from should ==(Arity taking:nothing) 
    
    
  • - should return the arity for the given arguments definition [ show source ]
    a = Arity from(a, b 0, c:, +(rest), +:(krest)) 
    a should mimic(Arity) 
    a should not ==(Arity taking:nothing) 
    a should not ==(Arity taking:everything) 
    
    
fromArgumentsCode(argumentsCode)

nil

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)) 
  )
Arity fromArgumentsCode
  • - should return an empty arity if given nil [ show source ]
    Arity fromArgumentsCode(nil) should ==(Arity taking:nothing) 
    
    
  • - should return an empty arity if given an empty text [ show source ]
    Arity fromArgumentsCode("") should ==(Arity taking:nothing) 
    
    
  • - should return taking:everything for ... [ show source ]
    Arity fromArgumentsCode("...") should ==(Arity taking:everything) 
    
    
  • - should return the arity for the given argumentsCode [ show source ]
    a = Arity fromArgumentsCode("a, b 0, c:, +rest, +:krest") 
    a should mimic(Arity) 
    a should not ==(Arity) 
    a should not ==(Arity taking:nothing) 
    a should not ==(Arity taking:everything) 
    
    
  • - should raise an error when given an invalid argumentsCode [ show source ]
    fn(Arity fromArgumentsCode(")") should signal(Condition Error)) 
    fn(Arity fromArgumentsCode("=>") should signal(Condition Error)) 
    
    
keywords()

returns the names for keyword arguments

Arity keywords
  • - should return empty for taking:nothing [ show source ]
    Arity taking:nothing keywords should be empty 
    
    
  • - should return empty for taking:everything [ show source ]
    Arity taking:everything keywords should be empty 
    
    
  • - should return keyword argument names [ show source ]
    Arity from(a:, b: c, +:(d)) keywords should ==([](:a, :b)) 
    
    
krest()

returns the symbol name for the krest argument.

Arity krest
  • - should return nil for taking:nothing [ show source ]
    Arity taking:nothing krest should be nil
    
  • - should return nil for taking:everything [ show source ]
    Arity taking:everything krest should be nil
    
  • - should return nil when not krest argument is present [ show source ]
    Arity from(foo) krest should be nil 
    
    
  • - should return the symbol name for the krest argument [ show source ]
    Arity from(foo, +:(bar)) krest should ==(:bar) 
    
    
max()

Return the maximum number of positional arguments. A negative value indicates rest positional arguments.

method(
  cond(takeNothing?, 0, 
    takeEverything?, -(1), 
    rest, -(1) *(positionals(true) length +(1)), 
    positionals(true) length) 
  )
Arity max
  • - should be 0 for taking:nothing [ show source ]
    Arity taking:nothing max should ==(0) 
    
    
  • - should be -1 for taking:everything [ show source ]
    Arity taking:everything max should ==(-(1)) 
    
    
  • - should return max number of required arguments [ show source ]
    Arity from(a, b) max should ==(2) 
    
    
  • - should return max number of required arguments including optionals [ show source ]
    Arity from(a, b, c 1) max should ==(3) 
    
    
  • - should return max number of required arguments including rest [ show source ]
    Arity from(a, b, c 1, +(d)) max should ==(-(4)) 
    
    
  • - should return negative when rest present [ show source ]
    Arity from(+(d)) max should ==(-(1)) 
    
    
min()

Return the minimun number of positional arguments

method(
  positionals(false) length)
Arity min
  • - should be 0 for taking:nothing [ show source ]
    Arity taking:nothing min should ==(0) 
    
    
  • - should be 0 for taking:everything [ show source ]
    Arity taking:everything min should ==(0) 
    
    
  • - should return minimum number of required arguments [ show source ]
    Arity from(a, b, c 1, +(d)) min should ==(2) 
    
    
optional()

Return the names of optional positional arguments.

method(
  positionals(true) -(positionals(false)))
positionals(includeOptionals true)

returns the names for positional arguments

Arity positionals
  • - should return empty for taking:nothing [ show source ]
    Arity taking:nothing positionals should be empty 
    
    
  • - should return empty for taking:everything [ show source ]
    Arity taking:everything positionals should be empty 
    
    
  • - should return positional argument names including optionals by default [ show source ]
    Arity from(a, b, c 1, +(d)) positionals should ==([](:a, :b, :c)) 
    
    
  • - should return positional argument names including optionals if given true [ show source ]
    Arity from(a, b, c 1, +(d)) positionals(true) should ==([](:a, :b, :c)) 
    
    
  • - should return positional argument names excluding optionals if given false [ show source ]
    Arity from(a, b, c 1, +(d)) positionals(false) should ==([](:a, :b)) 
    
    
required()

Return the names of required positional arguments.

method(
  positionals(false))
Arity required
  • - should return empty for taking:nothing [ show source ]
    Arity taking:nothing required should be empty 
    
    
  • - should return empty for taking:everything [ show source ]
    Arity taking:everything required should be empty 
    
    
  • - should return required positional names [ show source ]
    Arity from(a, b, c 1, +(d)) required should ==([](:a, :b)) 
    
    
rest()

returns the symbol name for the rest argument.

Arity rest
  • - should return nil for taking:nothing [ show source ]
    Arity taking:nothing rest should be nil
    
  • - should return nil for taking:everything [ show source ]
    Arity taking:everything rest should be nil
    
  • - should return nil when not rest argument is present [ show source ]
    Arity from(foo) rest should be nil 
    
    
  • - should return the symbol name for the rest argument [ show source ]
    Arity from(foo, +(bar)) rest should ==(:bar) 
    
    
satisfied?(...)

nil

macro(
  call resendToMethod(:apply) order ==(0))
Arity satisfied?
  • - should not evaluate by default [ show source ]
    o = Origin mimic do(m = method(@ evaled = true)) 
    Arity from(n) satisfied?(nono) should be true 
    o cell?(:evaled) should be false 
    
    
satisfiedOn?(...)

nil

macro(
  call resendToMethod(:applyOn) order ==(0))
Arity satisfiedOn?
  • - should evaluate by default [ show source ]
    o = Origin mimic do(m = method(@ evaled = true)) 
    Arity from(n) satisfiedOn?(o, m) should be true 
    o cell?(:evaled) should be true 
    
    
takeEverything?()

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

method(
  self ==(taking:everything))
Arity takeEverything?
  • - should be false for taking:nothing [ show source ]
    Arity taking:nothing should not takeEverything 
    
    
  • - should be true for taking:everything [ show source ]
    Arity taking:everything should takeEverything 
    
    
  • - should be false for arity taking arguments [ show source ]
    Arity from(a) should not takeEverything 
    
    
  • - should be false for arity taking rest arguments [ show source ]
    Arity from(+(a), +:(b)) should not takeEverything 
    
    
takeKeyword?(keyword)

nil

method(keyword, 
  if(krest, true, 
    keywords include?(keyword)))
Arity takeKeyword?
  • - should be false for taking:nothing [ show source ]
    Arity taking:nothing takeKeyword?(:foo) should be false 
    
    
  • - should be false for taking:everything [ show source ]
    Arity taking:nothing takeKeyword?(:foo) should be false 
    
    
  • - should be false for arity having no keywords [ show source ]
    Arity from(a, b 2) takeKeyword?(:foo) should be false 
    
    
  • - should be true for arity having the keyword [ show source ]
    Arity from(a, b 2, foo:) takeKeyword?(:foo) should be true 
    
    
  • - should be false for arity missing the keyword [ show source ]
    Arity from(a, b 2, bar:) takeKeyword?(:foo) should be false 
    
    
  • - should be false for arity taking krest [ show source ]
    Arity from(a, b 2, +:(bar)) takeKeyword?(:foo) should be true 
    
    
takeNothing?()

Return true if this arity takes nothing. For things that take no arguments at all.

method(
  self ==(taking:nothing))
Arity takeNothing?
  • - should be true for taking:nothing [ show source ]
    Arity taking:nothing should takeNothing 
    
    
  • - should be false for taking:everything [ show source ]
    Arity taking:everything should not takeNothing 
    
    
  • - should be false for arity taking arguments [ show source ]
    Arity from(a) should not takeNothing