Re: get the 'up value of a variable across a lambda
Ok, I see my mistake. I assumed that let and the rest could create enclosing environments, when only a function call can. Another example I made of how to use 'up: : (de f () (and 1000 (up 1 @) @)) -> f : (and 10 (f)) -> 10 Thanks for the clarification alex! On Mon, May 24, 2021 at 12:55 AM Alexander Burger wrote: > On Sun, May 23, 2021 at 08:44:32PM -0500, polifemo wrote: > > `(let @ 1 (let @ 10 (let @ 20 (up 2 @` > > This are two misunderstandings in this example: > > 1. It has not a good idea to bind '@' in a 'let' expression. '@' is set >implicitly by flow- and logic-functions, so a correct usage would be > > (and 1 (or 10 (while 20 (up 2 @ > >or - more realistically - > > (and (foo) (or (bar) (while (zup) (up 2 @ > > 2. 'up' does not care about 'let', 'use', 'for' etc. They are ignored. An > up >"enclosing environment" always means the enclosing *function* > environment. So >all the above 'let's all run in the same environment. The same rule > applies >to the environment offsets to 'eval' and 'run'. > > > > returns 1, as I expected, if I enclose the 'up expression inside a > function > > This return value of '1' just happens because the environment setup in > bindeng > '@' in 'let' is undefined. > > > Let me try to give an example. > >(when 7 # The result of 'when' is what we are interested in > (extract > '((N) # Here we are in a function > (when (num? N) # 'when' sets '@' >(+ N @) ) ) # so we add the wrong '@' > (1 a 2 b 3))) >-> (2 4 6) > >(when 7 > (extract > '((N) # in a function > (when (num? N) >(+ N (up 1 @)) ) ) # Here we get the '7' > (1 a 2 b 3))) >-> (8 9 10) > > ☺/ A!ex > > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: get the 'up value of a variable across a lambda
On Sun, May 23, 2021 at 08:44:32PM -0500, polifemo wrote: > `(let @ 1 (let @ 10 (let @ 20 (up 2 @` This are two misunderstandings in this example: 1. It has not a good idea to bind '@' in a 'let' expression. '@' is set implicitly by flow- and logic-functions, so a correct usage would be (and 1 (or 10 (while 20 (up 2 @ or - more realistically - (and (foo) (or (bar) (while (zup) (up 2 @ 2. 'up' does not care about 'let', 'use', 'for' etc. They are ignored. An up "enclosing environment" always means the enclosing *function* environment. So all the above 'let's all run in the same environment. The same rule applies to the environment offsets to 'eval' and 'run'. > returns 1, as I expected, if I enclose the 'up expression inside a function This return value of '1' just happens because the environment setup in bindeng '@' in 'let' is undefined. Let me try to give an example. (when 7 # The result of 'when' is what we are interested in (extract '((N) # Here we are in a function (when (num? N) # 'when' sets '@' (+ N @) ) ) # so we add the wrong '@' (1 a 2 b 3))) -> (2 4 6) (when 7 (extract '((N) # in a function (when (num? N) (+ N (up 1 @)) ) ) # Here we get the '7' (1 a 2 b 3))) -> (8 9 10) ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: get function for chart holding list of db objects
Hi Olaf, you are quite close, I think. The 'keyA' relation has a small problem (class +Foo +Entity) (rel keyA (+Ref +Number) 2) (rel keyB (+Ref +String)) '+Ref' takes an optional argument, and '2' should be for '+Number', so correct would be (rel keyA (+Ref +Number) NIL 2) Then, instead of using Pilog (solve '( @F Floor @C Ceil (db keyA (@F . @C) @FooObj) ) @FooObj) ) you could also simply (collect 'keyA '+Foo) to get a list of all objects. Note, however, that both 'solve' and 'collect' are not so wise if the database has many '+Foo' objects, because they return _all_ objects and thus the chart may become huge. For displaying a possibly infinite number of objects in a chart, it is better to use '+QueryChart' which displays just the first page of hits and then lets you scroll down as far as you like. Examples for +QueryChart can be found in doc/family.l and app/gui.l. Besides this, your approach (gui '(+Init +Chart) (getFooObjs 5 100) 3 is not bad or wrong at all. However, the '+Lock' prefixes in (gui 1 '(+Lock +NumField) 10) make the fields non-editable. Thus,I would try something like (gui '(+Init +Chart) (collect 'keyA '+Foo) 2 '((This) (list (: keyA) (: keyB))) '((L D) (when D (put! D 'keyA (car L)) (put! D 'keyB (cadr L)) D ) ) ) (table NIL NIL '((NIL KeyA) (NIL KeyB)) (do 8 (row NIL (gui 1 '(+NumField) 10) (gui 2 '(+TextField) 10) ) ) ) (scroll 8 T) ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe