2019-09-21 14:59:48 -07:00
|
|
|
// Test list type and related built-in functions in PascaLIGO
|
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
type foobar is list (int)
|
2019-05-12 20:56:22 +00:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
const fb : foobar = list [23; 42]
|
2019-05-12 20:56:22 +00:00
|
|
|
|
2019-09-08 12:34:29 +02:00
|
|
|
const fb2 : foobar = 144 # fb
|
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
const fb3 : foobar = cons (688, fb2)
|
2019-09-08 12:34:29 +02:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function size_ (const m : foobar) : nat is size (m)
|
2019-05-12 20:56:22 +00:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
// function hdf (const m : foobar) : int is hd (m)
|
2019-05-12 20:56:22 +00:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
const bl : foobar = list [144; 51; 42; 120; 421]
|
2019-11-20 12:16:31 +00:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function fold_op (const s : list (int)) : int is
|
|
|
|
block {
|
|
|
|
function aggregate (const prec: int; const cur: int) : int is prec+cur
|
2020-02-27 19:09:14 +01:00
|
|
|
} with List.fold (aggregate, s, 10)
|
2019-11-20 12:16:31 +00:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function iter_op (const s : list (int)) : int is
|
|
|
|
block {
|
|
|
|
var r : int := 0;
|
2019-11-18 16:10:48 +01:00
|
|
|
function aggregate (const i : int) : unit is
|
2020-02-10 19:27:58 +01:00
|
|
|
block { r := r + i } with unit;
|
2020-02-27 19:09:14 +01:00
|
|
|
List.iter (aggregate, s)
|
2020-02-10 19:27:58 +01:00
|
|
|
} with r
|
2019-07-20 16:18:50 +02:00
|
|
|
|
2020-02-10 19:27:58 +01:00
|
|
|
function map_op (const s : list (int)) : list (int) is
|
2019-11-18 16:10:48 +01:00
|
|
|
block {
|
2020-02-10 19:27:58 +01:00
|
|
|
function increment (const i : int) : int is i+1
|
2020-02-27 19:09:14 +01:00
|
|
|
} with List.map (increment, s)
|