| ![](/includes/contimages/spacer.gif) |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: private vs public mata (user written) functions
On Jul 13, 2006, at 2:14 PM, Zurab Sajaia wrote:
I have a "public" mata function that is used by a stata command
(.ado file). My mata function in turn uses two other "private" mata
functions. Either I'm making some other mistake or all three must
be added to a library for everything to work and then we have a
situation that two "private" functions, which are no use outside of
main "public" one are also visible. I know that following Stata's
open-source spirit I might end up distributing the un-compiled code
anyways but wanted to know for sure if the private/public function
setup is possible.
The only way I know of to restrict a function in Mata (i.e., to limit
where it can be used) is to place its code directly into an ado-file;
in that case, the function can be used only within that file,
presumably within the code for the Stata command defined by the
file. I believe such functions are referred to as private, with all
other functions automatically becoming public (i.e., available
anywhere) by default.
I'm guessing that you've written a Mata function you want to document
and make available for others to use, and that that function relies
on a few helper functions which you suspect will not be of interest
to others, do not wish to document, or perhaps do not even wish to
share. In this case, I believe your only option may be to give the
helper function(s) difficult names so that users are unlikely to call
them up by accident (e.g., if your function is called my_function_foo
(), you might call your helpful function _mff_helper()). Of course,
if they try, users can still see the names of your helper function(s)
by using:
mata describe using <libname>
but if you distribute only the compiled library, they will not be
able to see the code, and without knowing the API for your helper
function, they'd be foolish to try to use it.
-- Phil
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/