Closed porky11 closed 7 years ago
On Fri, Sep 30, 2016 at 04:59:41PM -0700, Fabio Krapohl wrote:
In other system programming languages, you should define specialized operations for arithmetic operations (like
operator+=
in c++ andAddAssign
in Rust) retval seems to make this unneccessary, but this is not clear in the documentation. Would(setv a (+ a b))
when called some array-like types, write the results of each sum directly toa
, if this+
is a retval-func? or is this only true for newly initialized variables? it would be a benefit over c++, if this is the case, and should be documented more clearly.
It doesn't cover the operator+= case: the retval binding provided to a retval function is always a pointer to a freshly-initialised value of the relevant type. It's essentially a more explicit version of C++'s named return value optimisation.
Would be nice, if retval would point to the set variable. A macro, which acts similar to retval-functions, but in this way, shouldn't be too difficult to write.
I think it would be unintuitive if retvals were permitted to access the state of the variable for the purposes of mutating it. While custom setf functions can access the state of the target variable, there is a legitimate expectation on the part of an author that these functions overwrite the target state with the argument state, putting aside any internal bookkeeping or similar that they might do.
I already had examples where overriding retvals may cause problems (matrix multiplication)
In other system programming languages, you should define specialized operations for arithmetic operations (like
operator+=
in c++ andAddAssign
in Rust) retval seems to make this unneccessary, but this is not clear in the documentation. Would(setv a (+ a b))
when called some array-like types, write the results of each sum directly toa
, if this+
is a retval-func? or is this only true for newly initialized variables? it would be a benefit over c++, if this is the case forsetf
, and should be documented more clearly.