Stabel

Check-in [442b0f85ca]
Login
Overview
Comment:Add a couple of more functions to list module.
Timelines: family | ancestors | descendants | both | stdlib
Files: files | file ages | folders
SHA3-256: 442b0f85caf3df26691a8e126f0b658c8724e33f54a45eb04bfaa76fb776e06f
User & Date: robin.hansen on 2021-04-17 11:04:25
Other Links: branch diff | manifest | tags
Context
2021-04-17
11:05
First implementation of the standard library. check-in: 7e9c8cf531 user: robin.hansen tags: trunk
11:04
Add a couple of more functions to list module. Closed-Leaf check-in: 442b0f85ca user: robin.hansen tags: stdlib
2021-04-16
14:56
Fix bug where generic arguments in quotations didn't renamed properly in the type checking phase, ca... check-in: a64dc94e65 user: robin.hansen tags: stdlib
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified stdlib/src/list.play from [df2166b9d8] to [a7b678c1a9].

4
5
6
7
8
9
10












11
12
13
14
15
16
17
..
19
20
21
22
23
24
25








26
27

28
29
30

defstruct: NonEmpty a
: first a
: rest (List a)

defstruct: Empty













defmulti: fold
type: (List a) b [ a b -- b ] -- b
: Empty
  drop swap drop
: NonEmpty
  pair/>Pair
  swap # (Pair b quot) (NonEmpty a)
................................................................................
  rotate swap # rest first Pair
  dup rotate # rest Pair first Pair
  pair/spill # rest Pair first b quot
  ! # rest Pair b
  swap pair/second> # rest b quot
  fold









def: test
: 1 2 3 Empty >NonEmpty >NonEmpty >NonEmpty

  0 [ + ] fold









>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>

<
>


<
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
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49


defstruct: NonEmpty a
: first a
: rest (List a)

defstruct: Empty

def: of-one
type: a -- (NonEmpty a)
: Empty >NonEmpty

def: of-two
type: a a -- (NonEmpty a)
: Empty >NonEmpty >NonEmpty

def: of-three
type: a a a -- (NonEmpty a)
: Empty >NonEmpty >NonEmpty >NonEmpty

defmulti: fold
type: (List a) b [ a b -- b ] -- b
: Empty
  drop swap drop
: NonEmpty
  pair/>Pair
  swap # (Pair b quot) (NonEmpty a)
................................................................................
  rotate swap # rest first Pair
  dup rotate # rest Pair first Pair
  pair/spill # rest Pair first b quot
  ! # rest Pair b
  swap pair/second> # rest b quot
  fold

def: reverse
type: (List a) -- (List a)
: Empty [ >NonEmpty ] fold

def: fold-right
type: (List a) b [ a b -- b ] -- b
: -rotate reverse rotate fold

def: test

: 1 2 3 of-three
  0 [ + ] fold