Re: make i:j equivalent to [(k,k=i,j)]?



highegg wrote:

beliavsky@xxxxxxx wrote:
Would it break anything in Fortran to make an expression

i:j

equivalent to the array constructor

[(k,k=i,j)]

The R programming language, which has a matrix language similar to
Fortran, effectively does this. I know that "not breaking" is not by
itself sufficient reason to add "syntactic sugar" to the language.

Since FORALL supersedes this, I guess this will never happen.
FORALL is less elegant but more powerful.

R has dynamically sized arrays, maybe more like Java's Object
references. You can say:

A <- 1:N

and it will assign to A an array containing the integers 1 through N,
as elements 1 through N. or

A <- 10:20

and it will assign A the integers 10 through 20 in elements
1 through 11.

You can say:

A <- 10:20
B <- x[A]

and it will assign the 10th through the 20th elements of x to B.
That is what you can't do in Fortran with vector subscripts.

You can say:

C <- x[-10:-1]

and it will assign all elements EXCEPT elements 1 through 10
of x to C. Any value of negative subscript will assign all except
that (those) element(s). You can't mix negative and positive subscripts.

y <- exp( (1:10)/10)

will assign exp(0.1), exp(0.2) through exp(1.) to y.

R has more array and matrix operators than Fortran, including
the matrix multiplication operator %*%.

You can also select array elements with an array of logical
values, so either:

x <- y>10
y <- y[x]

or

y <- y[y>10]

will assign only the elements greater than 10, resizing the
array during the assignment.

R has many operations similar to other mathematical interpreted
languages like Mathematica or Matlab.

-- glen

.



Relevant Pages

  • Re: multi-dimentional arrays
    ... In FORTRAN, we didn't have complex data types. ... of the COUNT array was the count, elementof the INUSE array was either ... FORTRAN must be very primitive language... ... DIMENSION INTEGER STARTX ...
    (microsoft.public.vc.mfc)
  • Re: Using unused variables
    ... I would prefer square brackets too, ... array constructors as replacements for the digraphs of. ... There are not enough symbols but one can wish that subscripts had ... I've heard other people argue that Fortran ...
    (comp.lang.fortran)
  • Re: Good function to test speed of language?
    ... > with math calculations; one test with intergers, ... C has pointers and Fortran doesn't, a program written to use pointers ... instead of array subscripts may well be just as fast. ... manual to write even "Hello world", the language has changed a lot since ...
    (comp.lang.c)
  • Re: Kind of NOT integer constant
    ... The Fortran 66 rules regarding DO loops and array subscripts ... not due to the number of index registers on the 704. ...
    (comp.lang.fortran)
  • Re: make i:j equivalent to [(k,k=i,j)]?
    ... Fortran, effectively does this. ... array sections. ... subscripts can be used to select the appropriate elements from ... Fortran allows for vector subscripts where a rank one array ...
    (comp.lang.fortran)