digitalmars.D - Ditch "out" variables
- James Dunne (34/34) Jun 07 2005 "out" variables would be much more useful as a set of multiple return va...
- Hasan Aljudy (4/51) Jun 07 2005 so much hassle for so little (read: for nothing).
- Unknown W. Brackets (5/52) Jun 07 2005 Many functions are logical using "out". Anyway, this is an idea that
- Craig Black (4/10) Jun 07 2005 Requires support for tuples, no? Definitely cool, more intuitive functi...
- John Reimer (20/67) Jun 07 2005 I really can sympathize with the desire for separating input and output....
- Hasan Aljudy (8/87) Jun 07 2005 There are alot of things that can be done in new languages, but one of
- Hasan Aljudy (2/27) Jun 07 2005 whoa man, chill.
- John Reimer (3/37) Jun 07 2005 Gotchya... sorry. Just a little touchy today.
- Derek Parnell (38/84) Jun 07 2005 What problem is this trying to solve?
- James Dunne (24/109) Jun 08 2005 We always view changes as trying to solve problems ... interesting. Som...
- Derek Parnell (35/112) Jun 08 2005 Another way of looking at this sort of change is that it involves a cost...
- James Dunne (11/123) Jun 08 2005 Agreed, but I wasn't referring to D specifically - I have a bad habit of...
- Eelco Hoogendoorn (7/47) Jun 17 2005 seems im the only one who likes this idea?
- Rodolfo Borges (38/64) Jun 18 2005 Good idea, we should learn more from Perl.
- Unknown W. Brackets (3/90) Jun 18 2005 Value types, like int and char, cannot be null. They'd have to be 0 in
"out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns? Regards, James Dunne
Jun 07 2005
so much hassle for so little (read: for nothing). I prefer the "out" method much better. Just my opinion. James Dunne wrote:"out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns? Regards, James Dunne
Jun 07 2005
Many functions are logical using "out". Anyway, this is an idea that comes from interfaces, and goes along with "in" and "inout". Since your proposal doesn't remove the need for, or the keywords for, "in" and "inout" it seems strange to remove the corresponding "out". -[Unknown]"out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns? Regards, James Dunne
Jun 07 2005
Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns?Requires support for tuples, no? Definitely cool, more intuitive function calls, but requires a lot of changes to compiler. Walter would never do this. -Craig
Jun 07 2005
James Dunne wrote:"out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns? Regards, James DunneI really can sympathize with the desire for separating input and output. It seems to make so much more sense to do in this fashion. Not only is it simple to understand, but it's clear to read. If you keep input as "input" in the function parameter section, and output separate... well it just seems more intuitive. About the only reason we still use the 'in' and 'out' methods is because of it's relationship to the old C/C++ style; but compatibility with that is simply maintained with the presence or absense '&' operator (more or less, I know... it's more equivalent to inout). Interestingly, we call inputs to a function "arguments" or "parameters" for a reason. We don't think of them as "outputs." That seems to be something computer languages have crammed into the design. In short, James, I like the general idea. It makes much more sense. This may not be the exact way one would go about this, but it's something to think about for the future. At the very least, it would be nice if it were enabled as an "alternative" in D, such that the current scheme would not be lost; breaking huge compatibility might not be a popular move. -JJR
Jun 07 2005
John Reimer wrote:James Dunne wrote:There are alot of things that can be done in new languages, but one of D's design goals is to keep the "look and feel" of C/C++ syntax. I see no problem with the "out" parameter. If it's not broken, don't fix it. unintuitive? well, I have to disagree. Any half decent programmer will find it familiar since it's applied the same way in many other languages. Even if it wasn't so intuitive, it makes for simple syntax. I think multipe return values would add uneeded complexity to the syntax."out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns? Regards, James DunneI really can sympathize with the desire for separating input and output. It seems to make so much more sense to do in this fashion. Not only is it simple to understand, but it's clear to read. If you keep input as "input" in the function parameter section, and output separate... well it just seems more intuitive. About the only reason we still use the 'in' and 'out' methods is because of it's relationship to the old C/C++ style; but compatibility with that is simply maintained with the presence or absense '&' operator (more or less, I know... it's more equivalent to inout). Interestingly, we call inputs to a function "arguments" or "parameters" for a reason. We don't think of them as "outputs." That seems to be something computer languages have crammed into the design. In short, James, I like the general idea. It makes much more sense. This may not be the exact way one would go about this, but it's something to think about for the future. At the very least, it would be nice if it were enabled as an "alternative" in D, such that the current scheme would not be lost; breaking huge compatibility might not be a popular move. -JJR
Jun 07 2005
John Reimer wrote:Hasan Aljudy wrote:whoa man, chill.There are alot of things that can be done in new languages, but one of D's design goals is to keep the "look and feel" of C/C++ syntax. I see no problem with the "out" parameter. If it's not broken, don't fix it. unintuitive? well, I have to disagree. Any half decent programmer will find it familiar since it's applied the same way in many other languages. Even if it wasn't so intuitive, it makes for simple syntax. I think multipe return values would add uneeded complexity to the syntax.Hmmm... you stated your opinion already, so there was no need to give it again; and I've been around here longer than you to know what D is about, so you stated nothing that nobody knows already. I was just giving my own opinion on this. I know D's relationship to C. I know languages have used this method of passing/returning arguments for a long time. I just decided to step "outside the box" for a moment and evaluate what might be more logical. What are trying to do? Pick a fight? Well good for you. -JJR
Jun 07 2005
Hasan Aljudy wrote:John Reimer wrote:Gotchya... sorry. Just a little touchy today. -JJRHasan Aljudy wrote:whoa man, chill.There are alot of things that can be done in new languages, but one of D's design goals is to keep the "look and feel" of C/C++ syntax. I see no problem with the "out" parameter. If it's not broken, don't fix it. unintuitive? well, I have to disagree. Any half decent programmer will find it familiar since it's applied the same way in many other languages. Even if it wasn't so intuitive, it makes for simple syntax. I think multipe return values would add uneeded complexity to the syntax.Hmmm... you stated your opinion already, so there was no need to give it again; and I've been around here longer than you to know what D is about, so you stated nothing that nobody knows already. I was just giving my own opinion on this. I know D's relationship to C. I know languages have used this method of passing/returning arguments for a long time. I just decided to step "outside the box" for a moment and evaluate what might be more logical. What are trying to do? Pick a fight? Well good for you. -JJR
Jun 07 2005
On Tue, 7 Jun 2005 13:02:29 +0000 (UTC), James Dunne wrote:"out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts?What problem is this trying to solve? I'll take a guess at a couple... (A) Making it clearer to a reader looking at a call statement as to which parameters are being modified by the called function. (B) Making the visual appearance of function declarations tidier and thus cheaper to maintain.Opinions?Using some general principles (large changes to the language's syntax should be minimised, D syntax should retain the flavour of the C family, syntax changes must benefit people using the language, syntax changes must not overly complicate the compiler). I think that problem (A) could also be solved by allowing the 'out' specifier on a standard function call. e.g. a = myfunction(4, out x, out y); This could also be used for inout arguments as well. Problem (B) is, in essence, a style issue. It could be said that (int x, real y, float[] a) myfunction (int b) is easier or harder to read than float[] a myfunction (int b, out int x, out real y) depending on the way individuals see things. However, one difference between the two syntaxes is that the current method *requires* that the return value is mandatory but it is not a requirement that the 'out' arguments are updated. The proposed method implies that none of the 'return' values are mandatory, and this is a fundamental idiom shift.Concerns?I suspect that this would be a medium change in the syntax rules and it is a definite step away from the C family syntax. I can see that the problem (A) is one that is justifiably addressed though a simpler way might be better. And problem (B) is not easily fixed because it might mean alternative syntaxes are needed to cater for personal styles. I also suspect that your suggestion would add quite a degree of new complexity to the compiler, as both function declarations and assignment statements would need extra parsing and different code generation. -- Derek Melbourne, Australia 8/06/2005 10:10:02 AM
Jun 07 2005
In article <7v4u469qtki1$.1tdcxi3k65eui.dlg 40tude.net>, Derek Parnell says...On Tue, 7 Jun 2005 13:02:29 +0000 (UTC), James Dunne wrote:We always view changes as trying to solve problems ... interesting. Sometimes I just like to go against the flow of current and try something different, just for change's sake. Some people say, "If it ain't broke, don't fix it." Well, I'd be one to say "It is broke, so I am fixing it"; but to some it just doesn't *look* broke."out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts?What problem is this trying to solve?I'll take a guess at a couple... (A) Making it clearer to a reader looking at a call statement as to which parameters are being modified by the called function. (B) Making the visual appearance of function declarations tidier and thus cheaper to maintain.You certainly nailed the two problems I was trying to solve here!That's not a sentence, but I get your parenthesized meaning ;). I was more throwing the idea out there because I'm working on my own pet language (ask me about it sometime - here is not the place).Opinions?Using some general principles (large changes to the language's syntax should be minimised, D syntax should retain the flavour of the C family, syntax changes must benefit people using the language, syntax changes must not overly complicate the compiler).I think that problem (A) could also be solved by allowing the 'out' specifier on a standard function call. e.g. a = myfunction(4, out x, out y);Hmm, that could get a bit ugly when your function parameters are numerous. But you're right - it certainly would be clear where the inputs and outputs lie.This could also be used for inout arguments as well. Problem (B) is, in essence, a style issue. It could be said that (int x, real y, float[] a) myfunction (int b) is easier or harder to read than float[] a myfunction (int b, out int x, out real y) depending on the way individuals see things.Exactly. I think that in order to progress we must disobey the Bob of Backwards Compatibility every now and then. You can't serve two masters.However, one difference between the two syntaxes is that the current method *requires* that the return value is mandatory but it is not a requirement that the 'out' arguments are updated. The proposed method implies that none of the 'return' values are mandatory, and this is a fundamental idiom shift.I noticed this as well. Doesn't it seem odd that forgetting to set the value of "out" arguments is allowed? It seems to me that they are outputs, and not input-outputs, and should be set at all times. Returning an output argument value with its default type initializer just doesn't seem to have much of a point to me. (Unless Exceptions are thrown, but let's not get into that - they're exceptional)Do you have a "simpler way" suggestion? As I said before, I'm working on my own pet language, so any insight you've got could be helpful to me.Concerns?I suspect that this would be a medium change in the syntax rules and it is a definite step away from the C family syntax. I can see that the problem (A) is one that is justifiably addressed though a simpler way might be better.And problem (B) is not easily fixed because it might mean alternative syntaxes are needed to cater for personal styles. I also suspect that your suggestion would add quite a degree of new complexity to the compiler, as both function declarations and assignment statements would need extra parsing and different code generation. -- Derek Melbourne, Australia 8/06/2005 10:10:02 AMRegards, James Dunne
Jun 08 2005
On Wed, 8 Jun 2005 13:05:15 +0000 (UTC), James Dunne wrote: [snip]Another way of looking at this sort of change is that it involves a cost. Is that cost justified? One way of working that out is to see if it is solving a problem that is already costing us so as to reduce that.What problem is this trying to solve?We always view changes as trying to solve problems ... interesting. Sometimes I just like to go against the flow of current and try something different, just for change's sake. Some people say, "If it ain't broke, don't fix it." Well, I'd be one to say "It is broke, so I am fixing it"; but to some it just doesn't *look* broke.Lucky guess ;-)I'll take a guess at a couple... (A) Making it clearer to a reader looking at a call statement as to which parameters are being modified by the called function. (B) Making the visual appearance of function declarations tidier and thus cheaper to maintain.You certainly nailed the two problems I was trying to solve here!The final period was meant to be an ellipsis.That's not a sentence, but I get your parenthesized meaning ;).Opinions?Using some general principles (large changes to the language's syntax should be minimised, D syntax should retain the flavour of the C family, syntax changes must benefit people using the language, syntax changes must not overly complicate the compiler).I was more throwing the idea out there because I'm working on my own pet language (ask me about it sometime - here is not the place).You have talking pets !?!? :DBeauty is in the eye of the beholder...;-) I suggested this because it is very simple to implement and does not change the syntax in any dramatic manner.I think that problem (A) could also be solved by allowing the 'out' specifier on a standard function call. e.g. a = myfunction(4, out x, out y);Hmm, that could get a bit ugly when your function parameters are numerous. But you're right - it certainly would be clear where the inputs and outputs lie.Oh! I didn't realize you were asking to replace the current syntax with your alternative. That would break *so* much existing code it could create enemies ;-)This could also be used for inout arguments as well. Problem (B) is, in essence, a style issue. It could be said that (int x, real y, float[] a) myfunction (int b) is easier or harder to read than float[] a myfunction (int b, out int x, out real y) depending on the way individuals see things.Exactly. I think that in order to progress we must disobey the Bob of Backwards Compatibility every now and then. You can't serve two masters.To repeat: one of your proposals makes all 'return' values optional.However, one difference between the two syntaxes is that the current method *requires* that the return value is mandatory but it is not a requirement that the 'out' arguments are updated. The proposed method implies that none of the 'return' values are mandatory, and this is a fundamental idiom shift.I noticed this as well. Doesn't it seem odd that forgetting to set the value of "out" arguments is allowed? It seems to me that they are outputs, and not input-outputs, and should be set at all times. Returning an output argument value with its default type initializer just doesn't seem to have much of a point to me. (Unless Exceptions are thrown, but let's not get into that - they're exceptional)For D, only the one I've already mentioned. However, for a totally new/different language then returning tuples seems a nice idea. The only sugar needed would be some syntax to indicate that you are accepting a pseudo tuple. The simple case would be something like ... tuple A; A = myfunction(4); but a pseudo tuple might be needed if updating elements currently belonging to disparate variables... int A; real B; string C; { A, B, C } = myfunction(4); But back to D, eh? -- Derek Parnell Melbourne, Australia 8/06/2005 11:33:07 PMDo you have a "simpler way" suggestion? As I said before, I'm working on my own pet language, so any insight you've got could be helpful to me.Concerns?I suspect that this would be a medium change in the syntax rules and it is a definite step away from the C family syntax. I can see that the problem (A) is one that is justifiably addressed though a simpler way might be better.
Jun 08 2005
In article <ip8as8je57ds$.jwl7zh79xait.dlg 40tude.net>, Derek Parnell says...On Wed, 8 Jun 2005 13:05:15 +0000 (UTC), James Dunne wrote: [snip]African Grey parrots doAnother way of looking at this sort of change is that it involves a cost. Is that cost justified? One way of working that out is to see if it is solving a problem that is already costing us so as to reduce that.What problem is this trying to solve?We always view changes as trying to solve problems ... interesting. Sometimes I just like to go against the flow of current and try something different, just for change's sake. Some people say, "If it ain't broke, don't fix it." Well, I'd be one to say "It is broke, so I am fixing it"; but to some it just doesn't *look* broke.Lucky guess ;-)I'll take a guess at a couple... (A) Making it clearer to a reader looking at a call statement as to which parameters are being modified by the called function. (B) Making the visual appearance of function declarations tidier and thus cheaper to maintain.You certainly nailed the two problems I was trying to solve here!The final period was meant to be an ellipsis.That's not a sentence, but I get your parenthesized meaning ;).Opinions?Using some general principles (large changes to the language's syntax should be minimised, D syntax should retain the flavour of the C family, syntax changes must benefit people using the language, syntax changes must not overly complicate the compiler).I was more throwing the idea out there because I'm working on my own pet language (ask me about it sometime - here is not the place).You have talking pets !?!? :DAgreed, but I wasn't referring to D specifically - I have a bad habit of doing that... My badBeauty is in the eye of the beholder...;-) I suggested this because it is very simple to implement and does not change the syntax in any dramatic manner.I think that problem (A) could also be solved by allowing the 'out' specifier on a standard function call. e.g. a = myfunction(4, out x, out y);Hmm, that could get a bit ugly when your function parameters are numerous. But you're right - it certainly would be clear where the inputs and outputs lie.Oh! I didn't realize you were asking to replace the current syntax with your alternative. That would break *so* much existing code it could create enemies ;-)This could also be used for inout arguments as well. Problem (B) is, in essence, a style issue. It could be said that (int x, real y, float[] a) myfunction (int b) is easier or harder to read than float[] a myfunction (int b, out int x, out real y) depending on the way individuals see things.Exactly. I think that in order to progress we must disobey the Bob of Backwards Compatibility every now and then. You can't serve two masters.My new language is more or less like C with a few extensions and a slightly "new" paradigm. I don't want it to turn into LISP by throwing tuples everywhere - only where they make sense.To repeat: one of your proposals makes all 'return' values optional.However, one difference between the two syntaxes is that the current method *requires* that the return value is mandatory but it is not a requirement that the 'out' arguments are updated. The proposed method implies that none of the 'return' values are mandatory, and this is a fundamental idiom shift.I noticed this as well. Doesn't it seem odd that forgetting to set the value of "out" arguments is allowed? It seems to me that they are outputs, and not input-outputs, and should be set at all times. Returning an output argument value with its default type initializer just doesn't seem to have much of a point to me. (Unless Exceptions are thrown, but let's not get into that - they're exceptional)For D, only the one I've already mentioned. However, for a totally new/different language then returning tuples seems a nice idea. The only sugar needed would be some syntax to indicate that you are accepting a pseudo tuple. The simple case would be something like ... tuple A; A = myfunction(4); but a pseudo tuple might be needed if updating elements currently belonging to disparate variables... int A; real B; string C; { A, B, C } = myfunction(4);Do you have a "simpler way" suggestion? As I said before, I'm working on my own pet language, so any insight you've got could be helpful to me.Concerns?I suspect that this would be a medium change in the syntax rules and it is a definite step away from the C family syntax. I can see that the problem (A) is one that is justifiably addressed though a simpler way might be better.But back to D, eh?Indeed. Sorry about my digressions, but it seems this is a familiar place for me to discuss general language features/syntax/ideas.-- Derek Parnell Melbourne, Australia 8/06/2005 11:33:07 PMRegards, James Dunne
Jun 08 2005
seems im the only one who likes this idea? also, i dont see why it would have to break any code. the compiler should be easily capable of converting between both syntaxes, no? its basicly just a matter of sweeping all out parameters to the left. both syntaxes could coexist with a little change here and there. "James Dunne" <james.jdunne gmail.com> wrote in message news:d845t5$2ck6$1 digitaldaemon.com..."out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b); I'd say the only complications arise in handling the return statement syntax - whether or not to specify a set of return values, or to implicitly return values by setting return-value variables. method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : } Both *examples* are equivalent, but each approach has its strengths and weaknesses. No weaker than forgetting to set an "out" variable as the language is now. Method 1 allows for cleaner reading until the list of return values gets unreasonably large. It also accomodates all return-values on function return. Method 2 allows more readability for longer lists of return values, but sacrifices understandability in following setting of return values throughout a complex control flow. Personally, I'd prefer method 2; but perhaps both forms can be supported. Calling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4); Thoughts? Opinions? Concerns? Regards, James Dunne
Jun 17 2005
In article <d8u60n$vdm$1 digitaldaemon.com>, Eelco Hoogendoorn says...seems im the only one who likes this idea?me too"James Dunne" <james.jdunne gmail.com> wrote in message news:d845t5$2ck6$1 digitaldaemon.com...Good idea, we should learn more from Perl. Not that D should be like Perl, but some good ideas could be borrowed."out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b);method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : }I think method 1 has to be there. It's much pratical in many situations. Both should be supported.Personally, I'd prefer method 2; but perhaps both forms can be supported.I prefer: : (int x, real y, float[] a) = myfunction(4); Also: : /* function returning arrays should be flexible: */ : : int[] fA(int n) { : if(n == 1) return 1; : if(n == 2) return [1, 2]; : if(n == 3) return [1, 2, 3]; : return; : } : : a = fA(1); // a=1 : (a, b) = fA(1); // a=1, b=null : (a, b) = fA(2); // a=1, b=2 : (a, b) = fA(3); // a=1, b=2 (third return value discarded) : (a, b) = fA(0); // a=null, b=null : (a, b) = fA(3)[1..3]; // a=2, b=3 : (a, null, b) = fA(3); // a=1, b=3 (discard second value) : (int x, int y) = fA(2); // declare and set : : : /* for list of types, it's more controversial : to loosen syntax restriction so much : */ : : (int i, char c) fM(int n) { : if(n == 1) return 1; // syntax ok? c would be null : if(n == 2) return (1, 'a'); : return; // syntax ok? both would be null : } Rodolfo BorgesCalling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4);
Jun 18 2005
Value types, like int and char, cannot be null. They'd have to be 0 in your example. -[Unknown]In article <d8u60n$vdm$1 digitaldaemon.com>, Eelco Hoogendoorn says...seems im the only one who likes this idea?me too"James Dunne" <james.jdunne gmail.com> wrote in message news:d845t5$2ck6$1 digitaldaemon.com...Good idea, we should learn more from Perl. Not that D should be like Perl, but some good ideas could be borrowed."out" variables would be much more useful as a set of multiple return values: : (int x, real y, float[] a) myfunction (int b);method 1: return with a set of values : (int, real, float[]) myfunction (int b) { : return (b + 2, b * 4.5, null); : } or method 2: return by setting return-value variables : (int x, real y, float[] a) myfunction (int b) { : x = b + 2; : y = b * 4.5; : a = null; : return; : }I think method 1 has to be there. It's much pratical in many situations. Both should be supported.Personally, I'd prefer method 2; but perhaps both forms can be supported.I prefer: : (int x, real y, float[] a) = myfunction(4); Also: : /* function returning arrays should be flexible: */ : : int[] fA(int n) { : if(n == 1) return 1; : if(n == 2) return [1, 2]; : if(n == 3) return [1, 2, 3]; : return; : } : : a = fA(1); // a=1 : (a, b) = fA(1); // a=1, b=null : (a, b) = fA(2); // a=1, b=2 : (a, b) = fA(3); // a=1, b=2 (third return value discarded) : (a, b) = fA(0); // a=null, b=null : (a, b) = fA(3)[1..3]; // a=2, b=3 : (a, null, b) = fA(3); // a=1, b=3 (discard second value) : (int x, int y) = fA(2); // declare and set : : : /* for list of types, it's more controversial : to loosen syntax restriction so much : */ : : (int i, char c) fM(int n) { : if(n == 1) return 1; // syntax ok? c would be null : if(n == 2) return (1, 'a'); : return; // syntax ok? both would be null : } Rodolfo BorgesCalling syntax is up for debate as well: : int x; : real y; : float[] a; : (x, y, a) = myfunction(4);
Jun 18 2005