Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You can't go home again, unless you set $HOME.


devel / comp.lang.postscript / in-place reverse?

SubjectAuthor
* in-place reverse?luser droog
+* Re: in-place reverse?luser droog
|+- Re: in-place reverse?luser droog
|`- Re: in-place reverse?luser droog
+- Re: in-place reverse?luser droog
+* Re: in-place reverse?James
|+- Re: in-place reverse?luser droog
|`- Re: in-place reverse?luser droog
`- Re: in-place reverse?jdaw1

1
in-place reverse?

<d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9949&group=comp.lang.postscript#9949

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:a05:620a:24cc:: with SMTP id m12mr8336803qkn.475.1634883892123;
Thu, 21 Oct 2021 23:24:52 -0700 (PDT)
X-Received: by 2002:a05:6830:57d:: with SMTP id f29mr8639403otc.285.1634883891771;
Thu, 21 Oct 2021 23:24:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Thu, 21 Oct 2021 23:24:51 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
Subject: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Fri, 22 Oct 2021 06:24:52 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 47
 by: luser droog - Fri, 22 Oct 2021 06:24 UTC

I was reading through some old code and found this function to
reverse an array.

reverse {
dup xcheck exch
[ exch dup length 1 sub -1 0 { 2 copy get 3 1 roll pop } for pop ]
exch {cvx} if }

And I wondered if it were possible to do it in-place, without creating
a new array. I'm primarily using this for my args-begin function
which does an {exch def} forall to assign names to local variables
and parameters. The reverse is used to pre-process the array
of names so it can be written left-to-right but operated top-down
against the stack.

I wrote it two ways but both are ugly. Is there a nicer way to do it?
Does it require the invention of a fancy new control structure for
a super "for" loop with 2 indices? I've almost done that with the
second try here. It looks almost ready to factor out a new kind
of loop.

{
%dup length 2 idiv -1 0 { % [A B C ..] idx(C)
0 1 2 index 2 idiv { % [A B C ..] idx(A)
1 index length 1 index sub % [A B C ..] idx(A) dst(A)
3 copy 3 copy pop get % [] i(C) d(C) [] i d A
4 copy pop % [] i d [] i d A [] i d
3 copy exch pop get % [] i d [] i d A [] i d .
exch pop put % [] i d [] i d A ([. B C ..])
3 -1 roll pop put % [] i d ([. B C .. A])
pop pop % []
} for
} @pop
{ % [A B C ..]
dup length 0 exch dup 2 div exch 1 sub % [ABC..] lo mid hi
{ % [ABC..] lo mid hi
3 copy gt exch % [] lo mid hi mid>hi lo
3 index gt or % [] lo mid hi mid>hi||lo>mid
{exit} if
4 copy exch pop % [] l m h [] l h
3 copy 6 copy % [] l m h [] l h [] l h [] l h [] l h
exch pop get % [] l m h [] l h [] l h [] l h [h]
4 1 roll pop get % [] l m h [] l h [] l h [h] [l]
5 1 roll exch pop put % [h] l m h [h] l h [l]
3 -1 roll pop put % [hl] l m h
3 2 roll 1 add 3 1 roll 1 sub
} loop
}

Re: in-place reverse?

<0e3a3d76-b801-4d13-b69f-80b450426cc7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9950&group=comp.lang.postscript#9950

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:a0c:f10b:: with SMTP id i11mr3064618qvl.2.1634947992909; Fri, 22 Oct 2021 17:13:12 -0700 (PDT)
X-Received: by 2002:aca:ad16:: with SMTP id w22mr12294519oie.109.1634947992629; Fri, 22 Oct 2021 17:13:12 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Fri, 22 Oct 2021 17:13:12 -0700 (PDT)
In-Reply-To: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0e3a3d76-b801-4d13-b69f-80b450426cc7n@googlegroups.com>
Subject: Re: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sat, 23 Oct 2021 00:13:12 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 76
 by: luser droog - Sat, 23 Oct 2021 00:13 UTC

On Friday, October 22, 2021 at 1:24:52 AM UTC-5, luser droog wrote:
> I was reading through some old code and found this function to
> reverse an array.
>
> reverse {
> dup xcheck exch
> [ exch dup length 1 sub -1 0 { 2 copy get 3 1 roll pop } for pop ]
> exch {cvx} if }
>
> And I wondered if it were possible to do it in-place, without creating
> a new array. I'm primarily using this for my args-begin function
> which does an {exch def} forall to assign names to local variables
> and parameters. The reverse is used to pre-process the array
> of names so it can be written left-to-right but operated top-down
> against the stack.
>
> I wrote it two ways but both are ugly. Is there a nicer way to do it?
> Does it require the invention of a fancy new control structure for
> a super "for" loop with 2 indices? I've almost done that with the
> second try here. It looks almost ready to factor out a new kind
> of loop.
>
> {
> %dup length 2 idiv -1 0 { % [A B C ..] idx(C)
> 0 1 2 index 2 idiv { % [A B C ..] idx(A)
> 1 index length 1 index sub % [A B C ..] idx(A) dst(A)
> 3 copy 3 copy pop get % [] i(C) d(C) [] i d A
> 4 copy pop % [] i d [] i d A [] i d
> 3 copy exch pop get % [] i d [] i d A [] i d .
> exch pop put % [] i d [] i d A ([. B C ..])
> 3 -1 roll pop put % [] i d ([. B C .. A])
> pop pop % []
> } for
> } @pop
> { % [A B C ..]
> dup length 0 exch dup 2 div exch 1 sub % [ABC..] lo mid hi
> { % [ABC..] lo mid hi
> 3 copy gt exch % [] lo mid hi mid>hi lo
> 3 index gt or % [] lo mid hi mid>hi||lo>mid
> {exit} if
> 4 copy exch pop % [] l m h [] l h
> 3 copy 6 copy % [] l m h [] l h [] l h [] l h [] l h
> exch pop get % [] l m h [] l h [] l h [] l h [h]
> 4 1 roll pop get % [] l m h [] l h [] l h [h] [l]
> 5 1 roll exch pop put % [h] l m h [h] l h [l]
> 3 -1 roll pop put % [hl] l m h
> 3 2 roll 1 add 3 1 roll 1 sub
> } loop
> }

Alright. Had to sleep on it. Two loops, sequentially. No new arrays
created. It uses a fancy loop I already wrote called "fortuple"

array n proc fortuple --
for each invocation of proc, the stack contains successive n-tuples
of elements from array using getinterval.

So, by doing `1 {} fortuple` on the array, I fill the stack with little one-
element subarrays of the original array. Then a little stack juggling
to grab a copy of the original array. And then a regular old forall
loop to put each value in its target box, consuming one of the
subarrays on each iteration.

{
[ 1 index 1 {} fortuple counttomark 1 add index { % [...] [ [0] [1] .. [n-1] 0
0 exch put
} forall pop
}

Aside: I considered "dup [ exch" instead of "[ 1 index" but that executes
two operators instead of just one. Probably an insignificant useless
microoptimization but that's why I did that.

Aside, aside: I haven't actually run and tested this. I'm 90% sure that
"counttomark 1 add index" correctly grabs the thing just below the mark,
but I reckon there's a 10% chance I'm wrong about that.

Re: in-place reverse?

<47e0d74a-9557-4991-ae20-ef7a4ff17f2an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9951&group=comp.lang.postscript#9951

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:ac8:4111:: with SMTP id q17mr3357679qtl.407.1634948175823;
Fri, 22 Oct 2021 17:16:15 -0700 (PDT)
X-Received: by 2002:a05:6808:1513:: with SMTP id u19mr1999914oiw.27.1634948175651;
Fri, 22 Oct 2021 17:16:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Fri, 22 Oct 2021 17:16:15 -0700 (PDT)
In-Reply-To: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <47e0d74a-9557-4991-ae20-ef7a4ff17f2an@googlegroups.com>
Subject: Re: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sat, 23 Oct 2021 00:16:15 +0000
Content-Type: text/plain; charset="UTF-8"
 by: luser droog - Sat, 23 Oct 2021 00:16 UTC

On Friday, October 22, 2021 at 1:24:52 AM UTC-5, luser droog wrote:
> 3 copy 6 copy % [] l m h [] l h [] l h [] l h [] l h

This line by itself ought to have been a red flag. It felt kinda overly
clever when I wrote it. But I thought it was "the good kind" of clever.
Ach.

Re: in-place reverse?

<acb229f0-ce29-45d3-98ab-44be3982fc8bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9952&group=comp.lang.postscript#9952

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:a05:6214:e84:: with SMTP id hf4mr3256776qvb.38.1634949734875;
Fri, 22 Oct 2021 17:42:14 -0700 (PDT)
X-Received: by 2002:a05:6808:130d:: with SMTP id y13mr12325637oiv.85.1634949734616;
Fri, 22 Oct 2021 17:42:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Fri, 22 Oct 2021 17:42:14 -0700 (PDT)
In-Reply-To: <0e3a3d76-b801-4d13-b69f-80b450426cc7n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com> <0e3a3d76-b801-4d13-b69f-80b450426cc7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <acb229f0-ce29-45d3-98ab-44be3982fc8bn@googlegroups.com>
Subject: Re: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sat, 23 Oct 2021 00:42:14 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 17
 by: luser droog - Sat, 23 Oct 2021 00:42 UTC

On Friday, October 22, 2021 at 7:13:13 PM UTC-5, luser droog wrote:

> Aside, aside: I haven't actually run and tested this. I'm 90% sure that
> "counttomark 1 add index" correctly grabs the thing just below the mark,
> but I reckon there's a 10% chance I'm wrong about that.

Okay, I've done some further post-hoc rationalizing. So my confidence
is up to 95% or so. Here's how I'm thinking it.

`counttomark` gives you the length of the array you want to make to
contain the stuff on the stack. So `counttomark index` is just going to
yield the `mark`. Since `0 index` == `dup`.
Eg.
[ /a /b /c counttomark % yields a 3
So.
[ /a /b /c counttomark index % yields that ol' mark

So, adding one is right. Yay, I'm so smart. Thanks, duckies.

Re: in-place reverse?

<f65c7a2a-0fdc-4df3-b0cd-01b2f596c180n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9953&group=comp.lang.postscript#9953

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:a05:6214:28f:: with SMTP id l15mr6653348qvv.16.1635033294260;
Sat, 23 Oct 2021 16:54:54 -0700 (PDT)
X-Received: by 2002:a9d:24c8:: with SMTP id z66mr6562302ota.279.1635033293877;
Sat, 23 Oct 2021 16:54:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Sat, 23 Oct 2021 16:54:53 -0700 (PDT)
In-Reply-To: <0e3a3d76-b801-4d13-b69f-80b450426cc7n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com> <0e3a3d76-b801-4d13-b69f-80b450426cc7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f65c7a2a-0fdc-4df3-b0cd-01b2f596c180n@googlegroups.com>
Subject: Re: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sat, 23 Oct 2021 23:54:54 +0000
Content-Type: text/plain; charset="UTF-8"
 by: luser droog - Sat, 23 Oct 2021 23:54 UTC

On Friday, October 22, 2021 at 7:13:13 PM UTC-5, luser droog wrote:
> On Friday, October 22, 2021 at 1:24:52 AM UTC-5, luser droog wrote:
> > I was reading through some old code and found this function to
> > reverse an array.
> >
> > reverse {
> > dup xcheck exch
> > [ exch dup length 1 sub -1 0 { 2 copy get 3 1 roll pop } for pop ]
> > exch {cvx} if }
> >
> > And I wondered if it were possible to do it in-place, without creating
> > a new array. I'm primarily using this for my args-begin function
> > which does an {exch def} forall to assign names to local variables
> > and parameters. The reverse is used to pre-process the array
> > of names so it can be written left-to-right but operated top-down
> > against the stack.
> >
> > I wrote it two ways but both are ugly. Is there a nicer way to do it?
> > Does it require the invention of a fancy new control structure for
> > a super "for" loop with 2 indices? I've almost done that with the
> > second try here. It looks almost ready to factor out a new kind
> > of loop.
> >
> > {
> > %dup length 2 idiv -1 0 { % [A B C ..] idx(C)
> > 0 1 2 index 2 idiv { % [A B C ..] idx(A)
> > 1 index length 1 index sub % [A B C ..] idx(A) dst(A)
> > 3 copy 3 copy pop get % [] i(C) d(C) [] i d A
> > 4 copy pop % [] i d [] i d A [] i d
> > 3 copy exch pop get % [] i d [] i d A [] i d .
> > exch pop put % [] i d [] i d A ([. B C ..])
> > 3 -1 roll pop put % [] i d ([. B C .. A])
> > pop pop % []
> > } for
> > } @pop
> > { % [A B C ..]
> > dup length 0 exch dup 2 div exch 1 sub % [ABC..] lo mid hi
> > { % [ABC..] lo mid hi
> > 3 copy gt exch % [] lo mid hi mid>hi lo
> > 3 index gt or % [] lo mid hi mid>hi||lo>mid
> > {exit} if
> > 4 copy exch pop % [] l m h [] l h
> > 3 copy 6 copy % [] l m h [] l h [] l h [] l h [] l h
> > exch pop get % [] l m h [] l h [] l h [] l h [h]
> > 4 1 roll pop get % [] l m h [] l h [] l h [h] [l]
> > 5 1 roll exch pop put % [h] l m h [h] l h [l]
> > 3 -1 roll pop put % [hl] l m h
> > 3 2 roll 1 add 3 1 roll 1 sub
> > } loop
> > }
> Alright. Had to sleep on it. Two loops, sequentially. No new arrays
> created. It uses a fancy loop I already wrote called "fortuple"
>
> array n proc fortuple --
> for each invocation of proc, the stack contains successive n-tuples
> of elements from array using getinterval.
>
> So, by doing `1 {} fortuple` on the array, I fill the stack with little one-
> element subarrays of the original array. Then a little stack juggling
> to grab a copy of the original array. And then a regular old forall
> loop to put each value in its target box, consuming one of the
> subarrays on each iteration.
>
> {
> [ 1 index 1 {} fortuple counttomark 1 add index { % [...] [ [0] [1] .. [n-1] 0
> 0 exch put
> } forall pop
> }
>
> Aside: I considered "dup [ exch" instead of "[ 1 index" but that executes
> two operators instead of just one. Probably an insignificant useless
> microoptimization but that's why I did that.
>
> Aside, aside: I haven't actually run and tested this. I'm 90% sure that
> "counttomark 1 add index" correctly grabs the thing just below the mark,
> but I reckon there's a 10% chance I'm wrong about that.

I rewrote it again to avoid using my fancy loop, since the fancy loop is itself
defined using /reverse.

{
dup % [] []
0 1 2 index length 1 sub { % [] ... [] 0
2 copy 1 getinterval % [] ... [] 0 [0]
3 1 roll pop % [] [0] ... []
} for % [] [0] [1] .. [n-1] []
{ 0 exch put } forall
}

So now I don't need the `mark ... counttomark` stuff because I can simply
carry along the original array in the loop and keep it close.
Finally, it becomes easier to see that the first loop isn't necessary.
All we truly need to do is calculate the target index and carry it along
on the stack.

{
dup length 1 sub 1 index { % [] n-1 0
3 copy put pop
1 sub
} forall pop
}

And this one, I think I'm happy with.

Re: in-place reverse?

<sl3b3v$50o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9954&group=comp.lang.postscript#9954

  copy link   Newsgroups: comp.lang.postscript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: new...@oxdrove.co.uk (James)
Newsgroups: comp.lang.postscript
Subject: Re: in-place reverse?
Date: Sun, 24 Oct 2021 11:04:47 +0100
Organization: poor
Lines: 19
Message-ID: <sl3b3v$50o$1@dont-email.me>
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 24 Oct 2021 10:04:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f3850f5e16c83004e618ea29562f8ad7";
logging-data="5144"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tfX5k601i4yjWfu0zuo4PwMxusIxfYK8="
User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:Ks4ELmvFBvog9Whl7MiSsINeGX4=
In-Reply-To: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
 by: James - Sun, 24 Oct 2021 10:04 UTC

On 22/10/2021 07:24, luser droog wrote:
> I was reading through some old code and found this function to
> reverse an array.

> And I wondered if it were possible to do it in-place, without creating
> a new array.

/reverse {
aload dup length 1 sub
0 exch 1 exch
{ exch dup 4 2 roll exch put } for
} def

[ 1 2 3 4 5 ]
dup
reverse
pstack

Re: in-place reverse?

<35dc8897-5893-495e-96ad-aaa5fc9d189dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9955&group=comp.lang.postscript#9955

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:ac8:7e96:: with SMTP id w22mr14226955qtj.28.1635123573389;
Sun, 24 Oct 2021 17:59:33 -0700 (PDT)
X-Received: by 2002:aca:502:: with SMTP id 2mr10288065oif.121.1635123573010;
Sun, 24 Oct 2021 17:59:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Sun, 24 Oct 2021 17:59:32 -0700 (PDT)
In-Reply-To: <sl3b3v$50o$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com> <sl3b3v$50o$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <35dc8897-5893-495e-96ad-aaa5fc9d189dn@googlegroups.com>
Subject: Re: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Mon, 25 Oct 2021 00:59:33 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 18
 by: luser droog - Mon, 25 Oct 2021 00:59 UTC

On Sunday, October 24, 2021 at 5:04:49 AM UTC-5, James wrote:
> On 22/10/2021 07:24, luser droog wrote:
> > I was reading through some old code and found this function to
> > reverse an array.
> > And I wondered if it were possible to do it in-place, without creating
> > a new array.
> /reverse {
> aload dup length 1 sub
> 0 exch 1 exch
> { exch dup 4 2 roll exch put } for
> } def
>
> [ 1 2 3 4 5 ]
> dup
> reverse
> pstack

Yes. You have to dump the values or copy them somewhere. That last
one I posted doesn't work. It would produce [1 2 3 2 1] for this example.

Re: in-place reverse?

<a3965da1-8a8e-4ce0-8a42-907599fe901bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9961&group=comp.lang.postscript#9961

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:a05:620a:450d:: with SMTP id t13mr794240qkp.427.1636394940195;
Mon, 08 Nov 2021 10:09:00 -0800 (PST)
X-Received: by 2002:aca:c6d0:: with SMTP id w199mr221716oif.30.1636394939876;
Mon, 08 Nov 2021 10:08:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Mon, 8 Nov 2021 10:08:59 -0800 (PST)
In-Reply-To: <sl3b3v$50o$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com> <sl3b3v$50o$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a3965da1-8a8e-4ce0-8a42-907599fe901bn@googlegroups.com>
Subject: Re: in-place reverse?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Mon, 08 Nov 2021 18:09:00 +0000
Content-Type: text/plain; charset="UTF-8"
 by: luser droog - Mon, 8 Nov 2021 18:08 UTC

On Sunday, October 24, 2021 at 5:04:49 AM UTC-5, James wrote:
> On 22/10/2021 07:24, luser droog wrote:
> > I was reading through some old code and found this function to
> > reverse an array.
> > And I wondered if it were possible to do it in-place, without creating
> > a new array.
> /reverse {
> aload dup length 1 sub
> 0 exch 1 exch
> { exch dup 4 2 roll exch put } for
> } def
>
> [ 1 2 3 4 5 ]
> dup
> reverse
> pstack

I adopted this version (since most of mine were ridiculous or broken
or both) but with a few tweaks. Substituting "dup ... exch ... exch" with "index",
and rearranging the innards of the loop to use "copy ... pop (pop)" which I'm
starting to like as an idiom. It's the same number of operators in the loop
but I find the changing stack picture easier to visualize with this rewrite.

/reverse { aload 0 1 2 index length 1 sub { 3 2 roll 3 copy put pop pop } for } def

Maybe "3 -1 roll" would be more readable (?). Is it more of a "grabbing the 3rd thing"
or "rearranging the 3 things with the top 2 at the bottom"? I'm not sure.

Re: in-place reverse?

<ff73cbfd-5f21-46cb-a504-7896f57e146fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10013&group=comp.lang.postscript#10013

  copy link   Newsgroups: comp.lang.postscript
X-Received: by 2002:a37:de07:0:b0:6b5:56d1:140f with SMTP id h7-20020a37de07000000b006b556d1140fmr22219244qkj.114.1660162268262;
Wed, 10 Aug 2022 13:11:08 -0700 (PDT)
X-Received: by 2002:a05:6870:ea84:b0:10d:fabe:9202 with SMTP id
s4-20020a056870ea8400b0010dfabe9202mr2185107oap.294.1660162267983; Wed, 10
Aug 2022 13:11:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.postscript
Date: Wed, 10 Aug 2022 13:11:07 -0700 (PDT)
In-Reply-To: <453841db-0109-45bb-a73d-836d3863009bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=185.176.160.84; posting-account=Cp97SgoAAAC0t1Gya5PaPqyoafMoOtAn
NNTP-Posting-Host: 185.176.160.84
References: <d9c46408-0992-4b61-a35e-85be12aa3b70n@googlegroups.com>
<61ea86a5$1@news.ausics.net> <453841db-0109-45bb-a73d-836d3863009bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ff73cbfd-5f21-46cb-a504-7896f57e146fn@googlegroups.com>
Subject: Re: in-place reverse?
From: jdawise...@gmail.com (jdaw1)
Injection-Date: Wed, 10 Aug 2022 20:11:08 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2200
 by: jdaw1 - Wed, 10 Aug 2022 20:11 UTC

%!PS

/StackReverse {-1 2 {1 roll} for} bind def

/ArrayReverse
{     1 dict begin dup dup xcheck exch cvlit /arr exch def
    0 1 arr length 2 sub 2 idiv
    {
        dup arr exch 2 copy get 4 -1 roll
        arr length 1 sub exch sub arr exch 2 copy get
        4 1 roll 3 -1 roll put put
    } for
    {cvx} if
} bind def % /ArrayReverse

mark (A) (B) (C) (D) (E) (F) (G)
7 StackReverse
(\n\n+pstack) = pstack (-pstack\n\n)
cleartomark

{ (1) (2) } ArrayReverse =() [] ArrayReverse =() [ (1) (2) (3) (4) (5) (6) (7) ] ArrayReverse =() [ (1) (2) (3) (4) (5) (6) (7) (8) ] ArrayReverse =
(\n\n+pstack) = pstack (-pstack\n\n)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor