Sempiler provides a construct to express optional types (in source languages that do not have them inherently) for targeting platforms that use them.
||Symbolic optional construct|
opt like other fakeywords, except it is aliased to
T rather than
A goal of the Sempiler design is to have code feel natural to write in the source language, whilst being valid for the target context.
T we can assign
T values directly to an optional datum as if it were being boxed and unboxed automatically.
If you are sempiling to a target platform that has strict optionality (eg. Swift) you must observe the following:
- If the parameter is optional and the default value is
nullor not provided, the parameter is
- If the parameter is NOT optional but it is annotated as
opt<T>then it may receive
- If the parameter is optional but has a non-null default value, you must annotate it as
opt<T>in order to pass
To unwrap an optional we can use a non-null assertion. In TypeScript we use the
! postfix unary operator.