From bil at ccrma.Stanford.EDU Mon Feb 7 05:47:40 2022 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 07 Feb 2022 05:47:40 -0800 Subject: [CM] Snd 22.1 Message-ID: Snd 22.1: no major changes checked: notcurses 3.0.2|3|4|5, Ubuntu 22.04 Thanks!: Christos Vagias, Iain Duncan, Rudolf Adamkovic, Woody Douglass From chris.actondev at gmail.com Mon Feb 21 14:32:56 2022 From: chris.actondev at gmail.com (Christos Vagias) Date: Mon, 21 Feb 2022 23:32:56 +0100 Subject: [CM] Bug in (apply set! ..) Message-ID: Hi Bil & co, Found a bug in (apply set! ..) : > (define x 'foo) foo > (apply set! 'x 'bar ()) ;unbound variable bar in (x bar) And it can get a bit weirder: > (define bar 'the-bar) > (apply set! 'x bar ()) ;unbound variable the-bar in (x the-bar) > (apply set! 'x 'bar ()) the-bar > (eq? x 'the-bar) #t Best, Christos -------------- next part -------------- An HTML attachment was scrubbed... URL: From bil at ccrma.Stanford.EDU Mon Feb 21 15:06:12 2022 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 21 Feb 2022 15:06:12 -0800 Subject: [CM] Bug in (apply set! ..) In-Reply-To: References: Message-ID: I don't immediately see the bug. apply evaluates all its arguments, and set! evaluates its second argument, so (define x 'foo) (apply set! 'x 'bar ()) becomes (#_set! x bar), but bar is not defined when evaluated by set! Similarly (define bar 'the-bar) (apply set! 'x bar ()) ; bar is not quoted -> 'the-bar becomes (#_set! x the-bar) because bar evaluates to the-bar which set! tries to evaluate (as a symbol), but it is not defined. (apply set! 'x 'bar ()) becomes (#_set! x bar) where bar is 'the-bar, so x is set to 'the-bar, so (eq? x 'the-bar) is #t. There is one level of evaluation here for the car (set! -> #_set!) and the target of set!, but two levels for the value (apply does one, and set! the other). From bil at ccrma.Stanford.EDU Mon Feb 21 15:12:11 2022 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 21 Feb 2022 15:12:11 -0800 Subject: [CM] Bug in (apply set! ..) In-Reply-To: References: Message-ID: <30d62d1077723ba97768404620ad2ecb@ccrma.stanford.edu> Maybe it's inconsistent with (apply + a b) where there's only one evaluation of a and b? Hmmm. From chris.actondev at gmail.com Mon Feb 21 15:29:30 2022 From: chris.actondev at gmail.com (Christos Vagias) Date: Tue, 22 Feb 2022 00:29:30 +0100 Subject: [CM] Bug in (apply set! ..) In-Reply-To: <30d62d1077723ba97768404620ad2ecb@ccrma.stanford.edu> References: <30d62d1077723ba97768404620ad2ecb@ccrma.stanford.edu> Message-ID: Oh, I have been missing something: "[..] and set! evaluates its second argument, so [..]" I now realize that to see get the behavior I was going after I needed to (apply set! 'x (quote 'bar) ()) I guess it's not inconsistent at all, I just completely missed the double evaluation going on with the 2nd argument. Thanks for the thorough explanation & sorry for the wrong alarm! On Tue, 22 Feb 2022 at 00:12, wrote: > Maybe it's inconsistent with (apply + a b) where > there's only one evaluation of a and b? Hmmm. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From elronnd at elronnd.net Mon Feb 21 16:20:44 2022 From: elronnd at elronnd.net (Elijah Stone) Date: Mon, 21 Feb 2022 16:20:44 -0800 (PST) Subject: [CM] Bug in (apply set! ..) In-Reply-To: <30d62d1077723ba97768404620ad2ecb@ccrma.stanford.edu> References: <30d62d1077723ba97768404620ad2ecb@ccrma.stanford.edu> Message-ID: <1b35aed8-473d-ca41-f421-a1a6a5dbddd9@elronnd.net> (+ a b) ;evaluates a and b once each (apply + a b ()) ;evaluates a and b once each (set! a b) ;evaluates a zero times and b once (apply set! a b ()) ;evaluates a once and b twice Making the last form apply a and b once each would also be inconsistent: b is supposed to be evaluated more times than a. What would be fully consistent is if (apply + a b ()) evaluated a and b _twice_ each; but that would be bizarre, incompatible, and broadly terrible. (Another thing that comes to mind is to not let apply evaluate any of the arguments to the function to be applied. But you have problems with the tail; how do you handle (apply + (list 1 2))? Well, you could have a 'funcall', which does not need to deal with a tail. But then (funcall f x y) would be the same as (f x y) in all cases...) Finally, I will note there is a simple solution to the original problem: (set! ((curlet) x) 'bar). -E On Mon, 21 Feb 2022, bil at ccrma.Stanford.EDU wrote: > Maybe it's inconsistent with (apply + a b) where > there's only one evaluation of a and b? Hmmm. > > _______________________________________________ > Cmdist mailing list > Cmdist at ccrma.stanford.edu > https://cm-mail.stanford.edu/mailman/listinfo/cmdist > From chris.actondev at gmail.com Tue Feb 22 12:51:56 2022 From: chris.actondev at gmail.com (Christos Vagias) Date: Tue, 22 Feb 2022 21:51:56 +0100 Subject: [CM] reader macro vector peculiarities Message-ID: Hi Bil, I stumbled upon something interesting: (let () (define x #(0 0)) (define (reset) (set! x #(0 0))) (set! (x 0) 1) (reset) (set! (x 1) 2) (reset) x) The x being returned is #(0 2). (Let's ignore the inefficient reset code). I'm guessing that in the reset lambda the #(0 0) is expanded to a cell which is captured in the lambda body & reused later on. Checking with guile, it complains about vector-set!: Wrong type argument in position 1 (expecting mutable vector): #(0 0) So apparently in guile with (define x #(0 0)), x is an immutable vector. Hope this is helpful, not like yesterday! -------------- next part -------------- An HTML attachment was scrubbed... URL: From bil at ccrma.Stanford.EDU Tue Feb 22 13:09:03 2022 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 22 Feb 2022 13:09:03 -0800 Subject: [CM] reader macro vector peculiarities In-Reply-To: References: Message-ID: The #(0 0) business returns a read-time vector That means when you assign it to x, x is now exactly the same vector as is in the reset body, so when you set some element of it via (set! (x...)...) you are changing the vector sitting in the reset function. To avoid this, use (vector 0 0) in reset -- the vector function makes a new vector each time it is called. The same problem affects any sequence (like a string constant, or a quoted list). I think there's something about this in s7.html -- will have to look around, and lint will complain about it. From bil at ccrma.Stanford.EDU Tue Feb 22 13:11:55 2022 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 22 Feb 2022 13:11:55 -0800 Subject: [CM] reader macro vector peculiarities In-Reply-To: References: Message-ID: I forgot to mention that if you set (*s7* 'safety) to 2 or more, these constants are marked as immutable, so you'll get an error if you try to set some element of it. From chris.actondev at gmail.com Tue Feb 22 13:40:03 2022 From: chris.actondev at gmail.com (Christos Vagias) Date: Tue, 22 Feb 2022 22:40:03 +0100 Subject: [CM] reader macro vector peculiarities In-Reply-To: References: Message-ID: Aha, now I get the 'safety comments in s7.html! Thanks for the explanation! On Tue, 22 Feb 2022 at 22:11, wrote: > I forgot to mention that if you set (*s7* 'safety) > to 2 or more, these constants are marked as immutable, > so you'll get an error if you try to set some element > of it. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: