aboutsummaryrefslogtreecommitdiff
path: root/notes/nested_inner_classes.txt
blob: fde5f60e737fc28c2f70eeb0756c682827290630 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

Nested/Inner Classes
====================

This is very useful for:
* small record types
    for example in:
    - multiple return values
    - extensible alternative to function parameters/return values
    - in data structures, e.g. lists, maps.
    - to avoid repetition.
* builder classes
* wrappers

Should it be allowed for all, or only for e.g. records?
- functions inside them will only be allowed to access data that belongs
  to the nested class.

Should it be possible to expose/export inner classes?
- within the module?
- outside of the module?


Syntax
------
Should it implicitly be a `data` block?
What keyword(s) to use?
- `local class`
- `inner class`
- `nested class`
- `nested`

Example:

    nested Point
        int x
        int y
    end

    data
        Point p1
        Point p2
    end

Or

    # or
    #nested data Point
    #inner data Point
    nested class Point
        int x
        int y
    end

Or (best?)

    nested Point
        data
            int x
            int y
        end
    end

    data
        Point p1
        Point p2
    end

Or

    # In order to give good error messages when `class N` is placed the
    # beginning of N.slul, let's use some distinctive keyword sequence
    # instead of just `class`:
    local class Point
        data
            int x
            int y
        end
    end

    data
        Point p1
        Point p2
    end