Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment for an array element fails in a loop #1962

Open
evertrol opened this issue Jan 8, 2025 · 1 comment
Open

Assignment for an array element fails in a loop #1962

evertrol opened this issue Jan 8, 2025 · 1 comment

Comments

@evertrol
Copy link

evertrol commented Jan 8, 2025

I have this simple procedure

pro testarray
  a = dblarr(2)
  k = 1
  for j = 0, 2 do begin
     print, j
     if j eq k then a[1] = -1
     print, a
     ind = where(a lt 0, /null)
     print, ind
     a[ind] = 0
     print, a
  endfor
end

When I run this (gdl -X -e testarray), the output is

       0
       0.0000000       0.0000000
!NULL
       0.0000000       0.0000000
       1
       0.0000000      -1.0000000
           1
       0.0000000      -1.0000000
       2
       0.0000000      -1.0000000
           1
       0.0000000      -1.0000000

which is not what I expect: the -1 should be changed to 0, and only show up once in the output.

If I change k to 2, similar incorrect behaviour happens. But if I change k to 0, the expected/correct behaviour happens (i.e., -1 shows up only once in the output).

If I remove the loop (and the j eq k condition), I also observe the correct behaviour.

I don't know if I'm missing something here, or whether this is an actual bug in GDL. (I am not able to test this behaviour with IDL.)

My set up is a Macbook Pro M1, Sonoma 14.6.1 (Darwin 23.6.0), running a self-installed GDL in the terminal (iTerm), with the GDL version given as GDL - GNU Data Language, Version v1.1-30-g35d32bbc.

@alaingdl
Copy link
Contributor

alaingdl commented Jan 8, 2025

Thanks for the clear report. Two bad news :

  • I succeed to reproduce the problem, on x86_64 :(
  • I absolutely not understood what happen :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants