Difference between is and ==

2014-02-04 Thread Suliman
What difference between if ((x = stdin.readln().chomp) is q) and if ((x = stdin.readln().chomp) == q) ?

Re: Difference between is and ==

2014-02-04 Thread Martijn Pot
On Tuesday, 4 February 2014 at 08:08:30 UTC, Suliman wrote: What difference between if ((x = stdin.readln().chomp) is q) and if ((x = stdin.readln().chomp) == q) ? My interpretation of tdpl p57: 'is' compares for alias equality for arrays and classes. Otherwise they are the same.

Re: Difference between is and ==

2014-02-04 Thread Suliman
My interpretation of tdpl p57: 'is' compares for alias equality for arrays and classes. Otherwise they are the same. So should next code have same behavior if I will use is instead of == import std.stdio; import std.string; void main() { getchar(); } void getchar() {

Re: Difference between is and ==

2014-02-04 Thread Martijn Pot
On Tuesday, 4 February 2014 at 08:25:18 UTC, Suliman wrote: My interpretation of tdpl p57: 'is' compares for alias equality for arrays and classes. Otherwise they are the same. So should next code have same behavior if I will use is instead of == import std.stdio; import std.string; void

Re: Difference between is and ==

2014-02-04 Thread bearophile
Suliman: What difference between if ((x = stdin.readln().chomp) is q) and if ((x = stdin.readln().chomp) == q) ? is performs a raw comparison of just the values, and the value of a string is its ptr and length field. While == compares their contents. So you want to use == here because you

Get struct template types

2014-02-04 Thread ed
Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a look at std.typecons and std.typetuple but I don't see what I'm missing something and cannot see a way to do the

Re: Get struct template types

2014-02-04 Thread evilrat
On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a look at std.typecons and std.typetuple but I don't see

Re: 3d vector struct

2014-02-04 Thread Francesco Cattoglio
On Monday, 3 February 2014 at 20:10:59 UTC, Brenton wrote: 6) Any other comments or suggestions? I know that the I'm learning the language factor plays a huge role, but after you are done studying your vector implementation, I think you could forget about it and use the ones provided by

Re: Get struct template types

2014-02-04 Thread evilrat
On Tuesday, 4 February 2014 at 09:39:48 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had

Decorators, Annotations, Macros, AST transforms…

2014-02-04 Thread Russel Winder
…choose you favourite term. Following on from trying to use D to write CPython extensions without using PyD: entry points will be functions: extern(C) type name() { initializeIfNoAlreadyDone(); … } This immediately looks like a job for a Python decorator. @pythonentry type name() { … }

Re: Python calling D

2014-02-04 Thread Russel Winder
On Tue, 2014-02-04 at 07:13 +, Artem Tarasov wrote: On Sunday, 2 February 2014 at 15:31:30 UTC, Russel Winder wrote: result is: | LD_LIBRARY_PATH=. python execute.py Segmentation fault You should call Runtime.initialize() prior to calling any other D functions.

Re: Get struct template types

2014-02-04 Thread evilrat
On Tuesday, 4 February 2014 at 09:58:53 UTC, ed wrote: On Tuesday, 4 February 2014 at 09:46:01 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:39:48 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is

Re: Get struct template types

2014-02-04 Thread Jakob Ovrum
On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a look at std.typecons and std.typetuple but I don't see

Re: Templates: generic return null;

2014-02-04 Thread Chris
On Tuesday, 4 February 2014 at 00:43:54 UTC, TheFlyingFiddle wrote: On Monday, 3 February 2014 at 10:25:19 UTC, Chris wrote: Is there a way I can make the return type in getAttribute generic? null does not work with numbers. MyStruct(T) { T[T] attributes; // public auto getAttribute(T

Re: Decorators, Annotations, Macros, AST transforms…

2014-02-04 Thread Dicebot
P.P.S. proof-of-concept implemenation of function attributes a bit more similar t python decorators : https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/internal/meta/funcattr.d

Re: Python calling D

2014-02-04 Thread Artem Tarasov
On Tuesday, 4 February 2014 at 11:33:40 UTC, Russel Winder wrote: The question is how to get this run. Pointing out obvious things, part 2: wrap it into a C function and call that function when loading the Python module. library.d: ... extern (C) export void attach() { Runtime.initialize();

How can i find my LAN IP Address using std.socket?

2014-02-04 Thread TheFlyingFiddle
I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket)

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Dicebot
On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) You can have lot of different local IP addresses on a single machine so

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) Create a connection to another LAN machine with a known address (e.g.

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Dicebot
On Tuesday, 4 February 2014 at 13:21:54 UTC, Stanislav Blinov wrote: Create a connection to another LAN machine with a known address (e.g. gateway or router), then use Socket's localAddress property to get your IP. Worth noting that this solution is not reliable in general either because

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread TheFlyingFiddle
On Tuesday, 4 February 2014 at 13:13:07 UTC, Dicebot wrote: On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) You can have

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread TheFlyingFiddle
On Tuesday, 4 February 2014 at 13:21:54 UTC, Stanislav Blinov wrote: On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket)

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 13:31:27 UTC, TheFlyingFiddle wrote: Problem is that i don't know in what local network the server will be running, so this is unfortunatly not an option for me. But if that's the case, the hostname solution may as well just give you your loopback address. :)

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Craig Dillabaugh
On Tuesday, 4 February 2014 at 15:48:50 UTC, Vladimir Panteleev wrote: On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket)

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Dicebot
On Tuesday, 4 February 2014 at 16:02:33 UTC, Craig Dillabaugh wrote: However if I run /sbin/ifconfig I get: enp7s0Link encap:Ethernet HWaddr 50:E5:49:9B:29:49 inet addr:10.1.101.52 Bcast:10.1.101.255 Mask:255.255.255.0 inet6 addr: fe80::52e5:49ff:fe9b:2949/64

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Vladimir Panteleev
On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) This program will print all of your computer's IP addresses: import

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Dicebot
On Tuesday, 4 February 2014 at 16:13:33 UTC, Dicebot wrote: It results in all addresses you hostname resolvs to. On all desktop linux machines /etc/hosts is configured to resolve hostname to localhost by default. On servers it usually resolves to externally accessible one. Update: I have

Re: Python calling D

2014-02-04 Thread Russel Winder
On Tue, 2014-02-04 at 12:45 +, Artem Tarasov wrote: On Tuesday, 4 February 2014 at 11:33:40 UTC, Russel Winder wrote: The question is how to get this run. Pointing out obvious things, part 2: wrap it into a C function and call that function when loading the Python module. I had

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Stanislav Blinov
On Tuesday, 4 February 2014 at 16:02:33 UTC, Craig Dillabaugh wrote: This computer is on a network with dynamically assigned IP address (DHCP). So shouldn't the 10.1.101.52 address have been reported? Nope. In out-of-the-box simple network setups (i.e. home network in the form PC/laptop -

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Craig Dillabaugh
On Tuesday, 4 February 2014 at 16:13:33 UTC, Dicebot wrote: On Tuesday, 4 February 2014 at 16:02:33 UTC, Craig Dillabaugh wrote: However if I run /sbin/ifconfig I get: enp7s0Link encap:Ethernet HWaddr 50:E5:49:9B:29:49 inet addr:10.1.101.52 Bcast:10.1.101.255

What does the alias attribute do here

2014-02-04 Thread Gary Willoughby
What does the alias attribute do here: void foo(alias bar) { ... } What is the idea behind this attribute when used here?

Re: What does the alias attribute do here

2014-02-04 Thread Adam D. Ruppe
On Tuesday, 4 February 2014 at 17:09:02 UTC, Gary Willoughby wrote: What does the alias attribute do here: void foo(alias bar) This specifically won't compile, alias params are only allowed in a compile-time list. So void foo(alias bar)() { ... } would work. Anyway, what it does is

Help with array maniipulation

2014-02-04 Thread ollie
I have a C Struct: typedef struct { enum LibRaw_image_formats type; ushort height, width, colors, bits; unsigned int data_size; unsigned char data[1]; }libraw_processed_image_t; with a D

Re: Help with array maniipulation

2014-02-04 Thread Ali Çehreli
On 02/04/2014 10:58 AM, ollie wrote: I have a C Struct: [...] uintdata_size; ubyte[1]data; Is that the C extension where the last array in a struct can have more elements than its size? That will be a problem in D. }

Re: Difference between is and ==

2014-02-04 Thread Steven Schveighoffer
On Tue, 04 Feb 2014 03:08:28 -0500, Suliman everm...@live.ru wrote: What difference between if ((x = stdin.readln().chomp) is q) and if ((x = stdin.readln().chomp) == q) ? The first compares the pointer of the arrays. The second compares the contents of the array. Both check length as well

Re: What does the alias attribute do here

2014-02-04 Thread Gary Willoughby
On Tuesday, 4 February 2014 at 17:17:13 UTC, Adam D. Ruppe wrote: On Tuesday, 4 February 2014 at 17:09:02 UTC, Gary Willoughby wrote: What does the alias attribute do here: void foo(alias bar) This specifically won't compile, alias params are only allowed in a compile-time list. So

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread TheFlyingFiddle
On Tuesday, 4 February 2014 at 13:24:59 UTC, Dicebot wrote: On Tuesday, 4 February 2014 at 13:21:54 UTC, Stanislav Blinov wrote: Worth noting that this solution is not reliable in general either because your server can possibly have complicated routing configurations that will make, for

Re: Help with array maniipulation

2014-02-04 Thread ollie
On Tue, 04 Feb 2014 11:16:00 -0800, Ali Çehreli wrote: Is that the C extension where the last array in a struct can have more elements than its size? That will be a problem in D. yes it is. int[] D_slice = C_array[0 .. C_array_number_of_elements]; Thank you, that gives me what I was

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Johannes Pfau
Am Tue, 04 Feb 2014 16:19:08 + schrieb Stanislav Blinov stanislav.bli...@gmail.com: On Tuesday, 4 February 2014 at 16:02:33 UTC, Craig Dillabaugh wrote: This computer is on a network with dynamically assigned IP address (DHCP). So shouldn't the 10.1.101.52 address have been

Re: How can i find my LAN IP Address using std.socket?

2014-02-04 Thread Dicebot
On Tuesday, 4 February 2014 at 20:19:14 UTC, TheFlyingFiddle wrote: I'm setting up a simple local network enabling me to connect phones to the computer through the local wi-fi. The simplest way i could think of to make this work without relying on an external server was to simply broadcast the

Re: Help with array maniipulation

2014-02-04 Thread bearophile
Ali Çehreli: Is that the C extension where the last array in a struct can have more elements than its size? That will be a problem in D. Since V.2.065 D supports well variable-length structs. You have to use ubyte[0] data, and then allocate a large enough memory for the whole

Re: What does the alias attribute do here

2014-02-04 Thread Mike
On Tuesday, 4 February 2014 at 17:17:13 UTC, Adam D. Ruppe wrote: This specifically won't compile, alias params are only allowed in a compile-time list. So void foo(alias bar)() { ... } would work. [...] Thanks, Adam, for the thorough explanation. This was quite helpful for me as well.

Re: Performant method for reading huge text files

2014-02-04 Thread Chris Williams
On Tuesday, 4 February 2014 at 00:04:23 UTC, Rene Zwanenburg wrote: On Monday, 3 February 2014 at 23:50:54 UTC, bearophile wrote: Rene Zwanenburg: The problem is speed. I'm using LockingTextReader in std.stdio, but it't not nearly fast enough. On my system it only reads about 3 MB/s with one

Re: Performant method for reading huge text files

2014-02-04 Thread Chris Williams
Parsing should be faster than I/O. Set up two buffers and have one thread reading into buffer A while you parse buffer B with a second thread. ...and then flip buffers whenever the slower of the two has completed.