Re: rfc: array literals
Ralf Juengling <[email protected]> Thu, 10 Sep 2009 16:19:14 -0700 (PDT)
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---58492207-1917855976-1252624754=:478 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed FYI, this change is now implemented. Note that Yann's version of test0 and the original version of test0 (below) now behave differently (intentionally so). I have attached a little script with examples you may run to see the new behavior. Ralf On Fri, 12 Dec 2008, Yann LeCun wrote: > 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 > > > > ---58492207-1917855976-1252624754=:478 Content-Type: TEXT/PLAIN; charset=US-ASCII; name=test-let.lsh Content-Transfer-Encoding: BASE64 Content-ID: <[email protected]> Content-Description: Content-Disposition: attachment; filename=test-let.lsh DQooZGVmdW4gdGVzdDAgKCkNCiAgKGZvciAoaSAwIDMpDQogICAgKGxldCAo KHYgWzAgMCAwIDAgMF0pKQ0KICAgICAgKHYgMCAoKyAodiAwKSAxKSkNCiAg ICAgIChwcmludGYgIiUuMWYgIiAodiAwKSkgKSkNCiAgKHByaW50ZiAiXG4i KSApDQoNCjs7IHNhbWUgYXMgdGVzdDAsIGp1c3Qgbm90IGNvbXBpbGVkDQoo ZGVmdW4gdGVzdDEgKCkNCiAgKGZvciAoaSAwIDMpDQogICAgKGxldCAoKHYg WzAgMCAwIDAgMF0pKQ0KICAgICAgKHYgMCAoKyAodiAwKSAxKSkNCiAgICAg IChwcmludGYgIiUuMWYgIiAodiAwKSkgKSkNCiAgKHByaW50ZiAiXG4iKSAp DQoNCjs7IHNhbWUgYXMgdGVzdDEsIHVzZXMgbGV0KiBpbnN0ZWFkIG9mIGxl dA0KKGRlZnVuIHRlc3QyICgpDQogIChmb3IgKGkgMCAzKQ0KICAgIChsZXQq ICgodiBbMCAwIDAgMCAwXSkpDQogICAgICAodiAwICgrICh2IDApIDEpKQ0K ICAgICAgKHByaW50ZiAiJS4xZiAiICh2IDApKSApKQ0KICAocHJpbnRmICJc biIpICkNCg0KKGRlZnVuIHRlc3QzICgpDQogIChmb3IgKGkgMCAzKQ0KICAg IChsZXQgKCgodSB2KSAnKGR1bW15IFswIDAgMCAwIDBdKSkpDQogICAgICAo diAwICgrICh2IDApIDEpKQ0KICAgICAgKHByaW50ZiAiJS4xZiAiICh2IDAp KSApKQ0KICAocHJpbnRmICJcbiIpICkNCg0KDQooZGVmcGFyYW1ldGVyICp2 KiBbMCAwIDAgMCAwXSkNCg0KKGRlZnVuIHRlc3Q0ICgpDQogIChmb3IgKGkg MCAzKQ0KICAgIChsZXQgKCh2ICp2KikpDQogICAgICAodiAwICgrICh2IDAp IDEpKQ0KICAgICAgKHByaW50ZiAiJS4xZiAiICh2IDApKSApKQ0KICAocHJp bnRmICJcbiIpICkNCg0KICANCihkaGMtbWFrZSAoKQ0KICAgICAgICAgIHRl c3QwKQ0KDQo= ---58492207-1917855976-1252624754=:478 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ---58492207-1917855976-1252624754=:478 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Lush-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/lush-devel ---58492207-1917855976-1252624754=:478--