Dyalog / Dyalog/link

Add `-merge` switch: allow `-flatten` links into a non-empty or already-linked namespace

Open
#780 0 comments 0 reactions 1 assignee Claimed by @Bombardier-C-Kram View on GitHub
enhancement
Dominant language
APL
Stars
26
Forks
11
Avg merge
1d 18h
Merged PRs (30d)
1

Description

#472: linking a directory of utilities into `#` with `-flatten` fails when `#` already holds application code. Flattened links can be used to add functions to an existing flat workspace, so a non-empty target is a reasonable use case.

```apl
]link.create # /repos/tools -flatten
⎕SE.Link.Create: Destination namespace not empty: #
```

## Proposal

New option `merge` (`]link.create ... -merge`, `opts.merge←1`), default off. It behaves like any other link option (stored in `.linkconfig`, shown by `]link.status`).

- Requires `flatten` and `source=dir`; otherwise `Create` errors, like the existing "flatten modifier requires source≡'dir'".
- The target may be non-empty. Existing objects are left alone.
- The target may already be linked, so several flattened directories can be linked into one namespace.
- **Conflicts are errors.** If a file defines a name that already exists with a different definition, or a name owned by another link, `Create` fails and names the file and the name. An identical unlinked definition is not a conflict.
- **New names** created in a namespace with several links are written to the root of the **first** link created, unless `getFilename` or `beforeWrite` decides otherwise. Renames keep today's rule: same folder as the original.
- `]link.break ns` breaks all links on that namespace.

```apl
]link.create # /repos/tools -flatten -merge
]link.create # /repos/more -flatten -merge
NewFn←{⍵} ⍝ → /repos/tools/NewFn.aplf
```

Document in the **merge** section of `Link.Create.md` that once `#` is merge-linked, editing a pre-existing application function (a function that was defined prior to any link creation) also writes it to the first link's root, exactly like a new function.

## Tests

`Test/test_merge.aplf`: merge without flatten errors; merge into a namespace with an unrelated function; two links on one namespace listed by Status; new name lands in the first link's root, and `getFilename` overrides that; differing definition and name owned by another link both error; `Break` removes both links.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.