On Sun, Nov 05, 2023 at 04:28:42PM +0100, Ralf Hemmecke wrote: > On 11/5/23 01:36, Waldek Hebisch wrote: > > _Any_ attempt to read elements of uninitialized array may lead > > to troubles. So it is not only printing, but in general it is > > unsafe to pass uninitialized array to a routine, unless one > > _knows_ that the routine will initialize the array. > > Yes, exactly that is the point. qnew claims to return an object of type %, > but, in fact, it doesn't.
Well, result of 'qnew' is uninitialized, but this does not differ much from (note no initialization) a : T Would you say that a does not have type T? In principle attempt to read 'a' before initialization may cause the same trouble as attempt to read elements of array returned by 'qnew'. > > We could add the followowing to description of 'qnew': > > > > Use only when you know what you are doing. > > That is one thing, but does not give enough information. How should a user > know what he is doing? Where would he get this information from? One of fundamental commandments of programming is: "Thou shall not attempt to read uninitialized variables" This is general programming knowledge, to get such knowledge Dijkstra "Discipline of programming" may be good start. For people wanting more concrete info, reading GCC bug reports marked "invalid" may provide plenty of examples. 'qnew' is for micro-optimization and here Knuth applies: "premature optimization is source of all evil". > A better phrase would perhaps be: > > qnew constructs structure with uninitialized elements. > Do not pass such a structure to other functions before > its parts are initialized via setelt! or qsetelt!. But there is more to this: people may think that someting like a := qnew(4, 4)$Matrix(Float) b := a(1,1) - a(1, 1) will reliably produce 0. But the above is wrong, because 'a' is uninitilied. The same error appears in a : Float b := a - a Do you want to add a warning in FriCAS book in section describing declarations that one should initialize variables before use? Also, discussion about 'qnew' started because we get crash in Clozure CL. However, once we use Lisp declaration to optimize, we are subject to possible crashes in buggy code. Nontrivial fraction of crashes when using GCL were due to user errors which were cought by other Lisps, but crashed GCL. This time GCL catches error, but Clozure CL crashes. Different Lisp may crash on something else. -- Waldek Hebisch -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/ZUmS3A%2BmxEvHIAjk%40fricas.org.