The PurpleFace programming language
Proposed Features:
- Function Inference
- Boolean datatype and operations replaced with optional data type
true
|false
|maybe
- every 'concrete' datatype is derived from
true
- the
maybe
keyword casts expressions to amaybe
- Lambdas cannot be bound to a variable
- will result in a compiler error of "Nice Try"
- There is no 'let' for binding variables; only
maybe
maybe 2?
returns a value that is either 2 (andtrue
) or not 2 (and therefore,maybe
)maybe a is 1 + (2?)?
will binda
to a value that may or may not be the sum of 1 and a number that may or may not be 2, so the possible values are (1?), 3, maybe, and false- Note:
1 + maybe
ismaybe 1
, which has the shorthand1?
1?
resolves, of course, to1
ormaybe
- Note:
- Optional values are all quantum-spooky. They do not resolve to concrete values until a concrete value is required.
- The whole program is generally lazy evaluated.
- At runtime,
maybe
bindings create multiple continuations. - Only continuations which result in valid result are retained.
- All expressions return a value.
- expressions are terminated by punctuation
- The return value of a continuation is the last returned value inside of it.
- Imperitive statements end with a
!
- 'Quantum' values and statements end with a
?
- Parameters to functions do not need to be surrounded in
()
, but still need to be separated by,
Possible Example Code:
maybe a is 2?
a < 3?
if true, print a!
Example Execution:
a
is allocated, and bound to a value which may be2
,maybe
, orfalse
- A new continuation is created for each.
- In each of the 3 continuations, evaluate
a < 3
, creating another new continuation for each possible result
- All conditional expressions return an optional value, so a new continuation is created for all possible results:
true
, ormaybe
in thea = 2
continuationmaybe
in thea = maybe
continuationfalse
, ormaybe
in thea = false
continuation
- Only the "
a < 3
istrue
" continuation will reach theprint
statement.
- The only continuation of the
print
statement prints2
, since the only continuation which reaches theprint
statement is the one in whicha < 3
is true, which in turn was spawned in the continuation in whicha = 2
, and ifprint
is given a valid (true
) argument it will returntrue
. - actually,
2
is not printed yet; it is -buffered- to be printed. All side effects are buffered until their execution is guaranteed.- side effects are only possible via buffered streams, or by opening and closing of those streams
- The end of the program has been reached. The remaining continuations are the one that prints
2
, and two which printed nothing, but in whicha
is eithertrue
ormaybe
. - Since multiple continuation threads remain, they must be eliminated until only one remains.
- The overall return value of each continuation is basically the last returned value.
maybe
is not valid as a terminal return value, since it is not a definite resolution. Therefore that continuation is removed.- actually, this happened as soon as there were no remaining execution paths on that continuation, which happened after the
if
statement, not after theprint
statement
- actually, this happened as soon as there were no remaining execution paths on that continuation, which happened after the
- as a rule,
false
continuations are only selected if notrue
continuations remain. Thefalse
continuation was retained after when themaybe
continuation was discarded, but now that all threads have completed, and atrue
continuation exists, thefalse
continuation is removed.
- only the
true
continuation remains, so its buffers are flushed, actuating its side effects
- in other words, the
2
is actually printed now.
Execution Steps:
- Trace execution paths
maybe a = 2? a
/ | \
/ / \
/ | \
a < 3? 2 maybe -----false
/ \ \ | \
if true, true maybe maybe false maybe
|
print a! [queue 2(value of a) on output buffer]
|
true
END OF PROGRAM
- Prune ambiguous (
maybe
) results from the tree
- pruning is recursive until no ambiguous ends remain
maybe a = 2? a
/\
/ \
a < 3? 2 false
| |
if true, true false
|
print a! [2 (value of a) queued on output buffer]
|
true
- Successful (
true
) results exist, so remove failures (false
results)
maybe a = 2 a
|
a < 3? 2
|
if true, true
|
print a! [2 (value of a) queued on output buffer]
|
true
- Collapse pure (non-effectful) nodes
print a! [2 (value of a) queued on output buffer]
- Flush buffered effects
prints 2