Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Carlos Newsgroups: comp.lang.postscript Subject: Re: map and higher order functions Date: Thu, 30 Oct 2014 19:55:24 +0100 Organization: A noiseless patient Spider Lines: 42 Message-ID: <20141030195524.77fe473f@samara.DOMA> References: <20141030172728.0983c6bc@samara.DOMA> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="f4fcdd466dcf73c2e008a0d28a614b04"; logging-data="1376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NhnAHuqbBGzguNwWq2ngrnAlwM/+ywMQ=" X-Newsreader: Claws Mail 3.10.1 (GTK+ 2.24.24; x86_64-pc-linux-gnu) Cancel-Lock: sha1:sqKQHSBlJTCjsV+1gaNOVWqK5g0= Xref: csiph.com comp.lang.postscript:2083 [ken , 2014-10-30 16:57] > In article <20141030172728.0983c6bc@samara.DOMA>, > angus@quovadis.com.ar says... > > > > How would you implement map and other higher order functions > > (procedures taking one or more procedures)? > > I'm not sure what your 'map' function is intended to do, but... This is what it's intended to do: GS>[ 1 2 3 4 ] { 1 add } map == [2 3 4 5] Inside map, I have to exec the proc ({ 1 add } in this case) without having anything on the stack. Otherwise, this GS> 3 [ 1 2 3 4 ] { 1 index add } map == [4 5 6 7] wouldn't work, since "1 index" would retrieve some value used internally by map, and not what the user expects. I can't also simply use an entry in userdict, because it would get clobbered if the function re-enters, and this would fail: GS>[ [ 1 2 3 ] [ 4 5 6 ] ] { { 1 add } map } map == [[2 3 4] [5 6 7]] Nor can I have anything on the dictionary stack (using "n dict begin ... end" to hold "local variables"), because the user might execute a "def" inside the procedure, and the entry would be stored in the wrong dictionary. I'd like to know what the options are to solve this problem. I hope it is clearer now. > [...] --