blob: 8b1a4a267f821da8c992a9278ad2c9bc4e40f556 (
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
|
Name-based type inferrence
==========================
Example:
names
bool found
Item item
List list
string name
int i j k
end
# Both `name` and identifiers that end with `Name`
# could be mapped using name-based type inferrence.
func process_item itemName
code
found <- false
# `itemList` is assumed to be a List of Items
for item in itemList
if item.name == itemName
found <- true
end
end
process_item itemName create_new=found
end
Downsides:
* Causes longer identifiers names, which could make the code
harder to read in some cases.
Syntax:
# Like this?
names
bool found
List list
end
# Or, like this?
names
found: bool
list: List
end
# Or, in a separate `names.lst` file?
# (Maybe some other name, because I think that filename is already
# in use by Liero (an old game) and perhaps other software;
# it's just too "common"-ish)
"This and that typing"
----------------------
Trivial example, to show the point:
func do_stuff
types
Item inp
Thing outp
code
outpList <- new
for inp in get_items
inpName <- inp.name
skip if is_skipped_name inpName
outp <- convert inp
add outpList outp
end
end
Problem: Extra lookups / ambuigity
----------------------------------
"someList"
"someString"
List is a generic type. String is not. But this might not be known at the
time when the particular source file is being parsed.
|