Class MultiFn<T extends ACell>

All Implemented Interfaces:
IValidated, IWriteable, IFn<T>

public class MultiFn<T extends ACell> extends AClosure<T>
  • Method Details

    • create

      public static <R extends ACell> MultiFn<R> create(AVector<AClosure<R>> fns)
    • isCanonical

      public boolean isCanonical()
      Description copied from class: ACell
      Returns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.
      Specified by:
      isCanonical in class ACell
      Returns:
      true if the object is in canonical format, false otherwise
    • toCanonical

      public MultiFn<T> toCanonical()
      Description copied from class: ACell
      Converts this Cell to its canonical version. Returns this if already canonical
      Specified by:
      toCanonical in class ACell
      Returns:
      Canonical version of Cell
    • print

      public void print(StringBuilder sb)
      Description copied from class: AObject
      Prints this Object to a readable String Representation
      Specified by:
      print in class AObject
      Parameters:
      sb - StringBuilder to append to
    • printInternal

      public void printInternal(StringBuilder sb)
      Description copied from class: AClosure
      Print the "internal" representation of a closure e.g. "[x] 1", excluding the 'fn' symbol.
      Specified by:
      printInternal in class AClosure<T extends ACell>
      Parameters:
      sb - StringBuilder to print to
    • invoke

      public Context<T> invoke(Context<ACell> context, ACell[] args)
      Description copied from interface: IFn
      Invoke this function in the given context.
      Specified by:
      invoke in interface IFn<T extends ACell>
      Specified by:
      invoke in class AFn<T extends ACell>
      Parameters:
      context - Context in which the function is to be executed
      args - Arguments to the function
      Returns:
      Context containing result of function invocation, or an exceptional value
    • hasArity

      public boolean hasArity(int n)
      Description copied from class: AFn
      Tests if this function supports the given arity.
      Specified by:
      hasArity in class AFn<T extends ACell>
      Parameters:
      n - Arity to check
      Returns:
      true if function supports the given arity, false otherwise
    • updateRefs

      public AFn<T> updateRefs(IRefFunction func)
      Description copied from class: ACell
      Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.
      Specified by:
      updateRefs in class AFn<T extends ACell>
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • validateCell

      public void validateCell() throws InvalidDataException
      Description copied from class: ACell
      Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.
      Specified by:
      validateCell in class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, excluding the tag byte
      Specified by:
      encodeRaw in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • read

      public static <T extends ACell> MultiFn<T> read(ByteBuffer bb) throws BadFormatException, BufferUnderflowException
      Throws:
      BadFormatException
      BufferUnderflowException
    • estimatedEncodingSize

      public int estimatedEncodingSize()
      Description copied from interface: IWriteable
      Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.
      Returns:
      The estimated size for the binary representation of this object.
    • getRefCount

      public int getRefCount()
      Description copied from class: ACell
      Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance. Contained Refs may be either external or embedded.
      Specified by:
      getRefCount in class ACell
      Returns:
      The number of Refs in this Cell
    • getRef

      public <R extends ACell> Ref<R> getRef(int i)
      Description copied from class: ACell
      Gets a numbered child Ref from within this Cell.
      Overrides:
      getRef in class ACell
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      i - Index of ref to get
      Returns:
      The Ref at the specified index
    • withEnvironment

      public <F extends AClosure<T>> F withEnvironment(AVector<ACell> env)
      Description copied from class: AClosure
      Produces an copy of this closure with the specified environment
      Specified by:
      withEnvironment in class AClosure<T extends ACell>
      Parameters:
      env - New lexical environment to use for this closure
      Returns:
      Closure updated with new lexical environment