octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Third input argument to __makeinfo__


From: Rik
Subject: Re: Third input argument to __makeinfo__
Date: Sat, 10 Sep 2011 09:43:22 -0700

On 09/09/2011 04:10 PM, Carlo de Falco wrote:
> After a bit more testing, the attached is the best I managed to come up with.
> I'll wait longer before pushing this time ;)
> c
9/10/11

Carlo,

Take a look at the attached patch.  It restores the third argument
functionality, but slightly differently.

Here are the design differences

1) I didn't pre-declare the see_also function to be [ ] in the function
declaration.  Instead, I use the nargin variable.  If there's a third
argument, as determined by nargin, then it must be a function handle.  This
avoids an isempty() test on see_also.

2) feval is really only necessary if the argument is a string.  If the
argument is a function handle then you can use it in code as any ordinary
function.  For example,

fh = @sin;
fh(1) = 0.84147

Thus, I simplified things by removing the feval call and using the function
handle directly.  To make it clearer that see_also is really a function I
renamed it to fsee_also.

3) The for loop over patterns won't work as intended

+  args = regexp (text, see_also_pat, 'tokens');
+  for ii = 1:numel (args)
+    if (! isempty (args{ii}))
+      expanded = feval (see_also, strtrim (strsplit (args{ii}{:}, ',',
true)));
+      text = regexprep (text, see_also_pat, expanded);
+    endif
+  endfor

The first time through the loop, args{1}{:} will be expanded into a
replacement string.  But the regexprep will replace all @seealso references
with the expanded string from the first instance.  The second time through
the loop the regexprep will match nothing.

On the other hand, it occurred to me that we never have more than 1
@seealso reference per function.  Thus, I took out the for loop and just
put in a check to make sure that we never exceed 1 @seealso reference per
function.  I think this is a fair tradeoff because this function is not a
general purpose one and does not need to be written to handle any generic
input.

Feel free to use this patch or merge it with your own.  I'm off on vacation
for a week so go ahead and check in a solution to Mercurial whenever you
have one.  I won't be around for review.

Cheers,
Rik




Attachment: patch.fsee_also
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]