Package convex.core.lang.impl
Class Fn<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.lang.AFn<T>
convex.core.lang.impl.AClosure<T>
convex.core.lang.impl.Fn<T>
- Type Parameters:
T- Return type of function
- All Implemented Interfaces:
IValidated,IWriteable,IFn<T>
Value class representing a instantiated closure / lambda function.
Includes the following information:
- Parameters of the function, as a vector of Syntax objects
- Body of the function, as a compiled operation
- captured lexical bindings at time of creation.
-
Field Summary
Fields inherited from class convex.core.lang.impl.AClosure
lexicalEnvFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionintencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag byteintEstimate the encoded data size for this Cell.getBody()Returns the declared param names for a function.getRef(int i)Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.booleanhasArity(int n)Tests if this function supports the given arity.Invoke this function in the given context.booleanReturns true if this Cell is in a canonical format for message writing.voidprint(StringBuilder sb)Prints this Object to a readable String RepresentationvoidPrint the "internal" representation of a closure e.g.read(ByteBuffer bb)Converts this Cell to its canonical version.updateRefs(IRefFunction func)Updates all Refs in this object using the given function.voidValidates the local structure and invariants of this cell.withEnvironment(AVector<ACell> env)Produces an copy of this closure with the specified environmentMethods inherited from class convex.core.lang.AFn
getTag, getType, isCVMValue, supportsArgsMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isEmbedded, toString, validate, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print
-
Method Details
-
create
-
withEnvironment
Description copied from class:AClosureProduces an copy of this closure with the specified environment- Specified by:
withEnvironmentin classAClosure<T extends ACell>- Parameters:
env- New lexical environment to use for this closure- Returns:
- Closure updated with new lexical environment
-
hasArity
public boolean hasArity(int n)Description copied from class:AFnTests if this function supports the given arity. -
invoke
Description copied from interface:IFnInvoke this function in the given context. -
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns 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:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
encode
public int encode(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, excluding the tag byte -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate 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.
-
read
- Throws:
BadFormatException
-
print
Description copied from class:AObjectPrints this Object to a readable String Representation -
printInternal
Description copied from class:AClosurePrint the "internal" representation of a closure e.g. "[x] 1", excluding the 'fn' symbol.- Specified by:
printInternalin classAClosure<T extends ACell>- Parameters:
sb- StringBuilder to print to
-
getParams
Returns the declared param names for a function.- Returns:
- A binding vector describing the parameters for this function
-
getBody
-
getRefCount
public int getRefCount()Description copied from class:ACellGets 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:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. -
updateRefs
Description copied from class:ACellUpdates 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:
updateRefsin classAFn<T extends ACell>- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
validateCell
Description copied from class:ACellValidates 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:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-