he '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
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.
Otherwise you could sort it
(by '((This) (: date)) sort (collect 'year '+Agenda (2
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
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
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) (
Ah!...that makes sense ... thanks Alex!
On Sat, May 4, 2019 at 7:48 AM Alexander Burger wrote:
> Hi Kashyap,
>
> > I noticed an odd behavior of sort -
> > (setq L '((2) (1) ))
> > (sort L)
>
> Note that 'sort' is a destructive function, it modifies
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 passe
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
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'
On 30 September 2016 at 20:24, Alexander Burger 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 used (sort)
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 (so
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 tran
-> (1 2 3 4 5 6)
: B
-> (4 5 6)
'A' is modified the way you expected for 'sort' (i.e. holding the return
value). This is not the case, however, if the first argument is 'NIL'
: (setq A NIL B (4 5 6))
-> (4 5 6)
: (conc A B)
Hi Tomas,
I can accept your explanation, but then I think the docs should make it
clear that the sorted list is what's returned by the function, and that
the state of the "input list" afterwards can be somewhat unpredictable.
/Jon
> Hi Jon,
>
>> (let L (3 2 5 4) (s
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 th
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 th
Hi Alex,
> now I changed 'sort' as discussed, accepting an optional function
thanks a lot!
Tomas
--
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Hi Tomas,
now I changed 'sort' as discussed, accepting an optional function
argument.
It is available in the testing release.
As described, some data have to be preserved in stack frames, to be
gc-safe. The code is quite a mess with that now, but the changes were
straightfo
Hi Alex,
> The current implementation does not need to save its arguments, because
> it can be sure that the garbage collector will not run during its
> execution.
so my 'sort2' function is broken anyway:-(
Thank you,
Tomas
--
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
single numeric value, but a list of
values in the order of sort priority (the same order a binary function
would perform a sequence of checks). But still it is not easy, and I
must confess that I did not understand the exact requirements for the
ordering of class lists in your multi-method example
as it naturally expresses the programmers idea while a
unary weight would have to be computed somehow: assuming that a unary
weight always exists, I can imagine that it could be computed from the
binary predicate taking into account the size of the set being sorted;
however, computing it that way wo
((<> (; CuSu1 nm) (; CuSu2 nm))
>>(> (; CuSu2 nm) (; CuSu1 nm)) )
>> (T
>>(> (; CuSu2 nr) (; CuSu1 nr)) ) ) ) )
>>
>> This binary function is rather complicated (and thus slow), and it might
>> be called nearly O
nr)) ) ) ) )
>
> This binary function is rather complicated (and thus slow), and it might
> be called nearly O(N^2) times.
it should be called O(N*log(N)) times if the built-in 'sort' function
implements a decent sorting algorithm (which I guess it does;-).
Cheers,
Tomas
--
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
to the point in general.
With the 'by' mechanism of PicoLisp, 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
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 element
ot the way to go. It is something related to
"topological" sort, ordering elements of a "tree".
> And, it looks like 'NIL's must be greater than anything else.
Yes, NIL here is like T type in Common Lisp, a "super-class of all
classes".
> So a fun
> 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
nr)) ) ) ) )
>
> This binary function is rather complicated (and thus slow), and it might
> be called nearly O(N^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
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
vel class
(while (type (last L))
(setq L @) )
(last L) ) ) )
(car Lst) )
sort
Table )
This assumes that 'Table' is of the form
(
(((+Asteroid) (+Asteroid)) (X Y) (prinl "aa"))
...
)
so that '
s located
(de rankClass (Cls)
(cond
((not Cls) 0)
((atom Cls) (rankClass (type Cls)))
(T
(dec
(min
(rankClass (car Cls))
(rankClass (cdr Cls)) ) ) ) ) )
then you could sort a list of the form
(set
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, dyn
Hi Alex,
> It seems that you underestimate the consequences and power of the
> built-in ordering principle.
Probably, I haven't got used to it yet;-)
> I believe that when you are able to define a binary 'less-than'
> function to be passed to your sort routine, you s
Hi Alex,
> For cases which are known to cause false positives, there is 'noLint'.
> For example, the 'gui' function in "lib/form.l" is similar to 'mmNext',
> being defined dynamically and called in another context. So there is a
> call (noLint 'gui) at the end of "lib/form.l".
good to know. Mayb
It seems that you underestimate the consequences and power of the
built-in ordering principle.
I believe that when you are able to define a binary 'less-than' function
to be passed to your sort routine, you should always also be able to
define a unary weighting function.
A typical example wou
Hi Tomas,
> -> ((mmApply (use mmNext)))
>
> A false positive? ('mmNext' can be called in the function under
Yep.
> 'apply'.) Maybe a dynamically scoped code is impossible to check
> reliably?
Yes. There are too many degrees of freedom in the code, so that a
reliable check will never be possib
cialized" thing
is my lessThan predicate for sorting.
> Built-in list functions can be used better and more efficiently to
> do the pre- and post-processing.
I think there are the following cases:
1) the built-in comparison (as implemented by compare()) is suitable
for the problem at
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
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 '
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
Hi Alex,
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?
I wanted to reuse the existing 'sort' function and came up with:
(de order (Lt Lst)
(let Q NIL
41 matches
Mail list logo