Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Helge Blischke Newsgroups: comp.lang.postscript Subject: Re: How does ghostscript make ints and reals equivalent as dictionary keys??!!! Followup-To: comp.lang.postscript Date: Fri, 23 Aug 2013 16:37:37 +0200 Lines: 48 Message-ID: References: <5a1784ab-352f-403e-878d-39740b1b23cd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: individual.net zHQZFwj4VgWB/q9tcm9kzAcJ3TdAHfD+NoZas617vP4abDiKQZ Cancel-Lock: sha1:DJotj4BV9CFLcUb1y62uCgGfQWk= User-Agent: KNode/0.99.01 Xref: csiph.com comp.lang.postscript:1584 luser- -droog wrote: > I've marveled at this behavior before. But I just can't imagine how > they do that! > > I suppose in many languages (PERL, Lua, JavaScript), the distinction > between ints and reals is very blurry all the way down the pipeline. > But postscript makes them distinct types for many operations > (array and string indexing, stack indexing, various other 'count' or > ordinal data), but blurs them during math. And C makes the distinction > very explicit, but permits 'usual implicit conversions' to provide > automatic promotions where appropriate. > > All of this is fine, and where an operator needs one or the other > it can check and signal an error; or when an operator can accept > either, it can check and promote if necessary before merging > the int and real cases. But... > > But how do you make them hash equally so you can look them up in a dict? > > My only guess is that ghostscript must merge them somehow into a single > canonical form: some kind of extended floating-integer hybrid super-duper > hackjob type. > > But then, how do you do the 'super-duper' part? Integers and reals don#t seem to be equivalent as dictionary keys. For instance, if you define (in Ghostscript) /1 (Heureka) def currentdict/1 .knownget puts (Heureka) true onto the operand stack, but currentdict/1.0 .knownget yields only false on the operand stack. Helge