Hi All,
Two related questions about naming conventions.
First question:
At the moment whenever you create a named type e.g.:
(bind-type MyObj <i64,String*,|4,i64|>)
Extempore creates two constructors for you. A reference constructor MyObj and a value constructor myObj (note case). This is also true for a lower-case named type e.g.
(bind-type my_other_obj <i64,String*,|4,i64|>)
Which gives a reference constructor My_other_obj and a value constructor my_other_obj.
Note that by convention we are trying to encourage capitalized camel style named-types. Although this is not enforced you will now get a little notification message about this. The is in contrast to xtlang procedures which are by convention lowercase and separated by underscores.
If you are wondering what I mean by reference and value constructors, here are two examples using MyObj.
(bind-func test_myobj_ref_constructor
(lambda ()
(let ((obj (MyObj 4 (Str "Hello") (array 1 2 3 4))))
obj)))
(bind-func test_myobj_val_constructor
(lambda ()
(let ((obj (myObj 4 (Str "Hello") (array 1 2 3 4))))
obj)))
The important thing to notice is (a) the use of MyObj vs myObj constructor, and the return type of the two functions.
Compiled: test_myobj_ref_constructor >>> [MyObj*]*
Compiled: test_myobj_val_constructor >>> [MyObj]*
The ref constructor example returning type MyObj* and the value constructor returning type MyObj. The reference constructor zone allocates memory for the new MyObj and returns a reference to that zone allocated memory. The value constructor stack allocates memory for the new MyObj and then returns a copy of that object (for small objects on 64bit architectures this will usually be by register).
Also worth mentioning here is the use of (array 1 2 3 4). You can "construct" arrays in xtlang using either "array" or "Array" where again the capitalization is by value "array" or reference "Array", where the reference allocation is (as with named types) zone allocation. So for example (array 1 2 3 4) is type |4,i64| and (Array 1 2 3 4) is type |4,i64|*. xtlang also supports similar semantics for tuples i.e. "(Tuple 1:i64 (Str "Andrew") " and "(tuple 1:i64 (Str "Andrew") and vectors "(Vector 1.0:f 2.0 3.0 4.0)" and "(vector 1.0:f 2.0 3.0 4.0)".
So, apart from providing a little more information, my main question is about this use of upper/lowercase constructors to differentiate ref vs value semantics. I'm obviously uncomfortable about this and was wondering if anyone has a better idea. We need as solution that is concise. Something like MyObj_r and MyObj_v might be ok - but MyObj and MyObj_val might not be? It would also be nice to use the same semantics for both named types, as well as array/vector/tuple constructors. So if we went with "_val" for example, we would also have Array & array_val, Tuple and tuple_val etc..
Please let me know what you think.
Second Question:
pref/aref/tref and pref-ptr/aref-ptr/tref-ptr or poorly named. The naming originally came from schemes 'list-ref' (the full expansion of aref in xtlang is actually array-ref). list-ref does actually make sense for scheme but array-ref doesn't make sense for extempore, because array-ref actually returns a value not a ref. In fact aref-ptr returns a reference.
So we really need a rename here. I'm pretty happy with aref (and friends) changing to aval and aref-ptr changing to aref. Of course this is going to be a little painful while we all adjust to 'aref' semantics changing.
Unfortunately this is a fairly aggressive change that will certainly break everyone's code - in some fairly nasty ways.
Alternatively, if we change aref-ptr to something other than aref we could run aref and aval in parallel for a while, and aref-ptr with xxxx in parallel for a while. This would make the change over much easier - but the question then is what would aref-ptr become? (aref really does make the most sense).
Please let me know what you think (a) about names and (b) about when might be a good time to introduce this kind of breaking change.
I would really appreciate a range of views on these topics so please sing out.
Cheers,
Andrew.