Size of array parameter in f2008 
Author Message
 Size of array parameter in f2008

It is convenient that one can declare a scalar character parameter
without having to count the number of characters by saying, e.g.

   CHARACTER(LEN=*),PARAMETER:: string='Hello world'

I find it annoying that a rank 1 array parameter can't be declared
with one symbol for its size corresponding to the character type's *.

The one symbol presumably couldn't be * because that already has a
different meaning in array declarations. The question mark ? is in
the f95 character set, it is not used for any other syntactic purpose,
and it suggests lack of knowledge until an answer is given, so IMHO
declaring a rank 1 array parameter with (dimension=?) might be a good  
way to specify that the actual size is that of the array constructor.

If one wishes to avoid counting the number of elements, the only
way obvious to me is to repeat the array constructor, e.g. as follows:

   REAL,PARAMETER:: numbers(size((/42,69,666/)))=(/42,69,666/)  

That's bearable with size 3, but would be tedious for big arrays.
Have I missed something obvious? If not, does anyone else feel that
this would be a useful enhancement to the language?

One could even imagine higher rank array parameters like that e.g.

   REAL,PARAMETER::num2(?,?)=reshape((/1,2,3,4,5,6/),(/2,3/))

John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington, New Zealand



Mon, 31 Mar 2008 10:54:27 GMT  
 Size of array parameter in f2008

Quote:

> It is convenient that one can declare a scalar character parameter
> without having to count the number of characters by saying, e.g.

>    CHARACTER(LEN=*),PARAMETER:: string='Hello world'

> I find it annoying that a rank 1 array parameter can't be declared
> with one symbol for its size corresponding to the character type's *.

> The one symbol presumably couldn't be * because that already has a
> different meaning in array declarations.

Not for parameters it doesn't. In fact, the situation seems identical to
that of character length to me. The * has a meaning for character length
also, but that meaning applies only to dummy arguments, which can't be
parameters.

Not only do I see no bar to using * for this, I woudl find it surprising
to use anything else. The parallel to character seems too strong to me.
Well, perhaps ":" would work - again, its other uses aren't compatible
with parameters.

I'm thinking I might have seen a proposal along these lines, but the
details escape me and I may be confusing it with something else. If I
did see a proposal, I don't recall its status.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain



Mon, 31 Mar 2008 11:37:29 GMT  
 Size of array parameter in f2008

Quote:

> It is convenient that one can declare a scalar character parameter
> without having to count the number of characters by saying, e.g.
>    CHARACTER(LEN=*),PARAMETER:: string='Hello world'
> I find it annoying that a rank 1 array parameter can't be declared
> with one symbol for its size corresponding to the character type's *.
> The one symbol presumably couldn't be * because that already has a
> different meaning in array declarations.

The C initialized array length indication is nothing at all, but
I do think * makes more sense for fortran.

int x[]={1,2,3,};  (the last comma is optional.)

Did you mean only for PARAMETER, or for initializers in general?

It is nice for both not to have to count.  There is an old saying,
computers are better at counting than people.

-- glen



Mon, 31 Mar 2008 13:47:46 GMT  
 Size of array parameter in f2008
Hello,

<snip>

Quote:
> I'm thinking I might have seen a proposal along these lines, but the
> details escape me and I may be confusing it with something else. If I
> did see a proposal, I don't recall its status.

05-194r1 passed during 173.  See the "work plan" link
from j3's home page.  http://www.j3-fortran.org

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Mon, 31 Mar 2008 17:45:18 GMT  
 Size of array parameter in f2008

Quote:

> Did you mean only for PARAMETER, or for initializers in general?

I meant only for PARAMETERS. That's the only case where you can do it
for character length now. I can't testify to what John meant, but
PARAMETER is what he said.

Initializers in general add extra issues. The extra issues are probably
not insurmountable, but they are there. For one, initializers in general
apply to things that might later change from their initialized value.
Thus, I'd think you would want to be careful to distinguish whether the
size/length inferred from the expression is a fixed one or just the
initial one, subject to change. At the moment, I don't off-hand think
there are any cases where you can initialize something that can have
variabe size, but it sure isn't hard to imagine future enhancements in
that area.

It probably all works, I'd guess, but I'd want to tread very carefully
on that ground to make sure.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Mon, 31 Mar 2008 22:59:34 GMT  
 Size of array parameter in f2008

Quote:

> 05-194r1 passed during 173.  See the "work plan" link
> from j3's home page.  http://www.j3-fortran.org

Having just read that, I see the syntax is proposed to be (wisely,
imo) extended to also allow

real, parameter :: v(0:*) = [0.1, 1.1]

where the upper bound may be inferred from the array length.

But the symmetrical case of

real, parameter :: v(*:1) = [0.1, 1.1]

is not intended to be permitted. Is there a reason for this? I can
imagine it being useful on occasion, and I can't see any
syntactical ambiguity.

--
Dr. Toby White
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK



Tue, 01 Apr 2008 02:05:23 GMT  
 Size of array parameter in f2008

Quote:

> But the symmetrical case of

> real, parameter :: v(*:1) = [0.1, 1.1]

> is not intended to be permitted. Is there a reason for this? I can
> imagine it being useful on occasion, and I can't see any
> syntactical ambiguity.

Well, there might not be any syntactical ambiguity, but neither is there
any syntactical comonality. In every other case, array lower bounds are
either assumed (in the case of pointers), explicitly declared, or
default to 1. Specifically, one cannot declare a dummy argument as being
dimensioned (*:1) and it wouldn't "work" to do so. It could concievably
work to have a dummy argument declared as (:1), but not (*:) (where I
assume the "obvious" meanings by extension of concept). That's because *
in a dummy argument size basically means "don't know", but the compiler
has to know the lower bounds in order to correctly compute addresses.

I suspect people would find it confusing to be able to use (*:1) in some
cases, but not in others. I'd be having to explain here why it doesn't
work for dummy arguments.

Adding the (1:*) form for parameters seems to me like making things
consistent. Adding (*:1) for parameters, though I agree it could work,
does not seem so consistent. IMO anyway.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Tue, 01 Apr 2008 02:22:11 GMT  
 Size of array parameter in f2008
Hello,

Quote:


>>05-194r1 passed during 173.  See the "work plan" link
>>from j3's home page.  http://www.j3-fortran.org

> Having just read that, I see the syntax is proposed to be (wisely,
> imo) extended to also allow

> real, parameter :: v(0:*) = [0.1, 1.1]

> where the upper bound may be inferred from the array length.

> But the symmetrical case of

> real, parameter :: v(*:1) = [0.1, 1.1]

> is not intended to be permitted. Is there a reason for this? I can
> imagine it being useful on occasion, and I can't see any
> syntactical ambiguity.

Oh, I don't know.  Van didn't write the paper that way?
To preserve the symmetry with assumed-size arrays?
J3 may have had a reason, or just didn't think
of all the possibilities.  Maybe Van simply wanted
to pass what he felt was needed without risking lengthy
discussion on extras which might turn out to be more
complicated to solve than the problem he was trying to solve?

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



Tue, 01 Apr 2008 02:32:58 GMT  
 Size of array parameter in f2008


Quote:

>> Did you mean only for PARAMETER, or for initializers in general?

>I meant only for PARAMETERS. That's the only case where you can do it
>for character length now. I can't testify to what John meant, but
>PARAMETER is what he said.

I said PARAMETER because I was thinking of the analogy with character
length, and I didn't want to suggest a generalization that might prevent
the more restricted suggestion passing J3. As Richard said:

Quote:
>Initializers in general add extra issues...

If those issues can be satisfactorily dealt with, that would be good.
But I'm not holding my breath.

John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington, New Zealand



Tue, 01 Apr 2008 06:58:38 GMT  
 Size of array parameter in f2008

Quote:
> Well, there might not be any syntactical ambiguity, but neither is there
> any syntactical comonality.  
[snip]
> I suspect people would find it confusing to be able to use (*:1) in some
> cases, but not in others. I'd be having to explain here why it doesn't
> work for dummy arguments.

All of these are reasonable answers, thanks. I didn't actually
realise that it was already legitimate to use this form for
dummy arguments, so I didn't appreciate the commonality.

Toby

--
Dr. Toby White
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK



Tue, 01 Apr 2008 19:01:21 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. allow size of parameter array to be inferred?

2. parameter syntax for array parameter

3. Size(ASSUMED Size ARRAY)

4. Array Selection Start / Array Selection Size

5. Numerical Python array math with different sized arrays

6. Variable Size arrays Was: Indeterminate arrays??

7. Array intrinsics with zero-size array argument

8. Array performance degrades as array size increases

9. stack size parameter?

10. Variable sized parameter lists.

11. FORTH Kernel Design -- Parameter Stack Size?

12. How to Push Funny Sized Parameters

 

 
Powered by phpBB® Forum Software