|
From: | Elias Mårtenson |
Subject: | Re: [Bug-apl] Bug when assigning variable to result of function call on self |
Date: | Thu, 20 Feb 2014 01:05:16 +0800 |
∇N disploop S→(N=0)/0next:S←next Sdisp ← '.#'[1+S]⎕DL ÷4N←N-1→next∇
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 ⍴ 0D[2 3 4;3]←1I then define the function next which calculates the next generation, based on the one passed in as argument:∇Z←next D;NN ← (↑+/, ¯1 0 1∘.⊖ ¯1 0 1⌽¨⊂D) - DZ ← (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 DINDEX ERRORdisploop[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: savein file: Archive.cc:743Call stack:------------------------------------------ Stack trace at Archive.cc:743----------------------------------------0x7fe1efa06de5 __libc_start_main0x434275 main0x51cced 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: 1Exec: 0x7fe1cc000ea8Pmode: ∇ disploop[4]PC: 20 ←Stat: disp ← '.#'[1+S]err_code: 0x50005thrown: at Value.cc:1033e_msg_1: 'INDEX ERROR'e_msg_2: 'disploop[4] disp←'.#'[1+S]'e_msg_3: ' ^ ^'Depth: 0Exec: 0x20578f0Pmode: ◊ 10 disploop DPC: 3 ENDLStat: 10 disploop Derr_code: 0x0thrown: at StateIndicator.cc:39e_msg_1: 'No Error'e_msg_2: ''e_msg_3: ''
==============================================================================*** immediate_execution() caught other exception ***Regards,Elias
[Prev in Thread] | Current Thread | [Next in Thread] |