Re: make i:j equivalent to [(k,k=i,j)]?
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 23:21:07 -0800
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
.
- References:
- make i:j equivalent to [(k,k=i,j)]?
- From: beliavsky
- Re: make i:j equivalent to [(k,k=i,j)]?
- From: highegg
- make i:j equivalent to [(k,k=i,j)]?
- Prev by Date: Re: make i:j equivalent to [(k,k=i,j)]?
- Next by Date: Re: io-unit has been opened
- Previous by thread: Re: make i:j equivalent to [(k,k=i,j)]?
- Next by thread: Re: make i:j equivalent to [(k,k=i,j)]?
- Index(es):
Relevant Pages
|