Re: Possible bug with prog1 and @
That makes sense now. Thanks for the clarification! Kevin On Tue, Feb 8, 2022 at 1:03 PM Alexander Burger wrote: > Hi Kevin, > > > I may have encountered a possible bug, unless my understanding of @ is > > incorrect. It appears the value of @ is not restored in a prog1 body when > > another flow/logic statement occurs as the car of an expression within > the > > This is right. All flow functions which set '@' do *not* bind it. The > value is > simply set. > > > > Test Cases: > > > > (let (A0 (1) > > A1 (2 3) > > A2 'x) > > (prog1 (cdr A1) > > At this moment '@' is set to the result of evaluating (cdr A1). > > > ((if (sym? A2) 'set 'con) A2 A0) > > Now '@' was overwritten by 'if'. > > > '@' is bound only on the function call level. That is, '@' is restored to > the > caller's value when the function returns. > > But inside a function's body the rule is that > > 1. Functions with controlling expressions just set '@' to the result. > 'prog1' is >such a function. > > 2. Functions with conditional expressions set '@' to the result *IF* the > result >is non-NIL (otherwise they leave it untouched). > > > All this is described in more detail in > >https://software-lab.de/doc/ref.html#atres > > ☺/ A!ex > > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: Possible bug with prog1 and @
Hi Kevin, > I may have encountered a possible bug, unless my understanding of @ is > incorrect. It appears the value of @ is not restored in a prog1 body when > another flow/logic statement occurs as the car of an expression within the This is right. All flow functions which set '@' do *not* bind it. The value is simply set. > Test Cases: > > (let (A0 (1) > A1 (2 3) > A2 'x) > (prog1 (cdr A1) At this moment '@' is set to the result of evaluating (cdr A1). > ((if (sym? A2) 'set 'con) A2 A0) Now '@' was overwritten by 'if'. '@' is bound only on the function call level. That is, '@' is restored to the caller's value when the function returns. But inside a function's body the rule is that 1. Functions with controlling expressions just set '@' to the result. 'prog1' is such a function. 2. Functions with conditional expressions set '@' to the result *IF* the result is non-NIL (otherwise they leave it untouched). All this is described in more detail in https://software-lab.de/doc/ref.html#atres ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Possible bug with prog1 and @
This behavior seems like it is "as advertised"? I see in the documentation: "Flow- and logic-functions store the result of their controlling expression - respectively non-NIL results of their conditional expression - in @." So the case when (sym? A2) seemingly would not update the current value of @, and... "@ is generally local to functions and methods, its value is automatically saved upon function entry and restored at exit." No function has been entered or exited here, unless I'm misunderstanding what constitutes a function. -wilhelm On 2/8/22 9:15 AM, Kevin Ednalino wrote: Hello, I may have encountered a possible bug, unless my understanding of @ is incorrect. It appears the value of @ is not restored in a prog1 body when another flow/logic statement occurs as the car of an expression within the said prog1 body. In both cases, the correct result is returned from prog1. Test Cases: (let (A0 (1) A1 (2 3) A2 'x) (prog1 (cdr A1) ((if (sym? A2) 'set 'con) A2 A0) # Prints T when sym? result is T (incorrect) # but prints (3) when sym? result is NIL (correct) # Expect (3) printed regardless of sym? result (println @))) (let (A0 (1) A1 (2 3) A2 (4)) (prog1 (cdr A1) ((if (sym? A2) 'set 'con) A2 A0) # Prints T when sym? result is T (incorrect) # but prints (3) when sym? result is NIL (correct) # Expect (3) printed regardless of sym? result (println @))) Thanks, Kevin
Possible bug with prog1 and @
Hello, I may have encountered a possible bug, unless my understanding of @ is incorrect. It appears the value of @ is not restored in a prog1 body when another flow/logic statement occurs as the car of an expression within the said prog1 body. In both cases, the correct result is returned from prog1. Test Cases: (let (A0 (1) A1 (2 3) A2 'x) (prog1 (cdr A1) ((if (sym? A2) 'set 'con) A2 A0) # Prints T when sym? result is T (incorrect) # but prints (3) when sym? result is NIL (correct) # Expect (3) printed regardless of sym? result (println @))) (let (A0 (1) A1 (2 3) A2 (4)) (prog1 (cdr A1) ((if (sym? A2) 'set 'con) A2 A0) # Prints T when sym? result is T (incorrect) # but prints (3) when sym? result is NIL (correct) # Expect (3) printed regardless of sym? result (println @))) Thanks, Kevin