Class Let<T extends ACell>

Type Parameters:
T - Result type of Op
All Implemented Interfaces:
IValidated, IWriteable

public class Let<T extends ACell> extends AMultiOp<T>
Op for executing a body after lexically binding one or more symbols. Can represent (let [..] ..) and (loop [..] ..). Loop version can act as a target for (recur ...) expressions.
  • Field Details

    • symbols

      protected final AVector<ACell> symbols
      Vector of binding forms. Can be destructuring forms
    • bindingCount

      protected final int bindingCount
    • isLoop

      protected final boolean isLoop
  • Constructor Details

  • Method Details

    • create

      public static <T extends ACell> Let<T> create(AVector<ACell> syms, AVector<AOp<ACell>> ops, boolean isLoop)
    • updateRefs

      public Let<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.
      Overrides:
      updateRefs in class AMultiOp<T extends ACell>
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • 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 and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.
      Overrides:
      getRefCount in class AMultiOp<T extends ACell>
      Returns:
      The number of Refs in this Cell
    • getRef

      public final <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 AMultiOp<T extends ACell>
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      i - Index of ref to get
      Returns:
      The Ref at the specified index
    • recreate

      protected Let<T> recreate(ASequence<AOp<ACell>> newOps)
      Description copied from class: AMultiOp
      Recreates this object with an updated list of child Ops.
      Specified by:
      recreate in class AMultiOp<T extends ACell>
      Returns:
    • recreate

      protected Let<T> recreate(ASequence<AOp<ACell>> newOps, AVector<ACell> newSymbols)
    • execute

      public <I extends ACell> Context<T> execute(Context<I> context)
      Description copied from class: AOp
      Executes this op with the given context. Must preserve depth unless an exceptional is returned.
      Specified by:
      execute in class AOp<T extends ACell>
      Type Parameters:
      I - Type of Context
      Parameters:
      context - Initial Context
      Returns:
      The updated Context after executing this operation
    • executeBody

      public Context<?> executeBody(Context<?> ctx)
    • print

      public boolean print(BlobBuilder bb, long limit)
      Description copied from class: AObject
      Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time if limit of printing is exceeded otherwise DoS attacks may be possible.
      Specified by:
      print in class AObject
      Parameters:
      bb - BlobBuilder to append to
      limit - Limit of printing in string bytes
      Returns:
      True if fully printed within limit, false otherwise
    • opCode

      public byte opCode()
      Description copied from class: AOp
      Returns the opcode for this op
      Specified by:
      opCode in class AOp<T extends ACell>
      Returns:
      Opcode as a byte
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: AOp
      Writes the raw data for this Op to the specified bytebuffer. Assumes Op tag and opcode already written.
      Overrides:
      encodeRaw in class AMultiOp<T extends ACell>
      Parameters:
      bs - Byte array to write to
      pos - Position to write in byte array
      Returns:
      The updated position
    • 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.
      Specified by:
      estimatedEncodingSize in interface IWriteable
      Overrides:
      estimatedEncodingSize in class AMultiOp<T extends ACell>
      Returns:
      The estimated size for the binary representation of this object.
    • read

      public static <T extends ACell> Let<T> read(ByteBuffer b, boolean isLoop) throws BadFormatException
      Throws:
      BadFormatException