Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #2088
| From | Carlos <angus@quovadis.com.ar> |
|---|---|
| Newsgroups | comp.lang.postscript |
| Subject | Re: map and higher order functions |
| Date | 2014-11-02 00:15 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <20141102001537.515de3e5@samara.DOMA> (permalink) |
| References | <20141030172728.0983c6bc@samara.DOMA> <95798773-17c6-41d3-8d80-06d1784a7e95@googlegroups.com> |
[luser- -droog <mijoryx@yahoo.com>, 2014-10-30 22:56]
> On Thursday, October 30, 2014 11:27:49 AM UTC-5, Carlos wrote:
> > How would you implement map and other higher order functions
> > (procedures taking one or more procedures)?
> >
> > Especially the part when the procedure is to be run, and you must
> > clear the stacks from your working elements.
> > [...]
>
> I've run into similar issues trying to write procedures that work
> like "control structures", like loops. The trick I've found is to
> use the `token` operator to dynamically build a new procedure body
> based on a string template.
> [...]
> I used this trick to make a loop body that calls a user proc.
> But it leaves the dictstack clean while the user proc is
> executing, and then reclaims the dictionary. Like this,
>
> 1 dict begin
> /DICT currentdict def
> /x 1 def
> ({ //x add //DICT begin /x 2 def end }) token pop exch pop
> end
> [...]
This is great! It makes everything so much simpler. That's exactly what
I was looking for. Thanks.
Carlos.
PS: the new implementation:
% <array/string> <proc> map <new array/string>
/map {
4 dict begin
/proc exch def
/arr exch def
/res arr length
arr type /stringtype eq { string } { array } ifelse
def
/i 1 array def
({
0 1 //arr length 1 sub { % for
dup //i 0 3 -1 roll put
//arr exch get
//proc exec
//res //i 0 get 3 -1 roll put
} for
//res
}) token pop exch pop bind
end
exec
} bind def
--
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
map and higher order functions Carlos <angus@quovadis.com.ar> - 2014-10-30 17:27 +0100
Re: map and higher order functions ken <ken@spamcop.net> - 2014-10-30 16:57 +0000
Re: map and higher order functions Carlos <angus@quovadis.com.ar> - 2014-10-30 19:55 +0100
Re: map and higher order functions ken <ken@spamcop.net> - 2014-10-31 12:17 +0000
Re: map and higher order functions Ross Presser <rpresser@gmail.com> - 2014-10-30 20:30 -0700
Re: map and higher order functions Carlos <angus@quovadis.com.ar> - 2014-11-01 23:58 +0100
Re: map and higher order functions luser- -droog <mijoryx@yahoo.com> - 2014-10-30 22:56 -0700
Re: map and higher order functions Carlos <angus@quovadis.com.ar> - 2014-11-02 00:15 +0100
Re: map and higher order functions luser- -droog <mijoryx@yahoo.com> - 2014-11-15 00:43 -0800
Re: map and higher order functions Carlos <angus@quovadis.com.ar> - 2014-11-16 01:37 +0100
Re: map and higher order functions luser- -droog <mijoryx@yahoo.com> - 2014-11-21 00:17 -0800
Re: map and higher order functions luser- -droog <mijoryx@yahoo.com> - 2015-02-27 00:59 -0800
csiph-web