From: NeilBrown Date: Sat, 13 Nov 2021 00:41:36 +0000 (+1100) Subject: updates X-Git-Url: https://ocean-lang.org/code/?p=ocean-D;a=commitdiff_plain;h=62fa958bc69d7b1701376c391a80382d7a7d00d7 updates --- diff --git a/00-TODO b/00-TODO index 13ea9e6..25b8eb1 100644 --- a/00-TODO +++ b/00-TODO @@ -17,12 +17,14 @@ Later Can be used for array size? What else? - anonymous field - array or struct (or pointer to these) multiple anon struct are allowed if they don't conflict - - [] can apply to anon array field - - anon struct field gets fields interpolated + no - transparent fields! They still have a name, but you can + look through it. + - [] can apply to transparent array field + - transparent struct field gets fields interpolated - - anon fields have no name before the :, so + - How to give attributes? just say the word? struct foobar: - :content + x:content transparent size:number - manifest values for arrays and structs [a,b,c] @@ -30,6 +32,13 @@ Later That last doesn't parse easily, unless we require tags... not a good idea. [ .[1] = a, .[2] = b ] ?? Maybe. or () to group, [] for index. To (.foo=a) ( [1] = b ) + + I think that last works. () might almost be optional + .foo=a + is an expression means a structure with a .foo field assined to 'a' + [3] = 2 + is an array for at least 4 elements with 4th set to 2. + - yet more operators << >> # bit-ops & | ~ &~ @@ -55,14 +64,20 @@ Much later - per-field attributes constant, stable, add-only, read-only, mutable, owned, borrowed, dependant, pure - records -- enum +- enum / set - classes - constructors and destructors - or "after" ?? + destructors, which can be declared inline - vtables, fat pointers, list of approaches - operators as interface methods + + - * / etc make an arith interface add sub mult div - interfaces, inheritance - modules, imports and exports + public(version) on types, fields etc - closures, threads, co-routines, generators +- generics/templates. These should be just a compile-time + decision. Same code can be called with suitable methods passed, or + recompiled in the new context and then optimised. - introspection / reflection ? e.g. support serialization find function given a string holding the name diff --git a/Ocean-errors b/Ocean-errors new file mode 100644 index 0000000..b677b86 --- /dev/null +++ b/Ocean-errors @@ -0,0 +1,12 @@ +How to handle errors + +I want things to be able to throw errors - or fail-safe(?) + + arithmetic can over-flow + pointer-dereference probably needs explicit tests + arbitrary functions might report an error + + I need an easy syntax for catching and a simple semantic for + when they aren't caught. + + I could have an 'else' on any simple statement which does error handling 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