Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1049

Re: Type of element on stack

From "luser.droog" <luser.droog@gmail.com>
Newsgroups comp.lang.postscript
Subject Re: Type of element on stack
Date 2012-11-16 18:19 -0600
Organization unorganized
Message-ID <k86l65$c3f$1@dont-email.me> (permalink)
References <87fw4gnafj.fsf@Compaq.site.inet> <agdtriFrm26U1@mid.individual.net> <87pq3ij9ou.fsf@Compaq.site.inet>

Show all headers | View raw


Cecil Westerhof wrote:

> Op dinsdag 13 nov 2012 05:41 CET schreef Don Lancaster:
> 
>>> Is there a way to check for the type of an element on the stack?
>>>
>>
>>
>> like dup type ?
> 
> Yep.
> 

The next cool bit is 'exec'.
'type' returns an executable name, so you can do type-dispatch with a
dictionary. eg.

/do { %different things to different types
   <<
      /integertype{1 add}
      /booleantype{not}
      /realtype{2 exp}
      /stringtype{cvr 1 add}
   >> 1 index type  % x dict x-type
   2 copy known not {pop/default} if
   get exec % x'
} def

Wait. rats. that doesn't use the 'executable' part.
How about...

/do2 { %coerce input to integer
    <<
       /integertype{}
       /realtype{cvi}
       /booleantype{{1}{0}ifelse}
       /stringtype{cvr round cvi}
    >> begin
    dup type exec
    end
} def

This is used by the = and == operators to operate on multiple types in a
sensible manner (without a nasty shrub of ifelse nonsense).

HTH

Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Type of element on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-11-11 03:24 +0100
  Re: Type of element on stack Dan Coby <adcoby@earthlink.net> - 2012-11-10 21:15 -0800
    Re: Type of element on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-11-11 10:34 +0100
  Re: Type of element on stack Don Lancaster <don@tinaja.com> - 2012-11-12 20:41 -0800
    Re: Type of element on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-11-13 07:31 +0100
      Re: Type of element on stack "luser.droog" <luser.droog@gmail.com> - 2012-11-16 18:19 -0600
        Re: Type of element on stack Cecil Westerhof <Cecil@decebal.nl> - 2012-11-17 14:39 +0100

csiph-web