Jump to page: 1 2
Thread overview
"#" symbol
Oct 24, 2005
Tomás Rossi
Oct 24, 2005
Hasan Aljudy
Re: #
Oct 24, 2005
Tomás Rossi
Oct 24, 2005
Hasan Aljudy
Oct 24, 2005
pragma
Oct 24, 2005
Walter Bright
Re:
Oct 25, 2005
Dan
Oct 26, 2005
Daniel Horn
Re: "#" symbol
Oct 26, 2005
Derek Parnell
Re:
Oct 26, 2005
Dan
Oct 26, 2005
Derek Parnell
Oct 26, 2005
Bruno Medeiros
Oct 30, 2005
Kris
Oct 30, 2005
Derek Parnell
Oct 31, 2005
Kris
October 24, 2005
Sorry for my D syntax ignorance but, is the "#" symbol used for anything in D? I ask cause I was reading the discussion about de "$" vs. "length". "#" is much 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
October 24, 2005
Tomás Rossi wrote:
> Sorry for my D syntax ignorance but, is the "#" symbol used for anything in D?
> I ask cause I was reading the discussion about de "$" vs. "length". "#" is much
> 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
http://www.digitalmars.com/d/lex.html
special token sequence:
# line <number> [<filename>]

or actually:

SpecialTokenSequence
	# line Integer EndOfLine
	# line Integer Filespec EndOfLine

Filespec
	" Characters "
October 24, 2005
In article <djhkm1$303g$1@digitaldaemon.com>, Hasan Aljudy says...
>
>Tomás Rossi wrote:
>> Sorry for my D syntax ignorance but, is the "#" symbol used for anything in D? I ask cause I was reading the discussion about de "$" vs. "length". "#" is much 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
>http://www.digitalmars.com/d/lex.html
>special token sequence:
># line <number> [<filename>]
>
>or actually:
>
>SpecialTokenSequence
>	# line Integer EndOfLine
>	# line Integer Filespec EndOfLine
>
>Filespec
>	" Characters "

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 :)


Tom
October 24, 2005
Tomás Rossi wrote:
> In article <djhkm1$303g$1@digitaldaemon.com>, Hasan Aljudy says...
> 
>>Tomás Rossi wrote:
>>
>>>Sorry for my D syntax ignorance but, is the "#" symbol used for anything in D?
>>>I ask cause I was reading the discussion about de "$" vs. "length". "#" is much
>>>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
>>
>>http://www.digitalmars.com/d/lex.html
>>special token sequence:
>># line <number> [<filename>]
>>
>>or actually:
>>
>>SpecialTokenSequence
>>	# line Integer EndOfLine
>>	# line Integer Filespec EndOfLine
>>
>>Filespec
>>	" Characters "
> 
> 
> 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 :)
> 
> 
> Tom

I personally don't know why would anyone need to use it .. I haven't seen any discussion on it in this NG!
October 24, 2005
In article <djimq6$rjp$1@digitaldaemon.com>, Hasan Aljudy says...
>
>Tomás Rossi wrote:
>> In article <djhkm1$303g$1@digitaldaemon.com>, Hasan Aljudy says...
>> 
>>>Tomás Rossi wrote:
>>>
>>>>Sorry for my D syntax ignorance but, is the "#" symbol used for anything in D? I ask cause I was reading the discussion about de "$" vs. "length". "#" is much 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
>>>
>>>http://www.digitalmars.com/d/lex.html
>>>special token sequence:
>>># line <number> [<filename>]
>>>
>>>or actually:
>>>
>>>SpecialTokenSequence
>>>	# line Integer EndOfLine
>>>	# line Integer Filespec EndOfLine
>>>
>>>Filespec
>>>	" Characters "
>> 
>> 
>> 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 :)
>> 
>> 
>> Tom
>
>I personally don't know why would anyone need to use it .. I haven't seen any discussion on it in this NG!

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 on line #2 will be reported by DMD as an error on line #2 in "helloworld.dsp" instead of line #6 in "helloworld.d".

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 its kind supported by the language, so arguably its not a good use 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 yahoo
October 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, and
is
> never really used during 'manual' programming.

That's right.

> 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
> on line #2 will be reported by DMD as an error on line #2 in
"helloworld.dsp"
> instead of line #6 in "helloworld.d".
>
> 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).

Yes.

> Now, as to wether or not its a waste of a symbol, #line is the only
directive of
> its kind supported by the language, so arguably its not a good use 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.

The idea was so one could use the C preprocessor without modification.


October 25, 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?  pound?  number?

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?


October 26, 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?  pound?  number?
> 
> 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?
> 
> 
October 26, 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?  pound?  number?
> 
> arr.$ says?  money!  a whole array of it!

No one is suggesting these syntaxes, Dan.

What is being suggested is that '$' or '#' is a shorthand for 'arr.length'
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
October 26, 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?


« First   ‹ Prev
1 2