File: Test3

package info (click to toggle)
omake 0.10.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,076 kB
  • sloc: ml: 49,729; ansic: 5,163; makefile: 688; sh: 110
file content (42 lines) | stat: -rw-r--r-- 709 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env osh

.LANGUAGE: program

errors = false

check(exp, e, r) =
    if e = r
        println($"$(exp) = $e [SUCCESS]")
    else
        eprintln($"$(exp) = $e, should be $r [FAILURE]")
	errors = true
	export
    export

################################################
# Factorial
#
fact(i) =
    if i = 0
        value 1
    else
        value i * fact(i - 1)

check($"fact(10)", fact(10), 3628800)

################################################
# Mapper
#
map(f, l) =
    public.l = l
    items[] =
    while l.is-nonempty
        items[] += f(l[0])
	l = nth-tl(1, l)
    value items

check($"map(i => i + 1, [10; 20; 30])", map(i => i + 1, [10; 20; 30]), [11; 21; 31])

if errors
    exit 1