Re: DMD chokes on UDAs of mixin enum members

2013-04-26 Thread BLM768

That's probably it. I guess I'll have to work around it for now.

On Saturday, 27 April 2013 at 00:21:02 UTC, anonymous wrote:

On Friday, 26 April 2013 at 21:50:51 UTC, BLM768 wrote:
[...]

Is there some subtle point I'm missing, or is this just a bug?


Looks like http://d.puremagic.com/issues/show_bug.cgi?id=9652




Re: DMD chokes on UDAs of mixin enum members

2013-04-26 Thread anonymous

On Friday, 26 April 2013 at 21:50:51 UTC, BLM768 wrote:
[...]

Is there some subtle point I'm missing, or is this just a bug?


Looks like http://d.puremagic.com/issues/show_bug.cgi?id=9652


Re: Internationalization vs. Unicode

2013-04-26 Thread H. S. Teoh
On Fri, Apr 26, 2013 at 06:09:48PM -0400, Tyro[17] wrote:
> There are myriad encoding schemes. D natively supports Unicode and
> provide functionality via phobos. A byproduct of this is that since
> ASCII is a subset of Unicode, it also natively support ASCII. This
> is a plus for the language but what of the other encoding schemes?
> What library functionality is provided to manipulate or convert
> between those encoding schemes and Unicode?
> 
> I have a need to convert from CKJ encoding (presently EUC-JP and
> Shift-JIS) to Unicode. How do I accomplish this using D/Phobos? Is
> there a standalone library that does this? If so, can someone point
> me to it? If not, is there planned functionality for inclusion in
> phobos or am I doomed to resorting to Java or some other language to
> accomplish this task (or at least until I'm educated enough to do it
> myself)?
[...]

If you're using a Posix system, you could look into the 'recode' utility
to convert from those legacy formats to Unicode before using your
program on them. You may be able to figure out how to do it by looking
at recode's source code. But AFAIK there is no way to do it in D
currently.

Maybe someone should invent std.recode and submit it for inclusion into
Phobos. ;-)


T

-- 
People tell me that I'm paranoid, but they're just out to get me.


Internationalization vs. Unicode

2013-04-26 Thread Tyro[17]
There are myriad encoding schemes. D natively supports Unicode and 
provide functionality via phobos. A byproduct of this is that since 
ASCII is a subset of Unicode, it also natively support ASCII. This is a 
plus for the language but what of the other encoding schemes? What 
library functionality is provided to manipulate or convert between those 
encoding schemes and Unicode?


I have a need to convert from CKJ encoding (presently EUC-JP and 
Shift-JIS) to Unicode. How do I accomplish this using D/Phobos? Is there 
a standalone library that does this? If so, can someone point me to it? 
If not, is there planned functionality for inclusion in phobos or am I 
doomed to resorting to Java or some other language to accomplish this 
task (or at least until I'm educated enough to do it myself)?


Thanks,
Andrew


Re: writeln, UFCS and flip

2013-04-26 Thread bearophile

Tyro[17]:

With that clarification, I just have one more question, since 
flip does what is intuitively implied by a reverse function


OK, better to name it reversedArgs :-)



and flip2 does what is intuitively implied by a flip function,


flip2 swaps just the fist two arguments and leaves the others at 
their place.



I would expect a flip and flip2 if both accomplish the exact 
same thing but both outperforms the other in certain scenarios 
thus warranting both to be present.


I think that the caos of this thread shows that keeping both will 
cause confusion :-(



why not name them as such? Understand the Haskell influence and 
all but, influence notwithstanding, this is D so why not 
designate functions in a manner that intuitively imply 
functionality?


I am starting to agree with Andrei. Short function names are 
handy, but in many situations the semantic confusion they can 
bring is not worth it. More food for thought for me.


Bye,
bearophile


DMD chokes on UDAs of mixin enum members

2013-04-26 Thread BLM768

I've got some code that reduces to the following test case:

--
mixin template stuff() {
enum someEnum = "testing";

static void test() {
foreach(member; __traits(allMembers, typeof(this))) {
pragma(msg, member);
			foreach(attribute; __traits(getAttributes, __traits(getMember, 
typeof(this), member))) {

pragma(msg, attribute);
}
}
}
}

enum Attribute;

struct Test {
mixin stuff;

@Attribute size_t n;
}
--

DMD handles most of the members just fine, but it is unable to 
process someEnum:


--

rdmd case.d

someEnum
case.d(7): Error: first argument is not a symbol
case.d(7): Error: invalid foreach aggregate false
test
n
Attribute
--

Is there some subtle point I'm missing, or is this just a bug?


Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]

On 4/26/13 5:09 PM, Tyro[17] wrote:

On 4/26/13 4:15 PM, bearophile wrote:

Tyro[17]:


> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate


Really? Just swapping the first two arguments and leaving the others at
their place is for a "rotate"?



Actually, by brain was thinking it but my eyes saw something completely
different. You are correct, this what I would expect flip to do. Thanks.


Why flip in the first place?


I don't know, it's the name used in the Haskell Prelude.

Bye,
bearophile




With that clarification, I just have one more question, since flip does 
what is intuitively implied by a reverse function and flip2 does what is 
intuitively implied by a flip function, why not name them as such? 
Understand the Haskell influence and all but, influence notwithstanding, 
this is D so why not designate functions in a manner that intuitively 
imply functionality?


I would expect a flip and flip2 if both accomplish the exact same thing 
but both outperforms the other in certain scenarios thus warranting both 
to be present.


Andrew


Re: Simple delete directory tree?

2013-04-26 Thread Nick Sabalausky
On Fri, 26 Apr 2013 17:01:43 -0400
Nick Sabalausky  wrote:

> On Fri, 26 Apr 2013 22:55:36 +0200
> "Andrej Mitrovic"  wrote:
> 
> > On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:
> > > Does phobos have a simple way to delete a directory tree?
> > > std.file.rmdir(path) and std.file.remove(path) don't seem to do 
> > > it.
> > 
> > Try rmdirRecurse
> 
> I don't know how I managed to overlook that! Thanks :)
> 
> Unfortunately, that's still choking with "Access is denied" on
> something inside a ".git" subdirectory.
> 

FWIW, This seems to work fine, at least on windows:

import std.process;
version(Windows)
system(`rmdir /S /Q "`~path~`"`);
else
system(`rm -rf '`~path~`'`);



Re: Simple delete directory tree?

2013-04-26 Thread Nick Sabalausky
On Fri, 26 Apr 2013 23:15:20 +0200
Andrej Mitrovic  wrote:

> On 4/26/13, Nick Sabalausky 
> wrote:
> > I don't know how I managed to overlook that! Thanks :)
> 
> I'd actually prefer if it was an enum or some other default parameter
> in the rmdir function itself:
> 
> rmdir(string path, bool doRecurse = false);

Yea, that'd be kinda nice.



Re: Simple delete directory tree?

2013-04-26 Thread Andrej Mitrovic
On 4/26/13, Nick Sabalausky  wrote:
> I don't know how I managed to overlook that! Thanks :)

I'd actually prefer if it was an enum or some other default parameter
in the rmdir function itself:

rmdir(string path, bool doRecurse = false);


Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]

On 4/26/13 4:15 PM, bearophile wrote:

Tyro[17]:


> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate


Really? Just swapping the first two arguments and leaving the others at
their place is for a "rotate"?



Actually, by brain was thinking it but my eyes saw something completely 
different. You are correct, this what I would expect flip to do. Thanks.



Why flip in the first place?


I don't know, it's the name used in the Haskell Prelude.

Bye,
bearophile




Re: Simple delete directory tree?

2013-04-26 Thread Nick Sabalausky
On Fri, 26 Apr 2013 22:55:36 +0200
"Andrej Mitrovic"  wrote:

> On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:
> > Does phobos have a simple way to delete a directory tree?
> > std.file.rmdir(path) and std.file.remove(path) don't seem to do 
> > it.
> 
> Try rmdirRecurse

I don't know how I managed to overlook that! Thanks :)

Unfortunately, that's still choking with "Access is denied" on
something inside a ".git" subdirectory.



Re: Simple delete directory tree?

2013-04-26 Thread Andrej Mitrovic

On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:

Does phobos have a simple way to delete a directory tree?
std.file.rmdir(path) and std.file.remove(path) don't seem to do 
it.


Try rmdirRecurse


Simple delete directory tree?

2013-04-26 Thread Nick Sabalausky
Does phobos have a simple way to delete a directory tree?
std.file.rmdir(path) and std.file.remove(path) don't seem to do it.



Re: writeln, UFCS and flip

2013-04-26 Thread Timon Gehr

On 04/26/2013 10:15 PM, bearophile wrote:

Tyro[17]:


> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate


Really? Just swapping the first two arguments and leaving the others at
their place is for a "rotate"?



Why flip in the first place?


I don't know, it's the name used in the Haskell Prelude.



And there it flips the first two arguments (of a curried function, since 
this is the standard for Haskell).




Re: writeln, UFCS and flip

2013-04-26 Thread bearophile

Tyro[17]:


> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate


Really? Just swapping the first two arguments and leaving the 
others at their place is for a "rotate"?




Why flip in the first place?


I don't know, it's the name used in the Haskell Prelude.

Bye,
bearophile


improve compile-time template

2013-04-26 Thread Namespace
Hi, I would like to see a few improvement suggestions for my 
template which can be found here: http://dpaste.1azy.net/9bf89ef9
It works mostly pretty nice so far, but it's a bit clumsy and I'm 
sure that it could be improved. Also it does not work correct for 
cases like

void foo(ref A a, int n) (as you can see by 'foo').


Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]

On 4/26/13 8:59 AM, bearophile wrote:
> ixid:
>
>> flip2 is the more general and useful function with new functionality
>> so there's no need for what was flip and we should call the new
>> function 'flip'.
>
> I don't agree. Maybe you are missing something.
>
> I expect a function named "flip" to do:
>
> flip!foo(a, b, c) === foo(c, b, a)
> flip!foo(a, b, c, d) === foo(d, c, b, a)

I would expect this to be called reverse

> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate

Why flip in the first place?

> Bye,
> bearophile



Re: std.net.curl is not working?

2013-04-26 Thread mab

On Friday, 26 April 2013 at 18:14:04 UTC, Jordi Sayol wrote:
[...]

You need to install the development curl package:

$ sudo apt-get install libcurl4-openssl-dev
or
$ sudo apt-get install libcurl4-gnutls-dev
or
$ sudo apt-get install libcurl4-nss-dev


[...]

That´s it.
Thank you!


Re: std.net.curl is not working?

2013-04-26 Thread John Colvin

On Friday, 26 April 2013 at 17:55:59 UTC, mab wrote:

Thank you for answering. But it didnt work.

I get:
#dmd hello.d -L-lcurl
/usr/bin/ld: cannot find -lcurl
collect2: ld returned 1 exit status
--- errorlevel 1

Curl is installed, as also libcurl3.

I forget to mention that i am using "DMD64 D Compiler v2.062".
Is std.net.curl working in this Version? Because it also didnt 
work on my Windows 7 System.


Do you know what the libcurl library is actually called on your 
system? (try "find /usr -name "*curl*.so*" " or "find /usr -name 
"*curl*.a*" )


if the name you find is e.g. "libcurl3.so" then you'll have to 
use the linker flag -lcurl3 instead of lcurl


p.s. Please don't be offended if you're already fully aware of 
this, it's just better to make sure the basics are covered first.


Re: std.net.curl is not working?

2013-04-26 Thread Ali Çehreli

On 04/26/2013 10:55 AM, mab wrote:

> Thank you for answering. But it didnt work.
>
> I get:
> #dmd hello.d -L-lcurl
> /usr/bin/ld: cannot find -lcurl

Try providing the directory that the curl library file is in:

#dmd hello.d -L-L/wherever/libcurl/is/in -L-lcurl

Ali



Re: std.net.curl is not working?

2013-04-26 Thread Jordi Sayol
On 26/04/13 19:55, mab wrote:
> Thank you for answering. But it didnt work.
> 
> I get:
> #dmd hello.d -L-lcurl
> /usr/bin/ld: cannot find -lcurl
> collect2: ld returned 1 exit status
> --- errorlevel 1
> 
> Curl is installed, as also libcurl3.

You need to install the development curl package:

$ sudo apt-get install libcurl4-openssl-dev
or
$ sudo apt-get install libcurl4-gnutls-dev
or
$ sudo apt-get install libcurl4-nss-dev

> 
> I forget to mention that i am using "DMD64 D Compiler v2.062".
> Is std.net.curl working in this Version? Because it also didnt work on my 
> Windows 7 System.
> 

-- 
Jordi Sayol


Re: How/why can toStringz() and toUTFz() be used as properties?

2013-04-26 Thread Ali Çehreli

On 04/26/2013 01:49 AM, anonymous wrote:

> On Friday, 26 April 2013 at 07:31:57 UTC, Trey Brisbane wrote:

> UFCS should be explained in the online language documentation,
> but if it's in there I can't find it.

Me neither. I wonder where in the language syntax a "function call" lives...

UFCS does not require more than what you have already said but it looks 
like I had managed to fill up more space than a couple of paragraphs: :)


  http://ddili.org/ders/d.en/ufcs.html

Ali



Re: std.net.curl is not working?

2013-04-26 Thread mab

Thank you for answering. But it didnt work.

I get:
#dmd hello.d -L-lcurl
/usr/bin/ld: cannot find -lcurl
collect2: ld returned 1 exit status
--- errorlevel 1

Curl is installed, as also libcurl3.

I forget to mention that i am using "DMD64 D Compiler v2.062".
Is std.net.curl working in this Version? Because it also didnt 
work on my Windows 7 System.


Re: does GtkD (win7) support opengl?

2013-04-26 Thread Mike Wey

On 04/26/2013 05:16 AM, Alexandr Druzhinin wrote:

26.04.2013 3:45, Mike Wey пишет:


http://gtkd.org/Downloads/SimpleGL.zip

After updating dmd the demo no longer draws the triangle, i still need
to figure out why.


Link is broken


Should be working now.

--
Mike Wey


Re: std.net.curl is not working?

2013-04-26 Thread ollie
On Fri, 26 Apr 2013 19:25:16 +0200, mab wrote:

> undefined reference to `curl_global_init'
> undefined reference to `curl_global_cleanup'

These functions are defined in libcurl. Make sure you have installed 
libcurl if it wasn't installed as a dependency for curl.


Re: std.net.curl is not working?

2013-04-26 Thread qznc
Fri, 26 Apr 2013 19:25:16 +0200: mab wrote

> Why i get the following Error, when i try to compile a simple "Hello
> World" that imports std.net.curl=
> 
> The Error:
> # dmd hello.d /usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In
> function `_D3std3net4curl4Curl19_sharedStaticCtor28FZv':
> std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticCtor28FZv+0xf):
> undefined reference to `curl_global_init'
> /usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function
> `_D3std3net4curl4Curl19_sharedStaticDtor29FZv':
> std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticDtor29FZv+0x5):
> undefined reference to `curl_global_cleanup'
> collect2: ld returned 1 exit status --- errorlevel 1
> 
> The Code:
> import std.stdio;
> import std.net.curl;
> 
> void main()
> {
>writeln("hello world");
> }
> 
> My Testsystem: Debian # uname -a Linux dexplorer 2.6.32-5-amd64 #1 SMP
> Mon Feb 25 00:26:11 UTC 2013 x86_64 GNU/Linux
> 
> curl is installed by apt-get install curl.
> 
> Thanks!

You have to link libcurl via argument:

  dmd hello.d -L-lcurl


std.net.curl is not working?

2013-04-26 Thread mab
Why i get the following Error, when i try to compile a simple 
"Hello World" that imports std.net.curl=


The Error:
# dmd hello.d
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function 
`_D3std3net4curl4Curl19_sharedStaticCtor28FZv':
std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticCtor28FZv+0xf): 
undefined reference to `curl_global_init'
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function 
`_D3std3net4curl4Curl19_sharedStaticDtor29FZv':
std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticDtor29FZv+0x5): 
undefined reference to `curl_global_cleanup'

collect2: ld returned 1 exit status
--- errorlevel 1

The Code:
import std.stdio;
import std.net.curl;

void main()
{
  writeln("hello world");
}

My Testsystem: Debian
# uname -a
Linux dexplorer 2.6.32-5-amd64 #1 SMP Mon Feb 25 00:26:11 UTC 
2013 x86_64 GNU/Linux


curl is installed by apt-get install curl.

Thanks!


Re: How/why can toStringz() and toUTFz() be used as properties?

2013-04-26 Thread ollie
On Fri, 26 Apr 2013 09:31:54 +0200, Trey Brisbane wrote:

> I need to understand this, as I wish to write a function toWinStr() that
> can be used in the same way which will accept any string type, and,
> based on something like version(Unicode) and const-ness, output a WinAPI
> LPSTR, LPCSTR, LPWSTR or LPCWSTR as appropriate.
> Is such a thing possible?

You might want to look at std.windows.charset. You'll find the following 
functions:

const(char)* toMBSz(in char[] s, uint codePage = 0)
string fromMBSz(immutable(char)* s, int codePage = 0)

These might work for you or you may be able to expand on them.


Re: writeln, UFCS and flip

2013-04-26 Thread bearophile

ixid:

flip2 is the more general and useful function with new 
functionality so there's no need for what was flip and we 
should call the new function 'flip'.


I don't agree. Maybe you are missing something.

I expect a function named "flip" to do:

flip!foo(a, b, c) === foo(c, b, a)
flip!foo(a, b, c, d) === foo(d, c, b, a)

While flip2 does:

flip2!foo(a, b, c) === foo(b, a, c)
flip2!foo(a, b, c, d) === foo(b, a, c, d)

Bye,
bearophile


Re: writeln, UFCS and flip

2013-04-26 Thread ixid

On Friday, 26 April 2013 at 10:52:09 UTC, bearophile wrote:

Timon Gehr:


I think what you call flip2 should be called flip.


Why?

Bye,
bearophile


flip2 is the more general and useful function with new 
functionality so there's no need for what was flip and we should 
call the new function 'flip'.




Re: How/why can toStringz() and toUTFz() be used as properties?

2013-04-26 Thread Trey Brisbane

On Friday, 26 April 2013 at 08:49:10 UTC, anonymous wrote:

On Friday, 26 April 2013 at 07:31:57 UTC, Trey Brisbane wrote:

Hey all,

Can someone please explain to me how and why it is that 
toStringz() and toUTFz() can be used in the following way?


string a = "123";
auto b = a.toStringz;
auto c = a.toUTFz;

Also, how is it that they can even be called as if they were 
class methods? That is:


string a = "123";
auto b = a.toStringz(); // <-- Note I've added parentheses
auto c = a.toUTFz();

As opposed to being limited to:

string a = "123";
auto b = toStringz(a);
auto c = toUTFz(a);


There's two things at work here:

a) Universal Function Call Syntax (UFCS). That basically means 
that you can call a free function via method/property-like dot 
syntax. The first argument to the function goes before the dot. 
UFCS should be explained in the online language documentation, 
but if it's in there I can't find it.

So, with UFCS you get from  toStringz(a)  to  a.toStringz() .

b) Empty parentheses are optional. -- Unless you compile with 
the -property flag. There has been some discussion about the 
future of the feature. Optional empty parentheses and/or the 
-property flag may go away in the future.

That gets you from  a.toString()  to  a.toString .

I need to understand this, as I wish to write a function 
toWinStr() that can be used in the same way which will accept 
any string type, and, based on something like version(Unicode) 
and const-ness, output a WinAPI LPSTR, LPCSTR, LPWSTR or 
LPCWSTR as appropriate.

Is such a thing possible?


You just write your function so that  toWinStr(stuff)  works. 
UFCS and optional empty parentheses then enable  stuff.toWinStr 
.


Ahhh ok, thanks for explaining :)


Re: writeln, UFCS and flip

2013-04-26 Thread bearophile

Timon Gehr:


I think what you call flip2 should be called flip.


Why?

Bye,
bearophile


Re: How/why can toStringz() and toUTFz() be used as properties?

2013-04-26 Thread anonymous

On Friday, 26 April 2013 at 07:31:57 UTC, Trey Brisbane wrote:

Hey all,

Can someone please explain to me how and why it is that 
toStringz() and toUTFz() can be used in the following way?


string a = "123";
auto b = a.toStringz;
auto c = a.toUTFz;

Also, how is it that they can even be called as if they were 
class methods? That is:


string a = "123";
auto b = a.toStringz(); // <-- Note I've added parentheses
auto c = a.toUTFz();

As opposed to being limited to:

string a = "123";
auto b = toStringz(a);
auto c = toUTFz(a);


There's two things at work here:

a) Universal Function Call Syntax (UFCS). That basically means 
that you can call a free function via method/property-like dot 
syntax. The first argument to the function goes before the dot. 
UFCS should be explained in the online language documentation, 
but if it's in there I can't find it.

So, with UFCS you get from  toStringz(a)  to  a.toStringz() .

b) Empty parentheses are optional. -- Unless you compile with the 
-property flag. There has been some discussion about the future 
of the feature. Optional empty parentheses and/or the -property 
flag may go away in the future.

That gets you from  a.toString()  to  a.toString .

I need to understand this, as I wish to write a function 
toWinStr() that can be used in the same way which will accept 
any string type, and, based on something like version(Unicode) 
and const-ness, output a WinAPI LPSTR, LPCSTR, LPWSTR or 
LPCWSTR as appropriate.

Is such a thing possible?


You just write your function so that  toWinStr(stuff)  works. 
UFCS and optional empty parentheses then enable  stuff.toWinStr .


How/why can toStringz() and toUTFz() be used as properties?

2013-04-26 Thread Trey Brisbane

Hey all,

Can someone please explain to me how and why it is that 
toStringz() and toUTFz() can be used in the following way?


string a = "123";
auto b = a.toStringz;
auto c = a.toUTFz;

Also, how is it that they can even be called as if they were 
class methods? That is:


string a = "123";
auto b = a.toStringz(); // <-- Note I've added parentheses
auto c = a.toUTFz();

As opposed to being limited to:

string a = "123";
auto b = toStringz(a);
auto c = toUTFz(a);

I need to understand this, as I wish to write a function 
toWinStr() that can be used in the same way which will accept any 
string type, and, based on something like version(Unicode) and 
const-ness, output a WinAPI LPSTR, LPCSTR, LPWSTR or LPCWSTR as 
appropriate.

Is such a thing possible?