PL/I Newsletter 
Author Message
 PL/I Newsletter

The September 2000 PL/I Newsletter is at:

http://www.*-*-*.com/



Fri, 21 Mar 2003 03:00:00 GMT  
 PL/I Newsletter
This Month's Problem
The problem of today uses some new features of the Visual Age PL/I compiler.
Given an ordinal variable T which can assume two values T1 and T2, I want a
function also named T which returns the ordinal value when the binary value
is passed to it:

   Problem2: proc options (main);

      define ordinal T (T1 value (-1),
                     T2 value (3)) prec (7) signed;
      put (ordinalname(T(-1)), ordinalname(T(3)));

   T: proc (N) returns (type T);
      dcl N fixed bin (31);

   ???

   end T;

   end Problem2;

Give FP6+:
  return (CAST (: T,  N :)):


Quote:
> The September 2000 PL/I Newsletter is at:

> http://www.users.bigpond.com/robin_v/pli-n2.htm



Sun, 23 Mar 2003 13:44:44 GMT  
 PL/I Newsletter
Mark Yudkin schrieb:

Quote:

> This Month's Problem
> The problem of today uses some new features of the Visual Age PL/I compiler.
> Given an ordinal variable T which can assume two values T1 and T2, I want a
> function also named T which returns the ordinal value when the binary value
> is passed to it:

>    Problem2: proc options (main);

>       define ordinal T (T1 value (-1),
>                      T2 value (3)) prec (7) signed;
>       put (ordinalname(T(-1)), ordinalname(T(3)));

>    T: proc (N) returns (type T);
>       dcl N fixed bin (31);

>    ???

>    end T;

>    end Problem2;

> Give FP6+:
>   return (CAST (: T,  N :)):



> > The September 2000 PL/I Newsletter is at:

> > http://www.users.bigpond.com/robin_v/pli-n2.htm

This is a very interesting solution but did you test it?
My compilers (OS/2 FP6 and Windows FP7) say:

   IBM2078I S Types with the attributes ORDINAL are not supported as the
              target of the CAST function.

In the "Messages and Codes" manual you can find:

   Explanation: The first argument to the type function CAST must be a
   type with one of the following sets of attributes: REAL FIXED
BIN(p,0)
   or NATIVE REAL FLOAT.

I must admit that I don't really understand CAST because it is defined
in
the following way:

   CAST converts the expression x to the type t using C conversion
rules.

What is meant by "C conversion rules"? ;-)

Best regards

Eberhard

/*---------------------------------------------------------------*/
     /* Eberhard Sturm                          Tel: +49-251-83-31679 */
    /* ZIV (Universitaetsrechenzentrum)        Fax: +49-251-83-31555 */
   /* Roentgenstr. 9-13                                             */

 /* http://www.uni-muenster.de/ZIV/Mitarbeiter/EberhardSturm.html */
/*---------------------------------------------------------------*/



Mon, 24 Mar 2003 03:00:00 GMT  
 PL/I Newsletter
 Problem2: Procedure Options(Main);

   Define Ordinal T (T1 Value(-1), T2 Value(3)) Precision(7) Signed;

   Put (Ordinalname(T(-1)), Ordinalname(T(3)));

 T: Procedure(N) Returns(Type T);

   Declare
       N Fixed Bin(31);

   Declare
       X Type T;

   /* Unfortunately, I don't see an alternative to a serial search.   */
   /* with the given problem, this is not important, but if the       */
   /* ordinal contained a large number of members, this would be      */
   /* rather slow.                                                    */

   Do X=First(:T:) Repeat(Ordinalsucc(X)) Until(X=Last(:T:));

     /* Since there is no guarantee that the argument to T is in the  */
     /* set Binaryvlue(T), we need to handle the error                */

     If N<Binaryvalue(X)      Then Signal Error;

     Else If N=Binaryvalue(X) Then Return(X);

   End;

 End T;

 End Problem2;


Quote:
> The September 2000 PL/I Newsletter is at:

> http://www.users.bigpond.com/robin_v/pli-n2.htm



Wed, 26 Mar 2003 03:00:00 GMT  
 PL/I Newsletter
This Month's Problem
The problem of today uses some new features of the Visual Age PL/I compiler.
Given an ordinal variable T which can assume two values T1 and T2, I want a
function also named T which returns the ordinal value when the binary value
is passed to it:

   Problem2: proc options (main);

      define ordinal T (T1 value (-1),
                     T2 value (3)) prec (7) signed;
      put (ordinalname(T(-1)), ordinalname(T(3)));

   T: proc (N) returns (type T);
      dcl N fixed bin (31);

   ???

   end T;

   end Problem2;

As with most problems of this sort, unspec is the usual resolution (prior to
whatever FixPak supports CAST (: :) for ordinals):

  dcl X type T;
  unspec (X) = unspec (bin (N, 7));
  return (X);


Quote:
> The September 2000 PL/I Newsletter is at:

> http://www.users.bigpond.com/robin_v/pli-n2.htm



Thu, 27 Mar 2003 03:00:00 GMT  
 PL/I Newsletter

Mark Yudkin schrieb:

Quote:

> This Month's Problem
> The problem of today uses some new features of the Visual Age PL/I compiler.
> Given an ordinal variable T which can assume two values T1 and T2, I want a
> function also named T which returns the ordinal value when the binary value
> is passed to it:

>    Problem2: proc options (main);

>       define ordinal T (T1 value (-1),
>                      T2 value (3)) prec (7) signed;
>       put (ordinalname(T(-1)), ordinalname(T(3)));

>    T: proc (N) returns (type T);
>       dcl N fixed bin (31);

>    ???

>    end T;

>    end Problem2;

> As with most problems of this sort, unspec is the usual resolution (prior to
> whatever FixPak supports CAST (: :) for ordinals):

>   dcl X type T;
>   unspec (X) = unspec (bin (N, 7));
>   return (X);



> > The September 2000 PL/I Newsletter is at:

> > http://www.users.bigpond.com/robin_v/pli-n2.htm

My article stated:

'The attributes "value", "precision", and "signed" are only examples of what
may happen to occur. Function T should be independent of these attributes.'

Thus UNSPEC is not sufficient.

      /*---------------------------------------------------------------*/
     /* Eberhard Sturm                          Tel: +49-251-83-31679 */
    /* ZIV (Universitaetsrechenzentrum)        Fax: +49-251-83-31555 */
   /* Roentgenstr. 9-13                                             */

 /* http://www.uni-muenster.de/ZIV/Mitarbeiter/EberhardSturm.html */
/*---------------------------------------------------------------*/



Fri, 28 Mar 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. The PL/I Connection (PL/I Newsletter No. 6)

2. The PL/I Newsletter

3. PL/I Newsletter

4. The PL/I Newsletter (August 2002)

5. Call for PL/I Newsletter articles

6. PL/I Newsletter

7. PL/I Newsletters - URLs for some back numbers (third try)

8. PL/I Newsletters -- URLs for back issues

9. PL/I Newsletters -- URLs for some back issues

10. PL/I Newsletter (June 2001)

11. PL/I Newsletter

12. Request for Articles for PL/I Newsletter

 

 
Powered by phpBB® Forum Software