Mathematica Asked by acacia on December 4, 2020
I will provide one example to show what the problem is.
Collatz[m_] :=
Collatz[m] = 1 + If[EvenQ[m], Collatz[m/2], Collatz[3 m + 1]];
Collatz[1] := 0;
this function works as expected but if I make a new function
myfunction[m_] := m
this generates and error
error: m is protected
I tried
f[# _] := #
f[4]
but the output is
f[4]
expected output is
4
I know I can use anonymous pure functions inline like
Function[#]&[arg]
but what if I want anonymous variable names that do not stay in memory? I want the function to be defined by name but I do not want to create more protected or reserved words inside the function arguments when I am defining the function. is there a way to use # or #_ to define a function without creating more protected variable names? is this possible in mathematica?
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP