mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 23:38:47 +00:00
Spec changed; Changes introduced; fixed minor bugs
This commit is contained in:
parent
7c7ef67e1d
commit
59f78fe38a
6 changed files with 49 additions and 23 deletions
|
|
@ -1,15 +1,16 @@
|
|||
printf ("if, case, for, while, repeat etc. are all expressions.\n");
|
||||
printf ("if, case, for, while etc. are all expressions.\n");
|
||||
|
||||
printf ("Case-expression: %s\n", case A (1, 2, 3) of A (x, y, z) -> z esac.string);
|
||||
|
||||
printf ("If-expression: %s\n", (if true then 2 else 3 fi +
|
||||
if false then 6 else 7 fi).string);
|
||||
|
||||
printf ("Scope-expression: %s\n", {local i, s = 0;
|
||||
|
||||
printf ("Scope-expression: %s\n", (var i, s = 0;
|
||||
for i := 0, i < 10, i := i + 1 do
|
||||
s := s + i
|
||||
od;
|
||||
s
|
||||
}.string
|
||||
).string
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
fun show (x) {
|
||||
fun show (level, x) {
|
||||
for local i; i := 0, i<level, i := i + 1 do
|
||||
for var i; i := 0, i<level, i := i + 1 do
|
||||
printf (" ")
|
||||
od;
|
||||
|
||||
case x of
|
||||
#unboxed -> printf ("integer %d\n", x);
|
||||
return
|
||||
| #array -> printf ("array\n")
|
||||
| #string -> printf ("string\n")
|
||||
| #sexp -> printf ("S-expression\n")
|
||||
| #fun -> printf ("closure 0x%x\n", x[0])
|
||||
#val -> printf ("integer %d\n", x)
|
||||
| #array -> printf ("array\n")
|
||||
| #str -> printf ("string\n")
|
||||
| #sexp -> printf ("S-expression\n")
|
||||
| #fun -> printf ("closure 0x%x\n", x[0])
|
||||
esac;
|
||||
|
||||
for local i; i := case x of #fun -> 1 | _ -> 0 esac, i < x.length, i := i + 1 do
|
||||
show (level + 2, x[i])
|
||||
od
|
||||
case x of
|
||||
#val -> skip
|
||||
| _ -> for var i; i := case x of #fun -> 1 | _ -> 0 esac, i < x.length, i := i + 1 do
|
||||
show (level + 2, x[i])
|
||||
od
|
||||
esac
|
||||
}
|
||||
|
||||
show (0, x)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
local samples = [
|
||||
var samples = [
|
||||
{"a", "b", "c"},
|
||||
"string",
|
||||
[],
|
||||
Fruit ("apple"),
|
||||
fun (){skip}
|
||||
fun () {skip}
|
||||
];
|
||||
|
||||
fun show () {
|
||||
-- Note: it would be much better to use iterArray from standard unit Array;
|
||||
-- in that case, however, we wouldn't be able to showcase
|
||||
-- for-loops and []-expressions.
|
||||
for local i; i := 0, i < samples.length, i := i+1 do
|
||||
for var i; i := 0, i < samples.length, i := i+1 do
|
||||
printf (" %s has %d subvalue(s):\n", samples[i].string, samples[i].length);
|
||||
for local j; j := 0, j < samples[i].length, j := j+1 do
|
||||
for var j; j := 0, j < samples[i].length, j := j+1 do
|
||||
printf (" subvalue [%d] = %s\n", j, samples[i][j].string)
|
||||
od
|
||||
od
|
||||
|
|
@ -29,5 +29,5 @@ printf ("And the subvalues of a composite value can be reassigned.\n");
|
|||
samples [2] := [1, 2, 3];
|
||||
samples [0][1] := {};
|
||||
|
||||
show ()
|
||||
show ()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue