X-Git-Url: https://ocean-lang.org/code/?p=ocean-D;a=blobdiff_plain;f=Ocean-methods;h=8af345589c7441835581fef592b415b86d7da2a1;hp=8876f5514168a75549537dc62a3a5b654599f967;hb=62fa958bc69d7b1701376c391a80382d7a7d00d7;hpb=509e0c8cd5c64e608032aa95a51dd5096185c338;ds=sidebyside diff --git a/Ocean-methods b/Ocean-methods index 8876f55..8af3455 100644 --- a/Ocean-methods +++ b/Ocean-methods @@ -27,9 +27,44 @@ Thought: Then foo.method can possible follow a chain of pointers from foo to find the method. foo might be an inode and have a pointer to a superblock, which has a - pointer to a methods struture contains 'getattr'. Then 'foo.getattr' + pointer to a methods structure contains 'getattr'. Then 'foo.getattr' transparently becomes 'foo.super.super_methods.getattr. Question. In what circumstances is 'foo' passed as first argument? Probably it happens by default, but some syntactic escape allows something else to be passed. Maybe foo::something() ?? + Or foo..something() ?? + Maybe if type of first arg is compatible, the value before '.' is interpolated + unless ".." is used. + + So the name after "." can: + - follow a pointer + - be field in struct/record + - follow a transparent field + - be constant in type - which includes functions. + + Transparent fields add extra distance and a closer name will match first. + So if foo.bar and foo.baz.bar are both valid and baz is transparent, then + "foo.bar' gets the former - no conflict is reported. Obviously foo.bax.bar + gets the latter + +Methods can be added to values to provide required interface for passing to +a function. This probably only works for references. +We can specify the methods using a type which includes them, or a value +which already has them, or individually +Syntax might be tricky. For 'sort' I want to pass an array, and a method +for comparing two elements of the array. I want the function to see an array +where the element are already comparable. +So the function declares that it needs a type + + func qsort(type:comparable, target:[size::]type) + +function will need size of members of array, size of array, and compare function. + func qsort (target:[size::]type:comparable) + + ra:[32]int + qsort(ra, :ra[].cmp(a, b) = a >= b) + +Same syntax could add a destructor + + foo: bar .free = myfunction