Re: Using lazy code to process large files

2017-08-02 Thread kdevel via Digitalmars-d-learn
On Wednesday, 2 August 2017 at 17:37:09 UTC, Steven Schveighoffer wrote: What is expected? What I see on the screen when I run my code is: [Ü] Upper case? What I see when I run your "working" code is: [?] Your terminal is incapable of rendering the Latin-1 encoding. The program

Re: Using lazy code to process large files

2017-08-02 Thread kdevel via Digitalmars-d-learn
On Wednesday, 2 August 2017 at 11:44:30 UTC, Martin Drašar wrote: Thank you for any hint. 1 import std.stdio; 2 import std.string; 3 import std.algorithm; 4 import std.conv; 5 6 void main () 7 { 8auto input = File("input.csv"); 9

NNTP error: Disconnected from server (Connection closed)

2017-07-09 Thread kdevel via Digitalmars-d-learn
What's going on here?

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread kdevel via Digitalmars-d-learn
On Saturday, 8 July 2017 at 23:12:15 UTC, Jonathan M Davis wrote: On Saturday, July 8, 2017 5:16:51 PM MDT kdevel via Digitalmars-d-learn wrote: [...] IMHO, if you want to check for empty, then you should use the empty property or check length directly, since those are clear about your

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread kdevel via Digitalmars-d-learn
On Sunday, 9 July 2017 at 15:10:56 UTC, ag0aep6g wrote: On 07/09/2017 03:51 PM, kdevel wrote: On Sunday, 9 July 2017 at 10:32:23 UTC, ag0aep6g wrote: [...] A null char* is not a proper C string. A C string is a sequence of storage units containing legitimate character values of which the

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread kdevel via Digitalmars-d-learn
On Sunday, 9 July 2017 at 10:32:23 UTC, ag0aep6g wrote: On 07/09/2017 01:12 AM, kdevel wrote: On Saturday, 8 July 2017 at 18:39:47 UTC, ag0aep6g wrote: On 07/08/2017 07:16 PM, kdevel wrote: [...] Moreover everything I've written about strings is also valid for e.g. dynamic arrays of

Re: The Nullity Of strings and Its Meaning

2017-07-09 Thread kdevel via Digitalmars-d-learn
On Sunday, 9 July 2017 at 13:51:44 UTC, kdevel wrote: But that second proposition what not the one chosen in the documentation. Shall read: "But that second predicate was not the one chosen in the documentation."

The Nullity Of strings and Its Meaning

2017-07-08 Thread kdevel via Digitalmars-d-learn
Yesterday I noticed that std.uri.decodeComponent does not 'preserve' the nullity of its argument: 1 void main () 2 { 3import std.uri; 4string s = null; 5assert (s is null); 6assert (s.decodeComponent); 7 } The assertion in line 6 fails. This failure gave

Re: The Nullity Of strings and Its Meaning

2017-07-08 Thread kdevel via Digitalmars-d-learn
Just saw that my first example was wrong, it should read 1 void main () 2 { 3import std.uri; 4string a = ""; 5assert (a); 6auto s = a.decodeComponent; 7assert (s); 8 } The non-nullity was not preserved. Only the second assert

Re: Using lazy code to process large files

2017-08-02 Thread kdevel via Digitalmars-d-learn
On Wednesday, 2 August 2017 at 13:45:01 UTC, Steven Schveighoffer wrote: As Daniel said, using byCodeUnit will help. stripLeft seems to autodecode even when fed with CodeUnits. How do I prevent this? 1 void main () 2 { 3import std.stdio; 4import std.string;

Re: Using lazy code to process large files

2017-08-02 Thread kdevel via Digitalmars-d-learn
On Wednesday, 2 August 2017 at 15:52:13 UTC, Steven Schveighoffer wrote: [...] First, as a tip, please post either a link to a paste site, or don't put the line numbers. It's much easier to copy-paste your code into an editor if you don't have the line numbers. With pleasure. [...] If

Re: dmd (v2.075.0): fully static linking: undefined reference to `__tls_get_addr'

2017-08-19 Thread kdevel via Digitalmars-d-learn
On Saturday, 19 August 2017 at 14:07:49 UTC, kdevel wrote: src/rt/sections_elf_shared.d:(.text._D2rt19sections_elf_shared11getTLSRangeFNbNimmZAv[_D2rt19sections_elf_shared11getTLSRangeFNbNimmZAv]+0x38): undefined reference to `__tls_get_addr' https://issues.dlang.org/show_bug.cgi?id=12268

dmd (v2.075.0): fully static linking: undefined reference to `__tls_get_addr'

2017-08-19 Thread kdevel via Digitalmars-d-learn
test.d --- void main () { } --- $ dmd -c test.d $ cc -o test test.o -L/[...]/dmd2/linux/lib64 -lphobos2 -static -lpthread -lrt /[...]/dmd2/linux/lib64/libphobos2.a(sections_elf_shared_774_420.o): In function `_D2rt19sections_elf_shared11getTLSRangeFNbNimmZAv':

Re: Get date at compile time

2017-05-26 Thread kdevel via Digitalmars-d-learn
On Saturday, 1 October 2016 at 15:00:29 UTC, pineapple wrote: Though I don't currently have any need for this feature I'd imagine that if I did I'd want the time in UTC, not locally You may invoke the compiler with TZ= prepended. (Linux)

Re: formattedRead can't work with tab delimiter input

2017-09-19 Thread kdevel via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 13:28:22 UTC, Ky-Anh Huynh wrote: Hi, I want to read two fields from STDIN string key; double value; line_st.formattedRead!"%s %f"(key, value); Well it's so different from C. I would use this: --- auto t = line_st.split.join (' ');

Re: How to Skip some field/word in formattRead?

2017-09-17 Thread kdevel via Digitalmars-d-learn
On Sunday, 17 September 2017 at 13:53:26 UTC, Ky-Anh Huynh wrote: Is it possible to read just the second word from an input string and skip all others? "one two three".formattedRead!("%s %s", _, saveme) --- import std.range; auto saveme = "one two three".split.array [2]; ---

Re: Assert and undefined behavior

2017-10-14 Thread kdevel via Digitalmars-d-learn
On Saturday, 14 October 2017 at 09:32:32 UTC, Timon Gehr wrote: Also, UB can and does sometimes mean that the program can execute arbitrary code. It's called "arbitrary code execution": https://en.wikipedia.org/wiki/Arbitrary_code_execution This confuses different levels of reasoning. In

Re: Why do I have to cast arguments from int to byte?

2017-10-13 Thread kdevel via Digitalmars-d-learn
On Friday, 13 October 2017 at 07:47:55 UTC, Daniel Kozak wrote: but it works ok with immutable, so until you really need to change bar you can use immutable bar = 9; foo!byte(bar + 1); As Adam wrote two days ago: 'D doesn't do implicit narrowing conversion... so x + 1 becomes int, but then

Re: Assert and undefined behavior

2017-10-13 Thread kdevel via Digitalmars-d-learn
On Friday, 13 October 2017 at 02:22:24 UTC, Jonathan M Davis wrote: You've told it that i should never be 3 at that point and that it's a bug if it is, and as such, it is free to assume that i is never 3 after the assertion even if the assertion is compiled out with -release - that is the only

Re: non-block reading from pipe stdout

2017-10-03 Thread kdevel via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 11:36:28 UTC, Oleg B wrote: EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and no data was immediately available for reading. And I can't check this without using exception handling? Your programm shall not read before data is

Re: non-block reading from pipe stdout

2017-10-03 Thread kdevel via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote: but get error "Resource temporarily unavailable". You get EAGAIN because there is no data available at the time of reading. From the manpage of read: ERRORS EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and no

Re: non-block reading from pipe stdout

2017-10-03 Thread kdevel via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 12:20:09 UTC, Oleg B wrote: while (!tryWait(pp.pid).terminated) { auto cnt = read(fd, buf.ptr, buf.length); // C-style reading if (cnt == -1 && errno == EAGAIN) // C-style error checking yield();

Re: Assert and undefined behavior

2017-10-12 Thread kdevel via Digitalmars-d-learn
On Thursday, 12 October 2017 at 15:37:23 UTC, John Burton wrote: C++ compilers can and do perform such optimizations so I was wondering if assert in D could cause such behavior according to the spec. In the context of ISO-C++ it is meaningless to reason about the "actual behavior" of a

Re: Why do I have to cast arguments from int to byte?

2017-10-12 Thread kdevel via Digitalmars-d-learn
On Wednesday, 11 October 2017 at 07:09:26 UTC, Daniel Kozak wrote: You can avoid cast: void foo(T)(T bar){...} byte bar = 9; foo!byte(bar + byte(1)); Sure? --- void foo(T)(T bar) { } byte bar = 9; void main () { foo!byte(bar + byte(1)); } --- byte2.d(7): Error: function

Re: Assert and undefined behavior

2017-10-12 Thread kdevel via Digitalmars-d-learn
On Thursday, 12 October 2017 at 20:27:03 UTC, Jonathan M Davis wrote: On Thursday, October 12, 2017 20:15:41 kdevel via --- void main () { assert (false); } --- qualifies as "invalid, and therefore has undefined behaviour." A statement, which makes no sense to me. Either it is a

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 14:22:51 UTC, Daniel Kozak wrote: And this one https://paste.ofcode.org/KNqxcrmACLZLseB45MvwC I thrash your code with two shell processes ``` while true; do curl 127.0.0.1: -o /dev/null; done ``` running parallel. Using strace -fFeclose on the binary

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 13:31:46 UTC, Daniel Kozak wrote: This one works ok for me, but I am on linux: https://dpaste.dzfl.pl/f54decee45bc It works, but it does not handle two connects in parallel. STR: 1. start the binary in console 1 2. telnet localhost in console 2 3. telnet

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-14 Thread kdevel via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 19:57:54 UTC, ade90036 wrote: socket.send("HTTP/1.1 200 OK Server: dland:v2.076.1 Date: Tue, 11 Nov 2017 15:56:02 GMT

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-14 Thread kdevel via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 19:57:54 UTC, ade90036 wrote: while(true) { listeningSet.add(listener); if (Socket.select(listeningSet, null, null, dur!"nsecs"(150)) > 0) { Why do you ever timeout? This loop consumes 100 % (a single core) when idle on my

associative array: unexpected results after static initialization

2017-11-30 Thread kdevel via Digitalmars-d-learn
This program ``` void aa_stat(T, U) (T[U] aa) { import std.stdio; writefln ("aa: %s", aa); writefln ("aa.length : %d", aa.length); writefln ("aa.keys : %s", aa.keys); writefln ("aa.values : %s", aa.values); foreach (k, v; aa) writeln (k, ": ", v); } void main

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-04 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 23:29:01 UTC, Basile B. wrote: On Sunday, 3 December 2017 at 22:33:40 UTC, kdevel wrote: On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote: In this case i'd go for a typed pointer, e.g --- immutable struct Configuration { this(string){/*load some

Re: Passing Function as an argument to another Function

2017-12-04 Thread kdevel via Digitalmars-d-learn
On Monday, 4 December 2017 at 11:05:22 UTC, Vino wrote: On Monday, 4 December 2017 at 10:46:03 UTC, rikki cattermole wrote: FunTest.d(52): Error: template FunTest.ptProcessFiles cannot deduce function from argument types !()(string, Array!(Tuple!(string, string)) function(string FFs, string

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote: In this case i'd go for a typed pointer, e.g --- immutable struct Configuration { this(string){/*load some file...*/} int value; } Configuration* config; void main() { try config = new Configuration("config.sdl");

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 16 November 2017 at 19:37:31 UTC, ade90036 wrote: Can we enable some sort of profiling to see what is going on? You may compile the code with dmd -g -O -profile -profile=gc I currently struggle getting meaningful output. I want to terminate the program after a number (say 400)

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-17 Thread kdevel via Digitalmars-d-learn
On Friday, 17 November 2017 at 14:28:38 UTC, kdevel wrote: On Thursday, 16 November 2017 at 19:37:31 UTC, ade90036 wrote: Can we enable some sort of profiling to see what is going on? You may compile the code with dmd -g -O -profile -profile=gc I currently struggle getting meaningful output.

Re: Binary serialization of a struct

2017-12-07 Thread kdevel via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 06:32:52 UTC, Nordlöw wrote: I want something straight forward without allot of plumbing on my end. https://github.com/msgpack/msgpack-d I can't unittest my 32-bit code: $ MODEL=32 make -f posix.mak unittest [...] src/msgpack/packer.d(1139): Error: function

Re: lower case only first letter of word

2017-12-05 Thread kdevel via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 17:25:57 UTC, Steven Schveighoffer wrote: [...] struct LowerCaseFirst(R) // if(isSomeString!R) { R src; bool notFirst; // terrible name, but I want default false dchar front() { import std.uni: toLower; return notFirst ? src.front :

Re: associative array: unexpected results after static initialization

2017-12-01 Thread kdevel via Digitalmars-d-learn
On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote: Here's the fix: https://github.com/dlang/druntime/pull/1980 And wouldn't it be reasonable to add assert(aa.values == [ "b" ]); to the unittest?

Re: associative array: unexpected results after static initialization

2017-12-01 Thread kdevel via Digitalmars-d-learn
On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote: Here's the fix: https://github.com/dlang/druntime/pull/1980 Great. By the way: It it true, that there cannot be more than 2^32 keys in an associative array (due to the use of uint)?

package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread kdevel via Digitalmars-d-learn
Given the functions void foo() and void bar() in their source files mymod/foo.d and mymod/bar.d. Also I have a mymod/package.d ``` module mymod; public import foo : foo; public import bar : bar; ``` and a client to the library: main.d ``` import mymod; void main () { foo; bar; } ```

Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread kdevel via Digitalmars-d-learn
On Thursday, 7 December 2017 at 17:36:22 UTC, Neia Neutuladh wrote: If you have a source tree like: pierce/ db/ core.d controllers/ feed.d then feed.d can have `import pierce.db.core;` instead of people being confused about how to refer to the parent directory in a relative

Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread kdevel via Digitalmars-d-learn
On Thursday, 7 December 2017 at 17:58:38 UTC, ag0aep6g wrote: On 12/07/2017 06:53 PM, kdevel wrote: Does that mean, that though the code is bundled in one library (libmymod.a) for the prototypes one has as many .di files as there were source files? yes Gosh! So in my example I need the

Re: associative array: unexpected results after static initialization

2017-12-01 Thread kdevel via Digitalmars-d-learn
On Friday, 1 December 2017 at 16:23:33 UTC, H. S. Teoh wrote: On Fri, Dec 01, 2017 at 04:06:50PM +, kdevel via Digitalmars-d-learn wrote: On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote: > Here's the fix: > > https://github.com/dlang/druntime/pull/1980 And

Re: associative array: unexpected results after static initialization

2017-12-01 Thread kdevel via Digitalmars-d-learn
On Friday, 1 December 2017 at 17:02:48 UTC, H. S. Teoh wrote: [...] There is at least 1 use case in the bugzilla issue that justifies AA literals with (possibly) duplicated keys: https://issues.dlang.org/show_bug.cgi?id=15290#c1 Code snippet: --- foreach (i; 0..10) foreach

Re: scope(exit) and Ctrl-C

2017-12-01 Thread kdevel via Digitalmars-d-learn
On Saturday, 2 December 2017 at 00:41:19 UTC, Wanderer wrote: I wonder why `scope(exit)` code is not executed when the program is terminated with Ctrl-C. Which OS? For example: ``` import std.stdio; import core.thread; void main() { scope (exit) { writeln("Cleanup"); }

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 05:49:54 UTC, Fra Mecca wrote: I have this code: Configuration conf = void ; try { conf = parse_config("config.sdl"); } catch (Exception e) { std.stdio.stderr.writeln("Error reading configuration file: ", e.msg); exit(1); }

Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 3 December 2017 at 14:16:42 UTC, kdevel wrote: int main () { try { real_main (); } catch (Exception e) { std.stdio.stderr.writeln(e.msg); return 1; } return 0; } ``` This is better: int main () { try { return real_main (); } catch

Re: fft and isPowerOf2?

2018-05-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 17 May 2018 at 12:34:25 UTC, Andre Pany wrote: this applications throws an error in std.numeric (Line 2826). => assert(isPowerOf2(range.length)); Isn't it possible to give an arbitrary length of data to fft like in numpy? There is a mathematical background which is well

Re: Mysql query result access by field name

2018-05-21 Thread kdevel via Digitalmars-d-learn
On Monday, 21 May 2018 at 14:17:23 UTC, Steven Schveighoffer wrote:    Data f;    allrows[0].toStruct (f); I haven't checked this. This only works if your struct has exactly the same layout as the fields. So if, for instance, your rows are selected "title", "name", "surname", but your

Re: Mysql query result access by field name

2018-05-21 Thread kdevel via Digitalmars-d-learn
On Sunday, 20 May 2018 at 16:08:03 UTC, ipkwena wrote: How does one access the columns fields in a Mysql query results by the column name. [...] Data f; f.name = to!string(allrows[0][0]); f.surname = to!string(allrows[0][1]); f.title = to!string(allrows[0][2]); I am using the mysql-native

Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn
On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote: On Monday, June 25, 2018 19:40:30 kdevel via Digitalmars-d-learn wrote: R r; if (r.s is null) throw new Exception ("some error message"); [...] Why can't this programming error be detected at co

Re: Nullable!T with T of class type

2018-06-26 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 14:32:59 UTC, Nathan S. wrote: On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote: Is it possible to "lower" the Nullable operations if T is a class type such that there is only one level of nullification? Yes: https://run.dlang.io/is/hPxbyf template

Nullable!T with T of class type

2018-06-25 Thread kdevel via Digitalmars-d-learn
Just stumbled over the following design: class S {...} class R { : Nullable!S s; : } s was checked in code like R r; : if (r.s is null) throw new Exception ("some error message"); At runtime the following was caught: fatal error: caught

Re: function template specialization question D vs. C++

2018-01-14 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 02:24:52 UTC, Adam D. Ruppe wrote: On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis wrote: If you're using template constraints rather than template specializations, then you can't have any unconstrained templates. Not true: see the tip of the week

variable template question

2018-01-14 Thread kdevel via Digitalmars-d-learn
vartmpl.d ``` import std.stdio : writeln; import decimal : decimal32; template F(T) { immutable T c = 3; } void foo (T) () { immutable T t = 1; } void main () { // immutable decimal32 i = 1; // Error: none of the overloads of '__ctor' are callable using a immutable object //

compile-time checked format strings

2018-01-13 Thread kdevel via Digitalmars-d-learn
occasion: http://forum.dlang.org/thread/mutegviphsjwqzqfo...@forum.dlang.org?page=3#post-mailman.2136.1515709204.9493.digitalmars-d-announce:40puremagic.com dmd checks the types but does not count the arguments. ctcfs.d ``` import std.stdio; import std.math; void unit (T) () { auto pi = 4

Re: compile-time checked format strings

2018-01-13 Thread kdevel via Digitalmars-d-learn
On Saturday, 13 January 2018 at 19:40:09 UTC, Adam D. Ruppe wrote: For ints, it catches all that, but for float, it just bails out of the check as soon as it actually *succeeds* - because that kills CTFE. Confirmed. Thanks! args.d ``` import std.stdio; void main () { // writefln!"%2.2d

Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread kdevel via Digitalmars-d-learn
Thanks for the quick answer! On Friday, 12 January 2018 at 02:16:39 UTC, Adam D. Ruppe wrote: On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: $ dmd crash.d $ ./crash Nicholas Wilson is right that you can use = "" to work around it, but with strings, null is supposed to behave the

union/toString: crash/segfault: What's happening here?

2018-01-11 Thread kdevel via Digitalmars-d-learn
crash.d ``` import std.stdio; union U { float f; int i; string toString () { string s; return s; } } void main () { U u; writeln (u); } ``` $ dmd crash.d $ ./crash std.exception.ErrnoException@/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(2776): (Bad

Re: enforce (i > 0) for i = int.min does not throw

2018-01-30 Thread kdevel via Digitalmars-d-learn
On Sunday, 28 January 2018 at 19:17:49 UTC, Steven Schveighoffer wrote: This is insane. i > 0 is used in so many places. The only saving grace appears to be that int.min is just so uncommonly seen in the wild. And another one that it does not happen when compiled with optimization (-O) and

std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
https://dlang.org/phobos/std_exception.html#enforce and also https://dlang.org/library/std/exception/enforce.html present this example: --- auto f = enforce(fopen("data.txt")); auto line = readln(f); enforce(line.length, "Expected a non-empty line."); --- fopen, readln and enforce need

enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread kdevel via Digitalmars-d-learn
I would expect this code enforce3.d --- import std.exception; void main () { int i = int.min; enforce (i > 0); } --- to throw an "Enforcement failed" exception, but it doesn't: $ dmd enforce3.d $ ./enforce3 [nothing]

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts are compiled out". So, an enforce() would disappear if it's inside such a block, which should not be what

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:51:23 UTC, Ali Çehreli wrote: On 01/27/2018 06:36 AM, kdevel wrote: On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts

assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
https://dlang.org/phobos/std_exception.html#enforce states: | Also, do not use enforce inside of contracts (i.e. inside of in and out blocks | and invariants), because they will be compiled out when compiling with -release. | Use assert in contracts. But assert is also ignored in release

Re: enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:49:52 UTC, Ali Çehreli wrote: But enforce is a red herring there. This prints true with 2.078 as well: import std.stdio; void main () { int i = int.min; writeln(i > 0);// prints 'true' with 2.078 } test.d --- import std.stdio; void main () {

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 16:19:30 UTC, Jonathan M Davis wrote: On Saturday, January 27, 2018 14:59:50 kdevel via Digitalmars-d-learn wrote: >>> https://github.com/dlang/phobos/blob/master/std/exception.d >> >> "Use $(D assert) in contracts." is s

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 16:10:29 UTC, Jonathan M Davis wrote: On Saturday, January 27, 2018 13:29:00 kdevel via Digitalmars-d-learn wrote: What's wrong here? And why is the "selective import" of enforce necessary? Because you named your module enforce. As such, by default,

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 18:34:35 UTC, Jonathan M Davis wrote: The example still does not compile. That has nothing to do with enforce. std.stdio.readln does not take a FILE*. In general, you shouldn't mix core.stdc.stdio and std.stdio. The code is from the official documentation:

Re: D generates large assembly for simple function

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret Could you please paste the source code? I mean in say 5 years when

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 18:00:32 UTC, rjframe wrote: I think I see what you mean; you interpret "use asserts, because enforce will be compiled out" to imply that asserts wouldn't be compiled out, correct? Is there any other meaningful interpretation? Since, in reality, both would be

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 20:33:46 UTC, Jonathan M Davis wrote: Shall I file a bug report? Yes. https://issues.dlang.org/show_bug.cgi?id=18319

array/Array: "hard" bounds checking

2018-02-21 Thread kdevel via Digitalmars-d-learn
Is there a D equivalent of the C++ at method? I would like to reformulate repro2.d --- void main () { import std.stdio; import std.container; import std.range; auto z = Array!char(); z.reserve(0xC000_); z.capacity.writeln; z.length.writeln; for (uint u = 0; u <

short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () { short s, t; t = -s; } --- $ dmd intprom.d intprom.d(6): Deprecation: integral promotion not done for -s, use '-transition=intpromote' switch or -cast(int)(s) What shall I do in order to

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 20:17:12 UTC, Steven Schveighoffer wrote: On 2/24/18 3:07 PM, kdevel wrote: I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () {    short s, t;    t = -s; } --- https://dlang.org/changelog/2.078.0.html#fix16997

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 22:30:09 UTC, Steven Schveighoffer wrote: The prime example is this: byte b = -128; int x = -b; What would you expect x to be? a) 128 b) -128 Neither nor. I would prefer the codomain of "-" be the range of byte and hence an exception thrown in that

compilers w/ different language features: version block

2018-02-24 Thread kdevel via Digitalmars-d-learn
A code fragment using static foreach https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-beruryblsptnunsowjph:40forum.dlang.org does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I tried to encapsulate this code into a version block but GDC still checks the

Re: What does auto std.stdio.File.ByChunkImpl byChunk (ulong chunkSize ); mean?

2018-08-03 Thread kdevel via Digitalmars-d-learn
On Friday, 3 August 2018 at 17:06:16 UTC, Adam D. Ruppe wrote: On Friday, 3 August 2018 at 16:58:26 UTC, kdevel wrote: What does auto std.stdio.File.ByChunkImpl byChunk ( ulong chunkSize ); on https://dlang.org/library/std/stdio/file.by_chunk.html mean? It looks like ddox trying

What does auto std.stdio.File.ByChunkImpl byChunk (ulong chunkSize ); mean?

2018-08-03 Thread kdevel via Digitalmars-d-learn
What does auto std.stdio.File.ByChunkImpl byChunk ( ulong chunkSize ); on https://dlang.org/library/std/stdio/file.by_chunk.html mean? Is that a (forward) declaration of a function named byChunk taking a single ulong argument name chunkSize. But what does that function return?

Re: What does auto std.stdio.File.ByChunkImpl byChunk (ulong chunkSize ); mean?

2018-08-03 Thread kdevel via Digitalmars-d-learn
On Friday, 3 August 2018 at 17:27:07 UTC, Adam D. Ruppe wrote: But remember, this is documentation that just happens to look like code, so it is intended to be legible by people rather than the compiler. I could not find any elucidation of the meaning of auto when used as a return type

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 13:03:32 UTC, rikki cattermole wrote: void func() { return; func2(); } Which is clearly an error. Hence why you need to add else block. There is no error in this generated code because func2 is unreachable. That there is a state/stage during

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 00:11:27 UTC, Steven Schveighoffer wrote: On 7/7/18 7:28 AM, kdevel wrote: It appears not to be possible to use static if in "guard clause style" as in    void bar (T ...) (T args)    {   static if (args.length == 0) return;   writeln (args

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 13:12:59 UTC, Alex wrote: The site you cited for the guard clause above (c2.com) works at runtime. ? The intention is to shorten the paths inside a function, I think. Therefore, a static "guard clause" is a contradiction, if I understand it correctly. The term

Re: guard clause style static if

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:56:40 UTC, rikki cattermole wrote: void bar (T ...) (T args) if (T.length == 0) { return; [...] } void bar (T ...) (T args) if (T.length > 0) { writeln (args [0]); return bar (args [1 .. $]); } This is a version without a

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 21:09:23 UTC, Steven Schveighoffer wrote: [...] As far as the OS is concerned, a[2 .. $] is within the process memory limit. Of course, that's an out of bounds access, so the compiler or the bounds check *should* complain. It complains at runtime > ./dumpme2

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 20:10:54 UTC, Adam D. Ruppe wrote: On Tuesday, 10 July 2018 at 19:01:22 UTC, Per Nordlöw wrote: [...] Run the program in a debugger, or run `ulimit -c unlimited` to enable core dumps [...] Works for null ptr deref but how do I enforce core dumps in this code:

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread kdevel via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 22:31:54 UTC, Adam D. Ruppe wrote: Turn off rtTrapExceptions though the command line switch PR is STILL NOT MERGED https://github.com/dlang/druntime/pull/2035 extern (C) __gshared bool rt_trapExceptions; static this () { rt_trapExceptions =

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:   static if (args.length == 0) return; else {   writeln (args [0]);   return bar (args [1 .. $]); } That's not guard clause style [1][2]. [1]

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:56:40 UTC, rikki cattermole wrote: On 07/07/2018 11:44 PM, kdevel wrote: On Saturday, 7 July 2018 at 11:29:35 UTC, rikki cattermole wrote:    static if (args.length == 0)   return; else {    writeln (args [0]);    return bar (args [1 ..

Re: guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote: On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing. What my original code was supposed to do. But it did not compile. Error: array index [0] is

guard clause style static if

2018-07-07 Thread kdevel via Digitalmars-d-learn
It appears not to be possible to use static if in "guard clause style" as in void bar (T ...) (T args) { static if (args.length == 0) return; writeln (args [0]); return bar (args [1 .. $]); } Is this intended?

Floating Point Literals: float (f) and real (L) suffix issue

2018-01-12 Thread kdevel via Digitalmars-d-learn
suffix.d ``` void main () { real r = 1.L; float f = 1.f; } ``` $ dmd suffix.d suffix.d(3): Error: no property 'L' for type 'int' suffix.d(4): Error: no property 'f' for type 'int' According to the grammar in dmd2/html/d/spec/lex.html both are valid FloatLiterals. Any comments?

Re: Floating Point Literals: float (f) and real (L) suffix issue

2018-01-12 Thread kdevel via Digitalmars-d-learn
On Friday, 12 January 2018 at 12:45:59 UTC, kdevel wrote: suffix.d ``` void main () { real r = 1.L; float f = 1.f; } ``` $ dmd suffix.d suffix.d(3): Error: no property 'L' for type 'int' suffix.d(4): Error: no property 'f' for type 'int' According to the grammar in

function template specialization question D vs. C++

2018-01-13 Thread kdevel via Digitalmars-d-learn
fusp.d ``` import std.stdio; import std.typecons; void foo (T) () { writeln ("(1) foo T = ", T.stringof); } void foo (T : float) () { writeln ("(2) foo T = ", T.stringof); } // void foo (T : double) () // { //writeln ("(2) foo T = ", T.stringof); // } void main () { foo!float;

Re: function template specialization question D vs. C++

2018-01-13 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 00:30:37 UTC, Nicholas Wilson wrote: The usual way to do what you are trying to do is with template constraints. void foo(T)() if (is(T== float)) { ...} Thanks. That works but looks a bit ugly. Am I right that I have to leave out the primary (unconstrained)

Declare and Define Before Use? [rant]

2018-04-04 Thread kdevel via Digitalmars-d-learn
Why are people writing import std.stdio; void main () { S s; s.foo; } struct S { void foo () { writeln ("a"); } } but not void main () { S s; s.foo; } struct S { void foo () { writeln

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread kdevel via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: On Wednesday, 4 April 2018 at 18:57:27 UTC, kdevel wrote: [...] I think the rules should have been the same everywhere and if there was an exception to be made, it could be made for the main function since the main function is special

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread kdevel via Digitalmars-d-learn
On Thursday, 29 March 2018 at 15:16:07 UTC, Ivan Kazmenko wrote: import std.stdio; void main () { int delegate () [] funs; funs ~= () => 0; funs ~= () => 1; foreach (i; 0..2) writeln (funs[i] ()); // 0 and 1 as expected int delegate () [] guns;

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread kdevel via Digitalmars-d-learn
On Thursday, 29 March 2018 at 20:05:35 UTC, ag0aep6g wrote: On Thursday, 29 March 2018 at 19:02:51 UTC, kdevel wrote: On Thursday, 29 March 2018 at 15:16:07 UTC, Ivan Kazmenko wrote: [...] int delegate () [] guns; foreach (i; 0..2) guns ~= () => i; foreach (i; 0..2)

errnoEnforce: which imports?

2018-06-28 Thread kdevel via Digitalmars-d-learn
In https://dlang.org/phobos/std_exception.html#errnoEnforce this example is shown: --- auto f = errnoEnforce(fopen("data.txt")); auto line = readln(f); enforce(line.length); // expect a non-empty line --- I added import std.stdio; import std.exception; and get an error message which

  1   2   3   >