global-variablesvariable-assignmentassignapldyalog

How to change the value of a variable defined outside the function in APL?


I am a beginner in APL (I use dyalog APL) and I want to change the value of a variable defined outside the function.

I've tried this function but marks_list is still empty after calling it:

Accessibilityset←{
    (⍴marks_list)=0 : marks_list←⍺
    marks_list
}

Solution

  • ⊢←

    That is,

    Accessibilityset←{ (⍴marks_list)=0 : marks_list⊢←⍺ marks_list }
    

    Note the to the left of .

    This is actually augmented (in APL lingo, known as modified) assignment, which you can think of as marks_list←marks_list⊢⍺ marks_list and therefore "forces" usage (and replacement) of the existing value, rather than creating a new, and thus automatically local, assignment.


    Shameless plug: One can find this and many other things using APLcart. (I'm its creator.)