Skip to content

Localising the effects of system functions in D.

Vector 18:1, page 90

programming techniques language design

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 90

People have noticed that from within a Dyalog ‘D’ function, it is difficult to localise the effect of object-creating system functions such as ⎕FX, ⎕WC and ⎕CY. Localisation in D takes place at assign time, whereas these system functions create objects as a side effect.

A (slightly naff) way around this is to have D localise a name prior to calling the system function. Notice that the dummy assignment must accommodate the system functions’ refusal to overwrite an object of differing name class.

foo←{}                  ⍝ local class 3 name
_←⎕FX'z←foo ...         ⍝ fix local function

or:

f1←'' ⋄ _←⎕EX'f1'       ⍝ local class 0 name
ref←⍎'f1'⎕WC'form'      ⍝ make local form

A similar problem arises with system functions that don’t return a result. A (rather awkward) code-around for this it to have ‘execute’ call the function and then return an ignored result:

_←⍎'wsid ⎕CY obid ⋄ 0'

This awkwardness seems (to me) to result from the clash between the procedural and declarative styles of programming. With the benefit of hindsight, we might prefer that ⎕FX and ⎕WC don’t create global workspace names but return function and object references suitable for assignment.