Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Carlos Newsgroups: comp.lang.postscript Subject: Re: Getting Rid Of PostScript Date: Tue, 25 Oct 2016 21:06:47 +0200 Organization: A noiseless patient Spider Lines: 122 Message-ID: <20161025210647.55ecd219@samara.DOMA> References: <52007eb3-d23e-4938-bb11-08ff341ed5a9@googlegroups.com> <76c2a057-6627-4de9-88fc-ca3e1c37c256@googlegroups.com> <1a6d41b2-6c18-4458-a18d-becdc92715a8@googlegroups.com> <040899ac-5cf7-40f5-9aa8-b1db05a900b6@googlegroups.com> <94a0f333-dcc9-4a76-8da9-57595c1433a7@googlegroups.com> <0e89f7c1-08ef-4a1d-9fc8-8d92fd687e03@googlegroups.com> <68890a35-ae58-4755-b6be-5f8a7d4b0362@googlegroups.com> <66538ba6-282f-4b3d-b8ba-94b93903385f@googlegroups.com> <41c5fbb5-a268-4cc1-8522-73f92980ce69@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: mx02.eternal-september.org; posting-host="872f6ced25f80d86aec738cb256baeb3"; logging-data="21682"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LNSahjjgXXWcm2+xy382MEcG92Kv2bJw=" X-Newsreader: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Cancel-Lock: sha1:9ZF100YgcVJIut7JcHUPhws9qrk= Xref: csiph.com comp.lang.postscript:2925 [Lawrence D=E2=80=99Oliveiro , 2016-10-25 10:32] > On Wednesday, October 26, 2016 at 3:26:52 AM UTC+13, Carlos wrote: > > > > On 25/10/2016 1:54, Lawrence D=E2=80=99Oliveiro wrote: > > =20 > >> Note that the actual drawing of a node is implemented by the > >> =E2=80=9Cdraw_node=E2=80=9D function which is passed as the argument, = while > >> =E2=80=9Cdraw_nodes_grid=E2=80=9D itself only implements the layout of= the entire > >> diagram. =20 > >=20 > > You can do that in PostScript, too. Pass a block to a procedure, > > then call it with exec. =20 >=20 > But you don=E2=80=99t get the lexical binding, which is what really makes > them useful. You can get the PostScript equivalent, as previously explained (more below). > >> cell_dims =3D pix.dimensions / Vector(10, 10) =20 > >>> =20 > >> See how the x- and y-dimensions of a single cell are computed from > >> the dimensions of the drawing area by a single division? =20 > >=20 > > Come on. Just because you wrote a vector library in Python and not > > in PostScript, that doesn't make Python better. =20 >=20 > You didn=E2=80=99t notice that the operation was done with the standard > division operator, then? Python allows you to define custom overloads > for the standard operators. This way, you can write your expressions > using notation much closer to the original maths. Operator overloading is a controversial issue. Some like it, some don't. Some think having it in a language makes it better, some think it makes it worse. In any case, you can never write your expressions close to mathematical notation in PostScript, so that's not a good reason to prefer overloading. I don't think much would be gained if people could multiply vectors using "mul" instead of "Vmul". >=20 > > assuming pix is a dictionary. Here is the start of a vector library: > >=20 > > /Vector { 2 packedarray } bind def > > /x { 0 get } bind def > > /y { 1 get } bind def > > /xy { aload pop } bind def > >=20 > > /Vop { 3 1 roll > > xy 3 -1 roll xy > > 3 -1 roll 4 index exec > > 3 1 roll exch 3 index exec > > exch Vector > > exch pop } bind def > >=20 > > /Vdiv { { div } Vop } bind def =20 >=20 > Not much of a start, don=E2=80=99t you think > ? Just the necessary to translate to PostScript the snippets you are posting. >=20 > > Again, a matter of libraries =20 >=20 > Which PostScript is, frankly, no help with. It helps with the writing; coding in PostScript is enjoyable. > > [Lexical binding is] a facility the Python compiler provides > > because it's otherwise impossible to return custom functions. You > > don't need the interpreter's help in PostScript, because procedures > > are arrays, and you can easily create arrays programmatically. (By > > the way, this is a recurring topic in this newsgroup lately.) =20 >=20 > But you cannot do the lexical binding. Not in a reentrant fashion. Yes you can, but the interpreter won't do it automatically for you. I just showed you! I don't know what you mean by "not in a reentrant fashion"; if you found a case where it doesn't work please tell me. Did you try it at all? GS>/add1 1 makeadder def /add4 4 makeadder def GS>8 add1 add5 =3D=3D 13 > > Try this: =20 >=20 > How many lines of PostScript code have you written so far? Compare it > to how many lines of Python code I needed to write. What? You wrote more lines. Or wasn't the code for Vector and Rectangle classes written by you? I mean, line for line, PostScript wins hands down. Compare: def __sub__(v1, v2) : "difference between two Vectors." return \ ( lambda : NotImplemented, lambda : type(v1)(v1.x - v2.x, v1.y - v2.y) )[isinstance(v2, Vector)]() #end __sub__ with /Vsub { { sub } Vop } bind def % vector difference > And your solution isn=E2=80=99t even complete yet. Well, you didn't post a complete solution either, just some snippets (the code in the original message also wasn't complete). If you want, post a complete solution and I'll try to produce a PostScript equivalent, so you can see Python isn't better :) --=20