Re: rfc: array literals

Ralf Juengling <[email protected]> Wed, 17 Dec 2008 13:55:45 -0800 (PST)
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
On Fri, 12 Dec 2008, Yann LeCun wrote:

> The proper way to fix this is to make array literal create a new
> matrix every time, and return it.

Alternatively, we could make array literals immutable. The
the code below would generate an error; the user would have
to explicitly create a copy that he can then modify.

Not sure way is be better.

Ralf


>
> On Friday 12 December 2008, Ralf Juengling wrote:
>> Hello,
>>
>> Consider this code, which exhibits a malicious bug.
>>
>> (defun test0 ()
>>    (for (i 0 3)
>>      (let ((v [0 0 0 0 0]))
>>        (v 0 (+ (v 0) 1))
>>        (printf "%f " (v 0)) ))
>>    (print) )
>>
>> ? (test0)
>> 1 2 3 4
>> = ()
>>
>> The desired output is "1 1 1 1". If I remember correctly,
>> somewhere in the documentation array literals are advertised
>> as a means to simulate something like "static variables" in
>> C. But here it does not square with the semantics of let.
>>
>> In my opinion, this is behavior will be confusing to many
>> users and we should change it in Lush2. When compiled, v
>> should simply be allocated on the stack when it is not returned
>> (and dynamically otherwise).
>>
>> Ralf
>>
>> ---------------------------------------------------------------------------
>> --- SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas,
>> Nevada. The future of the web can't happen without you.  Join us at MIX09
>> to help pave the way to the Next Web now. Learn more and register at
>> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com
>> / _______________________________________________
>> Lush-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/lush-devel
>
>
>
>

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/