Operating System - OpenVMS
1828186 Members
2390 Online
109975 Solutions
New Discussion

HP Pascal SELECT and SELECTONE expressions

 
SOLVED
Go to solution
Jeremy Begg
Trusted Contributor

HP Pascal SELECT and SELECTONE expressions

Hi,

I'm writing a Pascal program which uses the SELECT and SELECTONE statements introduced in HP Pascal V6. The only documentation I can find is the description in the Release Notes and there's something I need clarified.

I'm assuming that the data types of the 'select-selector' expression and the 'select-label-list' expressions have to be the same, or at least type-compatible. But do they have to be ordinal types, or can they be more complex? For example, can these expressions be character strings?

(Yes, I know I can do this by making the 'select-selector' the boolean constant TRUE and then having each 'select-label-list' consist of string comparisons producing TRUE or FALSE results.)

Thanks,

Jeremy Begg
4 REPLIES 4
Heinz W Genhart
Honored Contributor

Re: HP Pascal SELECT and SELECTONE expressions

Hi Jeremy

you are right. There is no documentation online (yet).
I would expect to find the documentation for Pascal V6 on the following page:
http://h71000.www7.hp.com/doc/pascal.html

regards

Heinz
John Gillings
Honored Contributor

Re: HP Pascal SELECT and SELECTONE expressions

Hi Jeremy,

I'd expect ordinal types, but then HP Pascal frequently surprises me in the way it pushes boundaries ;-)

I expect you'll get an authoritative answer from John Reagan soon...
A crucible of informative mistakes
John Reagan
Respected Contributor
Solution

Re: HP Pascal SELECT and SELECTONE expressions

Here's some background on how I arrived on SELECT/SELECTONE.

An outstanding wishlist item was to CASE on character strings. Something like:

CASE string-expression OF

'ABC': stmt1;
'DEF': stmt2;
END;

However, I would have to start dealing with errors like:

CASE string-expression OF

'ABC': stmt1;
'DEF': stmt2;
'ABC ': stmt3;
END:

While trying to figure out the best place to do that (the internal structures were not prepared for string values), I mumbled to myself "Gee if only CASE could just do the FIRST one it found, then I wouldn't have to do any checking at all. Just dump the 'problem' back on the user." (I'm such a nice guy, eh?)

While in the compiler looking at CASE, I saw that I use the BLISS SELECT statement (which only takes ordinal values) as:

SELECTONE True OF
SET
[CH$EQL(.Expr,'ABC')]: ...
[CH$EQL(.Expr,'DEF')]: ...
TES;


I said, "Ah, if I allow full run-time expressions and define an 'order of evaluation' for the SELECT parts, that will let me provide a 'CASE over strings' plus with SELECT vs SELECTONE, you can get even more power.

So off I went to re-implement BLISS' SELECT and SELECTONE statements into Pascal.

With that background, the SELECT selector must be an ordinal type. The way you 'CASE on strings' is:

SELECTONE True OF
String-expression = 'ABC': ...
String-expression = 'DEF': ...
END;

John

PS As for adding it to the documenation, we didn't update the docset for V6.0. The release notes is the only place for the information right now. I hope to update it next time as I have a few more customer requests I'd like to add. (spoiler alert: I've had several requests for the compiler to understand/generate 64bit descriptors for conformant array parameters.)
Jeremy Begg
Trusted Contributor

Re: HP Pascal SELECT and SELECTONE expressions

Great explanation, John.

Thanks!