Re: rfc: array literals
Yann LeCun <[email protected]> Fri, 12 Dec 2008 19:54:13 -0500
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
Even though the behavior of "static" variables is semantically well
defined, it's true that this particular behavior is a bit confusing
(like the behavior of defvar which most people expect to work like
setq or defparameter).
The semantic of the code below is exactly like:
(defparameter some_random_name [0 0 0 0 0])
(defun test0 ()
(for (i 0 3)
(let ((v some_random_name))
(v 0 (+ (v 0) 1))
(printf "%f " (v 0)) ))
(print) )
The proper way to fix this is to make array literal create a new
matrix every time, and return it.
-- Yann
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/