• Join/Login
  • Business Software
  • Open Source Software
  • For Vendors
  • Blog
  • About
  • More
    • Articles
    • Create
    • SourceForge Podcast
    • Site Documentation
    • Subscribe to our Newsletter
    • Support Request
SourceForge logo
For Vendors Help Create Join Login
SourceForge logo
Business Software
Open Source Software
SourceForge Podcast
Resources
  • Articles
  • Case Studies
  • Blog
Menu
  • Help
  • Create
  • Join
  • Login
  • Home
  • Browse
  • FMSLogo
  • Bugs
FMSLogo

Macros don't preserve array identity -- can't use SETITEM in RUN

A Logo programming environment for Microsoft Windows

Brought to you by: david_costanzo
  • Summary
  • Files
  • Reviews
  • Support
  • Tickets ▾
    • Feature Requests
    • Bugs
    • Support Requests
  • Discussion
  • Code
Menu ▾ ▴
  • Create Ticket
  • View Stats

Group

  • v_6.06x
  • v_6.07.X
  • v_6.08.X
  • v_6.10.X
  • v_6.11.X
  • v_6.13.X
  • v_6.22.X
  • v_6.25.X
  • v_6.26.X
  • v_6.27.X
  • v_6.28.X
  • v_6.29.X

Searches

  • Changes
  • Closed Tickets
  • Open Tickets

Help

  • Formatting Help

#619 Macros don't preserve array identity -- can't use SETITEM in RUN

v_6.06x
open
nobody
None
5
2026-07-30
2026-06-01
David Costanzo
No

Macros don't preserve an array's identity when they are evaluated. Instead, any arrays in the macro's return list are invisibly copied before being used. It is therefore impossible to use SETITEM in a macro as it ends up modifying a copy of the array that is inaccessible to the programmer, instead of the array the programmer specified.

This bug is also reproducible in UCBLogo 6.2.5.

How Reproducible:
Every Time

Steps to Reproduce:

MAKE "array {1}
RUN (LIST "SETITEM 1 :array 2)
SHOW :array

What Happens:
SHOW prints {1}.

Expected Result:
SHOW prints {2}. This is the same as if SETITEM 1 :array 2 had been run.

Impact:
This prevents anyone from using SETITEM in a macro, including macroized primitives like RUN.

Notes:
I suspect that this is due to the logic to copy the array when it's evaluated as a literal in eval.cpp

    case ARRAY:
        // array must be copied
        {
            assign(val, make_array(getarrdim(exp)));
            setarrorg(val, getarrorg(exp));

            NODE ** p = getarrptr(exp);
            NODE ** q = getarrptr(val);
            for (int i = 0; i < getarrdim(exp); i++)
            {
                *q++ = vref(*p);
                p++;
            }
        }
        goto fetch_cont;

The above logic makes sense for array literals, as it would be bad if SETITEM modified the definition a procedure that returned the array instead of just the array. However, in a macro evaluation, it makes sense to use the original array's reference.

Discussion

  • David Costanzo

    David Costanzo - 2026-07-25
    • summary: Macros don't preserved array identity -- can't use SETITEM in RUN --> Macros don't preserve array identity -- can't use SETITEM in RUN
     
    If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
  • Vilim

    Vilim - 2026-07-29

    Is this really a bug? It might be simpler to call this intended behavior, because the array is turned into a literal.
    The desired behavior can be achieved using RUN (LIST "SETITEM 1 ":array 2).

     
    If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
  • Vilim

    Vilim - 2026-07-30

    Another interesting corner case:

    TO FOO
    OP [{1}]
    END
    SETITEM 1 FIRST FOO 2
    SHOW FOO
    

    I don't think it's possible to do "what the programmer intended" every time, so maybe the behavior should just be documented. There are workarounds to get the other behavior in either case (wrap in a list literal or unwrap into a LIST invocation).

     
    If you would like to refer to this comment somewhere else in this project, copy and paste the following link:

Log in to post a comment.

SourceForge
  • Create a Project
  • Open Source Software
  • Business Software
  • Top Downloaded Projects
Company
  • About
  • Team
  • SourceForge Headquarters
    1320 Columbia Street Suite 310
    San Diego, CA 92101
    +1 (858) 422-6466
Resources
  • Support
  • Site Documentation
  • Site Status
  • SourceForge Reviews
SourceForge logo
© 2026 Slashdot Media. All Rights Reserved.
Terms Privacy Opt Out Advertise
MongoDB Logo MongoDB