2019-09-22 01:59:48 +04:00
|
|
|
// Test list type and related built-in functions in PascaLIGO
|
|
|
|
|
2019-05-13 00:56:22 +04:00
|
|
|
type foobar is list(int)
|
|
|
|
|
|
|
|
const fb : foobar = list
|
|
|
|
23 ;
|
|
|
|
42 ;
|
|
|
|
end
|
|
|
|
|
2019-09-08 14:34:29 +04:00
|
|
|
const fb2 : foobar = 144 # fb
|
|
|
|
|
|
|
|
const fb3 : foobar = cons(688 , fb2)
|
|
|
|
|
2019-05-13 00:56:22 +04:00
|
|
|
function size_ (const m : foobar) : nat is
|
|
|
|
block {skip} with (size(m))
|
|
|
|
|
|
|
|
// function hdf (const m : foobar) : int is begin skip end with hd(m)
|
|
|
|
|
|
|
|
const bl : foobar = list
|
|
|
|
144 ;
|
|
|
|
51 ;
|
|
|
|
42 ;
|
|
|
|
120 ;
|
|
|
|
421 ;
|
|
|
|
end
|
2019-07-20 15:46:42 +04:00
|
|
|
|
|
|
|
function iter_op (const s : list(int)) : int is
|
|
|
|
var r : int := 0 ;
|
|
|
|
function aggregate (const i : int) : unit is
|
|
|
|
begin
|
|
|
|
r := r + i ;
|
|
|
|
end with unit
|
|
|
|
begin
|
|
|
|
list_iter(s , aggregate) ;
|
|
|
|
end with r
|
2019-07-20 18:18:50 +04:00
|
|
|
|
|
|
|
function map_op (const s : list(int)) : list(int) is
|
|
|
|
function increment (const i : int) : int is block { skip } with i + 1
|
|
|
|
block { skip } with list_map(s , increment)
|