View mode: basic / threaded / horizontal-split · Log in · Help
March 02, 2005
Re: $ instead of length
On Wed, 02 Mar 2005 23:26:10 +0000, cahoots wrote:

> In article <d052lp$h8q$1@digitaldaemon.com>, Walter says...
> 
> 
> Using a symbol instead seems like the right approach since a) it can never be
> confused with user-space, and b) it doesn't extend the reserved-word list (it
> can't be used within an identifier).
> 
> Perhaps # could be applied (if present on European keyboards) ? Perhaps '^'? Or
> perhaps use a compound symbol, such as [] to represent length?  X[0..[]] ?

About European keyboards, '#' is present on French, Azerty keyboards (only
with AltGr, but so are {} and [] anyway). '^' is also present, but not
very practical since it's a dead key (so you have to type it twice, or
type ^+space).

I'm not really for using a compound symbol... I like '#' :)
March 02, 2005
Re: $ instead of length
> The $ idea for the length is a good one.

<alert comment="rude and uncalled for">

Interesting thread, but are the "fired neurons" expended on this
thread getting us closer to 1.0?

That's pretty harsh/tacky for me to say ... and I suppose it is
relaxing and/or motivating for you to think about $ (on several levels
:-)

but the juxtaposition to the "Will D ever be ready?" thread brings out
my flawed sarcastic tendencies. Mea culpa.

Give me an F. What does it stand for? Focus.
Give me another F. What does it stand for? Focus.

I speak as a deeply unfocused person poking around unproductively at a
lot of stuff that isn't getting finished.

I suspect "The WB" is one of the most focused people on the face of
this planet.

</alert>
March 03, 2005
Re: $ instead of length
"Walter" <newshound@digitalmars.com> wrote in message 
news:d052lp$h8q$1@digitaldaemon.com...
> [Starting a new thread on this, because the original is old and wandered 
> off
> topic too far]
>
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cu90r1$1e7t$1@digitaldaemon.com...
>> Agreed. I have always supported the use of a symbol rather than an 
>> English
>> word to represent the array's length property. I'm keen to promote the
>> readibilty of source code by humans, so an extra 'dot' seems counter
>> productive to that aim.
>
>
> The $ idea for the length is a good one. The reason I didn't adopt it was
> because I am trying to save $ for something big. I have a lot of thoughts
> (inspired by some emails from Andrei A.) that $ could be very, very useful
> in a future metaprogramming feature. Using $ as a length is a minor use, 
> too
> minor for such an important symbol!
>
> So the options are:
>
> 1) Make it illegal for length within [ ] to hide another length in an 
> outer
> scope. This would essentially preclude length being used as a global, or
> even as a class member.
>
> 2) Same as (1), but only restrict it if length is a variable local to a
> function.
>
> 3) Make length a keyword. This is not that much different from (1).
>
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.
>
> 5) Invent a token for it that is other than '$'.
>
>

Here's a wacky idea: in an indexing expression [expr1] or [expr1 .. expr2] 
if the type of expr1 or expr2 is imaginary or complex then replace expr with 
(length - cast(int)expr.im + cast(int)expr.re) where expr is evaulated once. 
For example
 x[1i] equivalent to x[x.length-1]
 x[ k+m*1i .. n*1i ] equivalent to x[k+x.length-m .. x.length-n]

Oh the fun we could have with complex arithmetic :-)
March 03, 2005
Re: $ instead of length
brad@domain.invalid wrote:
> 
>>
>> I find ` hard to see, but I still prefer the 5th option... is # already
>> used somewhere ?
>>
>> Or what about '!', I don't think using it for length would conflict with
>> the existing uses ? (same for ':')
>>
>> SeeSchloss
> 
> 
> I actually like ` being hard to see because it is less intrusive :)
> But # would work well too I think.
> 
> Brad

There're #line and # ... something else that I already forgot ...

And they're CPP directives, so should you run a preprocessor on your D 
code, it'd become a complete mess.

(Sure, you'd say: we don't have or maybe even need a preprocessor, but 
even Walter has said you could always use one if badly needed. So, as 
long as it's an option, I don't think # is viable....)

_______________________
Carlos Santander Bernal
March 03, 2005
Re: $ instead of length
"Ben Hinkle" <ben.hinkle@gmail.com> wrote in message
news:d05lv5$18ar$1@digitaldaemon.com...
> Oh the fun we could have with complex arithmetic :-)

Yes, if it doesn't work, rotate your code 90 degrees and try again.
March 03, 2005
Re: $ instead of length
In article <pan.2005.03.02.23.37.41.379145@seeschloss.org>, SeeSchloss says...
>
>On Wed, 02 Mar 2005 23:26:10 +0000, cahoots wrote:
>
>> In article <d052lp$h8q$1@digitaldaemon.com>, Walter says...
>> 
>> 
>> Using a symbol instead seems like the right approach since a) it can never be
>> confused with user-space, and b) it doesn't extend the reserved-word list (it
>> can't be used within an identifier).
>> 
>> Perhaps # could be applied (if present on European keyboards) ? Perhaps '^'? Or
>> perhaps use a compound symbol, such as [] to represent length?  X[0..[]] ?
>
>About European keyboards, '#' is present on French, Azerty keyboards (only
>with AltGr, but so are {} and [] anyway). '^' is also present, but not
>very practical since it's a dead key (so you have to type it twice, or
>type ^+space).
>
>I'm not really for using a compound symbol... I like '#' :)

I do also. But it would conflict with CPP, as someone else pointed out. 

This kind of thing really seems to be the domain of meta-tags, since there's a
bit of "implication" involved. I think it might be worth briefly exploring the
general notion of meta-tags, and applying it to this case (e.g. $length, or
@length, and so on)
March 03, 2005
Re: $ instead of length
> The $ symbol already denotes 'end of' in regular expressions, and many
> people are familiar with that. It is not a large context shift in people's
> current thinking.

And symbol '#' means 'number (of)' which is also close I guess.

I think that it make sense to use some generic approach for all
builtin varables. Either declare all of them as keywords either use
very distinct and uniform notation like:

# - just length
#arguments - var args
#argptr

Otherwise it is going to be a neverending story about name conflicts.

BTW:

# could be parsed without need of '.', so:

char a[];
if( a# < 28) writef("yep, I like this string");
March 03, 2005
Re: $ instead of length
On Wed, 2 Mar 2005 21:26:33 -0800, Andrew Fedoniouk wrote:

>> The $ symbol already denotes 'end of' in regular expressions, and many
>> people are familiar with that. It is not a large context shift in people's
>> current thinking.
> 
> And symbol '#' means 'number (of)' which is also close I guess.
> 
> I think that it make sense to use some generic approach for all
> builtin varables. Either declare all of them as keywords either use
> very distinct and uniform notation like:
> 
> # - just length
> #arguments - var args
> #argptr
> 
> Otherwise it is going to be a neverending story about name conflicts.
> 
> BTW:
> 
> # could be parsed without need of '.', so:
> 
> char a[];
> if( a# < 28) writef("yep, I like this string");

Ok, I could live with that.

 b = a[3 ..#-2];

Yeah, why not? It seems to work okay as a concept.

-- 
Derek Parnell
Melbourne, Australia
http://www.dsource.org/projects/build/
3/03/2005 5:00:01 PM
March 03, 2005
Re: $ instead of length
"cahoots" <cahoots_member@pathlink.com> skrev i en meddelelse 
news:d05p58$1bn6$1@digitaldaemon.com...
I do also. But it would conflict with CPP, as someone else pointed out.

I don't see any serious conflict with the preprocessor. First, '#' used 
within the brackets is unlikely to appear as the first token on a line. 
Second, an identifier is unlikely to appear as the following token. The only 
place i see a potential conflict is within macro replacement lists, but i 
could easily live with that.

Regards,
Martin
March 03, 2005
Re: $ instead of length
Derek Parnell wrote:

>>What about the ` (backtick) character, I don't think that we use that 
>>for anything right now.
>
> 
> The tick (back-quote) is already being used. It defines a raw string
> literal.
> 
>    char[] X = `c:\dmd\bin\`

Yeah, and this is unfortunate enough since in both shell and Perl
backticks mean escape and run a command - which is how I read it.

Luckily I don't have any Windows paths here, so I'll just ignore it.
And if I do need wysiwyg strings, I'll probably use the raw: r""...

--anders
1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home