aboutsummaryrefslogtreecommitdiff
path: root/notes/functional.txt
blob: a4e2d73e0665dbe8616c3d8284882fa4cee11a04 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55


Intuitive functions
-------------------

* map
* filter

Less intuitive functions
-------------------------

* fold/reduce

    fold 0, sum, list
    fold 1, multiply, list
    fold min_value, max, list  # unexpected result for empty lists


Can it be renamed to something else?

Or can it be skipped entirely, using "piped functions"?

    sum list
    multiply list
    max list

...How should "piped functions" work for empty lists?
Or just require that the list is non-empty, as a compile-time pre-condition?

Repeating lists
---------------

When a function takes multiple values:

    func stuff
        int a
        int b
        int c
        int d
    code
        ...
    end

it is possible that all of the scalar parameters are non-lists.
Or that all parameter values are lists.
But it is also possible that some subset are lists. In that case, the
other parameters could be passed in as "single-value repeated lists".
I.e. with the following call:

    stuff(list_a, b, list_c, d)

list_a and list_c would be passed as-in, while for b and c, a "single-value
repeated lists" for each of them can be constructed (perhaps on the stack)
and passed as a list to the function.

That way, only two different variants of the function has to be generated.