From: Bruno Luong on 6 Jan 2010 17:20 "us " <us(a)neurol.unizh.ch> wrote in message <hi30pr$nku$1(a)fred.mathworks.com>... > "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message > > bruno - well: NO(!, sorry)... > this were just the points - and: > - let's dissect the stuff once more > > 1) GOO creates A and B at different mem locs (A & B=A+1)... > 2) if their size is too big, GOO itself will fail (trivial)... Agree until now, and this common behavior stands regardless how GOO is called. Are you agree? > 3) but let's keep in mind: there's a CALLER's workspace (WS) as well: FOO Stop right there!!! Workspaces are important in one aspects: - visibility - and possibility the stack memory of the main thread But data are still stored in a big common computer memory pool, regardless which workspace they belong. > 4) IT (foo) is filled with a lot of different vars [A_x/B_x] created by > GOO (again, not failing by itself in each call) No. A_x will share the data in a quantum laps of time with the intern variable B (which anyway created). > 5) however, FOO (now slowly filling up) is failing earlier if BOTH vars are put into its WS No extra filling up if CLEAR is called after A_x is created and unmodified. > > altogether, the snippet intended to simulate a function's WS which is filled by calls to many (in real life: different) subroutines returning a lot of DUMMY(ie)s... > naturally, the (keen) programmer would have to take care of this by adding a CLEAR DUMMY statement after EACH call (because it's there, in the mem and contaminating any subsequent request in a subfunction!) ... quite tedious and ...unlovely... Beauty is in the eye of the beholder. Bruno
From: Jan Simon on 6 Jan 2010 17:27 Dear Bruno! > > SO - old CSSMers will stick with the > > [foo,foo,foo,goo,goo]=f(); > > syntax... > > > > Well, new member(s) still not entirely convinced... (see my reply to you us) > Btw, do we consider Jos as considered as junior or senior member? I consider myself and Jan as senior members - well relatively to some other. ;-) I find Jos' first post in Feb 1997 ==> senior. I'm posting since May 2004 ==> mid aged. But google groups claims, that Bruno starts posting July 2008 ?! Bruno: what have you done before July 2008? What have you been waiting for? Of course, all CSSMers are welcome to use the foofoofoogoogoo. And I really did not want to start a discussion about taste or the wise insertion of CLEAR commands. My question was simply, if it wouldn't be nice to create a SORT function, which replies just the needed output. Or in the terms of Us: Old CSSMers: [foo,foo,foo,goo,goo]=f(); Fresh CSSMers: [foo, goo]=f2(); Jan
From: us on 6 Jan 2010 17:42 "Bruno Luong" > Beauty is in the eye of the beholder. > Bruno well then, no matter how we turn and twist this thingy - the previous snippet FOO simply shows the ML community... [a,a]=f(); [b,b]=g(); % is advantageous when compared to [D,a]=f(); [D,b]=g(); % <- G has to deal with the useless waste of memory by D... % and certainly more elegant than [D,a]=f(); clear D; % <- a line of simple code [D,b]=g(); clear D; % <- yet another line of simple code the cliché 'beauty and the eye': whilst ok in real life - often get's one into a predicament in computer programming... again, just a thought... us
From: Bruno Luong on 6 Jan 2010 18:45 "us " <us(a)neurol.unizh.ch> wrote in message <hi33jr$o4r$1(a)fred.mathworks.com>... > "Bruno Luong" > > Beauty is in the eye of the beholder. > > Bruno > > well then, no matter how we turn and twist this thingy > - the previous snippet FOO simply shows the ML community... > > [a,a]=f(); Some complementary: %% The proper "beautiful" code is % We don't need the first output. % When the same variable is repeated on the lhs, the final value taken % corresponds to the most right, i.e. second output of f() here, since Matlab % affects from left to right out the output list (Attention: this convenstion % is opposite direction of arabic reading) . % Note: this is not documented, programmers who maintain this code % need to check this behavior stands consistently when for any newer Matlab % releases (twice a year) from now until year 3000. % Also beware unexpected results when you do something like replacing % all instant of "a" by "a(end+1)" using editor replacement feature. [a,a]=f(); %%%%%%%%%% %% The "ugly" code is [D,a]=f(); clear D % not used Bruno ;-)
From: Matt Fig on 6 Jan 2010 19:22
Wow, I didn't realize what a hornets nest my simple question would kick up. ;-) Bruno, From the documentation: "Functions return output values in the order in which the corresponding output variables appear in the function definition line within the M-file." So for M-Files, at least, there is some documentation. Also, even Loren admits to using this technique, at least prior to the ~ introduction! But for non-M-Files, you may have a point about the assumption that this behavior will persist. I guess, to *some* degree, ([a,b], clear a) or ([b,b]) is personal preference. |