luv

Workshop wiki

frontend.lisp

arithmetic/language/frontend.lisp

system luv/arithmetic · 139 definitions · on GitHub

Backend-neutral compiled arithmetic definitions and expression graphs.

This is the shared source/semantic frontend. It deliberately does not choose single versus double floats, a vector representation, an execution strategy, or a lowering backend. A realization consumes these inspectable objects after quantity checking and chooses those machine details itself.

in-package#:luv.arithmetic.language
define-conditionarithmetic-language-error
error
form:initarg:form:initformnil:readerarithmetic-language-error-form
reason:initarg:reason:readerarithmetic-language-error-reason
details:initarg:details:initformnil:readerarithmetic-language-error-details
:report
lambda
conditionstream
formatstream"Cannot understand arithmetic expression ~S: ~A~@[ (~S)~]."
arithmetic-language-error-formcondition
arithmetic-language-error-reasoncondition
arithmetic-language-error-detailscondition
defmacrowith-arithmetic-quantity-errors
source-formreason
&bodybody
`
handler-case
progn,@body
math:undefined-unit
condition
error'arithmetic-language-error:form,source-form:reason:undefined-unit:details
math:undefined-unit-namecondition
math:quantity-operation-error
condition
error'arithmetic-language-error:form,source-form:reason,reason:details
math:quantity-operation-error-reasoncondition
defclassarithmetic-named-object
name:initarg:name:readerarithmetic-object-name
source-form:initarg:source-form:initformnil:readerarithmetic-object-source-form
defclassarithmetic-expression
quantity-specification:initarg:quantity-specification:initformnil:readerarithmetic-expression-quantity-specification
quantity-layout:initarg:quantity-layout:initformnil:readerarithmetic-expression-quantity-layout
source-form:initarg:source-form:readerarithmetic-expression-source-form
name:initarg:name:initformnil:accessorarithmetic-expression-name
quantity-checked-memo:documentation

The remembered answer of arithmetic-expression-quantity-checked-p.

Unbound until the question is first asked of this expression. See the :AROUND method on that generic function for why the memory is needed and what makes it sound.

:documentation

A source expression with semantic meaning but no chosen machine form.

defclassarithmetic-parameter
quantity-specification:initarg:quantity-specification:initformnil:readerarithmetic-parameter-quantity-specification
quantity-layout:initarg:quantity-layout:initformnil:readerarithmetic-parameter-quantity-layout
defmethodmath:declaration-representation-type
declare
ignoreparameter
nil
defmethodmath:declaration-quantity-specification
arithmetic-parameter-quantity-specificationparameter
defmethodmath:declaration-quantity-layout
arithmetic-parameter-quantity-layoutparameter
defmethodmath:declaration-source-form
arithmetic-object-source-formparameter
defclassarithmetic-binding
expression:initarg:expression:readerarithmetic-binding-expression
defclassarithmetic-function-parameter-binding
:documentation

A lexical alias binding one function argument inside an application.

defclassarithmetic-literal
value:initarg:value:readerarithmetic-literal-value
defclassarithmetic-reference
target:initarg:target:readerarithmetic-reference-target
defclassarithmetic-call
operator:initarg:operator:readerarithmetic-call-operator
operands:initarg:operands:readerarithmetic-call-operands
parameters:initarg:parameters:initformnil:readerarithmetic-call-parameters
defclassarithmetic-conditional
condition:initarg:condition:readerarithmetic-conditional-condition
consequent:initarg:consequent:readerarithmetic-conditional-consequent
alternative:initarg:alternative:readerarithmetic-conditional-alternative
:documentation

A value conditional shared by every arithmetic realization.

defclassarithmetic-quantity-boundary
operand:initarg:operand:readerarithmetic-quantity-boundary-operand
defclassarithmetic-unit-conversion
operand:initarg:operand:readerarithmetic-unit-conversion-operand
factor:initarg:factor:readerarithmetic-unit-conversion-factor
defgenericarithmetic-reference-target-name
target
:documentation

Return the source name denoted by reference target.

defmethodarithmetic-reference-target-name
arithmetic-object-nametarget
defgenericarithmetic-reference-target-quantity-checked-p
target
:documentation

Whether semantic checking is active at reference target.

defgenericarithmetic-reference-target-quantity-specification
target
:documentation

Return target's homogeneous quantity specification, or NIL.

defgenericarithmetic-reference-target-quantity-layout
target
:documentation

Return target's packed quantity layout, or NIL.

defmethodarithmetic-reference-target-quantity-checked-p
or
arithmetic-parameter-quantity-specificationtarget
arithmetic-parameter-quantity-layouttarget
defmethodarithmetic-reference-target-quantity-specification
arithmetic-parameter-quantity-specificationtarget
defmethodarithmetic-reference-target-quantity-layout
arithmetic-parameter-quantity-layouttarget
defmethodarithmetic-reference-target-quantity-specification
arithmetic-expression-quantity-specification
arithmetic-binding-expressiontarget
defmethodarithmetic-reference-target-quantity-layout
arithmetic-expression-quantity-layout
arithmetic-binding-expressiontarget
defgenericarithmetic-expression-quantity-checked-p
expression
:documentation

Whether semantic quantity checking is active at expression.

defmethodarithmetic-expression-quantity-checked-p:around

Answer once per expression and remember it.

A parsed expression is a directed acyclic graph, not a tree: one binding referenced three times is one object with three references to it, and an inlined function call shares its argument expressions with the call site. The methods below recurse through operands, through a reference's target binding, and through a function call's result, so a plain recursive walk visits every path rather than every node -- which is exponential in the depth of the sharing, not linear in the size of the graph. A shader with a few nested distance-field helpers is enough to make the difference minutes.

The memory is sound because the graph is immutable once built: an expression's operands, a binding's expression, and a call's result are all read-only after construction, and every child is fully constructed before the parent that refers to it. So the answer for a given object can never change, and asking early during parsing gives the same answer as asking at the end.

if
slot-boundpexpression'quantity-checked-memo
slot-valueexpression'quantity-checked-memo
setf
slot-valueexpression'quantity-checked-memo
call-next-method
defmethodarithmetic-expression-quantity-checked-p
expressionarithmetic-call
or
arithmetic-expression-quantity-specificationexpression
arithmetic-expression-quantity-layoutexpression
some#'arithmetic-expression-quantity-checked-p
arithmetic-call-operandsexpression
defmethodarithmetic-expression-quantity-checked-p
or
arithmetic-expression-quantity-checked-p
arithmetic-conditional-consequentexpression
arithmetic-expression-quantity-checked-p
arithmetic-conditional-alternativeexpression
defmethodarithmetic-expression-quantity-checked-p
declare
ignoreexpression
nil
defgenericarithmetic-expression-form
expression
:documentation

Reconstruct the compact source form of expression.

defmethodarithmetic-expression-form
arithmetic-literal-valueexpression
defmethodarithmetic-expression-form
arithmetic-reference-target-name
arithmetic-reference-targetexpression
defmethodarithmetic-expression-form
expressionarithmetic-call
append
cons
arithmetic-call-operatorexpression
mapcar#'arithmetic-expression-form
arithmetic-call-operandsexpression
arithmetic-call-parametersexpression
defmethodarithmetic-expression-form
list'if
arithmetic-expression-form
arithmetic-conditional-conditionexpression
arithmetic-expression-form
arithmetic-conditional-consequentexpression
arithmetic-expression-form
arithmetic-conditional-alternativeexpression
defmethodarithmetic-expression-form
arithmetic-expression-source-formexpression
defmethodarithmetic-expression-form
arithmetic-expression-source-formexpression
defmethodprint-object
stream
print-unreadable-object
expressionstream:typet
prin1stream
defgenericarithmetic-expression-children
expression
:documentation

Return expression's immediate source operands.

defmethodarithmetic-expression-children
expressionarithmetic-call
arithmetic-call-operandsexpression
defmethodarithmetic-expression-children
list
arithmetic-conditional-conditionexpression
arithmetic-conditional-consequentexpression
arithmetic-conditional-alternativeexpression
defmethodarithmetic-expression-children
list
arithmetic-quantity-boundary-operandexpression
defmethodarithmetic-expression-children
list
arithmetic-unit-conversion-operandexpression
defclassarithmetic-function-source
parameter-forms:initarg:parameter-forms:readerarithmetic-function-parameter-forms
parameter-names:initarg:parameter-names:readerarithmetic-function-parameter-names
body:initarg:body:readerarithmetic-function-body
:documentation

The shared source identity of a reusable expression-language function.

defclassarithmetic-function-definition
parameters:initarg:parameters:readerarithmetic-function-parameters
bindings:initarg:bindings:initformnil:readerarithmetic-function-bindings
result:initarg:result:readerarithmetic-function-result
:documentation

A checked arithmetic source definition awaiting an execution backend.

defclassarithmetic-function-call
definition:initarg:definition:readerarithmetic-function-call-definition
arguments:initarg:arguments:readerarithmetic-function-call-arguments
bindings:initarg:bindings:readerarithmetic-function-call-bindings
result:initarg:result:readerarithmetic-function-call-result
:documentation

One inspectable application of shared function source to checked values.

defclassarithmetic-counted-fold
count:initarg:count:readerarithmetic-counted-fold-count
initial:initarg:initial:readerarithmetic-counted-fold-initial
index-binding:initarg:index-binding:readerarithmetic-counted-fold-index-binding
state-binding:initarg:state-binding:readerarithmetic-counted-fold-state-binding
bindings:initarg:bindings:initformnil:readerarithmetic-counted-fold-bindings
update:initarg:update:readerarithmetic-counted-fold-update
until:initarg:until:initformnil:readerarithmetic-counted-fold-until:documentation

A truth-valued expression over the index and the carried state, tested before each iteration; when it holds the fold stops early with the state it has. NIL means the fold always runs to COUNT.

:documentation

A bounded value-producing fold over an index and one carried state.

The binding list is (INDEX COUNT STATE INITIAL), optionally followed by :UNTIL TEST, whose TEST sees INDEX and STATE and ends the fold early.

defmethodarithmetic-expression-form
arithmetic-expression-source-formexpression
defmethodarithmetic-expression-children
append
arithmetic-function-call-argumentsexpression
mapcar#'arithmetic-binding-expression
arithmetic-function-call-bindingsexpression
list
arithmetic-function-call-resultexpression
defmethodarithmetic-expression-form
arithmetic-expression-source-formexpression
defmethodarithmetic-expression-children
append
list
arithmetic-counted-fold-countexpression
arithmetic-counted-fold-initialexpression
mapcar#'arithmetic-binding-expression
arithmetic-counted-fold-bindingsexpression
list
arithmetic-counted-fold-updateexpression
let
until
arithmetic-counted-fold-untilexpression
anduntil
listuntil
defgenericarithmetic-function-definition-for
name
:documentation

Return the live arithmetic definition named by name, or NIL.

defmethodarithmetic-function-definition-for
name
declare
ignorename
nil
defgenericnote-arithmetic-function-redefinition
name
:documentation

Notify loaded realizations that reusable arithmetic source changed.

defmethodnote-arithmetic-function-redefinition
name
declare
ignorename
nil
defunarithmetic-function-expressions

Return definition's expression graph in source order without duplicates.

let
seen
make-hash-table:test#'eq
expressionsnil
labels
visit
expression
unless
gethashexpressionseen
setf
gethashexpressionseen
t
pushexpressionexpressions
mapc#'visit
dolist
binding
arithmetic-function-bindingsdefinition
visit
arithmetic-binding-expressionbinding
visit
arithmetic-function-resultdefinition
nreverseexpressions
defvar*arithmetic-operator-documentation*
make-hash-table:test#'eq
defmethoddocumentation
namesymbol
type
eql'arithmetic-operator
defmethod
new-value
namesymbol
type
eql'arithmetic-operator
ifnew-value
setfnew-value
defgenericarithmetic-operator-p
operator
:documentation

Whether operator belongs to the compiled arithmetic language.

defmethodarithmetic-operator-p
operator
declare
ignoreoperator
nil
defmacrodefine-arithmetic-operator
name&optionaldocumentation

Admit name to the open arithmetic vocabulary through an EQL method.

`
progn
defmethodarithmetic-operator-p
operator
eql',name
declare
ignoreoperator
t
,@
whendocumentation`
setf
documentation',name'arithmetic-operator
,documentation
',name
define-arithmetic-operator+"Addition over compatible quantities."
define-arithmetic-operator-"Subtraction or unary negation."
define-arithmetic-operator*"Multiplication and scalar scaling."
define-arithmetic-operator/"Division of two represented quantities."
define-arithmetic-operatormod"The non-negative remainder of integer division."
define-arithmetic-operatordot"The inner product of two vectors."
define-arithmetic-operatormin"The minimum of compatible quantities."
define-arithmetic-operatormax"The maximum of compatible quantities."
define-arithmetic-operatorabs"The componentwise absolute value of a raw value."
define-arithmetic-operatorsqrt"The componentwise square root of a raw value."
define-arithmetic-operatorclamp"Constrain a quantity between compatible bounds."
define-arithmetic-operatormix"Interpolate compatible quantities by a scalar amount."
define-arithmetic-operatorsmoothstep"Produce dimensionless progress across compatible edges."
define-arithmetic-operatorstep"Compare compatible quantities and produce dimensionless values."
define-arithmetic-operatornormalize"Normalize a dimensionless vector."
define-arithmetic-operatorexpt"Raise a dimensionless value to a dimensionless power."
define-arithmetic-operator<"Test whether one compatible scalar is less than another."
define-arithmetic-operator<="Test whether one compatible scalar is at most another."
define-arithmetic-operator>"Test whether one compatible scalar is greater than another."
define-arithmetic-operator>="Test whether one compatible scalar is at least another."
define-arithmetic-operator="Test whether two compatible scalars are equal."
define-arithmetic-operatorquantity"Construct a meaningful literal."
define-arithmetic-operatorassume-quantity"State external meaning for a raw value."
define-arithmetic-operatorinterpret"Name a compatible derived quantity."
define-arithmetic-operatorrepresentation"Expose a quantity's raw representation."
define-arithmetic-operatorconvert-unit"Convert a quantity to a compatible unit."
define-arithmetic-operatorand"Logical conjunction of tests and raw truth values."
define-arithmetic-operatoror"Logical disjunction of tests and raw truth values."
define-arithmetic-operatornot"Logical negation of one test or raw truth value."
defunarithmetic-environment-value
nameenvironmentsource-form
or
cdr
assocnameenvironment:test#'eq
error'arithmetic-language-error:formsource-form:reason:unknown-name:detailsname
defunmake-arithmetic-reference
nameenvironmentsource-form
let
target
arithmetic-environment-valuenameenvironmentsource-form
make-instance'arithmetic-reference:targettarget:quantity-specification:quantity-layout:source-formsource-form
defunparse-source-quantity-specification
optionssource-form&key
default-tensor-order0
with-arithmetic-quantity-errors
source-form:invalid-quantity-declaration
math:make-declared-quantity-specificationoptions:default-tensor-orderdefault-tensor-order
defuninfer-arithmetic-call-quantity-specification
operatoroperandssource-form
when
memberoperator':test#'eq
unless
=2
lengthoperands
error'arithmetic-language-error:formsource-form:reason:comparison-arity:details
lengthoperands
when
let
specifications
mapcar#'arithmetic-expression-quantity-specificationoperands
unless
every#'identityspecifications
error'arithmetic-language-error:formsource-form:reason:missing-quantity-specification:details
loopforoperandinoperandsforspecificationinspecificationsunlessspecificationcollect
with-arithmetic-quantity-errors
source-form:invalid-quantity-operation
if
memberoperator':test#'eq
prognnil
apply#'math:derive-quantity-specificationoperatorspecifications
defgenericparse-arithmetic-operator-call
operatorformenvironment
:documentation

Parse one arithmetic call into an inspectable expression.

defmethodparse-arithmetic-operator-call
operatorformenvironment
let
operands
mapcar
lambda
operand
parse-arithmetic-expressionoperandenvironment
restform
make-instance'arithmetic-call:operatoroperator:operandsoperands:quantity-specification:source-formform
defclassarithmetic-logical-call
:documentation

A truth-valued combination of tests. Like a comparison it carries no quantity, and unlike an arithmetic call it never infers one from operands, so checked comparisons and raw flags may combine freely.

defmethodarithmetic-expression-quantity-checked-p
declare
ignoreexpression
nil
defunparse-arithmetic-logical-call
operatorformenvironment
when
and
eqoperator'not
/=
lengthform
2
error'arithmetic-language-error:formform:reason:negation-arity:details
1-
lengthform
make-instance'arithmetic-logical-call:operatoroperator:operands
mapcar
lambda
operand
parse-arithmetic-expressionoperandenvironment
restform
:source-formform
defmethodparse-arithmetic-operator-call
operator
eql'and
formenvironment
parse-arithmetic-logical-calloperatorformenvironment
defmethodparse-arithmetic-operator-call
operator
eql'or
formenvironment
parse-arithmetic-logical-calloperatorformenvironment
defmethodparse-arithmetic-operator-call
operator
eql'not
formenvironment
parse-arithmetic-logical-calloperatorformenvironment
defgenericarithmetic-constant-expression-p
expression
:documentation

Whether expression is a literal construction source.

defmethodarithmetic-constant-expression-p
expression
declare
ignoreexpression
nil
defunparse-raw-quantity-boundary
classformenvironment&keyconstant-only-p
destructuring-bind
nameoperand-form&restoptions
form
declare
ignorename
let*
operand
parse-arithmetic-expressionoperand-formenvironment
specification
unlessspecification
error'arithmetic-language-error:formform:reason:missing-quantity-interpretation
when
or
arithmetic-expression-quantity-layoutoperand
error'arithmetic-language-error:formform:reason:quantity-already-has-semantics:details
when
error'arithmetic-language-error:formform:reason:quantity-requires-literal-construction:details
make-instanceclass:operandoperand:quantity-specificationspecification:source-formform
defmethodparse-arithmetic-operator-call
operator
formenvironment
declare
ignoreoperator
defmethodparse-arithmetic-operator-call
operator
formenvironment
declare
ignoreoperator
defmethodparse-arithmetic-operator-call
operator
formenvironment
declare
ignoreoperator
destructuring-bind
nameoperand-form&restoptions
form
declare
ignorename
let*
operand
parse-arithmetic-expressionoperand-formenvironment
interpretation
unlessinterpretation
error'arithmetic-language-error:formform:reason:missing-quantity-interpretation
with-arithmetic-quantity-errors
form:invalid-quantity-interpretation
math:interpret-quantity-specification
and
arithmetic-expression-quantity-specificationoperand
interpretation
make-instance'arithmetic-interpretation:operandoperand:quantity-specificationinterpretation:source-formform
defmethodparse-arithmetic-operator-call
operator
formenvironment
declare
ignoreoperator
unless
=
lengthform
2
error'arithmetic-language-error:formform:reason:representation-arity
let
operand
unless
error'arithmetic-language-error:formform:reason:representation-requires-quantity:details
make-instance'arithmetic-representation:operandoperand:source-formform
defmethodparse-arithmetic-operator-call
operator
formenvironment
declare
ignoreoperator
destructuring-bind
nameoperand-form&key
unitnilunit-supplied-p
form
declare
ignorename
unlessunit-supplied-p
error'arithmetic-language-error:formform:reason:missing-target-unit
let*
operand
parse-arithmetic-expressionoperand-formenvironment
source
and
arithmetic-expression-quantity-specificationoperand
unlesssource
error'arithmetic-language-error:formform:reason:unit-conversion-requires-quantity
with-arithmetic-quantity-errors
form:invalid-unit-conversion
multiple-value-bind
targetfactor
make-instance'arithmetic-unit-conversion:operandoperand:factorfactor:quantity-specificationtarget:source-formform
defunarithmetic-state-compatible-p
leftright
or
and
let
left-specification
arithmetic-expression-quantity-specificationleft
right-specification
arithmetic-expression-quantity-specificationright
or
and
nullleft-specification
nullright-specification
andleft-specificationright-specification
math:quantity-specification=left-specificationright-specification
let
left-layout
arithmetic-expression-quantity-layoutleft
right-layout
arithmetic-expression-quantity-layoutright
or
and
nullleft-layout
nullright-layout
andleft-layoutright-layout
math:quantity-layout=left-layoutright-layout
defuncounted-fold-form-parts
form

Destructure a COUNTED-FOLD form into (VALUES INDEX-NAME COUNT-FORM STATE-NAME INITIAL-FORM UPDATE-FORM UNTIL-FORM), or return NIL when the shape is not (COUNTED-FOLD (INDEX COUNT STATE INITIAL [:UNTIL TEST]) UPDATE).

when
and
=
lengthform
3
consp
secondform
or
and
eq
fifth
secondform
:until
destructuring-bind
index-namecount-formstate-nameinitial-form&optionaluntil-keyworduntil-form
secondform
declare
ignoreuntil-keyword
valuesindex-namecount-formstate-nameinitial-form
thirdform
until-formt
defunparse-arithmetic-counted-fold
formenvironment
multiple-value-bind
index-namecount-formstate-nameinitial-formupdate-formuntil-formvalid-p
unlessvalid-p
error'arithmetic-language-error:formform:reason:invalid-counted-fold
unless
and
symbolpindex-name
symbolpstate-name
not
eqindex-namestate-name
error'arithmetic-language-error:formform:reason:invalid-counted-fold-bindings
let*
count
parse-arithmetic-expressioncount-formenvironment
initial
parse-arithmetic-expressioninitial-formenvironment
index-binding
make-instance'arithmetic-binding:nameindex-name:expression:source-form
listindex-name0
state-binding
make-instance'arithmetic-binding:namestate-name:expressioninitial:source-form
liststate-nameinitial-form
fold-environment
list*
consindex-nameindex-binding
consstate-namestate-binding
environment
multiple-value-bind
update-bindingsupdate
parse-arithmetic-body
listupdate-form
fold-environment
unless
error'arithmetic-language-error:formform:reason:counted-fold-state-mismatch:details
make-instance'arithmetic-counted-fold:countcount:initialinitial:index-bindingindex-binding:state-bindingstate-binding:bindingsupdate-bindings:updateupdate:until
anduntil-form
parse-arithmetic-expressionuntil-formfold-environment
:quantity-specification
arithmetic-expression-quantity-specificationinitial
:quantity-layout
arithmetic-expression-quantity-layoutinitial
:source-formform
defunparse-arithmetic-conditional
formenvironment
unless
=4
lengthform
error'arithmetic-language-error:formform:reason:conditional-arity
let
condition
consequent
parse-arithmetic-expression
thirdform
environment
alternative
parse-arithmetic-expression
fourthform
environment
unless
arithmetic-state-compatible-pconsequentalternative
error'arithmetic-language-error:formform:reason:conditional-branch-mismatch:details
make-instance'arithmetic-conditional:conditioncondition:consequentconsequent:alternativealternative:quantity-specification
arithmetic-expression-quantity-specificationconsequent
:quantity-layout
arithmetic-expression-quantity-layoutconsequent
:source-formform
defunparse-arithmetic-call
formenvironment
let*
operator
firstform
cond
eqoperator'counted-fold
eqoperator'if
t
error'arithmetic-language-error:formform:reason:unknown-operator:detailsoperator
defunparse-arithmetic-expression
formenvironment
cond
realpform
make-instance'arithmetic-literal:valueform:quantity-specification:source-formform
symbolpform
make-arithmetic-referenceformenvironmentform
conspform
parse-arithmetic-callformenvironment
t
error'arithmetic-language-error:formform:reason:unsupported-expression
defunparse-arithmetic-parameter
form
destructuring-bind
name&restoptions
form
unless
symbolpname
error'arithmetic-language-error:formform:reason:invalid-parameter-name:detailsname
make-instance'arithmetic-parameter:namename:quantity-specification:source-formform
defunparse-arithmetic-body
bodyenvironment
unless
=
lengthbody
1
error'arithmetic-language-error:formbody:reason:expected-single-arithmetic-body
let
form
firstbody
if
and
conspform
eq
firstform
'let*
destructuring-bind
operatorraw-bindings&restresults
form
declare
ignoreoperator
unless
=
lengthresults
1
error'arithmetic-language-error:formform:reason:expected-single-result
let
bindingsnil
lexical-environmentenvironment
dolist
raw-bindingraw-bindings
unless
and
conspraw-binding
=
lengthraw-binding
2
symbolp
firstraw-binding
error'arithmetic-language-error:formraw-binding:reason:invalid-binding
let*
name
firstraw-binding
expression
parse-arithmetic-expression
secondraw-binding
lexical-environment
binding
make-instance'arithmetic-binding:namename:expressionexpression:source-formraw-binding
setf
arithmetic-expression-nameexpression
name
pushbindingbindings
push
consnamebinding
lexical-environment
values
nreversebindings
parse-arithmetic-expression
firstresults
lexical-environment
valuesnil
defunensure-arithmetic-function-argument-compatible
parameterargumentsource-form
let
expected-specification
arithmetic-parameter-quantity-specificationparameter
actual-specification
arithmetic-expression-quantity-specificationargument
expected-layout
arithmetic-parameter-quantity-layoutparameter
actual-layout
arithmetic-expression-quantity-layoutargument
unless
or
nullexpected-specification
andactual-specification
math:quantity-specification=actual-specificationexpected-specification
error'arithmetic-language-error:formsource-form:reason:function-argument-quantity-mismatch:details
list:parameter
arithmetic-object-nameparameter
:expectedexpected-specification:actualactual-specification
unless
or
nullexpected-layout
andactual-layout
math:quantity-layout=actual-layoutexpected-layout
error'arithmetic-language-error:formsource-form:reason:function-argument-layout-mismatch:details
list:parameter
arithmetic-object-nameparameter
:expectedexpected-layout:actualactual-layout
argument
defunparse-arithmetic-function-call
definitionformenvironment

Parse a call by specializing shared function source to its actual values.

let*
name
arithmetic-object-namedefinition
parameters
arithmetic-function-parametersdefinition
argument-forms
restform
unless
=
lengthparameters
lengthargument-forms
error'arithmetic-language-error:formform:reason:arithmetic-function-arity:details
list:expected
lengthparameters
:actual
lengthargument-forms
when
error'arithmetic-language-error:formform:reason:recursive-arithmetic-function:details
let*
arguments
mapcar
lambda
argument-form
parse-arithmetic-expressionargument-formenvironment
argument-forms
parameter-bindings
loopforparameterinparametersforargumentinargumentsdocollect
make-instance'arithmetic-function-parameter-binding:name
arithmetic-object-nameparameter
:expressionargument:source-form
list
arithmetic-object-nameparameter
argument
function-environment
loopforparameterinparametersforbindinginparameter-bindingscollect
cons
arithmetic-object-nameparameter
binding
let
multiple-value-bind
body-bindingsresult
parse-arithmetic-body
arithmetic-function-bodydefinition
function-environment
make-instance'arithmetic-function-call:definitiondefinition:argumentsarguments:bindings
appendparameter-bindingsbody-bindings
:resultresult:quantity-specification
arithmetic-expression-quantity-specificationresult
:quantity-layout
arithmetic-expression-quantity-layoutresult
:source-formform
defunparse-arithmetic-function-definition
nameparameter-formsbody

Parse one backend-neutral arithmetic function definition.

let*
parameters
mapcar#'parse-arithmetic-parameterparameter-forms
environment
mapcar
lambda
parameter
cons
arithmetic-object-nameparameter
parameter
parameters
multiple-value-bind
bindingsresult
make-instance'arithmetic-function-definition:namename:parameter-formsparameter-forms:parameter-names
mapcar#'arithmetic-object-nameparameters
:bodybody:parametersparameters:bindingsbindings:resultresult:source-form
list*'define-arithmetic-functionnameparameter-formsbody
defmacrodefine-arithmetic-function
nameparameters&bodybody

Define one inspectable arithmetic function through an EQL method.

let
function-name
gensym"FUNCTION-NAME"
`
progn
defmethodarithmetic-function-definition-for
,function-name
eql',name
declare
ignore,function-name
load-time-value
parse-arithmetic-function-definition',name',parameters',body
',name