digitalmars.D - "#" symbol
- Tomás Rossi (6/6) Oct 23 2005 Sorry for my D syntax ignorance but, is the "#" symbol used for anything...
- Hasan Aljudy (10/18) Oct 23 2005 http://www.digitalmars.com/d/lex.html
- Tomás Rossi (5/23) Oct 24 2005 Oh, ok, though I can't see in which cases would anyone use that special ...
- Hasan Aljudy (3/36) Oct 24 2005 I personally don't know why would anyone need to use it .. I haven't
- pragma (27/63) Oct 24 2005 AFAIK, this feature is intended for preprocessors and code-generators, a...
- Walter Bright (14/39) Oct 24 2005 is
- Dan (11/11) Oct 25 2005 Curious why you folk are insistent on putting obscure unreadable
- Daniel Horn (20/40) Oct 25 2005 People are complaining about the language construct that automatically
- Derek Parnell (24/37) Oct 25 2005 Yes it does.
- Dan (17/17) Oct 25 2005 Okay, so the problem is the scope issue, and when "array" is a 63 charac...
- Derek Parnell (9/13) Oct 25 2005 On Wed, 26 Oct 2005 03:24:24 +0000 (UTC), Dan wrote:
- Bruno Medeiros (26/38) Oct 26 2005 What you speak here is a particular case of a more general issue, which
- Kris (5/12) Oct 30 2005 True. Yet, is there really such an issue with the following alternate su...
- Derek Parnell (7/24) Oct 30 2005 No. I said "small symbol" and "$len" looks small to me.
- Kris (2/14) Oct 30 2005 Me too :-)
more natural for the purpose (speaking of the cardinal or length of something). Also the "$" symbol feels like a waste in using it as length. Regards Tom
Oct 23 2005
Tomás Rossi wrote:more natural for the purpose (speaking of the cardinal or length of something). Also the "$" symbol feels like a waste in using it as length. Regards Tomhttp://www.digitalmars.com/d/lex.html special token sequence: or actually: SpecialTokenSequence Filespec " Characters "
Oct 23 2005
In article <djhkm1$303g$1 digitaldaemon.com>, Hasan Aljudy says...Tomás Rossi wrote:Oh, ok, though I can't see in which cases would anyone use that special token sequence anyway. Seem's like a preprocessor command to me, like the ones Walter took away for many reasons. Another waste of nice symbols :) Tommore natural for the purpose (speaking of the cardinal or length of something). Also the "$" symbol feels like a waste in using it as length. Regards Tomhttp://www.digitalmars.com/d/lex.html special token sequence: or actually: SpecialTokenSequence Filespec " Characters "
Oct 24 2005
Tomás Rossi wrote:In article <djhkm1$303g$1 digitaldaemon.com>, Hasan Aljudy says...I personally don't know why would anyone need to use it .. I haven't seen any discussion on it in this NG!Tomás Rossi wrote:Oh, ok, though I can't see in which cases would anyone use that special token sequence anyway. Seem's like a preprocessor command to me, like the ones Walter took away for many reasons. Another waste of nice symbols :) Tommore natural for the purpose (speaking of the cardinal or length of something). Also the "$" symbol feels like a waste in using it as length. Regards Tomhttp://www.digitalmars.com/d/lex.html special token sequence: or actually: SpecialTokenSequence Filespec " Characters "
Oct 24 2005
In article <djimq6$rjp$1 digitaldaemon.com>, Hasan Aljudy says...Tomás Rossi wrote:AFAIK, this feature is intended for preprocessors and code-generators, and is never really used during 'manual' programming. Actually, I'm using it quite heavily for DSP. For example, given the following HTML: <b>hello world</b> <dsp:code>uint a = ;</dsp:code> DSP generates something like the following: // output file: helloworld.d /** DSP runtime stuff and additional code would appear here **/ #line 1 "helloworld.dsp" response.put("<b>hello world</b>"); #line 2 "helloworld.dsp" uint a = ; This feature makes debugging actually possible, as the line numbers reported by DMD will correspond to the line numbers in the actual source. The syntax error Use of #line makes such a virtual line number mapping possible, without having to resort to parsing the compiler's output while maintaining some sort of line number translation table (icky). Now, as to wether or not its a waste of a symbol, #line is the only directive of Honestly, I wouldn't mind if #line were changed into "pragma(line,lineno,"filename")" instead; if anything it would appear to be less of language wart in that respect. - EricAnderton at yahooIn article <djhkm1$303g$1 digitaldaemon.com>, Hasan Aljudy says...I personally don't know why would anyone need to use it .. I haven't seen any discussion on it in this NG!Tomás Rossi wrote:Oh, ok, though I can't see in which cases would anyone use that special token sequence anyway. Seem's like a preprocessor command to me, like the ones Walter took away for many reasons. Another waste of nice symbols :) Tommore natural for the purpose (speaking of the cardinal or length of something). Also the "$" symbol feels like a waste in using it as length. Regards Tomhttp://www.digitalmars.com/d/lex.html special token sequence: or actually: SpecialTokenSequence Filespec " Characters "
Oct 24 2005
"pragma" <pragma_member pathlink.com> wrote in message news:djipt1$uag$1 digitaldaemon.com...AFAIK, this feature is intended for preprocessors and code-generators, andisnever really used during 'manual' programming.That's right.Actually, I'm using it quite heavily for DSP. For example, given thefollowingHTML: <b>hello world</b> <dsp:code>uint a = ;</dsp:code> DSP generates something like the following: // output file: helloworld.d /** DSP runtime stuff and additional code would appear here **/ #line 1 "helloworld.dsp" response.put("<b>hello world</b>"); #line 2 "helloworld.dsp" uint a = ; This feature makes debugging actually possible, as the line numbersreported byDMD will correspond to the line numbers in the actual source. The syntaxerror"helloworld.dsp"Use of #line makes such a virtual line number mapping possible, withouthavingto resort to parsing the compiler's output while maintaining some sort oflinenumber translation table (icky).Yes.Now, as to wether or not its a waste of a symbol, #line is the onlydirective ofHonestly, I wouldn't mind if #line were changed into "pragma(line,lineno,"filename")" instead; if anything it would appear tobe lessof language wart in that respect.The idea was so one could use the C preprocessor without modification.
Oct 24 2005
Curious why you folk are insistent on putting obscure unreadable characters into a compiled language. What is the value? arr.length says it loud and clear. arr.$ says? money! a whole array of it! It doesn't make the binary smaller. It doesn't make the code easier to read. It makes it about three keystrokes easier (shift down, pound, shift up), but if you really are in that much of a hurry maybe copy and paste it. Just double click on length and Ctrl C, Ctrl V. Unless you care to inform me why it matters?
Oct 25 2005
People are complaining about the language construct that automatically binds a local variable length to the array's length... hiding class vars and local vars i.e. int length=0; int array [10]; return array[length]; will segfault...because the code is translated into int length=0; int array [10]; { int length=array.length; return array[length]; } so people suggested using characters that you could NOT name an identifier to prevent the above mistake... and $ was one of them--anything is better than the above mistake that's currently in the compiler--including your solution of naming array each time. Dan wrote:Curious why you folk are insistent on putting obscure unreadable characters into a compiled language. What is the value? arr.length says it loud and clear. arr.$ says? money! a whole array of it! It doesn't make the binary smaller. It doesn't make the code easier to read. It makes it about three keystrokes easier (shift down, pound, shift up), but if you really are in that much of a hurry maybe copy and paste it. Just double click on length and Ctrl C, Ctrl V. Unless you care to inform me why it matters?
Oct 25 2005
On Tue, 25 Oct 2005 23:47:02 +0000 (UTC), Dan wrote:Curious why you folk are insistent on putting obscure unreadable characters into a compiled language. What is the value? arr.length says it loud and clear.Yes it does.arr.$ says? money! a whole array of it!No one is suggesting these syntaxes, Dan. in the context of a slice expression. It is not shorthand for the word 'length' but the combined array name *and* the length property.It doesn't make the binary smaller.No, but so what? We are talking about the D language which is a human-readable language.It doesn't make the code easier to read.This is the point of most dispute. I suspect that we need some empirical evidence to resolve it.It makes it about three keystrokes easier (shift down, pound, shift up), but if you really are in that much of a hurry maybe copy and paste it. Just double click on length and Ctrl C, Ctrl V.SomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &= AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 .. AnotherClass.User_Choice.length-1]; SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];Unless you care to inform me why it matters?I still think that code legibility is enhanced by using a small symbol to represent the concept of 'the current array's length'. -- Derek (skype: derek.j.parnell) Melbourne, Australia 26/10/2005 9:52:57 AM
Oct 25 2005
Okay, so the problem is the scope issue, and when "array" is a 63 character long namespace. Both are valid points. Hmm... To prevent the scope issues we might try: a) make array/struct etc. properties only accessible using the myArray.length instead of just length. b) make it an identifier c) leave it the way it is and document it To cope with the long namespace issue and slicing: a) use a variable. b) use an alias. c) Maybe the MyObject. (and later) .property or .method() might not be a bad idea? Another problem you suddenly run into when using $ for "this array" is correctly and consistently making it obvious what "this array" is. As you mentioned in your own example, we had two arrays with messy names. How do you switch the $ to mean one and then the other?
Oct 25 2005
On Wed, 26 Oct 2005 03:24:24 +0000 (UTC), Dan wrote: [snip]Another problem you suddenly run into when using $ for "this array" is correctly and consistently making it obvious what "this array" is. As you mentioned in your own example, we had two arrays with messy names. How do you switch the $ to mean one and then the other?You don't. It always refers to the array being sliced. -- Derek (skype: derek.j.parnell) Melbourne, Australia 26/10/2005 1:57:26 PM
Oct 25 2005
Derek Parnell wrote:What you speak here is a particular case of a more general issue, which is having several repeated names in a piece of code. For instance in: SomeClass.Selected_Items.SomeMethod( SomeClass.Selected_Items.member, AnotherClass.User_Choice.member + AnotherClass.User_Choice.member*2); we have a similar problem. The solution you have (whether with "$" or "length") is particular for arrays only, and it works only for accessing the length of the indexed array, not of other arrays. Why not use the general solution to this issue, that is, use alias and/or intermediate objects to refactor code, as appropriate for the semantics of the code: auto selItems = SomeClass.Selected_Items; auto member = AnotherClass.User_Choice.member; selItems.SomeMethod( selItems.member, member + member*2); Is it worth it, to have a keyword that works only in a specific case with arrays? I'm not saying yet that it isn't, but I think I'm more inclined to writing verbose code (with or without intermediate objects, depending) which only sometimes, perhaps not very often, will be annoyingly bigger than a "$" keyword version. Also, note that the existence of IDE code auto-completion will soften most of the burden of writing the verbose way. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."It makes it about three keystrokes easier (shift down, pound, shift up), but if you really are in that much of a hurry maybe copy and paste it. Just double click on length and Ctrl C, Ctrl V.SomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &= AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 .. AnotherClass.User_Choice.length-1]; SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];
Oct 26 2005
"Derek Parnell" <derek psych.ward> wrote in messageSomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &= AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 .. AnotherClass.User_Choice.length-1]; SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];True. Yet, is there really such an issue with the following alternate sugar? The benefits are notable: SomeClass.Selected_Items [$len-1] &= AnotherClass.User_Choice [$len-2 .. $len-1];Unless you care to inform me why it matters?I still think that code legibility is enhanced by using a small symbol to represent the concept of 'the current array's length'.
Oct 30 2005
On Sun, 30 Oct 2005 13:08:46 -0800, Kris wrote:"Derek Parnell" <derek psych.ward> wrote in messageNo. I said "small symbol" and "$len" looks small to me. -- Derek (skype: derek.j.parnell) Melbourne, Australia 31/10/2005 9:30:17 AMSomeClass.Selected_Items[SomeClass.Selected_Items.length-1] &= AnotherClass.User_Choice[AnotherClass.User_Choice.length-2 .. AnotherClass.User_Choice.length-1]; SomeClass.Selected_Items[$-1] &= AnotherClass.User_Choice[$-2 .. $-1];True. Yet, is there really such an issue with the following alternate sugar? The benefits are notable: SomeClass.Selected_Items [$len-1] &= AnotherClass.User_Choice [$len-2 .. $len-1];Unless you care to inform me why it matters?I still think that code legibility is enhanced by using a small symbol to represent the concept of 'the current array's length'.
Oct 30 2005
"Derek Parnell" <derek psych.ward> wrote ...On Sun, 30 Oct 2005 13:08:46 -0800, Kris wrote:Me too :-)No. I said "small symbol" and "$len" looks small to me.I still think that code legibility is enhanced by using a small symbol to represent the concept of 'the current array's length'.True. Yet, is there really such an issue with the following alternate sugar? The benefits are notable: SomeClass.Selected_Items [$len-1] &= AnotherClass.User_Choice [$len-2 .. $len-1];
Oct 30 2005