Re: The effect of ref

2019-11-21 Thread ketmar via Digitalmars-d-learn
Adam D. Ruppe wrote: On Friday, 22 November 2019 at 03:42:26 UTC, dokutoku wrote: Is there a difference in the execution speed and stability when executing the program by rewriting the parameter of the function argument like this? the generated code the processor sees is generally

Re: -O flag ; automatic cast in a bitshift

2018-09-20 Thread ketmar via Digitalmars-d-learn
Guillaume Lathoud wrote: this is UB. by the specs, values are promoted to int, and shifting int by 50 is UB. so both results are nonsense.

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread ketmar via Digitalmars-d-learn
vit wrote: thanks, that code can be modified to pure nothrow @nogc @safe. Is that lib ok? Is little complicated... converting float to string is a *very* complicated task. that lib is quite small for what it is doing ('cause it hacks around some... interesting cases). the *real* thing will

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread ketmar via Digitalmars-d-learn
vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? i don't think that you can make it `pure`, but you certainly can make it `nothrow`, `@nogc` and ctfe-able. it's dangerous to go alone! take this[0]. [0]

Re: @safe - why does this compile?

2018-07-16 Thread ketmar via Digitalmars-d-learn
Johan Engelen wrote: On Friday, 13 July 2018 at 14:51:17 UTC, ketmar wrote: yeah. in simple words: safe code is *predictable*, but not "segfault-less". segfaults (null dereferences) in safe code are allowed, 'cause they have completely predictable behavior (instant program termination).

Re: @safe - why does this compile?

2018-07-16 Thread ketmar via Digitalmars-d-learn
Johan Engelen wrote: On Friday, 13 July 2018 at 14:51:17 UTC, ketmar wrote: yeah. in simple words: safe code is *predictable*, but not "segfault-less". segfaults (null dereferences) in safe code are allowed, 'cause they have completely predictable behavior (instant program termination).

Re: @safe - why does this compile?

2018-07-13 Thread ketmar via Digitalmars-d-learn
Steven Schveighoffer wrote: To emphasize the point, this is @safe as well: X2 x2; // = null x2.run(); D does not consider a segmentation fault due to null dereferencing to be unsafe -- no memory corruption happens. yeah. in simple words: safe code is *predictable*, but not "segfault-less".

Re: @safe - why does this compile?

2018-07-13 Thread ketmar via Digitalmars-d-learn
Piotr Mitana wrote: This code: import std.stdio; class X1 {} class X2 : X1 { void run() @safe { writeln("DONE"); } } void main() @safe { X1 x1 = new X1; X2 x2 = cast(X2) x1; x2.run(); }

Re: Debugging silent exit of threads in Phobos calls

2018-06-01 Thread ketmar via Digitalmars-d-learn
Steven Schveighoffer wrote: Can you put in some more debug messages and see what the exact types of A and T are? Just put it right before the assert. you prolly asked Russel here, as i don't have his sources to experiment with. ;-)

Re: Debugging silent exit of threads in Phobos calls

2018-06-01 Thread ketmar via Digitalmars-d-learn
Russel Winder wrote: On Fri, 2018-06-01 at 17:53 +0300, ketmar via Digitalmars-d-learn wrote: […] it looks like "// type T is not constructible from A" phobos assertion triggered. that is, std.variant cannot wrap the struct, and all hell breaks loose. An instance of Fronte

Re: Debugging silent exit of threads in Phobos calls

2018-06-01 Thread ketmar via Digitalmars-d-learn
Russel Winder wrote: On Fri, 2018-06-01 at 16:37 +0300, ketmar via Digitalmars-d-learn wrote: […] yeah. if it receives something it doesn't expect (and there is no `Variant` clause to catch it), it throws. and exceptions from threads are silently dropped on the floor -- along with the dead

Re: Debugging silent exit of threads in Phobos calls

2018-06-01 Thread ketmar via Digitalmars-d-learn
Steven Schveighoffer wrote: On 6/1/18 7:12 AM, Russel Winder wrote: So I had a play and gdb seems to be useless for trying to find out why calls to std.concurrency.receive exit silently. Obviously std.concurrency.receive should never terminate a thread, and it should never terminate a thread

Re: Compile-time variables

2018-04-05 Thread ketmar via Digitalmars-d-learn
Kayomn wrote: I'll give a better example of what it is I'm trying to do. These are node types. Their contents are not important in this explanation, only that they operate as a tree structure. class Node; class RootNode : Node; class SpriteNode : Node; The result of getNodeID on a

Re: Initializing a class member that is an object

2018-03-30 Thread ketmar via Digitalmars-d-learn
Laurent Tréguier wrote: On Friday, 30 March 2018 at 11:04:59 UTC, ketmar wrote: p.s.: still, it may be nice to warn user about that. 'cause such runtime initializations are really belong to static ctor. dunno, i'm ok both with warning and without it. I simply think a word about it in the

Re: Initializing a class member that is an object

2018-03-30 Thread ketmar via Digitalmars-d-learn
p.s.: still, it may be nice to warn user about that. 'cause such runtime initializations are really belong to static ctor. dunno, i'm ok both with warning and without it.

Re: Initializing a class member that is an object

2018-03-30 Thread ketmar via Digitalmars-d-learn
Laurent Tréguier wrote: Is this behavior really intentional ? yes. default values should be the same for all objects. it is predictable, and allows to initialize objects to the known state simply by blitting `.init`. that is, default values aren't a syntax sugar for defining implicit ctor

Re: #import mapi.h

2018-03-21 Thread ketmar via Digitalmars-d-learn
Martin Tschierschke wrote: or tutorial ok, tutorial: 1. learn C. 2. learn D. 3. DO IT! ;-)

Re: signbit question

2018-03-15 Thread ketmar via Digitalmars-d-learn
Miguel L wrote: as the calculations on f guarantee it cannot be 0 at all. than `f` will become zero very soon. something that "cannot happen" is the most probable thing to happen. otherwise, LGTM.

Re: how to make private class member private

2018-03-13 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: Whatever happened to the 'discussion' component of these 'discussions'? dunno. try to ask yourself, why repeating the same point again and again when you were given the answer and the rationale doesn't make a good discussion.

Re: how to make private class member private

2018-03-13 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: On Tuesday, 13 March 2018 at 06:25:39 UTC, ketmar wrote: psychoticRabbit wrote: So the 3 most used languages got it wrong?? yes. do you know any other language, where a private class memeber, is not private to the class? (btw. that's a question, not a

Re: how to make private class member private

2018-03-13 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: So the 3 most used languages got it wrong?? yes.

Re: how to make private class member private

2018-03-13 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: On Tuesday, 13 March 2018 at 05:52:55 UTC, ketmar wrote: psychoticRabbit wrote: There are two problems I see: 1) it is not how C++ done it. 2) it is not how C++ done it. and you're completely right: it is not how C++ done it. umm...didn't you forget something: 1)

Re: how to make private class member private

2018-03-12 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: There are two problems I see: 1) it is not how C++ done it. 2) it is not how C++ done it. and you're completely right: it is not how C++ done it.

Re: how to make private class member private

2018-03-12 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: On Tuesday, 13 March 2018 at 01:39:13 UTC, Jonathan M Davis wrote: private is private to the module, not the class. There is no way in D to restrict the rest of the module from accessing the members of a class. This simplification makes it so that stuff like C++'s

Re: docs/definition: !object

2018-03-07 Thread ketmar via Digitalmars-d-learn
Nick Sabalausky (Abscissa) wrote: (Or does return the address of the *reference* to the object rather than the address of the object?...You can see just how often I do OO in D ;) ) exactly. if you want to convert object to a pointer safely, do this: MyObject o; void* p =

Re: docs/definition: !object

2018-03-07 Thread ketmar via Digitalmars-d-learn
Nick Sabalausky (Abscissa) wrote: I'm having trouble finding the documentation for what exactly the unary "not" operator does when applied to a class/interface object. Does this documentation exist somewhere? I know at least part of it involves "is null", but I seem to remember hearing

Re: issue with each specifically for x86

2018-03-07 Thread ketmar via Digitalmars-d-learn
Matt Gamble wrote: Ok, this has been submitted as a bug. https://issues.dlang.org/show_bug.cgi?id=18573 thank you.

Re: issue with each specifically for x86

2018-03-07 Thread ketmar via Digitalmars-d-learn
Matt Gamble wrote: On Wednesday, 7 March 2018 at 21:02:30 UTC, ag0aep6g wrote: On 03/07/2018 09:09 PM, ag0aep6g wrote: double f() { return 1; } void main() {     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();    

Re: issue with each specifically for x86

2018-03-07 Thread ketmar via Digitalmars-d-learn
ag0aep6g wrote: On 03/07/2018 09:09 PM, ag0aep6g wrote: double f() { return 1; } void main() {     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     double b = 2;     assert(b == 2); /*

Re: issue with each specifically for x86

2018-03-07 Thread ketmar via Digitalmars-d-learn
H. S. Teoh wrote: On Wed, Mar 07, 2018 at 10:21:42PM +0200, ketmar via Digitalmars-d-learn wrote: [...] it looks like ignoring `double` result causes FPU stack imbalance ('cause compiler doesn't insert "FPU pop" instruction), and that affects the computations. on 64 bit it does

Re: issue with each specifically for x86

2018-03-07 Thread ketmar via Digitalmars-d-learn
H. S. Teoh wrote: On Wed, Mar 07, 2018 at 10:21:42PM +0200, ketmar via Digitalmars-d-learn wrote: [...] it looks like ignoring `double` result causes FPU stack imbalance ('cause compiler doesn't insert "FPU pop" instruction), and that affects the computations. on 64 bit it does

Re: issue with each specifically for x86

2018-03-07 Thread ketmar via Digitalmars-d-learn
Steven Schveighoffer wrote: it seems that the only difference between `void` and `double` lambda is one asm instruction: `fldl (%edi)`. it is presend in `double` labmda, and absent in `void` lambda. it looks like ignoring `double` result causes FPU stack imbalance ('cause compiler doesn't

Re: Aliasing member's members

2018-02-26 Thread ketmar via Digitalmars-d-learn
Kayomn wrote: On Monday, 26 February 2018 at 21:04:51 UTC, TheFlyingFiddle wrote: On Monday, 26 February 2018 at 20:50:35 UTC, Kayomn wrote: [...] Don't think you can alias member variables directly. You could do this though: struct Player { Entity entity; ref auto pos() inout {

Re: Forward references

2018-02-25 Thread ketmar via Digitalmars-d-learn
works for me with 2.076.

Re: Destructor called twice.

2018-02-25 Thread ketmar via Digitalmars-d-learn
add postblit debug prints, and you will see.

Re: Function overloading between modules

2018-02-22 Thread ketmar via Digitalmars-d-learn
JN wrote: same idea? absolutely the same. non-qualified imports (be it template, or function) won't take part in overload resoultion.

Re: Function overloading between modules

2018-02-22 Thread ketmar via Digitalmars-d-learn
JN wrote: Is this expected behaviour? bar.d --- void foo(string s) { } app.d --- import std.stdio; import bar; void foo(int x) { } void main() { foo("hi"); }; === Error: function app.foo (int x) is not callable using argument types (string) yes. this is done so unqualified won't

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread ketmar via Digitalmars-d-learn
Nick Sabalausky (Abscissa) wrote: Are there any tutorials or articles out there for "getting started with converting a C++ codebase to D one module at a time?" Or at the very least: tips, tricks, lessions learned, from those who have come before. from my experience (various codebases up to

Re: Destructing Struct

2018-02-21 Thread ketmar via Digitalmars-d-learn
Jiyan wrote: Hi :), What i thought was that when i create a struct dynamically i can just deconstruct it with __dtor lets say: struct U {...} struct S {... private U _member;} S* p; p = cast(S*)malloc(S.sizeof); // just run that if it compiles, for simplicity // we dont use

Re: C++ std::string_view equivalent in D?

2018-02-21 Thread ketmar via Digitalmars-d-learn
0x wrote: On Wednesday, 21 February 2018 at 09:21:58 UTC, 0x wrote: What is the equivalent of C++17 std::string_view (an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero) in D? PS: I'm

Re: How to make AA key a pointer

2018-02-19 Thread ketmar via Digitalmars-d-learn
Clinton wrote: On Monday, 19 February 2018 at 14:55:01 UTC, Clinton wrote: Hi all, I need advice from better developers on this concern. I'm using an AA to reference another array for quicker access: [...] Sorry, on second look my explanation isn't very clear. I want to know if:

Re: ubyte[4] to int

2018-02-15 Thread ketmar via Digitalmars-d-learn
Nicholas Wilson wrote: On Thursday, 15 February 2018 at 16:51:05 UTC, Kyle wrote: Hi. Is there a convenient way to convert a ubyte[4] into a signed int? I'm having trouble handling the static arrays returned by std.bitmanip.nativeToLittleEndian. Is there some magic sauce to make the static

Re: import strangeness with std.stdio.write

2018-02-13 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: Also, if I do this below, how does the compiler choose the correct write function? import std.stdio; import std.file; void main() { write("hello"); writeln("hello again"); } it's easy: just take a look at `std.file.write()`. first, it require two

Re: import strangeness with std.stdio.write

2018-02-13 Thread ketmar via Digitalmars-d-learn
psychoticRabbit wrote: So, strange problem below. The commented-out line will not compile (if I un-comment it), unless I either move std.stdio into main, or, move std.file out of main. Whereas writeln works just fine as is. - module test; import std.stdio; void main()

Re: inout question

2018-02-12 Thread ketmar via Digitalmars-d-learn
lobo wrote: sure, i meant that you have to modify the second parameter accordingly. ;-) anyway, it's good that you fixed it.

Re: inout question

2018-02-11 Thread ketmar via Digitalmars-d-learn
Norm wrote: Hi, I'm new to D so can someone explain to me what is happening here? void func(const char* s, char** e) { import core.stdc.stdlib; auto result = strtod(s, e); } Error: function core.stdc.stdlib.strtod (scope inout(char)* nptr, scope inout(char)** endptr) is not

Re: -transition=safe and DIP1000

2018-01-21 Thread ketmar via Digitalmars-d-learn
Mike Franklin wrote: And what does "NB" mean? "nota bene". used as "pay attention to the following".

Re: why ushort alias casted to int?

2017-12-22 Thread ketmar via Digitalmars-d-learn
crimaniak wrote: Both operands are the same type, so as I understand casting to longest type is not needed at all, and longest type here is ushort in any case. What am I doing wrong? it is hidden in specs: all types shorter than int are promoted to int before doing any math.

Re: Scope failure is not preventing application crush in case of uncaught exceptions

2017-12-16 Thread ketmar via Digitalmars-d-learn
kerdemdemir wrote: On Saturday, 16 December 2017 at 20:56:26 UTC, ketmar wrote: kerdemdemir wrote: As far as I know scope(failure) should be collecting all failure cases. nope. `failure` scope won't stop exception propagation, it is just called before exception leaves your function, to

Re: Scope failure is not preventing application crush in case of uncaught exceptions

2017-12-16 Thread ketmar via Digitalmars-d-learn
kerdemdemir wrote: As far as I know scope(failure) should be collecting all failure cases. nope. `failure` scope won't stop exception propagation, it is just called before exception leaves your function, to give you a last chance to do some immediate cleanup.

Re: lower case only first letter of word

2017-12-05 Thread ketmar via Digitalmars-d-learn
Marc wrote: Does D have a native function to capitalize only the first letter of the word? (I'm asking that so I might avoid reinvent the wheel, which I did sometimes in D) http://dpldocs.info/experimental-docs/std.string.capitalize.html

Re: git workflow for D

2017-12-03 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: On Sunday, 3 December 2017 at 22:22:47 UTC, Arun Chandrasekaran wrote: Git CLI is arcane and esoteric. I've lost my commits before (yeah, my mistake). Who hasn't ;) me. Happened to me last time because i tried a command supposed to remove untracked files in

Re: How to modify process environment variables

2017-10-16 Thread ketmar via Digitalmars-d-learn
Ky-Anh Huynh wrote: Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive:

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-15 Thread ketmar via Digitalmars-d-learn
Michael V. Franklin wrote: In fact, you might want to propose matching bounty from the community on this specific bug to encourage funding. For example, make an announcement on the forum that anyone who places a bounty on the bug in question will receive a matching contribution from you.

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-13 Thread ketmar via Digitalmars-d-learn
Jack Applegame wrote: Compiler creates struct on the stack and silently (without postblitting and destruction old object) moves it to another address. Is it normal? yes. WAT??? Compiler creates struct on the stack copies it without postblitting and destructs both objects. and this is the

Re: Does writing from NNTP work?

2017-10-04 Thread ketmar via Digitalmars-d-learn
Tristan B. Kildaire wrote: Does this work? btw. there is "D" newsgroup which you can use for testing your NNTP client. web interface: http://forum.dlang.org/group/D NNTP name: "D"

Re: Does writing from NNTP work?

2017-10-04 Thread ketmar via Digitalmars-d-learn
Tristan B. Kildaire wrote: Does this work? if you can see this reply, it works.

Re: Why isn't there more if( ctfe) in std.math ?

2017-09-23 Thread ketmar via Digitalmars-d-learn
user1234 wrote: "if (__ctfe) {}" is a test happening at runtime. Both the if and the else branches got compiled nope. compiler knows about this special pseudovariable, and will not generate code neither for condition, nor for ctfe branch.

Re: traits for function having actual source declaration?

2017-09-01 Thread ketmar via Digitalmars-d-learn
bitwise wrote: On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote: When I'm using __traits(allMembers), I get a all the invisible functions added by the compiler as well "__ctor", "__xdtor", "__cpctor", etc.. Is there a way to filter them out? dlang's "Lexical" page says:

Re: DIPs - question about mores, etiquette and DIP1009 in particular

2017-08-30 Thread ketmar via Digitalmars-d-learn
Cecil Ward wrote: On Wednesday, 30 August 2017 at 17:19:52 UTC, ketmar wrote: it is explicitly stated in DIP that existing syntax will not be deprecated/removed. i guess that reading the DIP before expressing your opinion is the prerequisite... Good to know. A relief. I am full of pain

Re: DIPs - question about mores, etiquette and DIP1009 in particular

2017-08-30 Thread ketmar via Digitalmars-d-learn
Cecil Ward wrote: Is there a way I can simply register my vote eg about DIP 1009? My vote is 'no thanks'. Like the existing system, don't care about the alleged verbosity / room thing, and please whatever do not deprecate the existing syntax because I use it all over the place and the blocks

Re: Bug in D?!

2017-08-11 Thread ketmar via Digitalmars-d-learn
Mr. Pib wrote: Wow, that is pretty screwed up! I thought D was against implicit conversions that might cause problems? I'm passing an int and I should be able to append an int without having to worry about the value of the int. Instead D chose to do something very strange, awkward, and error

Re: Bug in D?!

2017-08-10 Thread ketmar via Digitalmars-d-learn
Mr. Pib wrote: string Q(alias T, alias D)() { pragma(msg, T); pragma(msg, D); enum x = T~" = "~D~";"; pragma(msg, x); } mixin(Q!(`x`, 100)()); outputs, at compile time, x 100 x = d; there is no lowercase d. I did initially define Q as string Q(alias T, D)(D

Re: How to build GUI-based applications in D ?

2017-08-01 Thread ketmar via Digitalmars-d-learn
ashit wrote: what is the simplest library to create gui applications in D? i want to create gui applications but couldnt configure the tools so far. i tried to install DFL several times, but it shows some errors while installing (that bold red lables showing : depreacated, depreacated, ... )

Re: Questions about dmd source

2017-07-30 Thread ketmar via Digitalmars-d-learn
Francis Nixon wrote: I have two completely unrelated questions about the dmd source code. 1. What does the mtype.Type.dotExp method do? The documentation comment says that it "Accesses the members of the object e". I'm not sure exactly why I would want to do that? Is it for handling types

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread ketmar via Digitalmars-d-learn
Clinton wrote: On Monday, 24 July 2017 at 14:51:04 UTC, rikki cattermole wrote: Stuff the GC. You don't need it to care about collecting (or destroying for that matter). Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); ``` Normally I would suggest to create your

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread ketmar via Digitalmars-d-learn
rikki cattermole wrote: Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); or just `delete arr;`. it is marked as "deprecated" in changelog, but who cares? it works.

Re: Having a strange issue with std.net.curl.HTTP as a struct dependency

2017-07-12 Thread ketmar via Digitalmars-d-learn
ikod wrote: On Wednesday, 12 July 2017 at 08:24:12 UTC, NoBigDeal256 wrote: On Monday, 10 July 2017 at 20:55:19 UTC, ketmar wrote: NoBigDeal256 wrote: Do you happen to have a link to the bug report for this specific issue that I could look at? I looked at the known bugs list and couldn't

Re: Static array with parameter based size?

2017-07-11 Thread ketmar via Digitalmars-d-learn
Miguel L wrote: I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic

Re: Having a strange issue with std.net.curl.HTTP as a struct dependency

2017-07-10 Thread ketmar via Digitalmars-d-learn
NoBigDeal256 wrote: Do you happen to have a link to the bug report for this specific issue that I could look at? I looked at the known bugs list and couldn't find anything related to this. nope. it is a kind of "known bug nobody bothered to report". ;-)

Re: Having a strange issue with std.net.curl.HTTP as a struct dependency

2017-07-10 Thread ketmar via Digitalmars-d-learn
NoBigDeal256 wrote: I'm currently learning D and started working on one of my first projects which is an API wrapper. I'm currently having an issue with my program getting a InvalidMemoryOperationError upon exiting the process on Windows 7. On my Debian VM I get a segmentation fault. known

Re: Why doesn't this work...Struct std.regex.Captures

2017-07-09 Thread ketmar via Digitalmars-d-learn
WhatMeForget wrote: c.hit is undefined when `c.empty` is `true`.

Re: std.json cannot read an array floats back from file

2017-07-03 Thread ketmar via Digitalmars-d-learn
Yuri wrote: On Monday, 3 July 2017 at 14:04:47 UTC, ketmar wrote: Yuri wrote: On Sunday, 2 July 2017 at 21:15:41 UTC, ketmar wrote: [...] I share your sentiment in relation to std.json, ketmar. On a side note, what would be a better way to serialize/deserialize objects in D if std.json

Re: std.json cannot read an array floats back from file

2017-07-03 Thread ketmar via Digitalmars-d-learn
Yuri wrote: On Sunday, 2 July 2017 at 21:15:41 UTC, ketmar wrote: so, write your own wrapper that will convert INTEGER/UINTEGER/FLOAT to `double`. i think this is the best solution (if there can be "best solution" with std.json at all). I share your sentiment in relation to std.json,

Re: std.json cannot read an array floats back from file

2017-07-02 Thread ketmar via Digitalmars-d-learn
Yuri wrote: Hi there, consider the following simple use case: import std.json; float[] floats = [1,2,3]; JSONValue j = "{}".parseJSON; j.object["floats"] = floats; std.file.write("test.json", j.toString); JSONValue jj = readText("test.json").parseJSON;

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: Oh, I should have mentioned that I don't expect anything but ugly platform-specific hacks possibly involving the object file format ;) Just enough of them to claim that the solution is somewhat cross-platform :D i guess you can loot at how TSL scanning is done

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: *** But in any case, the null-terminated string was just an example application. I'm interested in a fast way to determine the "storage class" of the memory a slice or a pointer point to. I'm expecting some magic along the lines of checking the range of

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
ketmar wrote: p.s.: btw, druntime tries to avoid that edge case by not checking for trailing out-of-bounds zero if string ends exactly on dword boundary. it will miss some strings this way, but otherwise it is perfectly safe. oops. not druntime, phobos, in `std.string.toStringz()`.

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
p.s.: btw, druntime tries to avoid that edge case by not checking for trailing out-of-bounds zero if string ends exactly on dword boundary. it will miss some strings this way, but otherwise it is perfectly safe.

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: Please note that not all static immutable strings have to be null terminated. It is possible to generate a string at ctfe which may appear the same as string literal, but does not have the \0 at the end. But in that case, the check `s.ptr[s.length] == 0` in

Re: More optional parens concerns

2017-06-24 Thread ketmar via Digitalmars-d-learn
Russel Winder wrote: On Sat, 2017-06-24 at 11:58 +0300, ketmar via Digitalmars-d-learn wrote: Russel Winder wrote: I note that: x.map!(…).array.sort is not valid, you have to have the parentheses on sort: x.map!(…).array.sort() Why? built-in property .sort kicks in and ruins

Re: More optional parens concerns

2017-06-24 Thread ketmar via Digitalmars-d-learn
Russel Winder wrote: I note that: x.map!(…).array.sort is not valid, you have to have the parentheses on sort: x.map!(…).array.sort() Why? built-in property .sort kicks in and ruins the day. luckily, it will be completely removed in the upcoming major release.

Re: Help me escape optional parens hell

2017-06-24 Thread ketmar via Digitalmars-d-learn
ketmar wrote: Meta wrote: So I have no clue what I'm doing wrong. This is driving me insane. h. known $#^#$@^@%. enum SymName = ().stringof[2..$]; // this, instead of symbol.stringof dirty hack, let's hope that DMD devs won't change `.toString()` output (i.e. first two chars will

Re: Help me escape optional parens hell

2017-06-24 Thread ketmar via Digitalmars-d-learn
Meta wrote: So I have no clue what I'm doing wrong. This is driving me insane. h. known $#^#$@^@%. enum SymName = ().stringof[2..$]; // this, instead of symbol.stringof dirty hack, let's hope that DMD devs won't change `.toString()` output (i.e. first two chars will always be

Re: Help me escape optional parens hell

2017-06-24 Thread ketmar via Digitalmars-d-learn
ketmar wrote: `.toString()` toChars(). ;-)

Re: Is it possible to call a delegate at compile time?

2017-06-22 Thread ketmar via Digitalmars-d-learn
Andrew Edwards wrote: I desire to call foo() at compile... As implemented it does not happen, but it's not immediately clear what I am missing. Or is this simply not possible as yet? What is the proper way to redesign this template so that it will execute at compile time? there are two

Re: Operator Overloading + / ~

2017-06-19 Thread ketmar via Digitalmars-d-learn
Martin Tschierschke wrote: Just a thought it might be useful for cut-n-paste when porting code: Would it be possible to define an operator overloading for '+'-Operator for strings to work as append? (like ~). I understand, that '~' is in general a better choice than '+', so this is of more

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Balagopal Komarath wrote: On Wednesday, 14 June 2017 at 11:40:02 UTC, ketmar wrote: interfaces *require* a full-featured class, with VMT, and some hidden pointers to support hidden interface machinery. I don't think that is the problem here. The type Test!Duck is a class and that type is

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Mike B Johnson wrote: I don't think it has to do with pasting code. d.Quack() is well defined through the alias. Inheritance requires that a Quack() exists, and it does, through the alias. The compiler could easily create an implementation wrapper that uses the alias this. this is called

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Balagopal Komarath wrote: On Wednesday, 14 June 2017 at 09:41:49 UTC, ketmar wrote: Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. 'cause `alias this` is *not* a tool that can be used to emulate

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. 'cause `alias this` is *not* a tool that can be used to emulate inheritance. no, `quack` is NOT impemented. `alias this` won't automagically paste the

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
Arafel wrote: I actually found a workaround for the original issue: yeah, sorry for not proposing a workaround: i thought that you already did it, and now you're just interested why the original code doesn't work. ;-) i think that this is a bug (or, rather, unimplemented feature).

Re: Generic operator overloading for immutable types?

2017-06-12 Thread ketmar via Digitalmars-d-learn
Gary Willoughby wrote: In the following code is there any way to make the `opBinary` method generic to be able to accept immutable as well as a standard type? The code currently passes the unit test but I wonder if I could get rid of the duplication to overload the operator? I'm failing

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
p.s.: while i understand the technical reason for second error message, it is still random and confusing.

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
more funny compiler messages: alias xx = size_t function (int[]); struct S1(T, typeof(xx) X) {} void main() { S1!(int, defaultChooser!int) s; } Error: type uint function(int[]) is not an expression but: struct S2(T, typeof(defaultChooser!T)

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Honey wrote: On Friday, 9 June 2017 at 16:34:28 UTC, ketmar wrote: Try -0.1685f. it doesn't matter if i can find the decimal representation for the given bit pattern or not. the whole post is about removing the need to rely on lossy binary->decimal->binary conversions. Lossless

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: On Friday, 9 June 2017 at 17:18:43 UTC, ketmar wrote: Basile B. wrote: enum binFloat = *cast(float*) i was SO sure that this won't work in CTFE that i didn't even tried to do it. "it will fail anyway, there is no reason in trying!" ;-) You can do the arithmetic as

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: enum binFloat = *cast(float*) i was SO sure that this won't work in CTFE that i didn't even tried to do it. "it will fail anyway, there is no reason in trying!" ;-)

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: Do HexFloats (http://dlang.org/spec/lex#HexFloat) help? hm. i somehow completely missed "%a" format specifier! yeah, "-0x1.6ep-3" did the trick. tnx. i should do my homework *before* posting big rants, lol.

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: ps. "-0.17 0xBE2AAAC1". it's not the same! (and yes, it matters). -0.17f is not representable as a 32 bit float. The actuall value that's stored is -0.169994592259765625, hence the difference. See https://www.h-schmidt.net/FloatConverter/IEEE754.html and

  1   2   3   4   5   6   7   8   9   10   >