Technical Details
Technical Reference
The operations that comprise the shared code file mechanism are implemented using three I-Beams:
8659⌶– List Shared Code Files/Attached Names- syntax:
{R}←{X}(8659⌶)Y - options:
- list shared code files:
(8659⌶) ncs - list attached names:
{slot} (8659⌶) ncs
- list shared code files:
- syntax:
8666⌶– Attach/Assimilate/Detach Shared Code Files- syntax:
{R}←{X}(8666⌶)Y - options:
- attach shared code file:
{nameclasses} (8666⌶) file - assimilate shared code files:
(8666⌶) ⎕NULL - detach shared code files:
(8666⌶) 0⍴⊂''
- attach shared code file:
- syntax:
8667⌶– Save Shared Code Files- syntax:
{R}←{X}(8667⌶)Y - options:
- save shared code file:
{names} (8667⌶) slot file
- save shared code file:
- syntax:
Technical Clarification
This section clarifies some of the functionality of shared code file support. Specifically:
-
why shared code files are read-only
-
the rules around attaching, assimilating, and detaching shared code files
Shared Code Files are Read-Only
A shared code file is a read-only repository. Items within it can be modified, but doing so can result in data being copied into the main workspace.
Consider these cases where item A is modified:
-
Ais a functionB←Awill introduce a new nameBinto the main workspace but no new data.- When
Ais edited or otherwise re-fixed, the new version will be stored in the main workspace.
-
Ais a simple array such as1 2 3 4B←Awill introduce a new nameBinto the main workspace but no new data.C←A,1will introduce a new nameCand new data into the main workspace.A,←1will create new data in the main workspace.
-
Ais a nested array such as'AB' 'CD'B←Awill introduce a new name B into the main workspace but no new data.A[1]←⊂'XY'will introduce some new data into the main workspace.
In each of these cases, the content of the attached shared code file remains unaltered. This means that, if names of items in a shared code file are expunged using ⎕EX and the shared code file(s) are detached and reattached, then the items in the shared code file will be restored to their original values. The only way to change the values in a shared code file is to recreate the entire file.
Although a shared code files can contain data, these values should either be constants or initial values for structures that will be copied into the workspace as soon as the application modifies them.
Attaching, Assimilating, and Detaching Shared Code Files
When one or more shared code files is attached, the following rules apply:
- When items with the same name exist in multiple workspaces, the one that is used in the active workspace is the first one found when going through the workspaces in the following order:
- the active workspace
- the shared code file specified first when attaching
- the shared code file specified second when attaching, and so so
- When the shared code files are assimilated:
- all references to each shared code file are resolved by copying data from the shared code file to the active workspace as required.
- When the shared code files are detached:
- names in the active workspace that reference data in a shared code file are deleted (namespace references are not deleted).
- all remaining references to the shared code file are resolved by copying data from the shared code file to the active workspace as required.
Example
The active workspace MAIN is populated using the following assignments:
FN1 ← {⍵ × 1}
FN2 ← {⍵ × 2}
NS1 ← ⎕NS ''
NS1.A ← 1 | Name | Parent | Value |
|---|---|---|
FN1 | # | {⍵ × 1} |
FN2 | # | {⍵ × 2} |
NS1 | # | Namespace ref |
A | NS1 | 1 |
Shared code files DWS1 is populated using the following assignments:
FN1 ← {⍵ × 1.1}
FN3 ← {⍵ × 3}
V ← 'AB' 'CD'
NS1 ← ⎕NS ''
NS1.A ← 2
NS1.B ← 3
| Name | Parent | Value |
|---|---|---|
FN1 | # | {⍵ × 1.1} |
FN3 | # | {⍵ × 3} |
V | # | 'AB' 'CD' |
NS1 | # | Namespace ref |
A | NS1 | 2 |
B | NS1 | 3 |
Shared code files DWS2 is populated using the following assignments:
FN3 ← {⍵ × 3.1}
FN4 ← {⍵ × 4}
NS2 ← ⎕NS ''
NS2.A ← 4
NS3 ← ⎕NS ''
NS3.A ← 5 | Name | Parent | Value |
|---|---|---|
FN3 | # | {⍵ × 3.1} |
FN4 | # | {⍵ × 4} |
NS2 | # | Namespace ref |
A | NS2 | 4 |
NS3 | # | Namespace ref |
A | NS3 | 5 |
After attaching DWX1 and DWX2 (in that order) to MAIN the following will be accessible:
| Name | Parent | Value | Location of Value | Notes |
|---|---|---|---|---|
FN1 | # | {⍵ × 1} | WS | FN1 in DWX1 is inaccessible |
FN2 | # | {⍵ × 2} | WS | |
FN3 | # | {⍵ × 3} | DWX1 | FN3 in DWX2 in inaccessible |
FN4 | # | {⍵ × 4} | DWX2 | |
V | # | 'AB' 'CD' | DWX1 | |
NS1 | # | Namespace ref | ||
A | NS1 | 1 | WS | NS1.A and NS1.B in DWX1 are inaccessible |
NS2 | # | Namespace ref | ||
A | NS2 | 4 | DWX2 | |
NS3 | # | Namespace ref | ||
A | NS3 | 5 | DWX2 |
Following these assignments:
FN3 ← {⍵ × 3.2}
FN5 ← FN4
V[1] ← ⊂'XY'
NS2.B ← 6 The following are now accessible:
| Name | Parent | Value | Location of Value | Notes |
|---|---|---|---|---|
FN1 | # | {⍵ × 1} | WS | |
FN2 | # | {⍵ × 2} | WS | |
FN3 | # | {⍵ × 3.2} | WS | Updated value |
FN4 | # | {⍵ × 4} | DWX2 | |
FN5 | # | {⍵ × 4} | DWX2 | |
V | # | 'XY' 'CD' | Split between WS and DWX1 | |
NS1 | # | Namespace ref | ||
A | NS1 | 1 | WS | |
NS2 | # | Namespace ref | ||
A | NS2 | 4 | DWX2 | |
B | NS2 | 6 | WS | New value |
NS3 | # | Namespace ref | ||
A | NS3 | 5 | DWX2 |
The shared code files are now disconnected. This is achieved either by assimilating them into the active workspace or by detaching them; the result of each of these operations is shown below.
Following assimilation of the shared code files, the main workspace will contain:
| Name | Parent | Value | Notes |
|---|---|---|---|
FN1 | # | {⍵ × 1} | |
FN2 | # | {⍵ × 2} | |
FN3 | # | {⍵ × 3.2} | |
FN4 | # | {⍵ × 4} | Copied into WS |
FN5 | # | {⍵ × 4} | Copied into WS |
V | # | 'XY' 'CD' | Partially copied into WS |
NS1 | # | Namespace ref | |
A | NS1 | 1 | |
NS2 | # | Namespace ref | |
A | NS2 | 4 | Copied into WS |
B | NS2 | 6 | |
NS3 | # | Namespace ref | |
A | NS3 | 5 | Copied into WS |
Alternatively, following detachment of the shared code files, the main workspace will contain the following values:
| Name | Parent | Value | Notes |
|---|---|---|---|
FN1 | # | {⍵ × 1} | |
FN2 | # | {⍵ × 2} | |
FN3 | # | {⍵ × 3.2} | |
FN5 | # | {⍵ × 4} | Copied into WS |
V | # | 'XY' 'CD' | Partially copied into WS |
NS1 | # | Namespace ref | |
A | NS1 | 1 | |
NS2 | # | Namespace ref | |
A | NS2 | 4 | Copied into WS , namespace has changed |
B | NS2 | 5 | |
NS3 | # | Namespace ref | |
A | NS3 | 5 | Copied into WS |