forked from Orchid/orchid
pre-recording backup
This commit is contained in:
15
examples/calculator/fn.orc
Normal file
15
examples/calculator/fn.orc
Normal file
@@ -0,0 +1,15 @@
|
||||
export Y := \f.(\x.f (x x))(\x.f (x x))
|
||||
|
||||
export loop $r on (..$parameters) with ...$tail =0x5p129=> Y (\$r.
|
||||
bind_names (..$parameters) (...$tail)
|
||||
) ..$parameters
|
||||
|
||||
-- bind each of the names in the first argument as a parameter for the second argument
|
||||
bind_names ($name ..$rest) $payload =0x1p250=> \$name. bind_names (..$rest) $payload
|
||||
bind_names () (...$payload) =0x1p250=> ...$payload
|
||||
|
||||
export ...$prefix $ ...$suffix:1 =0x1p34=> ...$prefix (...$suffix)
|
||||
export ...$prefix |> $fn ..$suffix:1 =0x2p32=> $fn (...$prefix) ..$suffix
|
||||
|
||||
export (...$argv) => ...$body =0x2p129=> (bind_names (...$argv) (...$body))
|
||||
$name => ...$body =0x1p129=> (\$name. ...$body)
|
||||
@@ -2,10 +2,13 @@ import std::(parse_float, to_string)
|
||||
import std::(readline, print)
|
||||
|
||||
export main := do{
|
||||
cps print "left operand: ";
|
||||
cps data = readline;
|
||||
let a = parse_float data;
|
||||
cps print "operator: ";
|
||||
cps op = readline;
|
||||
cps print ("\"" ++ op ++ "\"\n");
|
||||
cps print ("you selected \"" ++ op ++ "\"\n");
|
||||
cps print "right operand: ";
|
||||
cps data = readline;
|
||||
let b = parse_float data;
|
||||
let result = (
|
||||
@@ -13,8 +16,8 @@ export main := do{
|
||||
else if op == "-" then a - b
|
||||
else if op == "*" then a * b
|
||||
else if op == "/" then a / b
|
||||
else "Unsupported operation" -- dynamically typed shenanigans
|
||||
else (panic "Unsupported operation")
|
||||
);
|
||||
cps print (to_string result ++ "\n");
|
||||
cps print ("Result: " ++ to_string result ++ "\n");
|
||||
0
|
||||
}
|
||||
Reference in New Issue
Block a user