Names and help

Inspect, list and erase names, and read help

Names

]help •nc

•nc — Name class

•nc names gives the class of each name: ¯1 invalid, 0 undefined, 2 value, 3 function, 4 operator. A character vector names one binding. Introspection has examples.

v←1 2 3 ⋄ mean←{+/⍵ ÷ ≢⍵}
•nc "v"
•nc "mean" "absent"
2ₓ
[3 0]ₓ
]help •nl

•nl — Name list

prefix •nl classes lists the visible user names in classes that begin with prefix, as a sorted vector of strings. •nl classes lists them all. Introspection has examples.

Errors: DOMAIN for unsupported classes; RANK for a class matrix.

Shadowed names appear once. Implicit argument and operand names are left out:

mean←{+/⍵ ÷ ≢⍵}
"me" •nl 3
"absent" •nl 2 3 4
["mean"]
0⍴⊂""
]help •src

•src — Source

•src name returns the definition text of a function or operator, including comments. Introspection has examples.

Errors: VALUE for an undefined name; DOMAIN for an argument that isn’t a name.

Primitives and derived functions give their BPL representation:

f←{≥⍵} ⋄ add←+
•src "f"
•src "add"
{≥⍵}
+
]help •ex

•ex — Erase

•ex names erases the nearest binding of each name. An outer binding can then become visible. It returns 1 when the name is gone, and 0 for an invalid or protected name. Introspection has examples.

An already absent name also gives 1. Retained function handles stay usable:

v←1
•ex "v"
•ex "v"
•ex "$a"
1ₓ
1ₓ
0ₓ

Interactive help

]help name shows help in the REPL and in notebooks. A leading ⍝ comment block inside a definition supplies its help text:

mean←{⍝ Mean of a vector
    +/⍵ ÷ ≢⍵}

]help mean shows the comment:

]help mean

Calls: f Y or X f Y

Mean of a vector

-source shows the definition:

]help mean -source
{⍝ Mean of a vector
    +/⍵ ÷ ≢⍵}

Glyphs work too. Their help comes from the glyph pages:

]help ?

? — Predicate

In a dfn, C? ends a predicate. When C is true, the rest of the body runs. When it’s false, the dfn moves on to its next body, after ;.

{⍵<0?-⍵;⍵}¯3      ⍝ 3
{⍵<0?-⍵;⍵}4       ⍝ 4

Statements before a predicate run first. After it, a body can run several statements, or hold more predicates.

{⍵<0?a←-⍵ ⋄ a×2;⍵}¯3   ⍝ 6
{⍵>0?⍵<10?⍵;0}15       ⍝ 0

C must be a Boolean singleton. A body that ends after its predicate returns no result. If every predicate fails, the call is a DOMAIN error. See Dfns.

In the BPL kernel, Shift-Tab inspects the name or glyph at the cursor. Tab completes user names, system names and backtick glyph names.

Inspection reads definitions without executing them. Arbitrary dfns show the one-/two-argument calling convention without inferring their supported valence.

Python covers help and completion for Python Function objects in IPython.