diff --git a/mathics/builtin/functional/application.py b/mathics/builtin/functional/application.py index 4a9683de8..e41a6138d 100644 --- a/mathics/builtin/functional/application.py +++ b/mathics/builtin/functional/application.py @@ -4,26 +4,28 @@ Function Application """ -# This tells documentation how to sort this module -sort_order = "mathics.builtin.function-application" - - from itertools import chain import sympy from mathics.core.atoms import Integer, Integer1 from mathics.core.attributes import A_HOLD_ALL, A_N_HOLD_ALL, A_PROTECTED -from mathics.core.builtin import Builtin, PostfixOperator, SympyFunction +from mathics.core.builtin import Builtin, PostfixOperator, PrefixOperator, SympyFunction from mathics.core.convert.sympy import SymbolFunction from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.symbols import Symbol, sympy_slot_prefix from mathics.core.systemsymbols import SymbolSlot +# This tells documentation how to sort this module +sort_order = "mathics.builtin.function-application" + class Function(PostfixOperator, SympyFunction): """ + :WMA link: + https://reference.wolfram.com/language/ref/Function.html +
'Function[$body$]'
'$body$ &' @@ -164,8 +166,11 @@ def to_sympy(self, expr: Expression, **kwargs): raise NotImplementedError -class Slot(SympyFunction): +class Slot(SympyFunction, PrefixOperator): """ + :WMA link: + https://reference.wolfram.com/language/ref/Slot.html +
'#$n$'
represents the $n$th argument to a pure function. @@ -190,6 +195,9 @@ class Slot(SympyFunction): """ attributes = A_N_HOLD_ALL | A_PROTECTED + + operator = "#" # FIXME generate this automatically + rules = { "Slot[]": "Slot[1]", "MakeBoxes[Slot[n_Integer?NonNegative]," @@ -204,8 +212,12 @@ def to_sympy(self, expr: Expression, **kwargs): return sympy.Symbol(f"{sympy_slot_prefix}{index.get_int_value()}") -class SlotSequence(Builtin): +class SlotSequence(PrefixOperator, Builtin): """ + :WMA link: + https://reference.wolfram.com/language/ref/SlotSequence.html + +
'##'
is the sequence of arguments supplied to a pure function. @@ -225,6 +237,8 @@ class SlotSequence(Builtin): attributes = A_N_HOLD_ALL | A_PROTECTED + operator = "##" # FIXME generate this automatically + rules = { "SlotSequence[]": "SlotSequence[1]", "MakeBoxes[SlotSequence[n_Integer?Positive]," diff --git a/mathics/builtin/functional/apply_fns_to_lists.py b/mathics/builtin/functional/apply_fns_to_lists.py index f6dbbffd4..8ab4650fb 100644 --- a/mathics/builtin/functional/apply_fns_to_lists.py +++ b/mathics/builtin/functional/apply_fns_to_lists.py @@ -29,6 +29,10 @@ class Apply(InfixOperator): """ + :WMA link: + https://reference.wolfram.com/language/ref/Apply.html + +
'Apply[$f$, $expr$]' @@ -67,6 +71,8 @@ class Apply(InfixOperator): summary_text = "apply a function to a list, at specified levels" grouping = "Right" + operator = "@@" # FIXME generate this automatically + options = { "Heads": "False", } @@ -100,6 +106,9 @@ def callback(level): class Map(InfixOperator): """ + :WMA link: + https://reference.wolfram.com/language/ref/Map.html +
'Map[$f$, $expr$]' or '$f$ /@ $expr$'
applies $f$ to each part on the first level of $expr$. @@ -155,6 +164,9 @@ def callback(level): class MapAt(Builtin): """ + :WMA link: + https://reference.wolfram.com/language/ref/MapAt.html +
'MapAt[$f$, $expr$, $n$]'
applies $f$ to the element at position $n$ in $expr$. If $n$ is negative, the position is counted from the end. @@ -211,6 +223,9 @@ def eval(self, f, expr, args, evaluation: Evaluation): class MapIndexed(Builtin): """ + :WMA link: + https://reference.wolfram.com/language/ref/MapIndexed.html +
'MapIndexed[$f$, $expr$]'
applies $f$ to each part on the first level of $expr$, including the part positions in the call to $f$. @@ -280,6 +295,9 @@ def callback(level, pos: Iterable): class MapThread(Builtin): """ + :WMA link: + https://reference.wolfram.com/language/ref/MapThread.html +
'MapThread[$f$, {{$a1$, $a2$, ...}, {$b1$, $b2$, ...}, ...}]
returns '{$f$[$a1$, $b1$, ...], $f$[$a2$, $b2$, ...], ...}'. @@ -367,6 +385,9 @@ def walk(args, depth=0): class Scan(Builtin): """ + :WMA link: + https://reference.wolfram.com/language/ref/Scan.html +
'Scan[$f$, $expr$]'
applies $f$ to each element of $expr$ and returns 'Null'. @@ -417,6 +438,9 @@ def callback(level): class Thread(Builtin): """ + :WMA link: + https://reference.wolfram.com/language/ref/Thread.html +
'Thread[$f$[$args$]]'
threads $f$ over any lists that appear in $args$.