Recently, I had to implement support for cancellable timers in
Perl. As maximum number of these was going to be small, I wanted to use
a sorted list as priority queue implementation. Originally, this used an
Rainer Weikusat <[email protected]> wrote:
Recently, I had to implement support for cancellable timers in
Perl. As maximum number of these was going to be small, I wanted to use
a sorted list as priority queue implementation. Originally, this used an
Doesn't this belong in some "Perl" newsgroup (Of which there are many) ?
It's about programming on UNIX
sub do_revl
{
my $l = $_[0];
my ($first, $last);
for (cdr($l)) {
return ($l, $l) unless defined;
($first, $last) = do_revl($_);
}
$l = cdr($last) = cons(car($l));
return ($first, $l);
}
On 2024-02-14, Rainer Weikusat <[email protected]> wrote:
sub do_revl
{
my $l = $_[0];
my ($first, $last);
for (cdr($l)) {
return ($l, $l) unless defined;
($first, $last) = do_revl($_);
}
$l = cdr($last) = cons(car($l));
return ($first, $l);
}
A concise way to write reverse is to iterate, and push the items onto a
new list:
(let (out)
(dolist (item list out)
(push item out)))
where (push item out) is equivalent to (setf out (cons item out)),
except that out is evaluated only once.
If your cancellable timers need the reverse operation, it's possible
that a destructive one could be used in place.
Then, I came up with the following idea: Anonymous arrays of size 2
make perfect cons cells in Perl and can thus be used to implement
LISP-style linked lists. This led to a much simpler implementation
of a priority queue represented as sorted list which doesn't keep
growing when handling the situation created above.
Here's a bit of Perl code to illustrate the principle:
----
sub cons { [@_] }
sub car : lvalue
{
$_[0][0]
}
sub cdr : lvalue
{
$_[0][1]
}
sub do_revl
{
my $l = $_[0];
my ($first, $last);
for (cdr($l)) {
return ($l, $l) unless defined;
($first, $last) = do_revl($_);
}
$l = cdr($last) = cons(car($l));
return ($first, $l);
}
sub revl
{
(do_revl($_[0]))[0]
}
[...]
Rainer Weikusat <[email protected]> writes:
Then, I came up with the following idea: Anonymous arrays of size 2
make perfect cons cells in Perl and can thus be used to implement
LISP-style linked lists. This led to a much simpler implementation
of a priority queue represented as sorted list which doesn't keep
growing when handling the situation created above.
Here's a bit of Perl code to illustrate the principle:
sub do_revl
{
my $l = $_[0];
my ($first, $last);
for (cdr($l)) {
return ($l, $l) unless defined;
($first, $last) = do_revl($_);
}
$l = cdr($last) = cons(car($l));
return ($first, $l);
}
sub revl
{
(do_revl($_[0]))[0]
}
[...]
Code to reverse a list can be a lot simpler:
sub rev
{
my ($r, $s) = @_;
($r) ? rev( cdr( $r ), cons( car( $r ), $s ) ) : $s;
}
Please excuse any poor choices in the perl code, today is the
first time I've ever looked at perl or written any code in it.
Tim Rentsch <[email protected]> writes:
Rainer Weikusat <[email protected]> writes:
sub do_revl
{
my $l = $_[0];
my ($first, $last);
for (cdr($l)) {
return ($l, $l) unless defined;
($first, $last) = do_revl($_);
}
$l = cdr($last) = cons(car($l));
return ($first, $l);
}
sub revl
{
(do_revl($_[0]))[0]
}
[...]
Code to reverse a list can be a lot simpler:
To keep this in line with the style of the example, it should be
sub do_revl
{
my ($l, $rl) = @_;
return $rl unless $l;
return do_revl(cdr($l), cons(car($l), $rl));
}
On Thu, 15 Feb 2024 11:33:01 +0000
Rainer Weikusat <[email protected]> wrote:
[email protected] (Kenny McCormack) writes:
Rainer Weikusat <[email protected]> wrote:It's about programming on UNIX and the Perl groups I'm aware no longer
Recently, I had to implement support for cancellable timers inDoesn't this belong in some "Perl" newsgroup (Of which there are many) ? >>
Perl. As maximum number of these was going to be small, I wanted to use
a sorted list as priority queue implementation. Originally, this used an >> >
have any traffic except sex spam.
I see plenty of legitimate posts on comp.lang.perl.misc .In fact , I even see
From: Rainer Weikusat <[email protected]>
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 19:35:23 +0000
Message-ID: <[email protected]>
References: <[email protected]>
It would have been strange if the group had gone totally downhill in 3 months.
Spiros Bousbouras <[email protected]> writes:
On Thu, 15 Feb 2024 11:33:01 +0000
Rainer Weikusat <[email protected]> wrote:
[email protected] (Kenny McCormack) writes:
Rainer Weikusat <[email protected]> wrote:It's about programming on UNIX and the Perl groups I'm aware no longer
Recently, I had to implement support for cancellable timers inDoesn't this belong in some "Perl" newsgroup (Of which there are many) ? >>>
Perl. As maximum number of these was going to be small, I wanted to use >>> >>a sorted list as priority queue implementation. Originally, this used an >>> >
have any traffic except sex spam.
I see plenty of legitimate posts on comp.lang.perl.misc .In fact , I even see
From: Rainer Weikusat <[email protected]>
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 19:35:23 +0000
Message-ID: <[email protected]>
References: <[email protected]>
It would have been strange if the group had gone totally downhill in 3 months.
It has. It's mostly flooded with sex and (illegal) drug ads.
Rainer Weikusat <[email protected]> writes:...
Spiros Bousbouras <[email protected]> writes:
From: Rainer Weikusat <[email protected]>
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 19:35:23 +0000
Message-ID: <[email protected]>
References: <[email protected]>
It would have been strange if the group had gone totally downhill in
3 months.
It has. It's mostly flooded with sex and (illegal) drug ads.
That will diminish in 6 days.
On Sun, 18 Feb 2024 13:08:14 -0500
James Kuyper <[email protected]> wrote:
On 2/18/24 11:24, Scott Lurndal wrote:
Rainer Weikusat <[email protected]> writes:...
Spiros Bousbouras <[email protected]> writes:
From: Rainer Weikusat <[email protected]>
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 19:35:23 +0000
Message-ID: <[email protected]>
References: <[email protected]>
It would have been strange if the group had gone totally downhill in >>>>> 3 months.
It has. It's mostly flooded with sex and (illegal) drug ads.
That will diminish in 6 days.
Why? They already stopped all posting of new messages through GG.
No they haven't. If you had bothered to actually visit
comp.lang.perl.misc ,
you would have seen that googlegroups posted spam continues unabated ;
same
On Sun, 18 Feb 2024 13:46:45 -0500[snip]
James Kuyper <[email protected]> wrote:
I can see that the spam continues unabated, but GG won't let me see the
headers, so I can't tell where it's being posted from. I had thought
they'd found a new server to post from.
If you want to check the spam situation , you can use a server like news.cyber23.de which doesn't filter spam. With this and your own
filters off , you will be able to see the spam including the headers.
It is very unlikely that any other newsserver will be as negligent as googlegroups so no , I don't expect that the spammers will find any
server anywhere near as convenient as googlegroups any time soon.
I thought there were more GG blocked groups tho.My apologies - I had thought that GG cut off posting of all new messages
a couple of months ago - they did turn off all of the newsgroups I
regularly frequent. However, I just checked, and it does let me start
the process of posting a message to comp.lang.perl.misc, something it no
longer permits me to do on most of the groups I subscribe to.
From what I remember , googlegroups turned off posting on comp.lang.c , comp.lang.c++ , comp.lang.fortran , comp.arch .With all the other groups ,
it was still spammers paradise.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 145:19:11 |
| Calls: | 12,089 |
| Calls today: | 2 |
| Files: | 15,000 |
| Messages: | 6,517,497 |