bburdette/schelme/3.0.0

Schelme.EvalStep

EvalStep

type Term a
= TString String
| TNumber Float
| TList (List (Term a))
| TSymbol String
| TBool Bool
| TBreak (Term a)
| TFunction (Function a)
| TBuiltIn (BuiltIn a)
| TSideEffector (SideEffector a)

A Schelme program is a list of Terms.

type alias NameSpace a =
Dict String (Term a)

schelme code is always executed with a namespace, which maps from symbol names to Terms.

type alias TermGlossary =
Dict String GlossaryEntry

type for a language reference

type alias GlossaryEntry =
{ syntax : String
, description : String
}

data structure used for making a language reference.

= EvalStart (NameSpace a) a (Term a)
| EvalFinal (NameSpace a) a (Term a)
| EvalListStep (ListStep a)
| EvalError String

EvalTermStep represents the possible states during eval of a single Term. As with all the 'Steps', the state is modified during eval, as is the namespace, although these changes may be thrown away by higher levels of eval.

= EtStart (NameSpace a) a (List (Term a))
| EtStep
{ ns : NameSpace a
, state : a
, unevaledTerms : List (Term a)
, currentTerm : EvalTermStep a
, evaledTerms : List (Term a)
}
| EtFinal (NameSpace a) a (List (Term a))
| EtError String

EvalTermsStep is a set of states used to eval a list of Terms, returning the list of resulting Terms. Mainly for processing function arguments.

= EbStart (NameSpace a) a (List (Term a))
| EbStep (NameSpace a) a (EvalTermStep a) (List (Term a))
| EbFinal (NameSpace a) a (Term a)
| EbError String

EvalBodyStep is for evaling a list of Terms, throwing away the results from all but the last Term. State is modified along the way, as is the namespace. Used for processing the body of a schelme function.

type ListStep a
= ListEvalStart (NameSpace a) a (List (Term a))
| ListTerm1 (NameSpace a) a (List (Term a)) (EvalTermStep a)
| ListFunction (NameSpace a) a (EvalFtnStep a)
| ListBuiltIn (NameSpace a) a (BuiltIn a) (BuiltInStep a)
| ListSideEffector
(NameSpace a)
a
(SideEffector a)
| ListFinal (NameSpace a) a (Term a)
| ListError String

The ListStep is the set of states for evaling a list Term. Evaling a list usually results in function calls - fuctions defined in schelme, functions that modify namespace but not state (builtin) and functions that modify namespace and state (sideeffectors).

type alias Function a =
{ args : List String
, body : List (Term a)
}

a schelme function is a list of arg names and a list of Terms, which are evaled sequentially when the function is called.

= EfStart (NameSpace a) a (Function a) (List (Term a))
| EfArgs (NameSpace a) a (Function a) (EvalTermsStep a)
| EfBody (NameSpace a) a (EvalBodyStep a)
| EfFinal (NameSpace a) a (Term a)
| EfError String

The set of states during eval of a schelme function.

type alias BuiltIn a =

A builtin function is defined in Elm. It should process any of the BuiltInStep states, hopefully resulting in a BuiltInFinal at the end. BuiltInFinal doesn't include the state ('a'), so any changes mades to state are always thrown away.

= BuiltInStart (NameSpace a) a (List (Term a))
| BuiltInArgs (NameSpace a) a (EvalTermsStep a)
| BuiltInEval (NameSpace a) a (List (Term a)) (EvalTermStep a)
| BuiltInFinal (NameSpace a) (Term a)
| BuiltInError String

The set of states used in defining a BuiltIn function.

A sideeffector function processes SideEffectorSteps, and should eventually return either a SideEffectorFinal or SideEffectorError. Unlike the BuiltIn, the SideEffector returns a modified state ('a') in its Final step.

= SideEffectorStart (NameSpace a) a (List (Term a))
| SideEffectorArgs (NameSpace a) a (EvalTermsStep a)
| SideEffectorEval
(NameSpace a)
a
(List (Term a))
| SideEffectorRequest (NameSpace a) a
| SideEffectorBody
(NameSpace a)
a
(List (Term a))
| SideEffectorFinal (NameSpace a) a (Term a)
| SideEffectorError String

The steps involved in a SideEffector function. Not all these steps have to be used. Check out the prelude for some examples.

sxpToTerm : Sxp -> Result (List DeadEnd) (Term a)

parse an s-expression, yielding a single term.

sxpsToTerms : List Sxp -> Result (List DeadEnd) (List (Term a))

parse a series of s-expressions, yielding a list of terms.