Package hydra.lisp.syntax
Class FunctionDefinition
- java.lang.Object
-
- hydra.lisp.syntax.FunctionDefinition
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<FunctionDefinition>
public class FunctionDefinition extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<FunctionDefinition>
A named function definition. Serializes as (defn name [params] body) in Clojure, (defun name (params) body) in Emacs Lisp and Common Lisp, (define (name params) body) in Scheme- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFunctionDefinition.BuilderA fluent builder forFunctionDefinition.
-
Field Summary
Fields Modifier and Type Field Description java.util.List<Expression>bodyThe function body (one or more expressions)static NameBODYName of thehydra.lisp.syntax.FunctionDefinition.bodyfield.Optional<Docstring>docOptional docstringstatic NameDOCName of thehydra.lisp.syntax.FunctionDefinition.docfield.SymbolnameThe function namestatic NameNAMEName of thehydra.lisp.syntax.FunctionDefinition.namefield.java.util.List<Symbol>paramsThe parameter liststatic NamePARAMSName of thehydra.lisp.syntax.FunctionDefinition.paramsfield.static NameREST_PARAMName of thehydra.lisp.syntax.FunctionDefinition.restParamfield.Optional<Symbol>restParamOptional rest/variadic parameterstatic NameTYPE_Name of thehydra.lisp.syntax.FunctionDefinitiontype.static NameTYPE_HINTSName of thehydra.lisp.syntax.FunctionDefinition.typeHintsfield.java.util.List<TypeHint>typeHintsOptional type hints for parameters and return type
-
Constructor Summary
Constructors Constructor Description FunctionDefinition(Symbol name, java.util.List<Symbol> params, Optional<Symbol> restParam, Optional<Docstring> doc, java.util.List<TypeHint> typeHints, java.util.List<Expression> body)Constructs an immutableFunctionDefinition.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FunctionDefinition.Builderbuilder()Creates a new fluent builder forFunctionDefinition.intcompareTo(FunctionDefinition other)booleanequals(java.lang.Object other)inthashCode()java.lang.StringtoString()FunctionDefinitionwithBody(java.util.List<Expression> body)Returns a copy of thisFunctionDefinitionwithbodyreplaced.FunctionDefinitionwithDoc(Optional<Docstring> doc)Returns a copy of thisFunctionDefinitionwithdocreplaced.FunctionDefinitionwithName(Symbol name)Returns a copy of thisFunctionDefinitionwithnamereplaced.FunctionDefinitionwithParams(java.util.List<Symbol> params)Returns a copy of thisFunctionDefinitionwithparamsreplaced.FunctionDefinitionwithRestParam(Optional<Symbol> restParam)Returns a copy of thisFunctionDefinitionwithrestParamreplaced.FunctionDefinitionwithTypeHints(java.util.List<TypeHint> typeHints)Returns a copy of thisFunctionDefinitionwithtypeHintsreplaced.
-
-
-
Field Detail
-
TYPE_
public static final Name TYPE_
Name of thehydra.lisp.syntax.FunctionDefinitiontype.
-
NAME
public static final Name NAME
Name of thehydra.lisp.syntax.FunctionDefinition.namefield.
-
PARAMS
public static final Name PARAMS
Name of thehydra.lisp.syntax.FunctionDefinition.paramsfield.
-
REST_PARAM
public static final Name REST_PARAM
Name of thehydra.lisp.syntax.FunctionDefinition.restParamfield.
-
DOC
public static final Name DOC
Name of thehydra.lisp.syntax.FunctionDefinition.docfield.
-
TYPE_HINTS
public static final Name TYPE_HINTS
Name of thehydra.lisp.syntax.FunctionDefinition.typeHintsfield.
-
BODY
public static final Name BODY
Name of thehydra.lisp.syntax.FunctionDefinition.bodyfield.
-
name
public final Symbol name
The function name
-
params
public final java.util.List<Symbol> params
The parameter list
-
typeHints
public final java.util.List<TypeHint> typeHints
Optional type hints for parameters and return type
-
body
public final java.util.List<Expression> body
The function body (one or more expressions)
-
-
Constructor Detail
-
FunctionDefinition
public FunctionDefinition(Symbol name, java.util.List<Symbol> params, Optional<Symbol> restParam, Optional<Docstring> doc, java.util.List<TypeHint> typeHints, java.util.List<Expression> body)
Constructs an immutableFunctionDefinition.- Parameters:
name- The function nameparams- The parameter listrestParam- Optional rest/variadic parameterdoc- Optional docstringtypeHints- Optional type hints for parameters and return typebody- The function body (one or more expressions)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(FunctionDefinition other)
- Specified by:
compareToin interfacejava.lang.Comparable<FunctionDefinition>
-
withName
public FunctionDefinition withName(Symbol name)
Returns a copy of thisFunctionDefinitionwithnamereplaced.
-
withParams
public FunctionDefinition withParams(java.util.List<Symbol> params)
Returns a copy of thisFunctionDefinitionwithparamsreplaced.
-
withRestParam
public FunctionDefinition withRestParam(Optional<Symbol> restParam)
Returns a copy of thisFunctionDefinitionwithrestParamreplaced.
-
withDoc
public FunctionDefinition withDoc(Optional<Docstring> doc)
Returns a copy of thisFunctionDefinitionwithdocreplaced.
-
withTypeHints
public FunctionDefinition withTypeHints(java.util.List<TypeHint> typeHints)
Returns a copy of thisFunctionDefinitionwithtypeHintsreplaced.
-
withBody
public FunctionDefinition withBody(java.util.List<Expression> body)
Returns a copy of thisFunctionDefinitionwithbodyreplaced.
-
builder
public static FunctionDefinition.Builder builder()
Creates a new fluent builder forFunctionDefinition.
-
-