blob: be130270e8ba36d0b96cdb4cfd530c662fd76c36 (
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
|
Constructor call syntax
=======================
Option 1: Some kind of function-like call:
list <- new List
str <- fromInt String i
# special handling for "new...", "make...", ... ?
# or just accept that there's an ambigiuity of
# constructors vs local variables vs constants?
List list <- new
String str <- fromInt i
# How about parametric types
List of int list <- new
List int list <- new
List Int list <- new
list: List of int = new
list: List Int = new
# Or name-based typing
itemList <- new
# (Maybe have some more compact syntax for common types
# such as lists and maps?)
Int+ list <- new
Int* list <- new
Int: list <- new
[Int] list <- new
Int[] list <- new
[]Int list <- new
Int>String map <- new
Int=String map <- new
Int:String map <- new
Int+String map <- new
[Int]String map <- new
Int[String] map <- new
Int[]String map <- new
String[]Int map <- new
Option 2:
# Without a constructor name, it calls `new`
list <- List
# Calling a specific constructor
str <- String fromInt i
# Calling a constructor with args would then require the constructor name:
list <- List new 16
Option 3:
List list +
String str + fromInt i
List list + new 16
Option 4:
# Infer what happens from name of function (and variable):
# new/from is a constructors, other prefixes are normal functions
list new
str fromInt i
list new 16
# Or with <-
list <- new
str <- fromInt i
list <- new 16
Option 5: (must be combined with another option)
# Implicitly call constructors before the first time a variable
# is used. In that case, the default constructor could be called.
add list 123
# Implicit calls can only be inserted when ALL code paths would
# lead to an implicit constructing; mixing implicit and explicit
# constructions is not allowed!
if should_add_number
# Not allowed! Explicitly constructed in the `else` block.
add list 123
else
list <- new
add list "abc"
end
|