annotate samples/testarray.tp @ 338:1458c069c715

Added "value" method to option value and option none. It behaves similarly to value:none, except the none case just propagates the none value and the value case wraps the result in an option value
author Michael Pavone <pavone@retrodev.com>
date Sat, 04 Apr 2015 11:54:46 -0700
parents 48daa1d3e052
children 810b6115c1d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
a997e42b9051 Add foreach method to array and add fib sample that can work in C environment and array example
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
40
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
2 sum <- :arr {
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
3 cursum <- 0
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
4 foreach: arr :idx el {
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
5 cursum <- cursum + el
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
6 }
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
7 cursum
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
8 }
39
a997e42b9051 Add foreach method to array and add fib sample that can work in C environment and array example
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 main <- {
a997e42b9051 Add foreach method to array and add fib sample that can work in C environment and array example
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 foo <- #[42 30 28]
40
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
11 bar <- #[]
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
12 bar append: 30
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
13 bar append: 28
927fd7911a01 Add append message to array
Mike Pavone <pavone@retrodev.com>
parents: 39
diff changeset
14 bar append: 42
82
48daa1d3e052 Update testarray sample to use print:
Mike Pavone <pavone@retrodev.com>
parents: 40
diff changeset
15 print: "" . ((sum: foo) + (sum: bar)) . "\n"
39
a997e42b9051 Add foreach method to array and add fib sample that can work in C environment and array example
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 }
a997e42b9051 Add foreach method to array and add fib sample that can work in C environment and array example
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 }
a997e42b9051 Add foreach method to array and add fib sample that can work in C environment and array example
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18