-
Notifications
You must be signed in to change notification settings - Fork 0
Type Coercion
Silvio Mayolo edited this page Jun 23, 2017
·
2 revisions
Many functions in ShinyLisp coerce arguments to desired types. So, for example, passing strings to the &
multiplication function will automatically parse them as integers first. The type coercion rules are defined by the table below.
The rows represent the types of values being passed in. The columns represent the "desired" type. In cases where a value, such as an integer, is "parsed", a failed parse will yield the "default" value, which is 0 or "".
Integer | String | List | Bool | |
---|---|---|---|---|
Integer | N/A | Stringify | Singleton | If Nonzero |
String | Parse | N/A | Singleton | If Nonempty |
Nil | 0 | "" | N/A | False |
Cons | Length | Concatenate | N/A | True |
Atom | Parse | Stringify | Singleton | True |
Built-in | Default | Default | Singleton | True |
Special | Default | Default | Singleton | True |
- Stringify - The value will be wrapped in quotation marks in a human-readable way.
- Singleton - The value will be placed in a list containing only the one element.
- Parse - The value will be parsed for a numerical value, defaulting to
0
on failure. - Length - The "length" of a cons cell is equal to
1
plus the length of the cdr cell. - Concatenate - Stringifying a cons cell stringifies the car and cdr and concatenates them.
- Default - If the function has a "default" return value of the appropriate type, it will be coerced to that value. Otherwise,
0
or""
.