View mode: basic / threaded / horizontal-split · Log in · Help
May 31, 2007
Re: string types: const(char)[] and cstring
Thanks for this.  It appears you're right :)

I can't get my console to show them either, which is annoying.  I'm on windows, I set the font to lucida console and typed "chcp 65001" which makes the precomposed character appear corrently but not the combining character.

Regan Heath
June 02, 2007
Re: string types: const(char)[] and cstring
Derek Parnell wrote:
> What is the syntax for an immutable array of mutable characters?

There isn't one. Such a construct is appealing in the abstract, but I 
haven't run across a legitimate use for it yet.
June 02, 2007
Re: string types: const(char)[] and cstring
Frits van Bommel wrote:
> For other cases though, I could see how a "unique" (or similar) type 
> constructor that would allow implicit conversion to both mutable and 
> invariant (and const) types could be useful.
> For instance, if the strings in your example were replaced by mutable 
> arrays, a "unique char[]" return value of .dup could then be assigned to 
> mutable/const/invariant references without needing casts.

We really tried to figure out a way to make "unique" work. It just 
doesn't offer anything useful over a cast(invariant).

The way to create an invariant out of data is to use cast(invariant). As 
with all casts, one has to trust the programmer to use it appropriately. 
After it is cast, the type system will handle enforcement.

You'll be able to cast away invariant, too, but you're on your own if 
you do so.
June 02, 2007
Re: string types: const(char)[] and cstring
Walter Bright wrote:
> Derek Parnell wrote:
>> What is the syntax for an immutable array of mutable characters?
> 
> There isn't one. Such a construct is appealing in the abstract, but I 
> haven't run across a legitimate use for it yet.

Are we only talking strings here or general arrays? Because if general 
arrays are concerned, I can come up with an example.

An immutable array of mutable data for... e.g. render to texture in a 
software renderer (or creating data for a hw texture, or whatnot) So you 
basically pass a texture buffer to a function. You don't want it to 
realloc the buffer, just to modify its contents...

What am I missing here? ;)


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode
June 03, 2007
Re: string types: const(char)[] and cstring
Tom S wrote:
> Walter Bright wrote:
>> Derek Parnell wrote:
>>> What is the syntax for an immutable array of mutable characters?
>>
>> There isn't one. Such a construct is appealing in the abstract, but I 
>> haven't run across a legitimate use for it yet.
> 
> Are we only talking strings here or general arrays? Because if general 
> arrays are concerned, I can come up with an example.

In general.


> An immutable array of mutable data for... e.g. render to texture in a 
> software renderer (or creating data for a hw texture, or whatnot) So you 
> basically pass a texture buffer to a function. You don't want it to 
> realloc the buffer, just to modify its contents...
> 
> What am I missing here? ;)

We can all come up with an example, the more interesting case is is it a 
compelling example? I'm not seeing that.
June 03, 2007
Re: string types: const(char)[] and cstring
Walter Bright wrote:
> We can all come up with an example, the more interesting case is is it a 
> compelling example? I'm not seeing that.

Well, it's based on a true story.


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode
June 03, 2007
Re: string types: const(char)[] and cstring
On Sat, 02 Jun 2007 18:25:46 -0700, Walter Bright wrote:

> Tom S wrote:
>> Walter Bright wrote:
>>> Derek Parnell wrote:
>>>> What is the syntax for an immutable array of mutable characters?
>>>
>>> There isn't one. Such a construct is appealing in the abstract, but I 
>>> haven't run across a legitimate use for it yet.
>> 
>> Are we only talking strings here or general arrays? Because if general 
>> arrays are concerned, I can come up with an example.
> 
> In general.
> 
> 
>> An immutable array of mutable data for... e.g. render to texture in a 
>> software renderer (or creating data for a hw texture, or whatnot) So you 
>> basically pass a texture buffer to a function. You don't want it to 
>> realloc the buffer, just to modify its contents...
>> 
>> What am I missing here? ;)
> 
> We can all come up with an example, the more interesting case is is it a 
> compelling example? I'm not seeing that.

Define 'compelling'. 

The only workaround I can see is bit restrictive ...

 final TextureBuffer t = CreateTextureBuffer();

 RenderToBuffer( t );
 DoLighting(t);
 ...


-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell
June 03, 2007
Re: string types: const(char)[] and cstring
Walter Bright wrote:
> Derek Parnell wrote:
>> What is the syntax for an immutable array of mutable characters?
> 
> There isn't one. Such a construct is appealing in the abstract, but I 
> haven't run across a legitimate use for it yet.

What, there isn't one? Isn't that what final does? Like this:
  final char[] charar = new char[](20);

  charar[1] = 'x'; // Allowed
  charar = new char[](20); // Not allowed
  charar.length = 10; // Not allowed


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
June 03, 2007
Re: string types: const(char)[] and cstring
Walter Bright wrote:
> Tom S wrote:
>> Walter Bright wrote:
>>> Derek Parnell wrote:
>>>> What is the syntax for an immutable array of mutable characters?
>>>
>>> There isn't one. Such a construct is appealing in the abstract, but I 
>>> haven't run across a legitimate use for it yet.
>>
>> Are we only talking strings here or general arrays? Because if general 
>> arrays are concerned, I can come up with an example.
> 
> In general.
> 
> 
>> An immutable array of mutable data for... e.g. render to texture in a 
>> software renderer (or creating data for a hw texture, or whatnot) So 
>> you basically pass a texture buffer to a function. You don't want it 
>> to realloc the buffer, just to modify its contents...
>>
>> What am I missing here? ;)
> 
> We can all come up with an example, the more interesting case is is it a 
> compelling example? I'm not seeing that.

Most array algorithms would apply.  But I'm still not sure I see the 
point of having an immutable reference, because it's just passed by 
value anyway.  Who cares if the size of the array is modified within a 
function where it's not passed by reference?  The change is just local 
to the function anyway.


Sean
June 03, 2007
Re: string types: const(char)[] and cstring
"Sean Kelly" <sean@f4.ca> wrote in message 
news:f3uoj5$1b1i$1@digitalmars.com...

> Most array algorithms would apply.  But I'm still not sure I see the point 
> of having an immutable reference, because it's just passed by value 
> anyway.  Who cares if the size of the array is modified within a function 
> where it's not passed by reference?  The change is just local to the 
> function anyway.

If that array is pointing into some meaningful area of memory (like in the 
example, a texture buffer), resizing the array could (probably would) move 
the array around, which I guess isn't illegal but then the function 
operating on the array wouldn't be accessing the correct place.  Prevent 
them from changing the length, it prevents them from accessing anywhere but 
there.
4 5 6 7 8 9
Top | Discussion index | About this forum | D home