Re: Sort order not always kept when querying the database

2019-10-15 Thread cilz
use the 'date' index, and calculate the range from the week (I don't know that algorithm at the moment. Assuming we had such functions, we could do (collect 'date '+Agenda (weekStart 2019 42) (weekEnd 2019 42)) This would be the most efficient way. Hum... Otherwise you could sort it (by '((

Re: Sort order not always kept when querying the database

2019-10-09 Thread Alexander Burger
he moment. Assuming we had such functions, we could do (collect 'date '+Agenda (weekStart 2019 42) (weekEnd 2019 42)) This would be the most efficient way. Otherwise you could sort it (by '((This) (: date)) sort (collect 'year '+Agenda (2019 42))) with a little more overhead.

Sort order not always kept when querying the database

2019-10-09 Thread cilz
Gear Guys, This mail is a kind of follow-up to the thread started here: https://www.mail-archive.com/picolisp@software-lab.de/msg09124.html . Based on Alex's tips I have set up my database like this: (class +Agenda +Entity) (rel id    (+Key +Number)) (rel date  (+Ref +Date)) (rel mag 

Re: Behavior of sort

2019-05-05 Thread JmageK
Copy appears to be most reliable as it does not modify the original list. Maybe a tiny bit slower than ->(setq L (sort L)) : (setq L (3 2 1 4 9 0] -> (3 2 1 4 9 0) : (sort (copy L] -> (0 1 2 3 4 9) : L -> (3 2 1 4 9 0)  : (setq L (sort L] -> (0 1 2 3 4 9) : L-> (0

Re: Behavior of sort

2019-05-04 Thread Lindsay Lawrence
Hi, The sort is destructive of the input. https://software-lab.de/doc/refS.html#sort There are other functions that behave like this that you need to be aware of when writing code. You have to assign the result of the sort to another variable. Back to itself is fine. : (setq L '((3) (2) (1

Re: Behavior of sort

2019-05-04 Thread Alexander Burger
Hi Kashyap, > I noticed an odd behavior of sort - > (setq L '((2) (1) )) > (sort L) Note that 'sort' is a destructive function, it modifies the order of cells in-place. Thus you must use the return value of 'sort', it may return another cell than was passed to it. In the above, t

Behavior of sort

2019-05-04 Thread C K Kashyap
Hi all, I noticed an odd behavior of sort - (setq L '((2) (1) )) (println (length L)) # 2 as expected (sort L) (println (length L)) # why 1? (println L) # ((2)) (bye) I would expect sort not to change the length. Am I missing something here or is sort broken? Regards, Kashyap

Re: Unexpected behaviour from (sort) with

2016-10-01 Thread Alexander Burger
Hi Rowan, > first sentence at http://www.software-lab.de/doc/refS.html#sort > changed from: > > > Sorts lst by destructively exchanging its elements. > > to something more explicit like: > > > Returns a sorted lst by destructively exchanging the original lst's &g

Re: Unexpected behaviour from (sort) with

2016-10-01 Thread Rowan Thorpe
On 30 September 2016 at 20:24, Alexander Burger <a...@software-lab.de> wrote: > Hi Rowan, > > the explanation is simple. > ... > It is the *return* value of 'sort' which is relevant: > ... Ah, [facepalm], thanks. Because I hadn't used picolisp for a while, when I first us

Re: Unexpected behaviour from (sort) with

2016-09-30 Thread Alexander Burger
Hi Rowan, the explanation is simple. > (println A) (sort A) (println A) This is not the right way. Though 'sort' works destructively, this does not mean that it sorts the cells in-place. It is the *return* value of 'sort' which is relevant: (println A) (println (sort A)) or (prin

Unexpected behaviour from (sort) with transient-sym-with-leading-numeral-in-cdr

2016-09-30 Thread Rowan Thorpe
I have a perplexing situation with the (sort) function sorting alphanumeric elements, and can't find any explanation in the documentation after searching for a while. Unless I am misunderstanding some painfully fundamental point, this appears to be a bug. When I try to sort alphanumeric transient

Re: Strange sort behaviour

2010-08-20 Thread Alexander Burger
', archetype of all destructive functions. While it sometimes works as one might expect : (setq A (1 2 3) B (4 5 6)) - (4 5 6) : (conc A B) - (1 2 3 4 5 6) : A - (1 2 3 4 5 6) : B - (4 5 6) 'A' is modified the way you expected for 'sort' (i.e

Strange sort behaviour

2010-08-19 Thread Jon Kleiser
Hi, The docs on the 'sort' function says Sorts lst by destructively exchanging its elements. From this I get the impression that (let L (3 2 5 4) (sort L) L) should give the same result as (let L (3 2 5 4) (sort L)) but that's not so, as the first one reveals that L get the value (3 4 5

Re: Strange sort behaviour

2010-08-19 Thread Tomas Hlavaty
Hi Jon, (let L (3 2 5 4) (sort L) L) should give the same result as (let L (3 2 5 4) (sort L)) it should not;-) Why couldn't L simply be given the same value? L is given the same value which you print in the first case. In the second case, you printed out the return value of 'sort'. L

Re: sort

2009-01-07 Thread Tomas Hlavaty
Hi Alex, : (let L (make (do 10 (link (rand (bench (sort L) T)) 0.251 sec - T thanks for pointing out the 'bench' function;-) Cheers, Tomas -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Re: sort

2009-01-07 Thread Tomas Hlavaty
^2) times. it will be called as many times as the C function 'compare' is called. Not sure about the picolisp 'sort' function, but usual sorting algorithms are O(N*log(N)) so it will be called O(N^2) times only if the built-in 'sort' is O(N^2). I guess the built-in 'sort' function is O(N*log(N

Re: sort

2009-01-07 Thread Tomas Hlavaty
I'm not sure. I feel that it is its ugliness which predestines it to denote such a local concept. Fair enough:-) Cheers, Tomas -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Re: sort

2009-01-07 Thread Tomas Hlavaty
Hi Alex, and on top of that calls the retrieval code twice on each invocation). I am not sure about what you mean. The 'sort' algorithm have some strategy how it accesses the elements and by the time the function compare() is called, it already has the elements available so it does not have

Re: sort

2009-01-07 Thread Alexander Burger
, this retrieval of raw data is performed only once for each object. The 'sort' routine then just has to do the direct comparison of simple lisp structures. Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Re: sort

2009-01-06 Thread Alexander Burger
)) ) ) ) ) ) then you could sort a list of the form (setq Table (quote (((+Cls1 +Cls2) (+Cls3 +Cls4)) ..) (((+Cls5 +Cls6) (+Cls7 +Cls8)) ..) ... ) ) with a function returning a list of lists of weights (by '((Lst) (mapcar '((L) (mapcar rankClass L)) (car

Re: sort

2009-01-06 Thread Alexander Burger
) ) ) ) (car Lst) ) sort Table ) This assumes that 'Table' is of the form ( (((+Asteroid) (+Asteroid)) (X Y) (prinl aa)) ... ) so that '(car Lst)' is '((+Asteroid) (+Asteroid))'. What do you think? Cheers, - Alex -- UNSUBSCRIBE: mailto:picol

Re: sort

2009-01-05 Thread Alexander Burger
Hi Tomas, good to know. Maybe this noLint should be added at the end of lib/xml.l? Not necessary as long as we write 'xml_' as '_xml_'. Well, 'Pre' and 'Nl' are indeed unused in 'xml'. Well, whether they are used or not depends on interpretation: lexically they are not used,

Re: sort

2009-01-02 Thread Tomas Hlavaty
Hi Alex, : (lintAll) - ((order (bnd S))) I tried it on the multi-method code and got a warning: (de mmApply @ (let (N (next) A (rest) K (mapcar type A) Mm (filter '((M) (mmApplicable K (car M))) (get N 'mm)) ) (ifn Mm (quit 'mm (list No

Re: sort

2008-12-23 Thread Alexander Burger
Hi Tomas, the 'sort' function has the less-than relation built-in. Is there an easy way of sorting a list using a user-defined less-than relation? Well, in a certain way you used it already, with 'by'. I'm not quite sure about the purpose of (when (apply Lt NIL X Y) 'apply

Re: sort

2008-12-23 Thread Alexander Burger
On Tue, Dec 23, 2008 at 07:15:16PM +0100, Alexander Burger wrote: 'S' is unbound when 'cons' is called, so the CARs of all elements end up with NIL (or whatever 'S' was before). BTW, such bugs are easily detected by 'lint': : (lint 'order) - ((bnd S)) This cryptic result means bind 'S'.