Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1139 > unrolled thread
| Started by | "luser.droog" <luser.droog@gmail.com> |
|---|---|
| First post | 2012-12-04 02:02 -0600 |
| Last post | 2012-12-24 19:20 -0800 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.postscript
Pointer loop "luser.droog" <luser.droog@gmail.com> - 2012-12-04 02:02 -0600
Re: Pointer loop sjprouty3765@gmail.com - 2012-12-04 12:22 -0800
Re: Pointer loop "luser.droog" <luser.droog@gmail.com> - 2012-12-04 15:46 -0600
Re: Pointer loop sjprouty3765@gmail.com - 2012-12-06 12:29 -0800
Re: Pointer loop "luser.droog" <luser.droog@gmail.com> - 2012-12-07 02:10 -0600
Re: Pointer loop luser- -droog <mijoryx@yahoo.com> - 2012-12-24 19:20 -0800
| From | "luser.droog" <luser.droog@gmail.com> |
|---|---|
| Date | 2012-12-04 02:02 -0600 |
| Subject | Pointer loop |
| Message-ID | <k9kaso$vcg$1@dont-email.me> |
Anybody done this yet?
508(1)02:00 AM:ps 0> cat foreach.ps
%!
%foreach
/foreachdict <<
/arraytype{ % A proc
0 1 src length 1 sub {
src exch 1 getinterval
proc
} for
}
/stringtype 1 index
/default{/foreach cvx /typecheck signalerror}
>> def
/foreach { % A|S proc
2 dict begin {proc src}{exch def}forall
//foreachdict src type
2 copy known not{pop/default}if %dict src-type
get exec
end
} def
/toupper{ dup 97 ge 1 index 122 le and { 32 sub } if }def
(hello, world! my name is oditszuaupuc)
dup {
0
2 copy get
toupper put
} foreach
==
%eof
GPL Ghostscript 8.62 (2008-02-29)
Copyright (C) 2008 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
(HELLO, WORLD! MY NAME IS ODITSZUAUPUC)
GS>GS>
[toc] | [next] | [standalone]
| From | sjprouty3765@gmail.com |
|---|---|
| Date | 2012-12-04 12:22 -0800 |
| Message-ID | <e74ab426-9bf0-4a13-8c03-a8f63fa18f13@googlegroups.com> |
| In reply to | #1139 |
On Tuesday, December 4, 2012 12:02:52 AM UTC-8, luser- -droog wrote:
> Anybody done this yet? 508(1)02:00 AM:ps 0> cat foreach.ps %! %foreach /foreachdict << /arraytype{ % A proc 0 1 src length 1 sub { src exch 1 getinterval proc } for } /stringtype 1 index /default{/foreach cvx /typecheck signalerror} >> def /foreach { % A|S proc 2 dict begin {proc src}{exch def}forall //foreachdict src type 2 copy known not{pop/default}if %dict src-type get exec end } def /toupper{ dup 97 ge 1 index 122 le and { 32 sub } if }def (hello, world! my name is oditszuaupuc) dup { 0 2 copy get toupper put } foreach == %eof GPL Ghostscript 8.62 (2008-02-29) Copyright (C) 2008 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. (HELLO, WORLD! MY NAME IS ODITSZUAUPUC) GS>GS>
The /toupper procedure of course depends on the string being ASCII encoded (and limited to the ASCII character set). It would need something more elaborate for the full ISO-8859-1 character set, and something even more for UTF-8 or UTF-16BE encoding of a character set.
The /foreach procedure is a nice concept, but I would have just used "forall" directly. Is there some advantage "foreach" has over "forall"?
[toc] | [prev] | [next] | [standalone]
| From | "luser.droog" <luser.droog@gmail.com> |
|---|---|
| Date | 2012-12-04 15:46 -0600 |
| Message-ID | <k9lqva$k5e$1@dont-email.me> |
| In reply to | #1145 |
sjprouty3765@gmail.com wrote:
> On Tuesday, December 4, 2012 12:02:52 AM UTC-8, luser- -droog wrote:
>> Anybody done this yet? 508(1)02:00 AM:ps 0> cat foreach.ps %! %foreach
>> /foreachdict << /arraytype{ % A proc 0 1 src length 1 sub { src exch 1
>> getinterval proc } for } /stringtype 1 index /default{/foreach cvx
>> /typecheck signalerror} >> def /foreach { % A|S proc 2 dict begin {proc
>> src}{exch def}forall //foreachdict src type 2 copy known
>> not{pop/default}if %dict src-type get exec end } def /toupper{ dup 97 ge
>> 1 index 122 le and { 32 sub } if }def (hello, world! my name is
>> oditszuaupuc) dup { 0 2 copy get toupper put } foreach == %eof GPL
>> Ghostscript 8.62 (2008-02-29) Copyright (C) 2008 Artifex Software, Inc.
>> All rights reserved. This software comes with NO WARRANTY: see the file
>> PUBLIC for details. (HELLO, WORLD! MY NAME IS ODITSZUAUPUC) GS>GS>
>
> The /toupper procedure of course depends on the string being ASCII encoded
> (and limited to the ASCII character set). It would need something more
> elaborate for the full ISO-8859-1 character set, and something even more
> for UTF-8 or UTF-16BE encoding of a character set.
>
> The /foreach procedure is a nice concept, but I would have just used
> "forall" directly. Is there some advantage "foreach" has over "forall"?
foreach gives you substrings or subarrays rather than elements so you can
make in-place modifications. forall doesn't help you put the elements back
into the structure. To do the equivalent of my example with forall, you'd
need yet another 'for' loop to reinsert the elements.
The obvious next step is to hard-bind the loop with 'token' so the local
dict can go away while executing 'proc'.
[toc] | [prev] | [next] | [standalone]
| From | sjprouty3765@gmail.com |
|---|---|
| Date | 2012-12-06 12:29 -0800 |
| Message-ID | <cd56e4dd-7caf-453a-80f3-14474c68d873@googlegroups.com> |
| In reply to | #1147 |
On Tuesday, December 4, 2012 1:46:05 PM UTC-8, luser- -droog wrote:
> sjprouty3765@gmail.com wrote: > On Tuesday, December 4, 2012 12:02:52 AM UTC-8, luser- -droog wrote: >> Anybody done this yet? 508(1)02:00 AM:ps 0> cat foreach.ps %! %foreach >> /foreachdict << /arraytype{ % A proc 0 1 src length 1 sub { src exch 1 >> getinterval proc } for } /stringtype 1 index /default{/foreach cvx >> /typecheck signalerror} >> def /foreach { % A|S proc 2 dict begin {proc >> src}{exch def}forall //foreachdict src type 2 copy known >> not{pop/default}if %dict src-type get exec end } def /toupper{ dup 97 ge >> 1 index 122 le and { 32 sub } if }def (hello, world! my name is >> oditszuaupuc) dup { 0 2 copy get toupper put } foreach == %eof GPL >> Ghostscript 8.62 (2008-02-29) Copyright (C) 2008 Artifex Software, Inc. >> All rights reserved. This software comes with NO WARRANTY: see the file >> PUBLIC for details. (HELLO, WORLD! MY NAME IS ODITSZUAUPUC) GS>GS> > > The /toupper procedure of course depends on the string being ASCII encoded > (and limited to the ASCII character set). It would need something more > elaborate for the full ISO-8859-1 character set, and something even more > for UTF-8 or UTF-16BE encoding of a character set. > > The /foreach procedure is a nice concept, but I would have just used > "forall" directly. Is there some advantage "foreach" has over "forall"? foreach gives you substrings or subarrays rather than elements so you can make in-place modifications. forall doesn't help you put the elements back into the structure. To do the equivalent of my example with forall, you'd need yet another 'for' loop to reinsert the elements. The obvious next step is to hard-bind the loop with 'token' so the local dict can go away while executing 'proc'.
(hello, world! my name is oditszuaupuc)
0
1 index
{
2 copy
2 copy get
toupper put
1 add
}
forall
pop
==
[toc] | [prev] | [next] | [standalone]
| From | "luser.droog" <luser.droog@gmail.com> |
|---|---|
| Date | 2012-12-07 02:10 -0600 |
| Message-ID | <k9s89t$du9$1@dont-email.me> |
| In reply to | #1152 |
sjprouty3765@gmail.com wrote:
> On Tuesday, December 4, 2012 1:46:05 PM UTC-8, luser- -droog wrote:
>> sjprouty3765@gmail.com wrote: > On Tuesday, December 4, 2012 12:02:52 AM
>> UTC-8, luser- -droog wrote: >> Anybody done this yet? 508(1)02:00 AM:ps
>> 0> cat foreach.ps %! %foreach >> /foreachdict << /arraytype{ % A proc 0 1
>> src length 1 sub { src exch 1 >> getinterval proc } for } /stringtype 1
>> index /default{/foreach cvx >> /typecheck signalerror} >> def /foreach {
>> % A|S proc 2 dict begin {proc >> src}{exch def}forall //foreachdict src
>> type 2 copy known >> not{pop/default}if %dict src-type get exec end } def
>> /toupper{ dup 97 ge >> 1 index 122 le and { 32 sub } if }def (hello,
>> world! my name is >> oditszuaupuc) dup { 0 2 copy get toupper put }
>> foreach == %eof GPL >> Ghostscript 8.62 (2008-02-29) Copyright (C) 2008
>> Artifex Software, Inc. >> All rights reserved. This software comes with
>> NO WARRANTY: see the file >> PUBLIC for details. (HELLO, WORLD! MY NAME
>> IS ODITSZUAUPUC) GS>GS> > > The /toupper procedure of course depends on
>> the string being ASCII encoded > (and limited to the ASCII character
>> set). It would need something more > elaborate for the full ISO-8859-1
>> character set, and something even more > for UTF-8 or UTF-16BE encoding
>> of a character set. > > The /foreach procedure is a nice concept, but I
>> would have just used > "forall" directly. Is there some advantage
>> "foreach" has over "forall"? foreach gives you substrings or subarrays
>> rather than elements so you can make in-place modifications. forall
>> doesn't help you put the elements back into the structure. To do the
>> equivalent of my example with forall, you'd need yet another 'for' loop
>> to reinsert the elements. The obvious next step is to hard-bind the loop
>> with 'token' so the local dict can go away while executing 'proc'.
>
>
> (hello, world! my name is oditszuaupuc)
> 0
> 1 index
> {
> 2 copy
> 2 copy get
> toupper put
> 1 add
> }
> forall
> pop
> ==
Well, phooey. :(
Harrummph.
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-12-24 19:20 -0800 |
| Message-ID | <a28910b7-164b-40c3-a6af-1b2430169e15@c16g2000yqi.googlegroups.com> |
| In reply to | #1153 |
I think this one's better than foreach. It iterates through a string
or array, pushing the initial value for the element, and after
executing the loop body it pops the new value back into the array or
string.
Plus, it "Curry"s all the arguments to leave nothing on the dictstack.
%!
%string proc map --
%array proc map --
/map{
4 dict dup begin
{/dic/proc/src}{exch def}forall
0 1 src length 1 sub
(
{
//dic/i 2 index put
//src exch get
//proc exec
//src exch //dic/i get exch put
}
)token pop exch pop
bind end for
}def
[1 1 1]dup{1 sub}map ==
(---)== flush
(this_is_a_lowercase_string___ish)dup
{16#20 sub}map
==
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web