changeset 26168:0a3561379dbe

Clarify documentation around locking functions and clear. * func.txi: Rewrite section on locking functions. * variables.cc (Fmlock, Fmunlock, Fmislocked): Add clear to list of @seealso references. Reference clear() function in the description of the functions.
author Rik <rik@octave.org>
date Tue, 04 Dec 2018 16:18:10 -0800
parents 247126168d23
children 096b38cac97f
files doc/interpreter/func.txi libinterp/corefcn/variables.cc
diffstat 2 files changed, 23 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/func.txi	Mon Aug 19 08:51:38 2013 +0200
+++ b/doc/interpreter/func.txi	Tue Dec 04 16:18:10 2018 -0800
@@ -1097,11 +1097,8 @@
 @node Function Locking
 @subsection Function Locking
 
-It is sometime desirable to lock a function into memory with the
-@code{mlock} function.  This is typically used for dynamically linked
-functions in Oct-files or mex-files that contain some initialization,
-and it is desirable that calling @code{clear} does not remove this
-initialization.
+It is sometime desirable to lock a function into memory with the @code{mlock}
+function.  This is typically used for dynamically linked functions in oct-files or mex-files that contain some initialization, and it is desirable that calling @code{clear} does not remove this initialization.
 
 As an example,
 
@@ -1110,14 +1107,15 @@
 function my_function ()
   mlock ();
   @dots{}
+endfunction
 @end group
 @end example
 
 @noindent
-prevents @code{my_function} from being removed from memory after it is
-called, even if @code{clear} is called.  It is possible to determine if
-a function is locked into memory with the @code{mislocked}, and to unlock
-a function with @code{munlock}, which the following illustrates.
+prevents @code{my_function} from being removed from memory after it is called,
+even if @code{clear} is called.  It is possible to determine if a function is
+locked into memory with the @code{mislocked}, and to unlock a function with
+@code{munlock}, which the following code illustrates.
 
 @example
 @group
@@ -1130,30 +1128,29 @@
 @end group
 @end example
 
-A common use of @code{mlock} is to prevent persistent variables from
-being removed from memory, as the following example shows:
+A common use of @code{mlock} is to prevent persistent variables from being
+removed from memory, as the following example shows:
 
 @example
 @group
 function count_calls ()
   mlock ();
   persistent calls = 0;
-  printf ("'count_calls' has been called %d times\n",
-          ++calls);
+  printf ("count_calls() has been called %d times\n", ++calls);
 endfunction
 
 count_calls ();
-@print{} 'count_calls' has been called 1 times
+@print{} count_calls() has been called 1 times
 
 clear count_calls
 count_calls ();
-@print{} 'count_calls' has been called 2 times
+@print{} count_calls() has been called 2 times
 @end group
 @end example
 
-@code{mlock} might equally be used to prevent changes to a function from having
-effect in Octave, though a similar effect can be had with the
-@code{ignore_function_time_stamp} function.
+@code{mlock} might also be used to prevent changes to an m-file, such as in an
+external editor, from having any effect in the current Octave session; A
+similar effect can be had with the @code{ignore_function_time_stamp} function.
 
 @DOCSTRING(mlock)
 
--- a/libinterp/corefcn/variables.cc	Mon Aug 19 08:51:38 2013 +0200
+++ b/libinterp/corefcn/variables.cc	Tue Dec 04 16:18:10 2018 -0800
@@ -835,8 +835,9 @@
 DEFMETHOD (mlock, interp, args, ,
            doc: /* -*- texinfo -*-
 @deftypefn {} {} mlock ()
-Lock the current function into memory so that it can't be cleared.
-@seealso{munlock, mislocked, persistent}
+Lock the current function into memory so that it can't be removed with
+@code{clear}.
+@seealso{munlock, mislocked, persistent, clear}
 @end deftypefn */)
 {
   if (args.length () != 0)
@@ -858,10 +859,11 @@
            doc: /* -*- texinfo -*-
 @deftypefn  {} {} munlock ()
 @deftypefnx {} {} munlock (@var{fcn})
-Unlock the named function @var{fcn}.
+Unlock the named function @var{fcn} so that it may be removed from memory with
+@code{clear}.
 
 If no function is named then unlock the current function.
-@seealso{mlock, mislocked, persistent}
+@seealso{mlock, mislocked, persistent, clear}
 @end deftypefn */)
 {
   int nargin = args.length ();
@@ -894,10 +896,10 @@
            doc: /* -*- texinfo -*-
 @deftypefn  {} {} mislocked ()
 @deftypefnx {} {} mislocked (@var{fcn})
-Return true if the named function @var{fcn} is locked.
+Return true if the named function @var{fcn} is locked in memory.
 
 If no function is named then return true if the current function is locked.
-@seealso{mlock, munlock, persistent}
+@seealso{mlock, munlock, persistent, clear}
 @end deftypefn */)
 {
   int nargin = args.length ();