Re: Format double in decimal notation without trailing zeros after the decimal point

2015-03-30 Thread akaDemik via Digitalmars-d-learn
Thank you. Actually, I'm doing this: format(%.4f, d).stripRight('0').stripRight('.') (not so elegant, but it works.) But I thinking that do not know much about the format string. On Sunday, 29 March 2015 at 03:29:26 UTC, Baz wrote: On Friday, 27 March 2015 at 15:02:19 UTC, akaDemik wrote:

Re: Passing myself, a struct, as a C callback context

2015-03-30 Thread via Digitalmars-d-learn
On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote: I'm registering a callback with some C code. The simplified story is here, but the actual code is on GitHub [1] at the end if you care. The call looks something like this. void register(void(*fp)(void*), void* context); I have a

Re: Format double in decimal notation without trailing zeros after the decimal point

2015-03-30 Thread akaDemik via Digitalmars-d-learn
Thanks for the reply. I remember about the accuracy of floating point numbers. It is encouraging that the %g can handle it. format(%.17g, 123456.789123); // == 123456.789123 And we have a flag #. As mentioned in documentation: '#' floating Always insert the decimal point and print trailing

Re: Windows - std.process - Setting env variables from D

2015-03-30 Thread wobbles via Digitalmars-d-learn
On Monday, 30 March 2015 at 12:54:28 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 12:28:19 UTC, wobbles wrote: Any solutions that people know of? You can't from an exe, it is a limitation of the operating system (same on Linux btw, environment variable inheritance is always from

Re: Windows - std.process - Setting env variables from D

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 12:28:19 UTC, wobbles wrote: Any solutions that people know of? You can't from an exe, it is a limitation of the operating system (same on Linux btw, environment variable inheritance is always from parent to child, never from child to parent). The reason batch

Re: Windows - std.process - Setting env variables from D

2015-03-30 Thread Laeeth Isharc via Digitalmars-d-learn
On Monday, 30 March 2015 at 12:28:19 UTC, wobbles wrote: I'm trying to set environment variables that will be visible when my D program exits. It is possible in a windows batch file using the set command (like set VAR=VALUE ) However, running this in D using: import std.process; import

Re: Specify an entire directory tree for string imports

2015-03-30 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 30 March 2015 at 02:51:56 UTC, Baz wrote: It's a DMD Windows bug. It's just been reported 2 days ago: https://issues.dlang.org/show_bug.cgi?id=14349 so nothing wrong from you side. Ok, glad to see it's a bug and not a (fairly limiting) feature. I might take a stab at fixing it,

Re: Windows - std.process - Setting env variables from D

2015-03-30 Thread Laeeth Isharc via Digitalmars-d-learn
On Monday, 30 March 2015 at 13:29:06 UTC, wobbles wrote: On Monday, 30 March 2015 at 12:54:28 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 12:28:19 UTC, wobbles wrote: Any solutions that people know of? You can't from an exe, it is a limitation of the operating system (same on

Windows - std.process - Setting env variables from D

2015-03-30 Thread wobbles via Digitalmars-d-learn
I'm trying to set environment variables that will be visible when my D program exits. It is possible in a windows batch file using the set command (like set VAR=VALUE ) However, running this in D using: import std.process; import std.stdio; void main(){ auto pid1 = spawnShell(`set

Re: D1 operator overloading in D2

2015-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/15 1:42 AM, ketmar wrote: it's still working. moreover, it is used in Phobos! and yet it's not documented anywhere. what i want to know is whether they will be removed for good, or brought back and properly documented? the current situation is awful: compiler has special treatment for

Re: Passing myself, a struct, as a C callback context

2015-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/15 5:12 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote: I'm registering a callback with some C code. The simplified story is here, but the actual code is on GitHub [1] at the end if you care. The call looks

Re: D1 operator overloading in D2

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Mon, 30 Mar 2015 11:25:01 -0400, Steven Schveighoffer wrote: On 3/30/15 1:42 AM, ketmar wrote: it's still working. moreover, it is used in Phobos! and yet it's not documented anywhere. what i want to know is whether they will be removed for good, or brought back and properly documented?

rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
Hi, Surely I am misunderstanding something. I got something like this : struct S { void opAssign(const ref s) { //... } } S genS() { S s; //... return s; } main() { S s; s = genS(); } DMD says : ...opAssign (ref const(S) point) is not callable using

Re: Windows - std.process - Setting env variables from D

2015-03-30 Thread wobbles via Digitalmars-d-learn
On Monday, 30 March 2015 at 14:14:50 UTC, Laeeth Isharc wrote: On Monday, 30 March 2015 at 13:29:06 UTC, wobbles wrote: On Monday, 30 March 2015 at 12:54:28 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 12:28:19 UTC, wobbles wrote: Any solutions that people know of? You can't from

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:18:01 UTC, Suliman wrote: same problem. I am preparing string to next SQL request: string sss = format(SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), -, ), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')); Here's your code

Re: rvalue based copy

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:20:30 UTC, matovitch wrote: Yes but you know what they say does it really do a copy of the struct or is the compiler smart enougth most of the time to avoid copy. (I think it's called return value optimization). Copying isn't necessarily a problem, for small

Re: rvalue based copy

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: One solution is to overload void opAssign(ref const S s) {...} void opAssign(const S s) {...} lvalues will go into the ref version, rvalues into the non-ref. There won't be any copying of data, so you still save a postblit

Re: string concatenation with %s

2015-03-30 Thread Suliman via Digitalmars-d-learn
string sss = format(foo-, bar); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something like it in docs, but I am not sure about it...

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:34:20 UTC, Suliman wrote: string sss = format(foo-, bar); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something like it

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:14:27 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 17:09:14 UTC, matovitch wrote: (I am gessing ref argument explitly means no rvalue) That's right. I'd first say don't use ref, just use const S and it will work and probably do what you need

Re: rvalue based copy

2015-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/15 1:09 PM, matovitch wrote: Hi, Surely I am misunderstanding something. I got something like this : struct S { void opAssign(const ref s) { //... } } S genS() { S s; //... return s; } main() { S s; s = genS(); } DMD says :

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
(it's not on line 79 obviously, you got me :D)

Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
Hi again, I have this simple toy code : import point; import std.random; import std.algorithm; import std.functional; void getRandomPoint(R)(R randVar, ref Point p) { p.x = randVar; p.y = randVar; p.z = randVar; } void main() { Point[500] points; auto randVar =

Re: rvalue based copy

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:09:14 UTC, matovitch wrote: (I am gessing ref argument explitly means no rvalue) That's right. I'd first say don't use ref, just use const S and it will work and probably do what you need efficiently. If you do want it to be ref though, rvalues aren't allowed

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
void opAssign(const ref s) should be void opAssign(const ref S s) btw and btw bis, I should probably make it const ref SopAssign(const ref S s) :/ I stop flooding there.

Re: Windows - std.process - Setting env variables from D

2015-03-30 Thread Laeeth Isharc via Digitalmars-d-learn
You tried setx, and it didn't work ? Or you don't want to set permanent environmental variables Yep, correct. Don't want them to be permanent. The systems have to be clean for other tests at all times, so they need to be on a shell by shell basis sadly. Thanks - was curious to know.

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
The title should be assignement not copy.

Re: string concatenation with %s

2015-03-30 Thread Suliman via Digitalmars-d-learn
same problem. I am preparing string to next SQL request: string sss = format(SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), -, ), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')); but I am getting next error: source\app.d(178): Error: invalid array

Re: rvalue based copy

2015-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/15 1:42 PM, matovitch wrote: On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: Annoying as this is (and blatantly awkward), it saves you from having to implement twice: void opAssign(T)(auto ref const T s) if(is(T == S)) {...} Yep, this seems awkward to me too

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: Annoying as this is (and blatantly awkward), it saves you from having to implement twice: void opAssign(T)(auto ref const T s) if(is(T == S)) {...} Yep, this seems awkward to me too thought according to Adam one can do :

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 18:23:32 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 18:07:18 UTC, matovitch wrote: kmeans_example.d(79): Error: template std.algorithm.iteration.map That error is easy: use points[].map!(test) instead of points.map. Since points is a static array, it

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
Well I have a bit of a similar problem with foreach. If I use classic T[] range, I can do : foreach(int i, auto t, myRange)... But if I use an Array!T (from std.container) I get : cannot infer argument types, expected 1 argument, not 2 Even if I add the brackets []. Any idea ? Thanks for

Re: D1 operator overloading in D2

2015-03-30 Thread Kagamin via Digitalmars-d-learn
Wow, it's quite old, 2.041.

Re: Mapping with partial

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 18:29:32 UTC, matovitch wrote: I tried importing std.range and points.array works too. Aye, that would work too, but the slice I think is more efficient as I'm pretty sure... not completely sure, but I think .array makes a copy of static arrays, whereas the slice

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:11:10 UTC, matovitch wrote: That settle the point for array as for [] ? I though that was clear. [] doesn't copy. I guess the documentation should have something to say about it too. ;) hopefully

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:08:24 UTC, anonymous wrote: On Monday, 30 March 2015 at 18:37:53 UTC, matovitch wrote: On Monday, 30 March 2015 at 18:34:19 UTC, Adam D. Ruppe wrote: [...] Aye, that would work too, but the slice I think is more efficient as I'm pretty sure... not completely

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:15:25 UTC, matovitch wrote: Language ref - Array - Slice An array slice does not copy the data, it is only another reference to it. So the total slice of a static array is a range using the underlying memory of the static array isnt it ? yes

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:31:54 UTC, anonymous wrote: On Monday, 30 March 2015 at 19:03:05 UTC, matovitch wrote: Well I have a bit of a similar problem with foreach. If I use classic T[] range, I can do : foreach(int i, auto t, myRange)... But if I use an Array!T (from std.container) I

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
Language ref - Array - Slice An array slice does not copy the data, it is only another reference to it. So the total slice of a static array is a range using the underlying memory of the static array isnt it ?

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:03:05 UTC, matovitch wrote: Well I have a bit of a similar problem with foreach. If I use classic T[] range, I can do : foreach(int i, auto t, myRange)... But if I use an Array!T (from std.container) I get : cannot infer argument types, expected 1 argument, not

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 18:34:19 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 18:29:32 UTC, matovitch wrote: I tried importing std.range and points.array works too. Aye, that would work too, but the slice I think is more efficient as I'm pretty sure... not completely sure, but I

Re: Mapping with partial

2015-03-30 Thread matovitch via Digitalmars-d-learn
Thanks. On a sader note, I found a respons'less thread about my second question : http://forum.dlang.org/thread/mailman.2247.1353945423.5162.digitalmars-d-le...@puremagic.com where std.container.Array is concerned: how come I can't use a foreach(i, x; myArray) formulation? I.e. one where

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 18:37:53 UTC, matovitch wrote: On Monday, 30 March 2015 at 18:34:19 UTC, Adam D. Ruppe wrote: [...] Aye, that would work too, but the slice I think is more efficient as I'm pretty sure... not completely sure, but I think .array makes a copy of static arrays,

Re: Mapping with partial

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 18:07:18 UTC, matovitch wrote: kmeans_example.d(79): Error: template std.algorithm.iteration.map That error is easy: use points[].map!(test) instead of points.map. Since points is a static array, it isn't a range. Static arrays can't be popped through. But if you

What ?

2015-03-30 Thread matovitch via Digitalmars-d-learn
Hi again again, ulong u = 1 63; Raise : Error: shift by 63 is outside the range 0..31 This is a bug isn't it, the ulong are supposed to be on 64 bits ? I guess it's time I go to bed. Have a nice night !

Re: What ?

2015-03-30 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 30 March 2015 at 22:34:00 UTC, matovitch wrote: Hi again again, ulong u = 1 63; Raise : Error: shift by 63 is outside the range 0..31 This is a bug isn't it, the ulong are supposed to be on 64 bits ? I guess it's time I go to bed. Have a nice night ! ulong, yes, but 1 is of

Re: What ?

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 22:34:55 UTC, Vladimir Panteleev wrote: On Monday, 30 March 2015 at 22:34:00 UTC, matovitch wrote: Hi again again, ulong u = 1 63; Raise : Error: shift by 63 is outside the range 0..31 This is a bug isn't it, the ulong are supposed to be on 64 bits ? I guess

Re: What ?

2015-03-30 Thread bearophile via Digitalmars-d-learn
Brian Schott: Do this instead: ulong u = 1L 63; I suggest a more explicit: ulong u = 1UL 63; Alternative: ulong u = 2UL ^^ 63; Bye, bearophile

Re: What ?

2015-03-30 Thread Brian Schott via Digitalmars-d-learn
On Monday, 30 March 2015 at 22:34:00 UTC, matovitch wrote: Hi again again, ulong u = 1 63; Raise : Error: shift by 63 is outside the range 0..31 This is a bug isn't it, the ulong are supposed to be on 64 bits ? I guess it's time I go to bed. Have a nice night ! The problem is that `1`

Re: Specify an entire directory tree for string imports

2015-03-30 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 30 March 2015 at 14:01:54 UTC, Alex Parrill wrote: On Monday, 30 March 2015 at 02:51:56 UTC, Baz wrote: It's a DMD Windows bug. It's just been reported 2 days ago: https://issues.dlang.org/show_bug.cgi?id=14349 so nothing wrong from you side. Ok, glad to see it's a bug and not a

Re: Mapping with partial

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Mon, 30 Mar 2015 19:36:49 +, matovitch wrote: The index is the problem. Generally, foreach doesn't do automatic indices for ranges. You can use std.range.enumerate or count yourself explicitly. foreach(i, t; myRange.enumerate) {...} size_t i = 0; foreach(t; myRange) {... ++i;}

Re: Passing myself, a struct, as a C callback context

2015-03-30 Thread Paul O'Neil via Digitalmars-d-learn
On 03/30/2015 11:32 AM, Steven Schveighoffer wrote: On 3/30/15 5:12 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: `this` is already a reference. You're taking the address of that reference. A simple cast should work: `cast(void*) this`. To build on this further, this for a

using exceptions in @nogc

2015-03-30 Thread weaselcat via Digitalmars-d-learn
was this ever solved? I did some research and saw static immutable ones suggested a few times, but they can't be chained AFAIK.

Re: using exceptions in @nogc

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote: was this ever solved? nope. there were some suggestions, but no decision was made. signature.asc Description: PGP signature

Re: D1 operator overloading in D2

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Mon, 30 Mar 2015 11:25:01 -0400, Steven Schveighoffer wrote: here is ER with patches: https://issues.dlang.org/show_bug.cgi?id=14382 sorry for breaking my promise of not making ERs anymore. ;-) signature.asc Description: PGP signature

Re: using exceptions in @nogc

2015-03-30 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 05:34:11 +, weaselcat wrote: On Tuesday, 31 March 2015 at 03:12:42 UTC, ketmar wrote: On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote: was this ever solved? nope. there were some suggestions, but no decision was made. sigh do you know if there's an open

Re: using exceptions in @nogc

2015-03-30 Thread weaselcat via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 03:12:42 UTC, ketmar wrote: On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote: was this ever solved? nope. there were some suggestions, but no decision was made. sigh do you know if there's an open enhancement request for this?

gdc and ldc command line examples?

2015-03-30 Thread Jeremy DeHaan via Digitalmars-d-learn
Hey all, I am finally working on moving out of dmd territory and playing with gdc and ldc. I was hoping that I could get some links to some example command lines. I'm mainly interested command lines regarding linking to libraries and building static libraries. My guess is that gdc will

Re: std.logger sharedLog usage

2015-03-30 Thread Robert burner Schadek via Digitalmars-d-learn
On Monday, 30 March 2015 at 04:05:12 UTC, lobo wrote: Thank you, lobo. next version will have equal default LogLevel for all Logger. https://github.com/D-Programming-Language/phobos/pull/3124