Module "Reflection": Reflecting on Builtin Types Except Lists

toBool \v

Given a statement v, results in the symbol t if v is true, otherwise the symbol f.

Definition:

REPL.define! 'toBool (\v if v 't else 'f)

symbolFromStr \s

Given a String s, results in a Symbol of that name.

Example:

symbolFromStr "x" => x

keyword? \v

Given v, results in whether it's a Keyword or not.

Example:

if (keyword? @mode:) 'yes else 'no => yes

keywordFromStr \s

Given a String s, results in a Keyword of that name.

Example:

keywordFromStr "mode:" => @mode:

keywordStr \k

Given a Keyword k, results in a Str with its name.

Example:

keywordStr @mode: => "mode:"

Most of the following functions in this section are a bad idea to use. Therefore, they are striked out.

int0

The value 0 as an Int.


intSucc \v

Given a Int value v, get its successor on the natural numerical axis. Not necessarily Int any longer (the range of Int is limited by machine register size).


number? \v

Given v, results in whether v is a number or not.


str? \v

Given v, results in whether v is a Str or not.


symbol? \v

Given v, results in whether v is a Symbol or not.


float? \v

Given v, results in whether v is a Float or not.


int?

Given v, results in whether v is an Int or not.


parseMath @position:0 @name:[] @terminator:[] \operatorPrecedenceList \inputFile \world

Given inputFile, results in the Abstract Syntax Tree for all input until the first occurence of the Symbol specified after @terminator: and a world.

position and name are used in error messages.

operatorPrecedenceList is the operator precedence list to use. This is not optional. If in doubt, just pass operatorPrecedenceList from a REPL.


parseMathStr @position:0 @name:[] @terminator:[] \operatorPrecedenceList \inputStr

Given inputStr, results in the Abstract Syntax Tree for all input until the first occurence of the Symbol specified after @terminator:.

position and name are used in error messages.

operatorPrecedenceList is the operator precedence list to use. This is not optional. If in doubt, just pass operatorPrecedenceList from a REPL.

Note that this function otherwise does no I/O.

Example:

REPL.getOperatorPrecedenceList! ;\OPL 
let Reflection = requireModule "Reflection" in 
REPL.execute! (Reflection.makeApp return! (Reflection.parseMathStr OPL "1 + 2⋅3\n"))