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


Groups > comp.lang.postscript > #1032 > unrolled thread

Type of element on stack

Started byCecil Westerhof <Cecil@decebal.nl>
First post2012-11-11 03:24 +0100
Last post2012-11-17 14:39 +0100
Articles 7 — 4 participants

Back to article view | Back to comp.lang.postscript


Contents

  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

#1032 — Type of element on stack

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-11-11 03:24 +0100
SubjectType of element on stack
Message-ID<87fw4gnafj.fsf@Compaq.site.inet>
Is there a way to check for the type of an element on the stack?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#1033

FromDan Coby <adcoby@earthlink.net>
Date2012-11-10 21:15 -0800
Message-ID<C5-dnQI9gIUsqQLNnZ2dnUVZ_s6dnZ2d@earthlink.com>
In reply to#1032
On 11/10/2012 6:24 PM, Cecil Westerhof wrote:
> Is there a way to check for the type of an element on the stack?
>

Yes. The type operator. See page 705 of the PLRM 3rd edition.
All of the operators are listed in the PLRM.


GS>1 type =
integertype
GS>[1] type =
arraytype
GS>(aaa) type =
stringtype

[toc] | [prev] | [next] | [standalone]


#1034

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-11-11 10:34 +0100
Message-ID<87zk2olbze.fsf@Compaq.site.inet>
In reply to#1033
Op zondag 11 nov 2012 06:15 CET schreef Dan Coby:

>> Is there a way to check for the type of an element on the stack?
>>
>
> Yes. The type operator. See page 705 of the PLRM 3rd edition.
> All of the operators are listed in the PLRM.
>
>
> GS>1 type =
> integertype
> GS>[1] type =
> arraytype
> GS>(aaa) type =
> stringtype

Works like a charm. Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#1038

FromDon Lancaster <don@tinaja.com>
Date2012-11-12 20:41 -0800
Message-ID<agdtriFrm26U1@mid.individual.net>
In reply to#1032
On 11/10/2012 6:24 PM, Cecil Westerhof wrote:
> Is there a way to check for the type of an element on the stack?
>


like dup type ?

-- 
Many thanks,

Don Lancaster                          voice phone: (928)428-4073
Synergetics   3860 West First Street   Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml   email: don@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com

[toc] | [prev] | [next] | [standalone]


#1039

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-11-13 07:31 +0100
Message-ID<87pq3ij9ou.fsf@Compaq.site.inet>
In reply to#1038
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.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#1049

From"luser.droog" <luser.droog@gmail.com>
Date2012-11-16 18:19 -0600
Message-ID<k86l65$c3f$1@dont-email.me>
In reply to#1039
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

[toc] | [prev] | [next] | [standalone]


#1054

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-11-17 14:39 +0100
Message-ID<877gpke4cr.fsf@Compaq.site.inet>
In reply to#1049
Op zaterdag 17 nov 2012 01:19 CET schreef luser droog:

> 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

I have to look into this, to understand what is happening here, but I
gladly will do so. ;-}

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web