I have some pattern functions and pure function in my package. If i set attributes Protected and ReadProtected. My pattern function definition is hidden from end user but for pure function just evaluating its name prints its definition. I believe pure function are storing their definition as OwnValues as opposed to DownValues. Is there a way i can make them available for use but hide their definition?

  • 2
    $\begingroup$ Yes and no. You can do this: f = Function[x, x^2]; SetAttributes[f, ReadProtected]; ?? f and you see that also the OwnValues of f are hidden from Definition and FullDefinition. But f will always evaluate to a Function and of course, one can see what it does. $\endgroup$ – Henrik Schumacher Jun 14 '18 at 13:22
  • $\begingroup$ So it means i have to rewrite all my pure functions as patterns. Also can someone confirm if any of the builtin functions are written as pure functions. $\endgroup$ – user13892 Jun 14 '18 at 15:27
  • $\begingroup$ Note that ReadProtected does not really protect from reading. My favorite example is Needs["GeneralUtilities`"];PrintDefinitions[HighlightGraph]. $\endgroup$ – Henrik Schumacher Jun 14 '18 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.