[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-apl] Bug when assigning variable to result of function call on self

From: Elias Mårtenson
Subject: [Bug-apl] Bug when assigning variable to result of function call on self
Date: Thu, 20 Feb 2014 01:01:14 +0800

As I mentioned previously, I've been playing around with Game of Life, and I wrote my own. When I try to put this code in a loop, I get array corruption, and subsequently a crash (as I mentioned earlier) when I try to )SAVE the workspace.

Here is the code. I start by creating a 5×5 field and initialise it with a blinker:

D←5 5 ⍴ 0
D[2 3 4;3]←1

I then define the function next which calculates the next generation, based on the one passed in as argument:

∇Z←next D;N
N ← (↑+/, ¯1 0 1∘.⊖ ¯1 0 1⌽¨⊂D) - D
Z ← (3≠2 3⍳N×D) ∨ 3=N×~D

Then create a function that repeatedly calls next on an array and formats the resulting field to an array called disp. This variable is the one that is displayed in the Emacs buffer (for this example, there is no need to use that).

I then try to run 10 generations on D which results in a very unexpected error:

      10 disploop D
disploop[4]  disp←'.#'[1+S]

After this, I can also display the content of S which is clearly wrong:

      8⎕CR S
│2 ┌→────────┐│
│  ↓0 0 0 0 0││
│  │0 0 1 0 0││
│  │0 0 1 0 0││
│  │0 0 1 0 0││
│  │0 0 0 0 0││
│  └─────────┘│

By the way, shouldn't S be local to the function disploop? Why is it visible at all here?

If I run this manually, outside of disploop, this does not happen.

Finally, I try to )SAVE this workspace, and I get the same error as before:

Assertion failed: sub_idx < values.size()
in Function:      save
in file:          Archive.cc:743

Call stack:

-- Stack trace at Archive.cc:743
0x7fe1efa06de5 __libc_start_main
0x434275  main
0x51cced   Workspace::immediate_execution(bool)
0x46173d    Command::process_line()
0x46139f     Command::process_line(UCS_string&)
0x51ffda      Workspace::save_WS(std::ostream&, std::vector<UCS_string, std::allocator<UCS_string> >&)
0x4404a4       XML_Saving_Archive::save()
0x4428ef        do_Assert(char const*, char const*, char const*, int)

SI stack:

Depth:    1
Exec:     0x7fe1cc000ea8
Pmode:    ∇ disploop[4]
PC:       20 ←
Stat:     disp ← '.#'[1+S]
err_code: 0x50005
thrown:   at Value.cc:1033
e_msg_1:  'INDEX ERROR'
e_msg_2:  'disploop[4]  disp←'.#'[1+S]'
e_msg_3:  '                  ^   ^'

Depth:    0
Exec:     0x20578f0
Pmode:    ◊  10 disploop D
PC:       3 ENDL
Stat:     10 disploop D
err_code: 0x0
thrown:   at StateIndicator.cc:39
e_msg_1:  'No Error'
e_msg_2:  ''
e_msg_3:  ''

*** immediate_execution() caught other exception ***


reply via email to

[Prev in Thread] Current Thread [Next in Thread]