Tool of Thought

APL for the Practical Man

"We make software the old-fashioned way, we write it."

APL Makes Us Smile

May 21, 2026

In Abacus we have a function for setting the value of a component:

SetComponentValue←{
     ⍝ ⍺ ←→ Component
     ⍝ ⍵ ←→ Value
     ⍺ ⍺.Class.SetValue ⍵
 }

The left argument is the component, so we need to have the component in hand before calling this function.

Abacus does not use Dyalog classes, but the "instance" has a reference to the component namespace that contains the SetValue function.

The component is often retrieved via its name from the document or a node using GetComponent, which takes a node as the left argument and the name as the right argument, so this pattern is common:

    C←D GetComponent 'MyComponentName' 
    C SetComponentValue 'MyValue'

It was suggested that SetComponentValue should be able to take a component name as its argument to avoid calling GetComponent. Of course it would also need know about the document or node. A first pass produced:

SetComponentValue←{
     ⍝ ⍺ ←→ Component|Node and Name
     ⍝ ⍵ ←→ Value
     1=≢⍺:⍺ ⍺.Class.SetValue ⍵
     c←(0⊃⍺) GetComponent 1⊃⍺
     c c.Class.SetValue ⍵
 }

But we noticed GetComponent could be called with a reduction:

     c←GetComponent/⍺

and then why have the guard? As reduction on single item returns that item, we can just write:

SetComponentValue←{
     ⍝ ⍺ ←→ Component|Node and Name
     ⍝ ⍵ ←→ Value
     c←GetComponent/⍺
     c c.Class.SetValue ⍵
 }

Little things like this are nice.