aboutsummaryrefslogtreecommitdiff
path: root/notes/assignment_and_arrays.txt
blob: b5cad363d4def16b59550de4ff5c898568486337 (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

Can arrays and dictionaries skip the [] characters?
---------------------------------------------------
Reading from an array. Some kind of "default method" would be
called on `arr`. Note that `arr` is always a local variable,
parameter (assuming that SLUL doesn't have top-level constants):

    int i = arr 1
    bool p = grid x, y

Similarly, there could be an "index assignment method":

    arr 1 = 123
    grid x, y = true

This would require that `=` is an operator with very low precedence.

Possibly some types could even override it?

Reference vs copying assignment
-------------------------------
Should there be a distinction between copying and referencing?

Example using symbols:

    # Simple value type
    int    i <- 123
    # referencing (decide on an operator to use)
    File   f2 <= f1
    File   f2 <-> f1
    # copying
    Array of int   arr2 <- arr2

Example using `=` and keywords:

    # Default could be "single-word semantically-copy-like operation"
    # For elementary types and referenced immutable types, it's simple:
    int    i = 123
    Array of int   arr2 = arr1
    # For mutable reference types (i.e. when the source is mutable or already aliased),
    # there's a distinction.
    File   f2 = ref f1
    Array of int   arr2 = copy arr1

Advantage of the keyword solution:
It works for function parameters as well!


Distinguishing between assignment and comparison
------------------------------------------------
Possible syntaxes for assignment:

    =
    <-   (but less intuitive to type)
    :=   (used by many languages, but why?)
    set d,s     (doens't work with array-index assingment!)

Note that some syntaxes make += -= style operations impossible.
* Work: =/+= set/inc
* Doesn't work: <- :=

Possible operators for comparison:
(should be disallowed where it doesn't make sense,
e.g. comparing two file/network streams for equality is pointless)

    ==
    =    (but leads to a bad habit, that can cause problems
          when coding in other languages)
    equal a,b      (but this still has a special character,
                    so maybe == is better?)

Possible operators for reference comparison:

    same a,b