"EBS " <ericDOTsampson@gmail.com> wrote in message <email@example.com>... > "Steven_Lord" <firstname.lastname@example.org> wrote in message <email@example.com>... > > > > > > "Andrea Tagliasacchi" <firstname.lastname@example.org> wrote in message > > news:email@example.com... > > > You don't need to go that hardcore. Matlab could simply allow 1-level of > > > functions (no nesting) in scripts only (no command line) and don't allow > > > those functions to be scoped *outside* the script. It's not that hard and > > > would allow for much more legible code! > > > > It may be possible to do that; I haven't thought through all the > > difficulties. > > > > I have to question both parts of your assertion, though. It likely would be > > hard to make sure there are no edge/special cases that will cause problems > > other than the "something that's possible to do in scripts but not in the > > command line", and "have a scope that's partway between script and function > > file" special cases that you're already asking for. I also disagree that > > the code would be any more legible than either converting your file into a > > function file or pulling the subfunction into a separate file. [If you're > > worried about namespacing, use a private function or a package directory.] > > > > I also question whether there's sufficient demand for this feature -- I > > don't remember the last time someone asked for this functionality. > > > > But if you feel that strongly, submit this request (along with a clear > > description of your use case) to Technical Support for capturing in the > > enhancement database. > > > > -- > > Steve Lord > > firstname.lastname@example.org > > comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ > > To contact Technical Support use the Contact Us link on > > http://www.mathworks.com > > Steve, I for one have always thought this functionality would be nice to have, in the simple form outlined by Andrea. I think scripts are very popular among users, and I've seen some very ugly ones because there is no way to define local utility subfunctions. It would also make it easier to send your script to another user if you don't have to send a number of associated function files along for the ride. > > I also seem to remember seeing a number of user requests for this functionality in the DB... > > Regards, > EBS
I would use this functionality as well, I find myself in Andrea's situation regularly. I usually choose to change the script into a function, and add a keyboard statement at the bottom, but that has always felt like a hack to me. It never occurred to me to ask to be able to define functions within scripts, because I assumed there was some architectural issue making it all but impossible.