Hi Karthik and Uwe,

Nice find.  I think the first solution Karthik suggests of just copying
over all local functions makes the most sense.  Chasing down all the
dependencies would be tricky.

It might also make sense to check if there are any functions in the file,
and improve the auto-selector for which region command to use.  If local
functions exist, it probably makes sense to always use the script
generator.  Doing that check will be much easier once we merge over the
hairyblocks branch.  I still owe that changelog, so I'll work on that today.

Eric


On Wed, Jul 7, 2021 at 1:10 PM Karthik Chikmagalur <
karthikchikmaga...@gmail.com> wrote:

> An alternative to including all local functions in the temp file is
> something like this:
>
> 1. Find the local function names referred to in the region being
> evaluated. The current version of matlab-shell-region->script does this.
> Let's call this list included-functions.
> 2. Find function calls to other local functions for each function in this
> list. Add these function names to included-functions.
> 3. Repeat step 2 until included-functions doesn't change. We've now
> traversed the dependency chain of local functions beginning with the region
> to be evaluated.
> 4. Insert all functions in included-functions at the end of the temp file.
>
> I can probably code this up but I'd like to know what Eric thinks first.
>
> Karthik
>
> Uwe Brauer <o...@mat.ucm.es> writes:
>
> >>>> "KC" == Karthik Chikmagalur <karthikchikmaga...@gmail.com> writes:
> >
> >> Hi,
> >
> >> I'm having trouble using matlab-shell-region->script when my script
> >> is structured as follows, and I call
> >> matlab-shell-run-region-or-line on the function call:
> >
> >> %---- 8< ----
> >> %% Function call
> >> func2(x)
> >
> >> %% Local functions
> >> function y = func1(x)
> >>   y = x * 2;
> >> end
> >
> >> function z = func2(x)
> >>   y = func1(x);
> >>   z = y + 1;
> >> end
> >> %---- 8< ----
> >
> >> When I call func2(x), matlab-shell-region->script copies over only
> >> func2 to the temporary file, even though func2 requires func1 to be
> >> defined.
> >
> >
> > Thanks, I was not aware of that problem
> >
> >> This probably makes the call to matlab-shell more expensive, but I
> >> think this should be the default behavior to avoid subtle failures
> >> like this.
> >
> > It looks fine to me, but I only deal with relatively small files. What
> > do others think, especially Eric, who provided the original code?
> >
> > Regards
> >
> > Uwe
>
>
> _______________________________________________
> Matlab-emacs-discuss mailing list
> Matlab-emacs-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
>
_______________________________________________
Matlab-emacs-discuss mailing list
Matlab-emacs-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss

Reply via email to