Re: Input from a newbie

2012-04-09 Thread Stefan

On Monday, 9 April 2012 at 20:18:29 UTC, Ali Çehreli wrote:


The GCC C compiler proves you wrong :) They have warnings. I 
guess it's
a hack (because printf really doesn't belong into the 
compiler) but that

doesn't matter. What matters is user-friendliness.


Indeed. dmd should warn about any incompatible data passed as 
variadic parameters. It's simple to decide: only fundamental 
types that correspond to C counterparts should be allowed. 
Hmmm... Even that's not that simple: int is 32 bits in D but 
unspecified in C.


Maybe printf should not be visible at all - or under a different 
name ("cprintf" or something similar). It's just too tempting...


C variadic arguments are one of the most unsafe features of the C 
language. A total mess.


Stefan


Re: A problem with mutable toString

2012-04-09 Thread Kenji Hara

On Monday, 9 April 2012 at 00:25:57 UTC, bearophile wrote:

Currently this code compiles and runs with no errors:

class Foo {
  override string toString() const {
  return "Foo";
  }
}
void main() {
  import std.stdio;
  const Foo[] foos = [new Foo];
  writeln(foos);
}


Output, DMD 2.059beta2:

[Foo]



While this gives errors:


class Foo {
  override string toString() /*const*/ {
  return "Foo";
  }
}
void main() {
  import std.stdio;
  const Foo[] foos = [new Foo];
  writeln(foos);
}


Output, DMD 2.059beta2:


[snip]

Current std.format doesn't support const class formatting with 
upcasting to mutable Object and using mutable toString().



Is this good/expected?


It is a gap between language const system and object.Object class 
interface.

I think Phobos should not break const system in basic.

Kenji Hara


Re: "How to set up QTD?".

2012-04-09 Thread Kevin Cox
On Apr 9, 2012 12:09 PM, "vmars316"  wrote:
>
> On Monday, 9 April 2012 at 12:52:47 UTC, Kevin Cox wrote:
>
>> I think rcc is the Qt resource compiler.  I'm not at my computer at the
>> moment to check, but if so it will translate xml resource files into D
>> source.
>
>
> "I think rcc is the Qt resource compiler."
> I don't know what the above means.
> What are its implications?
> Is my setup ok?: C:\D\dmd2\QT
> Or do I need to dump 'QT Folder' into 'drcc.exe Folder'?
>
> Also, do I need to create '*.bat' files for every '*.d' I want to
edit/compile?
> Pls, what would that .bat file look like?
> Could someone show me a working cmd-line for the .bat file?
> Do I need to specify 'environmental-variables'?
>
> Thanks a lot for your helps...Vernon

Qt as quite extensive documentation.  Look into the documents about
compiling projects.  It is not a 1 to 1 translation but the workflow is the
same.


Re: isRandomAccessRange on static array

2012-04-09 Thread Brad Anderson

On Monday, 9 April 2012 at 23:22:57 UTC, Jonathan M Davis wrote:

On Tuesday, April 10, 2012 00:20:20 Brad Anderson wrote:
A user in IRC was having difficulty using std.algorithm.sort 
on a

static array. It appears to be due to static arrays don't pass
the isRandomAccessRange constraint.

static assert(isRandomAccessRange!(uint[5]));

Results in:

Error: static assert (isRandomAccessRange!(uint[5u])) is
false

Is this a bug or am I missing something?


Static arrays are not ranges:

http://stackoverflow.com/questions/8873265/is-a-static-array-a-forward-range

If you want to pass a static array to a range-based function, 
you must slice

it first.

- Jonathan M Davis


Ah, ok.  That makes sense.  Thanks.

Regards,
Brad Anderson


Re: isRandomAccessRange on static array

2012-04-09 Thread Jonathan M Davis
On Tuesday, April 10, 2012 00:20:20 Brad Anderson wrote:
> A user in IRC was having difficulty using std.algorithm.sort on a
> static array. It appears to be due to static arrays don't pass
> the isRandomAccessRange constraint.
> 
> static assert(isRandomAccessRange!(uint[5]));
> 
> Results in:
> 
> Error: static assert (isRandomAccessRange!(uint[5u])) is
> false
> 
> Is this a bug or am I missing something?

Static arrays are not ranges:

http://stackoverflow.com/questions/8873265/is-a-static-array-a-forward-range

If you want to pass a static array to a range-based function, you must slice 
it first.

- Jonathan M Davis


Re: isRandomAccessRange on static array

2012-04-09 Thread Ali Çehreli

On 04/09/2012 03:20 PM, Brad Anderson wrote:

A user in IRC was having difficulty using std.algorithm.sort on a static
array. It appears to be due to static arrays don't pass the
isRandomAccessRange constraint.

static assert(isRandomAccessRange!(uint[5]));

Results in:

Error: static assert (isRandomAccessRange!(uint[5u])) is false

Is this a bug or am I missing something?

Regards,
Brad Anderson



Static arrays cannot be even InputRanges because they can't provide 
popFront(). But a whole slice of a static array is even a RandomAccessRange:


   int[3] s;
   s[]; // whole slice

Ali


Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread q66

On Monday, 9 April 2012 at 17:24:35 UTC, Andrej Mitrovic wrote:

On 4/9/12, q66  wrote:

Positional specifier works just fine for me.


Which version are you using? I'm on 2.058.


git


isRandomAccessRange on static array

2012-04-09 Thread Brad Anderson
A user in IRC was having difficulty using std.algorithm.sort on a 
static array.  It appears to be due to static arrays don't pass 
the isRandomAccessRange constraint.


static assert(isRandomAccessRange!(uint[5]));

Results in:

Error: static assert  (isRandomAccessRange!(uint[5u])) is 
false


Is this a bug or am I missing something?

Regards,
Brad Anderson


Re: Input from a newbie

2012-04-09 Thread Ali Çehreli

On 04/09/2012 08:50 AM, Jonas H. wrote:

On 04/09/2012 05:39 PM, Andrej Mitrovic wrote:

I don't think the compiler can warn about this. Isn't printf one of
those unsafe C variadic functions? Someone correct me if I'm wrong.


The GCC C compiler proves you wrong :) They have warnings. I guess it's
a hack (because printf really doesn't belong into the compiler) but that
doesn't matter. What matters is user-friendliness.


Indeed. dmd should warn about any incompatible data passed as variadic 
parameters. It's simple to decide: only fundamental types that 
correspond to C counterparts should be allowed. Hmmm... Even that's not 
that simple: int is 32 bits in D but unspecified in C.


Ali


Re: Latest versions of Entice Designer and DFL?

2012-04-09 Thread vmars316

On Monday, 9 April 2012 at 18:34:36 UTC, Jesse Phillips wrote:
 You're going to need to step
back from the build system for a moment and either use dfl.exe 
or the dmd command suggested. If your program is more than one 
file, make a program that is only one file.


My only observation is -gui is not a command for bud.


No prob stepping back.
D/DFL/Entice was my original goal, got side tracked.
Installing D/DFL/Entice is very frustrating.
There seems to be no roadmap,
so many links, some meaningful.
I can't tell which are uptodate, which are not.
For instance, right now i am searching for DFL KEYWORDS.
I searched this forum, and straight google, but got nowhere.
I wish there was a webPage that says "These are the most
up to date DOCS for installing D, DFL, Entice. Last Updated: 
04/09/2012".


Anyways,
I tried the following .bat to get dflKeywords:

C:\D\dmd2\windows\bin\dfl.exe -help
pause

But no go.

I tried this to run dfl.exe:

C:\D\dmd2\windows\bin\dfl.exe -gui 
C:\D\dmd2\windows\bin\vmPrograms\myForm\myForm.d

(the above is all one line)
pause

I got the following results:

C:\D\dmd2\windows\bin\vmPrograms\myForm>C:\D\dmd2\windows\bin\dfl.exe 
-gui C:\D\

dmd2\windows\bin\vmPrograms\myForm\myForm.d
DFL lib files not found.
Would you like to build the DFL lib files now? [Y/n] y
Error: DFL import directory not found

C:\D\dmd2\windows\bin\vmPrograms\myForm>pause
Press any key to continue . . .

How can I link DFL/Entice/LIBS up?
Is there a Envvironmental.variables that I should be setting?

Or should I Dump dfl.exe into the LIBs Directory?

Thanks...vm





Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread Ali Çehreli

On 04/09/2012 10:35 AM, Andrej Mitrovic wrote:

On 4/9/12, Jonathan M Davis  wrote:

Posix positional arguments seem to work for writefln but not format for
whatever reason. Report it as a bug.


Thanks, http://d.puremagic.com/issues/show_bug.cgi?id=7877


Thanks. I hadn't seen this branch of the thread before sending my 
response. Some newsgroup software break threads into multiple branches. 
Could be my Thunderbird... (?)


Ali


Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread Ali Çehreli

On 04/09/2012 10:24 AM, Andrej Mitrovic wrote:

On 4/9/12, q66  wrote:

Positional specifier works just fine for me.


Which version are you using? I'm on 2.058.


Positional parameters[*] are supported in 2.058. This example prints the 
same argument in decimal, hexadecimal, octal, and binary:


writefln("%1$d %1$x %1$o %1$b", 42);

Ali

[*] http://ddili.org/ders/d.en/formatted_output.html


Re: Latest versions of Entice Designer and DFL?

2012-04-09 Thread Jesse Phillips

On Monday, 9 April 2012 at 17:35:41 UTC, vmars316 wrote:


and my Bud.Bat looks like this:

bud myForm.d -info -gui -version=gui -run -V
pause


Well, now you've added a level of indirection, which just makes 
identifying an issue even harder. You're going to need to step 
back from the build system for a moment and either use dfl.exe or 
the dmd command suggested. If your program is more than one file, 
make a program that is only one file.


My only observation is -gui is not a command for bud.


Re: Input from a newbie

2012-04-09 Thread Jonas H.

On 04/09/2012 07:22 PM, Andrej Mitrovic wrote:

I think most mentions of printf should just be removed from the dpl
docs except maybe a few special places. People (or rather C++
refugees) seem to expect D to be a syntax sugared version of C++, but
this myth has to be busted.


I don't think that's true, or at least I didn't think of D like that. 
It becomes pretty clear after reading the introduction that D does not 
try to emulate C++, let alone be compatible to C(++).


Nevertheless, because the syntax and terminology are quite similar, 
people expect stuff to have the same names. That's why I expected the 
standard printing function to be named `printf` and this attempt failed 
miserably, without any guidance from the compiler/stdlib/whatever.


Re: Issue with const

2012-04-09 Thread Jacob Carlborg

On 2012-04-09 19:56, Steven Schveighoffer wrote:


Then c.data cannot be the same reference as foo.data.

Counter-case:

void bar( const Foo foo)
{
auto c = foo.clone(); // assume this works;
*(cast(int*)c.data) = 6; // note even though I'm casting, there is no
removal of const, so this should be defined behavior.
}

immutable int i = 5;
const foo = new Foo(&i);
bar(foo);

assert(i == 5); // oops, it's 6!

In that case, you have to clone the data as well.

-Steve


Ok, I see, thanks.

--
/Jacob Carlborg


Re: Issue with const

2012-04-09 Thread Jonathan M Davis
On Monday, April 09, 2012 19:51:17 Jacob Carlborg wrote:
> On 2012-04-09 17:30, Steven Schveighoffer wrote:
> > // untested
> > inout(Foo) clone() inout {
> > return new inout(Foo)(data);
> > }
> > 
> > Note, you can't post-assign data, since inout is effectively const
> > inside an inout function.
> > 
> > -Steve
> 
> Ok, that works. But then I want to modify the clone:
> 
> void bar (const Foo foo)
> {
> auto c = foo.clone();
> c.data = ...
> }
> 
> But now "c" is const. I don't want "c" to be const, I just want "foo" to
> be const.

I don't see how that's possible with a void* member variable. clone can be 
const as long as you actually deep copy all of foo's member variables. If 
there are any that you don't deep copy, then the fact that clone is const 
forces the return value to be const because of transivity. And with a void* 
member variable, I don't see how you could deep copy it, so the void* member 
variable is stuck as const, making the return value stuck as const.

- Jonathan M Davis


Re: Issue with const

2012-04-09 Thread Steven Schveighoffer

On Mon, 09 Apr 2012 13:51:17 -0400, Jacob Carlborg  wrote:


On 2012-04-09 17:30, Steven Schveighoffer wrote:


// untested
inout(Foo) clone() inout {
return new inout(Foo)(data);
}

Note, you can't post-assign data, since inout is effectively const
inside an inout function.

-Steve


Ok, that works. But then I want to modify the clone:

void bar (const Foo foo)
{
 auto c = foo.clone();
 c.data = ...
}

But now "c" is const. I don't want "c" to be const, I just want "foo" to  
be const.


Then c.data cannot be the same reference as foo.data.

Counter-case:

void bar( const Foo foo)
{
   auto c = foo.clone(); // assume this works;
   *(cast(int*)c.data) = 6; // note even though I'm casting, there is no  
removal of const, so this should be defined behavior.

}

immutable int i = 5;
const foo = new Foo(&i);
bar(foo);

assert(i == 5); // oops, it's 6!

In that case, you have to clone the data as well.

-Steve


Re: A problem with mutable toString

2012-04-09 Thread bearophile

Maybe related to this?
http://d.puremagic.com/issues/show_bug.cgi?id=7864


Re: Issue with const

2012-04-09 Thread Jacob Carlborg

On 2012-04-09 17:30, Steven Schveighoffer wrote:


// untested
inout(Foo) clone() inout {
return new inout(Foo)(data);
}

Note, you can't post-assign data, since inout is effectively const
inside an inout function.

-Steve


Ok, that works. But then I want to modify the clone:

void bar (const Foo foo)
{
auto c = foo.clone();
c.data = ...
}

But now "c" is const. I don't want "c" to be const, I just want "foo" to 
be const.


--
/Jacob Carlborg


Re: Latest versions of Entice Designer and DFL?

2012-04-09 Thread vmars316

On Monday, 9 April 2012 at 03:23:52 UTC, Jesse Phillips wrote:
Thanks,
I have DFL here: C:\D\dmd2\windows\bin\DFL
and Entice here: C:\D\dmd2\windows\bin\Entice

I decided to take the BUD route from here:
http://www.dsource.org/projects/build

And I installed it here: C:\D\dmd2\vmPrograms\BUDsrc

and my Bud.Bat looks like this:

bud myForm.d -info -gui -version=gui -run -V
pause

But what happens,
is that the the .bat goes into an endless loop.
It never gets to the "pause" statement.
I did a search in C:\D\dmd2\vmPrograms\ and sub folders
for *.exe . There are none.
I was expecting Bud.exe but found none.

Can someone help me with this?
Surely, I can't be the only one trying this.

Thanks...vm


Here are the BUD Commonly Used Switches:

-cleanup  Ensures that all working files created during the 
run are removed.
-full Causes all source files, except ignored modules, to 
be compiled.

-info Displays the version and path of the Bud application
-namesDisplays the names of the files used in building 
the target.
-noautoimport Prevents source file paths from being added to the 
list of Import Roots
-obj  Just creates object files. No linker or librarian 
is launched.

-od   Nominates the temporary file directory.
-run  Runs the application after successful linking.
-silent   Prevents unnecessary messages being displayed.
-T  Identifies the target name to Bud.
-test Does a test run only. No compiling, linking or 
library work is done.
-VSet verbose mode on for just Bud and not for the 
compiler

-X  Identifies a module or package to ignore


Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread Andrej Mitrovic
On 4/9/12, Jonathan M Davis  wrote:
> Posix positional arguments seem to work for writefln but not format for
> whatever reason. Report it as a bug.

Thanks, http://d.puremagic.com/issues/show_bug.cgi?id=7877


Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread Jonathan M Davis
On Monday, April 09, 2012 19:08:54 Andrej Mitrovic wrote:
> import std.string;
> 
> void main()
> {
> string foo = "foo";
> string bar = format("%s %s %s", foo);
> }
> 
> format expects 3 arguments, but what I really want is foo to be used
> for all 3 specifiers and not repeat 'foo' 3 times manually. Are there
> any format specifiers that do what I want? I've tried using positional
> specifiers but that didn't work:
> 
> string bar = format("%1$s %1$s %1$s", foo);
> $ std.format.FormatException@std\format.d(4363): string
> 
> That's a great error message btw.

Posix positional arguments seem to work for writefln but not format for 
whatever reason. Report it as a bug.

- Jonathan M Davis


Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread Andrej Mitrovic
On 4/9/12, q66  wrote:
> Positional specifier works just fine for me.

Which version are you using? I'm on 2.058.


Re: Input from a newbie

2012-04-09 Thread Andrej Mitrovic
On 4/9/12, Artur Skawina  wrote:
> However, there's no reason why *std.stdio* should expose the raw printf
> function - i didn't even realize it did until now...
> It either shouldn't be available via std.stdio at all, or something
> like this wrapper should be added there, to catch the inevitable mistakes:

I think most mentions of printf should just be removed from the dpl
docs except maybe a few special places. People (or rather C++
refugees) seem to expect D to be a syntax sugared version of C++, but
this myth has to be busted.


Re: Multiple %s format specifiers with a single argument

2012-04-09 Thread q66

On Monday, 9 April 2012 at 17:09:03 UTC, Andrej Mitrovic wrote:

import std.string;

void main()
{
string foo = "foo";
string bar = format("%s %s %s", foo);
}

format expects 3 arguments, but what I really want is foo to be 
used
for all 3 specifiers and not repeat 'foo' 3 times manually. Are 
there
any format specifiers that do what I want? I've tried using 
positional

specifiers but that didn't work:

string bar = format("%1$s %1$s %1$s", foo);
$ std.format.FormatException@std\format.d(4363): string

That's a great error message btw.


Positional specifier works just fine for me.


Multiple %s format specifiers with a single argument

2012-04-09 Thread Andrej Mitrovic
import std.string;

void main()
{
string foo = "foo";
string bar = format("%s %s %s", foo);
}

format expects 3 arguments, but what I really want is foo to be used
for all 3 specifiers and not repeat 'foo' 3 times manually. Are there
any format specifiers that do what I want? I've tried using positional
specifiers but that didn't work:

string bar = format("%1$s %1$s %1$s", foo);
$ std.format.FormatException@std\format.d(4363): string

That's a great error message btw.


Re: Input from a newbie

2012-04-09 Thread Artur Skawina
On 04/09/12 17:39, Andrej Mitrovic wrote:
> On 4/9/12, Jonas  wrote:
>> On Saturday, 7 April 2012 at 22:42:19 UTC, Stefan wrote:
>>> printf is a C function which expects 0-terminated strings. D's
>>> strings are variable-length arrays and not zero-terminated.
>>>
>>> Don't use printf. Try using writef instead. Same arguments.
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=7872
> 
> I don't think the compiler can warn about this. Isn't printf one of
> those unsafe C variadic functions? Someone correct me if I'm wrong.

It is, but arguably this is exactly why it should warn - it's unlikely
that passing a D array to an extern(C) variadic function is really what
the programmer intended. Except of course when he relies on the internal
D array representation - and, as this hack is given as an example on 
dlang.org, issuing a warning is out of the question, w/o special-casing
for printf and parsing the format string...

However, there's no reason why *std.stdio* should expose the raw printf
function - i didn't even realize it did until now...
It either shouldn't be available via std.stdio at all, or something
like this wrapper should be added there, to catch the inevitable mistakes:

int printf(string F=__FILE__, int L=__LINE__, A...)(A args) {
   import std.typetuple;
   import std.string;
   import std.c.stdio;
   alias ReplaceAll!(immutable(char)[], char*, A) CA;
   CA cargs;
   foreach (i, arg; args) {
  static if (is(typeof(arg):const(char)[])) {
 pragma(msg, F ~ ":" ~ L.stringof ~
   " Warning: C function printf expects zero-terminated (char*), not D 
array");
 cargs[i] = cast(char*)toStringz(arg);
  }
  else
 cargs[i] = arg;
   }
   return std.c.stdio.printf(cargs);
}

The raw printf can then still be used via std.c.stdio or core.stdc.stdio, 
but a program using just std.stdio will print a warning instead of segfaulting.
Parsing the format string to avoid the warnings for the "%.*s" case could be
done too, i guess.


On 04/09/12 17:50, Jonas H. wrote:
> The GCC C compiler proves you wrong :) They have warnings. I guess it's a 
> hack (because printf really doesn't belong into the compiler) but that 
> doesn't matter.  What matters is user-friendliness.

D doesn't even need compiler support for this - it can be done completely
inside the library.

artur


Re: Input from a newbie

2012-04-09 Thread bearophile

Jonas:

Could you please elaborate on this a bit more? What's the 
problem with helpful compiler messages?


Walter likes helpful error messages, but I think he doesn't want 
to:
1) Use too much time to improve them. There are usually more 
important problems to fix.
2) Slow down the compiler (or make it use more RAM) to generate 
better errors (this seems to happen if you want the column number 
too of the error).
3) Produce too much long error messages because he thinks most 
people are annoyed by a command line interface that gets too much 
scrolling caused by many long error messages (I think most people 
think this is a bit ridiculous justification).


But if you want to add/improve specific error messages, then ask 
for the specific improvements in D Bugzilla as enhancement 
request.



That looks great, thanks, although it's a bit cluttered with 
all those languages ;-)


That 'clutter' is the real purpose of that site.

If you know language X, you don't know language Y but you want to 
learn language Y, often in that site you are able to find the 
same algorithm/code implemented in both X and Y. Comparing them 
you are able to learn some Y and  the best idioms of Y too. Just 
like the true Rosetta Stone did for Egyptian language :-)


That site has other secondary purposes:
- There you often find good computer science ideas or good 
programming ideas/tricks to learn from.
- Comparing the same algorithms in many very different languages 
you are sometimes able to catch better the essence of an 
algorithm, that is what's invariant of those implementations. A 
good book that introduces to algorithms is supposed to show this 
"essence" but often it doesn't, because a book on algorithms like 
the one by Robert Sedgewick is mostly procedural, even if he has 
written books for Java, C, C++. On that site you find wildly 
different implementations based on different programming 
paradigms, like templates, pure lazy functional, dynamic 
homoiconic functional, parallel, OOP, logic programming, 
concatenative programming, stack-based, even flow programming. 
All those programming paradigms are usually absent on books like 
Robert Sedgewick ones. And often the comparison teaches you 
something. Because sometimes an algorithm or data structure must 
be changed to fit (otherwise you get things like QuickSort or the 
Sieve of Eratosthenes implemented naively in Haskell, with so bad 
performance that they essentially have become a different 
algorithm).
- If you are interested not just in algorithms (or little 
programs) and their implementations, but also in programming 
languages themselves and their design, then that site helps you 
slowly gain a broader vision of what different languages offer to 
solve specific problems, what the "taste" of a language is, what 
languages are elegant or not, what languages seem an 
agglomeration of features, what languages are practical 
"engineering products" like D or not, what type systems seem 
intrusive and what are too much rigid, and so on and on. So if 
you want you are able to use that site to learn how to design 
languages too, a bit.

- That site has several other smaller purposes.

Bye,
bearophile


Re: Input from a newbie

2012-04-09 Thread Jonas H.

On 04/09/2012 05:39 PM, Andrej Mitrovic wrote:

I don't think the compiler can warn about this. Isn't printf one of
those unsafe C variadic functions? Someone correct me if I'm wrong.


The GCC C compiler proves you wrong :) They have warnings. I guess it's 
a hack (because printf really doesn't belong into the compiler) but that 
doesn't matter.  What matters is user-friendliness.


Re: string concatenation

2012-04-09 Thread Steven Schveighoffer

On Sun, 08 Apr 2012 01:08:09 -0400, dnewbie  wrote:


I have a wchar[] and I want to convert it to UTF8
then append a string. This is my code.

import std.c.windows.windows;
import std.string;
import std.utf;

int main()
{
   wchar[100] v;
   v[0] = 'H';
   v[1] = 'e';
   v[2] = 'l';
   v[3] = 'l';
   v[4] = 'o';
   v[5] = 0;


D does not use null terminated strings, so...


   string s = toUTF8(v) ~ ", world!";


a fixed-sized wchar array is always passed full-bore.  What you are doing  
is appending ", world!" to a 100-element char array.


The resulting string is:
Hello\0\xff\xff\xff\xff\xff, world
where that xff represnts the octet 0xff as a char, to fill out the 100  
elements.


So what you want is a slice of the original string, use v[0..n] where n is  
the length of the string.  Since you don't need that 0, you can just do  
v[0..5]:


string s = toUTF8(v[0..5]) ~ ", world!";


   MessageBoxA(null, s.toStringz, "myapp", MB_OK);
   return 0;
}

I want "Hello, world!", but the result is "Hello" only. Please help me.


Yeah, that's what I would have expected.  MessageBox is hitting that 0  
embedded in the string and stopping.


-Steve


Re: "How to set up QTD?".

2012-04-09 Thread vmars316

On Monday, 9 April 2012 at 12:52:47 UTC, Kevin Cox wrote:

I think rcc is the Qt resource compiler.  I'm not at my 
computer at the
moment to check, but if so it will translate xml resource files 
into D

source.


"I think rcc is the Qt resource compiler."
I don't know what the above means.
What are its implications?
Is my setup ok?: C:\D\dmd2\QT
Or do I need to dump 'QT Folder' into 'drcc.exe Folder'?

Also, do I need to create '*.bat' files for every '*.d' I want to 
edit/compile?

Pls, what would that .bat file look like?
Could someone show me a working cmd-line for the .bat file?
Do I need to specify 'environmental-variables'?

Thanks a lot for your helps...Vernon


Re: Input from a newbie

2012-04-09 Thread Andrej Mitrovic
On 4/9/12, Jonas  wrote:
> On Saturday, 7 April 2012 at 22:42:19 UTC, Stefan wrote:
>> printf is a C function which expects 0-terminated strings. D's
>> strings are variable-length arrays and not zero-terminated.
>>
>> Don't use printf. Try using writef instead. Same arguments.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=7872

I don't think the compiler can warn about this. Isn't printf one of
those unsafe C variadic functions? Someone correct me if I'm wrong.


Re: Issue with const

2012-04-09 Thread Steven Schveighoffer

On Mon, 09 Apr 2012 11:22:54 -0400, Jacob Carlborg  wrote:


On 2012-04-09 16:52, Timon Gehr wrote:

On 04/09/2012 04:49 PM, Jacob Carlborg wrote:


But now when I compile this code I get this error:

Error: cannot implicitly convert expression (this.data) of type
const(void*) to void*

Any idea how to solve this? Or would I need to drop const.

--
/Jacob Carlborg


Either clone the data too or use inout.


Where would I use inout, on "clone"?



// untested
inout(Foo) clone() inout {
   return new inout(Foo)(data);
}

Note, you can't post-assign data, since inout is effectively const inside  
an inout function.


-Steve


Re: Input from a newbie

2012-04-09 Thread Jonas

On Sunday, 8 April 2012 at 03:55:33 UTC, Jonathan M Davis wrote:

On Sunday, April 08, 2012 00:21:35 Jonas wrote:
1) First off, I really couldn't figure out were I was supposed 
to

post this sort of message.  Apparently there aren't any mailing
lists (a la Google groups) for D?


These are both newsgroups and mailing lists, and there's forum 
software on top

of it as well.

Newsgroups: http://www.digitalmars.com/NewsGroup.html
Mailing Lists: 
http://lists.puremagic.com/cgi-bin/mailman/listinfo

Forum: http://forum.dlang.org/

You can pick which interface you want to use. They're all the 
same thing. It's
just a question of how you access it. But no, it's not quite 
like google

groups.


Thanks Jonathan, the mailman interface is what I looked for.


Re: Issue with const

2012-04-09 Thread Jacob Carlborg

On 2012-04-09 16:52, Timon Gehr wrote:

On 04/09/2012 04:49 PM, Jacob Carlborg wrote:


But now when I compile this code I get this error:

Error: cannot implicitly convert expression (this.data) of type
const(void*) to void*

Any idea how to solve this? Or would I need to drop const.

--
/Jacob Carlborg


Either clone the data too or use inout.


Where would I use inout, on "clone"?

--
/Jacob Carlborg


Re: Input from a newbie

2012-04-09 Thread Jonas

On Saturday, 7 April 2012 at 23:58:20 UTC, bearophile wrote:

Jonas:


Hello D community! :-)


Welcome here.


I was looking for a sane, object-oriented, 
possible-to-go-low-level programming language, so I decided to 
give D a try today.


D supports OOP well enough, but template-based programming 
seems equally fit or even more. Also keep in mind that the D GC 
is not so efficient, so avoid creating too many small objects, 
as you do in Java.



1) First off, I really couldn't figure out were I was supposed 
to post this sort of message.


This is the right place.


2) I couldn't find any good documentation on the build process 
and tools I'm supposed to use. Do you guys use standard 
Makefiles? Do you have your own build system? Would be really 
helpful if that was covered on the website.


One tool fit for not huge programs is rdmd. I use "bud" still, 
but it's getting obsolete.



3) While your error messages are a lot better than GCCs (gives 
you more context, hints about how the compiler interpreted 
your buggy program, etc) it wouldn't hurt if you made them a 
bit more graphical using colors and markers and such (LLVM 
like).


I don't think Walter will love this idea.


Could you please elaborate on this a bit more? What's the problem 
with helpful compiler messages?


What are use cases for explicit pointers when passing objects? 
That's not covered in the documentation AFAIT.


It's not documented because you don't use explicit pointers to 
pass objects around. Pointers are used to pass structs around 
when you don't want to copy them.


Thanks for the explanation!

Take a look here for many small examples programs in D to do 
many different kind of things (not all of them are up to date 
or fully correct, but most of them are good, and the wrong ones 
are being fixed one after the other):

http://rosettacode.org/wiki/Category:D


That looks great, thanks, although it's a bit cluttered with all 
those languages ;-)


Re: Input from a newbie

2012-04-09 Thread Jonas

On Saturday, 7 April 2012 at 22:42:19 UTC, Stefan wrote:

printf is a C function which expects 0-terminated strings. D's
strings are variable-length arrays and not zero-terminated.

Don't use printf. Try using writef instead. Same arguments.


http://d.puremagic.com/issues/show_bug.cgi?id=7872



Re: Issue with const

2012-04-09 Thread Timon Gehr

On 04/09/2012 04:49 PM, Jacob Carlborg wrote:


But now when I compile this code I get this error:

Error: cannot implicitly convert expression (this.data) of type
const(void*) to void*

Any idea how to solve this? Or would I need to drop const.

--
/Jacob Carlborg


Either clone the data too or use inout.


Issue with const

2012-04-09 Thread Jacob Carlborg

Say I have type and a function look like this:

class Foo
{
void* data;

Foo clone ()
{
auto c = new Foo;
c.data = data;

return c;
}
}

void bar (Foo foo)
{
auto c = foo.clone();
...
}

Since I'm not changing anything on "foo" I thought that it could be a 
good idea to declare it as const.


void bar (const Foo foo)
{
auto c = foo.clone();
...
}

In this case I also have to make "clone" const as well. Which is fine 
sine "clone" doesn't change any of the fields.


class Foo
{
void* data;

Foo clone () const
{
auto c = new Foo;
c.data = data;

return c;
}
}

But now when I compile this code I get this error:

Error: cannot implicitly convert expression (this.data) of type 
const(void*) to void*


Any idea how to solve this? Or would I need to drop const.

--
/Jacob Carlborg


Re: "How to set up QTD?".

2012-04-09 Thread Kevin Cox
On Apr 8, 2012 10:59 PM, "vmars316"  wrote:
>
> Greetings,
> I would also like to try out QTD.
>
> So far, I have set things up this:
> C:\D\dmd2\QT
>
> I made a .batch file for both drcc.exe and duic.exe .
> duic.exe gave no feedback.
>
> drcc.exe gave the following feedback:
>
> C:\D\dmd2\QT\bin>ECHO ON
>
> C:\D\dmd2\QT\bin>drcc.exe
> Qt resource compiler
> Usage: drcc.exe  [options] 
>
> Options:
>  -o filewrite output to file rather than stdout
>  -name name create an external initialization function with
name
>  -threshold level   threshold to consider compressing files
>  -compress levelcompress input files by level
>  -root path prefix resource access path with root path
>  -no-compress   disable all compression
>  -no-static-initialize  disable automatic initialization of resources
with prog
> ram start
>  -binaryoutput a binary file for use as a dynamic resource
>  -namespace turn off namespace macros
>  -project   Output a resource file containing all
> files from the current directory
>  -version   display version
>  -help  display this information
>
> C:\D\dmd2\QT\bin>REM C:\D\dmd2\windows\bin\dmd.exe
>
> C:\D\dmd2\QT\bin>pause
> Press any key to continue . . .
>
> Pls, do I need to re-do file/Folder placement?
> Also, do I need to create .bat files for every .d I want to compile?
> Can someone show me how to get qtd running?
>
> Thanks...Vernon
>
>

I think rcc is the Qt resource compiler.  I'm not at my computer at the
moment to check, but if so it will translate xml resource files into D
source.


Re: Operator Overloading with class template

2012-04-09 Thread Eyyub

On Monday, 9 April 2012 at 09:09:05 UTC, James Miller wrote:
* Eyyub  [2012-04-09 01:14:32 
+0200]:



Hello,

How can I rewrite the exemple 2 (http://pastebin.com/q50903Zh) 
in D

lang. ?
This source code doesn't work...why ?
http://paste.pocoo.org/show/wy1kDIpqTi2ApRuOxRRb/

Thx. :)



What you want is something like this:

class Value(int M, int K, int S)
{

private
{
float _value;
}

public
{
this(float val)
{
_value = val;
}

auto opBinary(string op : "/", int MO, int KO, int 
SO)(Value(MO, KO, SO) other) {
return new Value!(M-MO, K-KO, 
S-SO)(_value/other.value);

}

}
}

A Few notes:
1. This isn't tested, might not work, but thats where you 
should aim...
2. Operator overloading is implemented as a lowering (as far as 
I'm aware) the
   compiler emits a template instantiation of opBinary("/") for 
the type. That

   means that you can add on more template arguments.
3. Using `auto` means that the compiler works out the type, so 
you don't have
   to add extra template arguments to calculate the correct 
type.


Hope that helps.

--
James Miller


Ho, yeah it works !!! :D :D

http://paste.pocoo.org/show/ye7VXQHfLxsVM38bKyS6/

Thanks a lot !


Re: Operator Overloading with class template

2012-04-09 Thread James Miller
* Eyyub  [2012-04-09 01:14:32 +0200]:

> Hello,
> 
> How can I rewrite the exemple 2 (http://pastebin.com/q50903Zh) in D
> lang. ?
> This source code doesn't work...why ?
> http://paste.pocoo.org/show/wy1kDIpqTi2ApRuOxRRb/
> 
> Thx. :)
> 

What you want is something like this:

class Value(int M, int K, int S)
{

private
{
float _value;
}

public
{
this(float val)
{
_value = val;
}

auto opBinary(string op : "/", int MO, int KO, int SO)(Value(MO, 
KO, SO) other) {
return new Value!(M-MO, K-KO, S-SO)(_value/other.value);
}

}
}

A Few notes:
1. This isn't tested, might not work, but thats where you should aim...
2. Operator overloading is implemented as a lowering (as far as I'm aware) the
   compiler emits a template instantiation of opBinary("/") for the type. That
   means that you can add on more template arguments.
3. Using `auto` means that the compiler works out the type, so you don't have
   to add extra template arguments to calculate the correct type.

Hope that helps.

--
James Miller