3 methods are any function that is found from a given value.
4 It can be associated with the type or the value
6 An interface is a set of methods. A concrete type can export an
7 interface and a formal type can require an interface.
9 A value can be combined with a concrete interface to override or augment
10 what it's type natively has. Value methods are not so easily
13 The first arg of a method must match the owner, and other args can be of
16 Interface names are per module.
17 Method names are per interface. When a variable supports multiple
18 interfaces and names don't conflict, interface name can be left out.
20 maybe value method use . and type methods use : ??
21 that would make "case functionname :" tricky to parse.
25 Rather than anon structs, allow struct AND references to be marked as 'follow'
26 so anything behind the object appears in the parent.
27 Then foo.method can possible follow a chain of pointers from foo to find the method.
29 foo might be an inode and have a pointer to a superblock, which has a
30 pointer to a methods structure contains 'getattr'. Then 'foo.getattr'
31 transparently becomes 'foo.super.super_methods.getattr.
33 Question. In what circumstances is 'foo' passed as first argument?
34 Probably it happens by default, but some syntactic escape allows something else
35 to be passed. Maybe foo::something() ??
36 Or foo..something() ??
37 Maybe if type of first arg is compatible, the value before '.' is interpolated
40 So the name after "." can:
42 - be field in struct/record
43 - follow a transparent field
44 - be constant in type - which includes functions.
46 Transparent fields add extra distance and a closer name will match first.
47 So if foo.bar and foo.baz.bar are both valid and baz is transparent, then
48 "foo.bar' gets the former - no conflict is reported. Obviously foo.bax.bar
51 Methods can be added to values to provide required interface for passing to
52 a function. This probably only works for references.
53 We can specify the methods using a type which includes them, or a value
54 which already has them, or individually
55 Syntax might be tricky. For 'sort' I want to pass an array, and a method
56 for comparing two elements of the array. I want the function to see an array
57 where the element are already comparable.
58 So the function declares that it needs a type
60 func qsort(type:comparable, target:[size::]type)
62 function will need size of members of array, size of array, and compare function.
63 func qsort (target:[size::]type:comparable)
66 qsort(ra, :ra[].cmp(a, b) = a >= b)
68 Same syntax could add a destructor
70 foo: bar .free = myfunction