For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > Re: Reduce Blanks challenge









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Reduce Blanks challenge
robin

2005-08-21, 6:57 pm


David Frank wrote in message ...
>we can go on to a 2nd challenge thats been running concurrently over in
>comp.lang.fortran.
>Posted only for PLI'er info, there wont be a PL/I translation.


>Since its my challenge I am narrowing the acceptable solutions in reduce.f90
>as follows:
>
>1. the output string must contain a blank last char (if input string has 1
>or more trailing blanks)
> by output of a null char after just 1 trailing blank char is output.
>2. the solution must use array syntax, no scalar processing with do loops
>3. Fast/Legible/Brief is a goal.
>
>My current solution that meets these revised specs, uses 3 statements:
>
>pad = char(0) ! allow pack to use null chars to pad its output
>a = Copy(line) ! copy line to char array
>outline = line(1:1) // Copy( PACK(a(2:), a(2:)/=' '.or.a(1:)/=' ',pad) )



I think that this will do it in PL/I :-

line = pack (a, (a^=' ') | (b ^= ' '), rank(0) );


David Frank

2005-08-21, 6:57 pm


"robin" <robin_v@bigpond.com> wrote in message
news:pt1Oe.6470$FA3.4172@news-server.bigpond.net.au...
>
>
>
> I think that this will do it in PL/I :-
>
> line = pack (a, (a^=' ') | (b ^= ' '), rank(0) );
>


I think NOT
Did you forget you cross-posted and are being read by REAL programmers here
in comp.lang.fortran?

Arent you embarrassed to post fictitious PL/I syntax?
1. There is no PL/I pack function

2. you cant write a COPY string into an array function as PL/I doesnt
support dynamic function output determined
by input size or length, so much for any possibility you can write a
generic Copy function.

3. You dont have a magical TRANSFER function to substitute, you gots lotsa
problems besides no pack.

4. what is "b" supposed to be?

As usual you never show your statements actually work in a test program



robin

2005-08-22, 9:57 pm


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:pt1Oe.6470$FA3.4172@news-server.bigpond.net.au...
>
>I think NOT
>Did you forget you cross-posted and are being read by REAL programmers here
>in comp.lang.fortran?


>Arent you embarrassed to post fictitious PL/I syntax?


It is not "ficticious". It is real PL/I code, but we have seen
that yours isn't, being buggy.

>1. There is no PL/I pack function



Since your code uses your own COPY function,
you will admit user-written PACK function.

>2. you cant write a COPY string into an array function as PL/I doesnt
>support dynamic function output determined
> by input size or length, so much for any possibility you can write a
>generic Copy function.




>3. You dont have a magical TRANSFER function to substitute, you gots lotsa

problems


Don't need one. In PL/I, the DEFINED attribute handles that.

> besides no pack


I wrote one a long while back.

>4. what is "b" supposed to be?



"b" is referred to the array "a" (see below).

>As usual you never show your statements actually work in a test program


dcl line char (*);
dcl outline char(length(line)) varz;
dcl a(length(s)) char(1) def line pos(1), b(length(s)) char(1) def a(min(1sub+1,
length(s)));



robin

2005-08-22, 9:57 pm


David Frank wrote in message ...
>
>"Tim Challenger" <tim.challenger@aon.at> wrote in message
>news:1124699765. 17b90c8dbed03e32764504cabd3dc93d@teranew
s...
>
>Thats absolutely true and I considered whether there was ANY possibility
>that PL/I syntax supported writing a user PACK function and it boggled my
>imagination so much I broke out laffing.




>Otoh, my generic Copy function WAS written and can be viewed:
> http://home.earthlink.net/~dave_gemini/strings.f90



Your Copy function is NOT generic.

-INTERFACE Copy
- MODULE PROCEDURE copy_a2s, copy_s2a
-END INTERFACE Copy
-CONTAINS
-! ------------------------
-FUNCTION Copy_a2s(a) RESULT (s) ! copy char array to string
-CHARACTER :: a(:)
-CHARACTER(SIZE(a)) :: s
-INTEGER :: i
-DO i = 1,SIZE(a)
- s(i:i) = a(i)
-END DO
-END FUNCTION Copy_a2s
-! ------------------------
-FUNCTION Copy_s2a(s) RESULT (a) ! copy string to char array
-CHARACTER(*) :: s
-CHARACTER :: a(LEN(s))
-INTEGER :: i
-DO i = 1,LEN(s)
- a(i) = s(i:i)
-END DO
-END FUNCTION Copy_s2a


>and its use demo'ed in the reduce_blanks benchmark
>
> http://home.earthlink.net/~dave_gemini/reduce.f90
>
>Do you agree that PL/I cannot duplicate my generic Copy function?


PL/I does not need one.

As well as the DEFINED attribute for this type of thing,
PL/I supports the STRING function (should an assignment be
appropriate).




robin

2005-08-22, 9:57 pm

David Frank wrote in message ...
>
>"Tim Challenger" <tim.challenger@aon.at> wrote in message
>news:1124709069. 7d47947a0368832b424783e50fa2110e@teranew
s...
[color=darkred]
>Why for truthfully answering your question?
>Otoh, my question to you
>

You have NOT written a generic COPY function,
as your own code PROVES.
[color=darkred]
>was ignored.
>I will add a 2nd question to you, do you think PL/I syntax supports a
>user-written PACK function?



Not only does PL/I support a user-written PACK function,
it supports a user-written GENERIC PACK function.

AND a generic COPY function.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com