[Thread Prev][Thread Next][Index]

Re: strang thing happend in doing loops over string array



Hi Xin,

Try this instead:

let name = {"a","b","c","d"}
repeat/i=1:4 (let n = name[i=`i`]; say `n`)

In what you have below, it looks like Ferret is translating the symbol ii
before it actually executes the "define symbol".  My guess is that Ferret
is taking several passes through the parenthesized commands; on the first
pass it translates all the symbols, on the next pass it evaluates the
backquotes, and on the final pass it evaluates the commands.  
(Developers: Is this correct?  If so, perhaps it'd be better for Ferret to
respect semicolons as it's doing its passes?)

Andrew

+---------------------------------------+
|  Andrew Wittenberg  |  GFDL/NOAA      |
|  atw@gfdl.noaa.gov  |  Princeton, NJ  |
+---------------------------------------+

On Tue, 19 Nov 2002, Xin Jin wrote:

> I have run this command in ferret v5.41 in linux system.
> 
> let name = {"a","b","c","d"}
> 
>  repeat/i=1:4 (define symbol ii `i`;SAY `name[i=($ii)]`)
> 
> I got 
> ---------------------------------------------------------
> 
> yes?  repeat/i=1:4 (define symbol ii `i`;SAY `name[i=($ii)]`)
>  !-> repeat/i=1:4 (define symbol ii `i`;SAY `name[i= ]`)
> !-> REPEAT: I=1
>  !-> define symbol ii 1
>  **ERROR: command syntax: I=
> MESSAGE/CONTINUE `name[i= ]`
> Command file, command group, or REPEAT execution aborted
> ----------------------------------------------------------------------------------------
> 
> command
> 
>  repeat/i=1:4 (define symbol ii `i`;SAY `name[i=($ii)]`)
> 
> again and got
> ------------------------------------------------------------------------------
> !-> repeat/i=1:4 (define symbol ii `i`;SAY `name[i=1]`)
> !-> REPEAT: I=1
>  !-> define symbol ii 1
>  !-> MESSAGE/CONTINUE a
> a
> !-> REPEAT: I=2
>  !-> define symbol ii 2
>  !-> MESSAGE/CONTINUE a
> a
> !-> REPEAT: I=3
>  !-> define symbol ii 3
>  !-> MESSAGE/CONTINUE a
> a
> !-> REPEAT: I=4
>  !-> define symbol ii 4
>  !-> MESSAGE/CONTINUE a
> a
> --------------------------------------------------
> command
> 
>  repeat/i=1:4 (define symbol ii `i`;SAY `name[i=($ii)]`)
> 
> once more  and got
> 
> ------------------------------------------------------------------
>  !-> repeat/i=1:4 (define symbol ii `i`;SAY `name[i=4]`)
> !-> REPEAT: I=1
>  !-> define symbol ii 1
>  !-> MESSAGE/CONTINUE d
> d
> !-> REPEAT: I=2
>  !-> define symbol ii 2
>  !-> MESSAGE/CONTINUE d
> d
> !-> REPEAT: I=3
>  !-> define symbol ii 3
>  !-> MESSAGE/CONTINUE d
> d
> !-> REPEAT: I=4
>  !-> define symbol ii 4
>  !-> MESSAGE/CONTINUE d
> d
> ----------------------------------------------------
> 
> NONE of these are correct.
> 
> What's wrong with this loop
> 
> 
> Thanks
> 
> Xin



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement