Files
compiler-the-translators/tests/carl/NoErrors/functionValue.alpha
Scarlett c091927fe7 carl
2025-04-15 14:46:00 -04:00

74 lines
1.2 KiB
Plaintext

(* Type definitions *)
(* mapping type *)
type string2int: string -> integer
(* array of functions *)
type funArray: 1 -> string2int
(* record of functions *)
type funRec: [ string2int: f; string2int: g ]
(* function returning function *)
type integer_2_string2int: integer -> string2int
(* function returning function *)
type string2int_2_integer: string2int -> integer
type iXiXc: [integer: a; integer: b; character: c]
type iic2b: iXiXc -> Boolean
(* Function declarations using the above type definitions *)
function a: string2int
function b: integer_2_string2int
function c: string2int_2_integer
function d: iic2b
d(x,y,z) := {
return (x < y & z < 'm');
}
function entry: string2int
a(x) := {
[string : s]
s := x;
return 0;
}
b(x) := {
[integer: i]
i := x;
return a;
}
c(x) := {
[string: s]
s := "Hi!";
return x(s);
}
(* Function definition
entry is the first function called
*)
entry(arg) := {
[integer: result; string2int: f; integer: temp]
temp := a("Hello");
f := b(temp);
result := c(f);
if (d(1,2,'c'))
then {
result := 0;
}
else {
[ Boolean : b]
result := entry("hello");
}
result := c(f);
return result;
}