Slot¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
or Slot[n] represents the n-th argument of a pure function. #name (Slot["name"], also #"str") is the value of key "name" in the association the function is applied to.¶
Examples (3)¶
Every input below was run against the current Mathilda build and its output recorded.
Applications (3)¶
In[1]:= (#1 + #2 &)[3, 4]
Out[1]= 7
In[2]:= Map[#^2 &, {1, 2, 3, 4}]
Out[2]= {1, 4, 9, 16}
In[3]:= FullForm[#2]
Out[3]= Slot[2]
Implementation notes¶
Slot[n] (#, #n) is an inert marker ā builtin_slot always returns NULL so the node stays unevaluated on its own. Substitution happens only when a pure Function is applied: substitute_slots walks the function body and replaces each Slot[n] with a copy of the n-th argument (when 1 ⤠n ⤠arg_count), stopping recursion at any nested Function so inner pure functions are not captured by the outer slots. ATTR_PROTECTED.
Attributes: Protected.
References¶
- Source:
src/purefunc.c - Specification:
docs/spec/builtins/functional-programming.md - Tests:
tests/test_assoc_forms.c - Tests:
tests/test_coefficient_rules.c - Tests:
tests/test_compile.c - Tests:
tests/test_eigen.c
Notes & additional examples¶
Notes¶
# (or #1) is Slot[1], the first argument of the enclosing pure function (&); #n refers to the n-th argument. A bare # inside Map (Out[2]) receives each list element in turn.