Re: D Logic bug

2018-10-15 Thread Nick Treleaven via Digitalmars-d
On Thursday, 11 October 2018 at 23:17:15 UTC, Jonathan Marler wrote: For example, the "Conditional operator" in D actually has a higher priority than an assignment, but in C++ it's the same and is evaluated right-to-left. So this expression would be different in C++ and D: a ? b : c = d In

Re: Deep nesting vs early returns

2018-10-05 Thread Nick Treleaven via Digitalmars-d
On Thursday, 4 October 2018 at 06:43:02 UTC, Gopan wrote: I have seen people enclosing the function logic inside a while(1) merely to stick on to single return at the end. while(1) { ... break; //otherwise return would come here. ... break; } return ...; I th

Re: DIP25/DIP1000: My thoughts round 2

2018-09-04 Thread Nick Treleaven via Digitalmars-d
Rust's lifetime syntax is noisy - the scope name is repeated, and why require a name if it's usually not given a meaningful one (`a`)? Rust is more limited semantically due to unique mutability, so it may have different requirements for function signatures to D. (I think they recently tweaked

Re: D is dead

2018-08-31 Thread Nick Treleaven via Digitalmars-d
On Thursday, 23 August 2018 at 09:09:40 UTC, Shachar Shemesh wrote: Please see the thread about lazy [1] for a case where a question actually has an answer, but nobody seems to know it I updated the spec for lazy parameters to add a link to lazy variadic functions at the end, and for the latte

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 21 August 2018 at 13:42:31 UTC, Kagamin wrote: int[] escape(scope int[] r) { return r; //error, can't return scoped argument } ... int[] escape(T)(scope int[] r) { return r; //ok! `scope` silently promoted to `return` } You can't have strictly scoped parameter in a template

Re: Automatic variable declaration

2018-08-15 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 15 August 2018 at 16:56:39 UTC, Everlast wrote: foo(int x = 3); foo(auto x = 3); If one has to declare the type it reduces it's effectiveness. auto is not a type ;-) Having e.g. auto or a type makes it clear that a new variable is being defined. I'd like this to work inside a p

Re: Is there any hope for "lazy" and @nogc?

2018-08-05 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 31 July 2018 at 20:03:39 UTC, ag0aep6g wrote: Looks like you can do it with a "lazy variadic function" [1], Interesting, thanks. I've made a pull to add a See Also link about this to the Lazy Parameters docs: https://github.com/dlang/dlang.org/pull/2439

Re: New edition of "The D Programming Language"?

2018-08-04 Thread Nick Treleaven via Digitalmars-d
On Friday, 3 August 2018 at 21:27:50 UTC, dlangPupil2 wrote: In lieu of a whole new edition maybe a web page listing major changes to D since Andrei's book came out might be useful (and help sales of his existing book too!!) https://wiki.dlang.org/Differences_With_TDPL

Re: Copy Constructor DIP

2018-07-11 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 10 July 2018 at 10:47:04 UTC, RazvanN wrote: [1] https://github.com/dlang/DIPs/pull/129 Thanks for making the DIP. I can't get this code to compile (my struct has an `int i` field): static foreach (i, ref field; src.tupleof) this.tupleof[i] = field; Error: constant value src

Re: Parenthesis around if/for/while condition is not necessary

2018-07-05 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 4 July 2018 at 14:37:49 UTC, Timon Gehr wrote: if (a+b)*c == d { ... } Error: found `{` when expecting `;` following statement Adding the semi-colon, `*c == d;` would likely cause: Error: `*c == d` has no effect Also multiplying (a+b) by a pointer is illegal, and c is probably

Re: Compilation is taking a ton of memory

2018-07-01 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 27 June 2018 at 16:00:37 UTC, Mario Silva wrote: Less than an year ago our project was taking around 17 seconds to compile - no libs requiring compilation - and maybe around 50 seconds for full compilation, and it now takes around 50 seconds for an incremental compilations and aro

Re: Parenthesis around if/for/while condition is not necessary

2018-07-01 Thread Nick Treleaven via Digitalmars-d
On Sunday, 24 June 2018 at 23:40:56 UTC, Timoses wrote: The others may be rewritten to not have a leading "!" as well, e.g. if (!(t1.ty == Tarray && t2.ty == Tarray && needsDirectEq(t1, t2)) if (t1.ty != Tarray || t2.ty != Tarray || ...) Yes, but you might make a mistake, and sometimes it

Re: Morale of a story: ~ is the right choice for concat operator

2018-05-26 Thread Nick Treleaven via Digitalmars-d
On Friday, 25 May 2018 at 08:27:30 UTC, Dukc wrote: If you add two characters, it interprets it as a concatenation that results in a string with two charactes. ... Now, if I were programming in D, this would not have happened. Using + always means an addition. I don't think it makes sense to

Re: Extend the call site default argument expansion mechanism?

2018-05-16 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 15 May 2018 at 15:02:36 UTC, jmh530 wrote: auto opDispatch(string s)() if (s == "bar") In case anyone isn't aware, this is better written: auto opDispatch(string s : "bar")()

Identifier from string - Re: static foreach considered

2018-05-14 Thread Nick Treleaven via Digitalmars-d
On Monday, 8 June 2015 at 21:32:52 UTC, Timon Gehr wrote: On 06/08/2015 10:16 PM, Idan Arye wrote: It would be nice together with this feature to be able to mixin identifiers: static foreach (ident; ["foo", "bar"]) { auto mixin(ident)() { // code for foo

Re: Bug?: Presence of "init()" Method Causes std.array.appender to Fail to Compile

2018-05-14 Thread Nick Treleaven via Digitalmars-d
On Monday, 14 May 2018 at 01:20:38 UTC, Jonathan M Davis wrote: Yeah. It's been discussed that it should be illegal to declare a struct or class member named init, but that change has yet to happen. https://issues.dlang.org/show_bug.cgi?id=7066 Walter and Timon have considered redefinition p

Re: Is there a strong reason for Nullable's alias get this?

2018-04-21 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 18 April 2018 at 13:36:15 UTC, FeepingCreature wrote: That said, I'm pretty sure that get will throw anyways if invoked without a default value. Not in release mode, but I suppose that doesn't matter. I've made a pull to update the docs to reflect this: https://github.com/dlang/

Re: Feature to get or add value to an associative array.

2018-04-20 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 18 April 2018 at 16:04:13 UTC, Giles Bathgate wrote: I understand where you are coming from, but I am not sure it is appropriate to shoehorn every use case into one api. It is not shoehorning, the difference here is just returning by ref vs pointer. I understand that, as the poin

Re: Feature to get or add value to an associative array.

2018-04-20 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 18 April 2018 at 16:47:50 UTC, ag0aep6g wrote: You can get a pointer from the ref return: Value* p = &aa.slot("key", { inserted = true; return Value.init; }); This is not @safe, even with -dip1000: Error: cannot take address of ref return of f() in @safe function main

Re: Is there a strong reason for Nullable's alias get this?

2018-04-18 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 18 April 2018 at 08:24:14 UTC, FeepingCreature wrote: If nobody objects, I'll make a PR to deprecate it. +1. Nullable has received some improvements lately, it would be great if `get` was no longer implicit. For new code, it is trivial to write `.get` to convert to the original

Re: Feature to get or add value to an associative array.

2018-04-18 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 17 April 2018 at 20:49:30 UTC, Steven Schveighoffer wrote: Why do you think it's less efficient to use a lazy parameter? Wouldn't an extra function call have to happen, at least in some cases? This pattern needs a pointer to be returned, instead of using `ref`. Note that `&inser

Re: Feature to get or add value to an associative array.

2018-04-17 Thread Nick Treleaven via Digitalmars-d
On Sunday, 15 April 2018 at 22:52:47 UTC, Giles Bathgate wrote: The function provides a means to get a value corresponding to the key, but if the value doesn't exist it will evaluate the lazy argument to create a new value, add this to the associative array and then return it. auto p = lookup

Re: Deprecating this(this)

2018-04-11 Thread Nick Treleaven via Digitalmars-d
On Thursday, 5 April 2018 at 18:46:25 UTC, H. S. Teoh wrote: I like this idea. Except the syntax could be improved: this(this orig) // <-- N.B. { It's already valid syntax, equivalent to `this(typeof(this) orig)`. It can be called explicitly, but is ignored for implic

Re: rvalues -> ref (yup... again!)

2018-03-29 Thread Nick Treleaven via Digitalmars-d
On Saturday, 24 March 2018 at 17:34:09 UTC, Manu wrote: You mutate a temporary that times out at the end of the statement... your statement is never assigned to anything, and has no effect. That is solved by having the ref function return its argument (so it can be chained): struct S; ref S

[OT] - Re: Could someone take a look at DIP PR 109?

2018-03-28 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 28 March 2018 at 06:43:15 UTC, Shachar Shemesh wrote: For those too lazy to click on the link, BTW It's not the reader's 'laziness', it's basic courtesy on the part of the poster to the newsgroup to provide a meaningful subject line for a thread. Far more people will read the su

Re: Tuple DIP

2018-03-15 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 17 January 2018 at 06:44:21 UTC, Timon Gehr wrote: It uses tuples because it uses zip. The code does not compile today, because the lambda I'm passing to "map" has two parameters: auto a = [1, 2, 4, 7, 2]; auto b = [3, 5, 3, 2, 4]; // auto c = zip(a, b).map!((x, y) => x + y); //

Re: rvalue types

2018-03-12 Thread Nick Treleaven via Digitalmars-d
On Monday, 12 March 2018 at 16:51:06 UTC, H. S. Teoh wrote: For example, today you can already make opBinary() return something other than the parent type, and use alias this to make it decay to the parent type. Sounds like this: https://en.wikipedia.org/wiki/Expression_templates

Re: C++ launched its community survey, too

2018-03-07 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 28 February 2018 at 20:01:34 UTC, H. S. Teoh wrote: As Andrei wrote in TDPL, (and I paraphrase,) it sucks when built-in types have magical abilities inaccessible to user code. This is a common defect in many programming languages... the "magical" behaviour is wonderful when it wo

Re: Why not flag away the mistakes of the past?

2018-03-07 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 7 March 2018 at 13:24:25 UTC, Jonathan M Davis wrote: I'd actually argue that that's the lesser of the problems with auto-decoding. The big problem is that it's auto-decoding. Code points are almost always the wrong level to be operating at. For me the fundamental problem is havi

Re: implicit construction operator

2018-03-02 Thread Nick Treleaven via Digitalmars-d
On Monday, 26 February 2018 at 21:07:52 UTC, Meta wrote: This is possible in the language today using the implicit class construction feature of runtime variadic arrays: class VArray { Variant[] va; this(T...)(T ts) { foreach(t; ts) { va ~= Variant(t); } } } void test(VArray ta...) .

Re: implicit construction operator

2018-02-28 Thread Nick Treleaven via Digitalmars-d
On Monday, 26 February 2018 at 21:36:49 UTC, ketmar wrote: aliak wrote: It makes libraries *much* more intuitive and expressive (C++ just got it wrong by choosing the wrong default). If you allow library authors to opt in instead of opt out then it becomes a conscious decision for one. libr

[OT] - Re: Workaround for https://issues.dlang.org/show_bug.cgi?id=18422?

2018-02-13 Thread Nick Treleaven via Digitalmars-d
On Sunday, 11 February 2018 at 15:34:07 UTC, Andrei Alexandrescu wrote: I'm trying to sketch a simple compile-time reflection system, and https://issues.dlang.org/show_bug.cgi?id=18422 is a blocker of the entire approach. BTW please write a descriptive subject, not a bug ID. The #dbugfix post

Re: ExpressionTuple is referenced in the specs, but doesn't seem to be defined

2018-02-02 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 31 January 2018 at 12:35:37 UTC, Nick Treleaven wrote: It's now called an Expression List: https://dlang.org/ctarguments.html#homogenous-lists That page needs an update too, we should call them sequences. I'll try to update the docs soon. There are still various places that ne

Re: The daily D riddle - this parameter

2018-02-01 Thread Nick Treleaven via Digitalmars-d
On Sunday, 28 January 2018 at 06:44:28 UTC, Timothee Cour wrote: likewise the following compiles, but IMO should not: class A{ void fun(this a){}} (instead we should have typeof(this) Yes, it's also confusing reading it, I thought it was template this for a second. It even works if fun is stat

Re: ExpressionTuple is referenced in the specs, but doesn't seem to be defined

2018-01-31 Thread Nick Treleaven via Digitalmars-d
On Friday, 26 January 2018 at 19:44:21 UTC, Dechcaudron wrote: See, for instance, definition https://dlang.org/spec/class.html#class_properties. If it is defined anywhere, I cannot seem to find it. It's now called an Expression List: https://dlang.org/ctarguments.html#homogenous-lists I'll tr

Re: The most confusing error message

2018-01-24 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 24 January 2018 at 14:22:59 UTC, Meta wrote: One way we could probably improve the error message is to change it to "template struct test.A(int var = 3) is used as a type. It must be instantiated", or something along those lines, to make it clear why you can't use A as a type. h

Re: Implementing tail-const in D

2018-01-24 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 23 January 2018 at 09:36:03 UTC, Simen Kjærås wrote: Unqual is the standard way today to get a head-mutable version of something. For dynamic arrays, static arrays, pointers and value types, including structs without aliasing, thi works. For AAs, classes, and structs with aliasing,

Re: Some thoughts about C and D, return data through parameters

2017-12-21 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 19 December 2017 at 08:54:38 UTC, Petar Kirov [ZombineDev] wrote: Reminds me of C#7's out variable declarations: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#out-variables However multiple return values are much better implemented through language-integrated tu

Re: Maybe D is right about GC after all !

2017-12-21 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 19 December 2017 at 11:30:14 UTC, ketmar wrote: but Rikki, we have this! i'm using refcounted structs for years, and it works like a charm! ;-) You can either have guaranteed memory-safe (due to DIP1000) but inefficient RC (due to extra runtime checks*), or efficient and not memor

Re: Inference of Scoped Destruction

2017-12-04 Thread Nick Treleaven via Digitalmars-d
On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote: How would this interact with explicit scope-qualification of `x`? That would allow the compiler to avoid GC allocation for x. It seems essentially the same case as Walter describes here: http://forum.dlang.org/post/ofo9f5$2bt7$1...

Re: Introducing Nullable Reference Types in C#. Is there hope for D, too?

2017-11-29 Thread Nick Treleaven via Digitalmars-d
On Sunday, 19 November 2017 at 22:54:38 UTC, Walter Bright wrote: I can't see the problem. You go from nullable to non-nullable by checking for null, and the other direction happens implicitly. Implicit conversions have their problems with overloading, The C# implementation doesn't affect ov

[OT] Re: Introducing Nullable Reference Types in C#. Is there hope for D, too?

2017-11-24 Thread Nick Treleaven via Digitalmars-d
On Thursday, 23 November 2017 at 06:35:17 UTC, codephantom wrote: I love not being able to edit posts. It's so convenient. It's not as much of a problem as not being able to hide all posts by a user who repeats arguments, derails the conversation onto irrelevant side discussions and judges in

Re: "body" keyword is unnecessary

2017-11-21 Thread Nick Treleaven via Digitalmars-d
On Sunday, 19 November 2017 at 11:54:04 UTC, Tony wrote: dmd --version DMD64 D Compiler v2.077.0 Copyright (c) 1999-2017 by Digital Mars written by Walter Bright dmd test_contracts.d test_contracts.d(13): Error: missing `body { ... }` after `in` or `out` Just made a pull to fix this: https://

Re: Introducing Nullable Reference Types in C#. Is there hope for D, too?

2017-11-20 Thread Nick Treleaven via Digitalmars-d
On Sunday, 19 November 2017 at 22:54:38 UTC, Walter Bright wrote: There's also an issue of how to derive a class from a base class. If you want null, use a nullable type: Base b = ...; Derived? d = cast(Derived?) base; if (d !is null) d.method; This implies one must know all the use cases of

Re: RAII in betterC

2017-11-20 Thread Nick Treleaven via Digitalmars-d
On Monday, 20 November 2017 at 17:13:37 UTC, Oleg B wrote: Hello. I know about some implementation issues http://forum.dlang.org/thread/nqctbzhrdldmnffch...@forum.dlang.org What work must be done for fix it? For what time is it scheduled? Looks like Walter is working on it: https://github.co

Re: Deprecate implicit `int` to `bool` conversion for integer literals

2017-11-14 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 14 November 2017 at 13:43:32 UTC, Michael V. Franklin wrote: Nick, if it's not in bugzilla already, can you please add it? Sure: https://issues.dlang.org/show_bug.cgi?id=17983

Re: Deprecate implicit `int` to `bool` conversion for integer literals

2017-11-14 Thread Nick Treleaven via Digitalmars-d
On Sunday, 12 November 2017 at 16:57:05 UTC, Andrei Alexandrescu wrote: The overload being called depends on (a) whether a - b can be computed during compilation or not, and (b) the actual value of a - b. Clearly a big problem for modular code. This is the smoking gun motivating the DIP. An v

Re: Project Elvis

2017-11-13 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 7 November 2017 at 13:43:20 UTC, user1234 wrote: On Monday, 6 November 2017 at 20:14:17 UTC, Meta wrote: The functionality is probably a good idea, but a library solution is doable today without any acrobatics. Show me a library solution that works fine with IDE completion (so for

Re: Project Elvis

2017-11-13 Thread Nick Treleaven via Digitalmars-d
On Saturday, 11 November 2017 at 05:20:39 UTC, codephantom wrote: I just saw this about the new 'damnit' operator, for C# 8. https://github.com/dotnet/csharplang/issues/556 The principle is a good one - by default you cannot dereference something that can be null, you get a compiler error ins

Re: Project Elvis

2017-11-13 Thread Nick Treleaven via Digitalmars-d
On Monday, 6 November 2017 at 13:02:43 UTC, Ola Fosheim Grøstad wrote: On Monday, 6 November 2017 at 10:12:11 UTC, Jonathan M Davis wrote: All it does is take the expression x ? x : y and make it x ?: y Yes, that is an issue because it means that typos no longer are caught. E.g. if you acc

switch - Re: Improve "Improve Contract Syntax" DIP 1009

2017-11-06 Thread Nick Treleaven via Digitalmars-d
On Thursday, 2 November 2017 at 20:37:11 UTC, user1234 wrote: switch (i) default: break; } you have 3 non-ambiguous and contiguous statements without a block: a switch, a default case (the "free-floating" one) and a break. Now why is this allowed is another story ;) I've found a

Re: Improve "Improve Contract Syntax" DIP 1009

2017-11-04 Thread Nick Treleaven via Digitalmars-d
On Saturday, 4 November 2017 at 06:08:22 UTC, Jonathan M Davis wrote: Heck, take a really simply one like sqrt. All you have to check in the out contract is the return value. You have no idea what was passed in. So, how would you write an out contract verifying that you got the correct number?

Re: Improve "Improve Contract Syntax" DIP 1009

2017-11-03 Thread Nick Treleaven via Digitalmars-d
On Friday, 3 November 2017 at 02:32:41 UTC, Jonathan M Davis wrote: Personally, I hate how verbose they are, but my solution is just not to use them. And IMHO, the only place that they add real value is in classes, where their success or failure can be &&ed or ||ed based on how that should work

Re: Project Elvis

2017-11-02 Thread Nick Treleaven via Digitalmars-d
On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote: Walter and I decided to kick-off project Elvis for adding the homonym operator to D. I'd like to mention null-coalescing assignment syntax. Perl has `$a //= $b`, and PHP has voted to support `$a ??= $b`, expanding to `$a

Re: Editor recommendations for new users.

2017-08-30 Thread Nick Treleaven via Digitalmars-d
On Sunday, 27 August 2017 at 10:28:29 UTC, Dukc wrote: The problem with geany is that it's syntax highlighting and auto-completion depend on having the file where the symbol's defined open. No, Geany supports generation and automatic loading of global tags files: http://www.geany.org/manual/

Re: DIP 1009--Improve Contract Usability--Preliminary Review Round 2 Begins

2017-07-31 Thread Nick Treleaven via Digitalmars-d
On Friday, 28 July 2017 at 16:58:41 UTC, Moritz Maxeiner wrote: Having a keyword delimit the end of an optional is both redundant and inconsistent You are arguing against the current syntax, not my proposal. In my case the `do` keyword would be disambiguating between out expressions and out b

Re: DIP 1009--Improve Contract Usability--Preliminary Review Round 2 Begins

2017-07-31 Thread Nick Treleaven via Digitalmars-d
On Friday, 28 July 2017 at 16:44:24 UTC, MysticZach wrote: On Friday, 28 July 2017 at 11:04:23 UTC, Nick Treleaven wrote: One option to solve the out contract ambiguity and aid parsing by tools is to require 'do' after out contract expressions. BTW `do` would only be required before the {} fun

Re: DIP 1012--Attributes--Preliminary Review Round 1

2017-07-28 Thread Nick Treleaven via Digitalmars-d
On Friday, 28 July 2017 at 01:50:24 UTC, Jonathan M Davis wrote: Should public have @ on it? Should static have @ on it? What about scope, const, or shared? If they are storage classes, they shouldn't have @. If they are statement or expression keywords, they shouldn't have @. Things like tha

Re: DIP 1009--Improve Contract Usability--Preliminary Review Round 2 Begins

2017-07-28 Thread Nick Treleaven via Digitalmars-d
On Friday, 21 July 2017 at 13:51:05 UTC, Mike Parker wrote: DIP 1009 is titled "Improve Contract Usability". https://github.com/dlang/DIPs/blob/master/DIPs/DIP1009.md I think the proposed in/out expression contracts should require pure expressions. In the rare case that impurity is required,

Re: New Garbage Collector?

2017-07-25 Thread Nick Treleaven via Digitalmars-d
On Saturday, 22 July 2017 at 10:17:49 UTC, Temtaime wrote: The new precise GC will be never added to druntime. 2.075 has precise scanning of the DATA and the TLS segments (on Windows): http://dlang.org/spec/garbage.html#precise_dataseg This seems like significant progress towards precise sca

Re: If Statement with Declaration

2017-07-24 Thread Nick Treleaven via Digitalmars-d
On Monday, 24 July 2017 at 13:12:17 UTC, Nick Treleaven wrote: static if (is(E == enum; alias V)) { // this inserts "V" V v; } The test comes first as it logically should, as the alias is not being used until the following statement. Hmm, it can be used in the test: is(Abc U : U*) is(AA A

Re: If Statement with Declaration

2017-07-24 Thread Nick Treleaven via Digitalmars-d
On Monday, 24 July 2017 at 13:12:17 UTC, Nick Treleaven wrote: On Friday, 21 July 2017 at 21:50:02 UTC, Johan Engelen wrote: static if (is(E V == enum)) { // this inserts "V" V v; } ``` Yes, but this is a bit different as the goal is to avoid repeating V Sigh. Repeating E. (unintentional

Re: If Statement with Declaration

2017-07-24 Thread Nick Treleaven via Digitalmars-d
On Friday, 21 July 2017 at 21:50:02 UTC, Johan Engelen wrote: We do have a construct like that already: ``` static if (is(E V == enum)) { // this inserts "V" V v; } ``` Yes, but this is a bit different as the goal is to avoid repeating V (as it may be complex). Repeating a local variable n

Re: The X Macro using D

2017-07-21 Thread Nick Treleaven via Digitalmars-d
On Friday, 21 July 2017 at 11:19:47 UTC, Patrick Schluter wrote: In C there's no point in the X macro anymore since C99. Designated initializer allow to do it properly[1] now. enum COLORS { red, blue, green, max }; char *cstring[max] = {[red]="red", [blue]="blue", [green]="green" }; /*

Re: Error in spec: struct init with member names

2017-07-04 Thread Nick Treleaven via Digitalmars-d
On Monday, 3 July 2017 at 18:14:43 UTC, Johan Engelen wrote: The spec (or DMD frontend) is broken regarding struct initialization with explicit mention of member field names: https://dlang.org/spec/struct.html#static_struct_init I agree, PR: https://github.com/dlang/dlang.org/pull/1794

Re: Why do "const inout" and "const inout shared" exist?

2017-07-03 Thread Nick Treleaven via Digitalmars-d
On Monday, 3 July 2017 at 15:48:26 UTC, Petar Kirov [ZombineDev] wrote: but can you explain exactly what part of Rust's type system provides extra benefits in terms of optimization over D's type system? In safe Rust, a reference to mutable data has to be unique [1]. So the optimizer could ass

Re: Isn't it about time for D3?

2017-06-19 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 14 June 2017 at 12:08:16 UTC, Mike wrote: * Drop the GC or at a minimum make it opt-in. Add a borrow checker, automatic reference counting, or some other GC alternative that doesn't require a separate thread. AIUI D's GC doesn't use a separate thread: https://dlang.org/spec/garb

Re: Expressing range constraints in CNF form

2017-06-11 Thread Nick Treleaven via Digitalmars-d
On Sunday, 11 June 2017 at 00:28:58 UTC, Andrei Alexandrescu wrote: https://github.com/dlang/phobos/pull/5461 There's many good advantages to this. The immediate one is the constraint is better structured and easier to understand. Then, the compiler can print the exact clause that failed, whic

Re: DIP 1008 Preliminary Review Round 1

2017-06-11 Thread Nick Treleaven via Digitalmars-d
On Friday, 26 May 2017 at 21:31:20 UTC, Steven Schveighoffer wrote: Part of this may mean clarifying what @nogc actually means. Does it mean no interaction with the GC system, or does it mean "cannot run a collection cycle"? I was pleased to find GC.addRange is now @nogc, so it seems potentia

Re: Check for duplicated AA keys at compile time

2017-06-11 Thread Nick Treleaven via Digitalmars-d
On Saturday, 3 June 2017 at 14:59:38 UTC, Jacob Carlborg wrote: Would it be reasonable for the compiler to check for duplicated keys in an associative array literal where all the keys are known at compile time? For example: auto aa = ["foo": 1, "foo": 1]; https://issues.dlang.org/show_bug.cg

Re: DIP 1008 Preliminary Review Round 1

2017-05-22 Thread Nick Treleaven via Digitalmars-d
On Saturday, 20 May 2017 at 09:35:34 UTC, Stanislav Blinov wrote: On Saturday, 20 May 2017 at 02:25:45 UTC, Walter Bright wrote: void foo(scope string s); string s = callCAPIAndAllocateString(); foo(s ~ "abc"); What will happen? The compiler will generate different code? Won't compile? The

Re: DIP 1008 Preliminary Review Round 1

2017-05-22 Thread Nick Treleaven via Digitalmars-d
On Saturday, 20 May 2017 at 02:05:21 UTC, Jonathan M Davis wrote: What we would probably need would be to change msg is a function which generates a message so that derived classes can override that rather than passing a message string. Further to Moritz's reply showing the existing toString o

Re: On the subject of error messages

2017-05-16 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 16 May 2017 at 11:20:57 UTC, Stanislav Blinov wrote: On Tuesday, 16 May 2017 at 09:04:32 UTC, Nick Treleaven wrote: The problem with this approach is all the work required to convert existing code to use this style. ... That's not a problem. In cases where compiler-provided diagnos

Re: On the subject of error messages

2017-05-16 Thread Nick Treleaven via Digitalmars-d
On Saturday, 13 May 2017 at 14:41:50 UTC, Stanislav Blinov wrote: template types(args...) { static if (args.length) alias types = AliasSeq!(typeof(args[0]), types!(args[1..$])); else alias types = AliasSeq!(); } ... foreach(i, T; types!args) { typeof(args) ;-)

Re: Interpolated strings

2017-04-21 Thread Nick Treleaven via Digitalmars-d
On Thursday, 20 April 2017 at 20:43:35 UTC, H. S. Teoh wrote: If you're doing internationalization, though, neither option is a good one (I gave an example using dates in another post): printf-style formats have ordering issues (is it year first, then month, then day? Or month first then day th

Re: Interpolated strings

2017-04-21 Thread Nick Treleaven via Digitalmars-d
On Thursday, 20 April 2017 at 21:34:44 UTC, Steven Schveighoffer wrote: Dmitry's solution is superior I think: $"{a} times 3 is {a * 3}" -> AliasSeq!(a, " times 3 is ", a * 3) +1, this is more flexible. Would work fine with writeln. Yep, and std.conv.text. We might want a function that t

Re: Interpolated strings

2017-04-21 Thread Nick Treleaven via Digitalmars-d
On Thursday, 20 April 2017 at 19:02:20 UTC, Kagamin wrote: Also how various kinds of strings would work? r$"{can}\i\has{slashes}" $`same {here}` r"" and `` are WysiwygStrings. Interpolation is not WYSIWYG. $"" would need to support escaping of the interpolation start character, so may as well

Re: Interpolated strings

2017-04-19 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 19 April 2017 at 00:08:19 UTC, Walter Bright wrote: There are additional problems, such as: $"{a} in %s {b}" % should be escaped: "%s in %%s %s". There would be no use for a single % otherwise. and positional parameters: $"{a} in {0}" That would be literal 0: `"%s

Re: Proposal 2: Exceptions and @nogc

2017-04-15 Thread Nick Treleaven via Digitalmars-d
On Thursday, 13 April 2017 at 05:29:28 UTC, Dukc wrote: The reason it needs: { scope Object ob = new RefCountableType("foo"); scope ob2 = ob; ob = new RefCountableType("bar"); } The "foo" instance would leak if the destruction would be done by calling at end of scope. I assume you

Re: Proposal 2: Exceptions and @nogc

2017-04-12 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 11 April 2017 at 11:08:34 UTC, Dukc wrote: This idea could be generalized: -DRuntime would add an interface "ReferenceCountable". -Throwable would implement it. -When a new expression of ReferenceCountable type is used to assign to a scope variable or argument, it's guaranteed to be

Re: [OT] ISO C++ 17 changes

2017-04-05 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 4 April 2017 at 13:30:47 UTC, Meta wrote: On Tuesday, 4 April 2017 at 08:38:32 UTC, Walter Bright wrote: http://dlang.org/phobos/std_algorithm_iteration.html#.fold Not quite the same as this is a fold over a TypeTuple/AliasSeq. You could of course do: only(args).fold!"a + b"()

Re: Zcoin implementation bug enabled attacker to create 548, 000 Zcoins

2017-03-13 Thread Nick Treleaven via Digitalmars-d
On Saturday, 11 March 2017 at 19:28:16 UTC, H. S. Teoh wrote: So the idea is to analyse the format string at compile-time to determine exactly what functionality is actually used, and instantiate only that. Think of it as a format-string mini-compiler: given a format string and a list of argume

Re: Zcoin implementation bug enabled attacker to create 548, 000 Zcoins

2017-03-11 Thread Nick Treleaven via Digitalmars-d
On Friday, 10 March 2017 at 19:02:06 UTC, H. S. Teoh wrote: A long-standing item on my todo list is to implement compile-time writefln format strings using this technique. Yes, the actual checking seems straightforward - here I implemented CT format as an overload: import std.format : format

Re: [Tidbit] making your D code more modular & unittestable

2017-03-10 Thread Nick Treleaven via Digitalmars-d
On Thursday, 9 March 2017 at 20:54:23 UTC, Nick Sabalausky (Abscissa) wrote: On 03/08/2017 04:34 PM, H. S. Teoh via Digitalmars-d wrote: auto parseFile(Slice)(Slice input) if (isRandomAccessRange!Slice && hasSlicing!Slice && is(ElementType!Slice : ubyt

Re: opIndex() may hide opSlice()

2017-03-10 Thread Nick Treleaven via Digitalmars-d
On Friday, 10 March 2017 at 01:10:21 UTC, H. S. Teoh wrote: On Fri, Mar 10, 2017 at 01:07:33AM +, XavierAP via Digitalmars-d wrote: The web reference tersely says under its *Slice* Operator Overloading chapter [1]: "To overload a[], simply define opIndex with no parameters." Should not th

Re: syntax sugar: std.path::buildPath instead of from!"std.path".buildPath

2017-02-21 Thread Nick Treleaven via Digitalmars-d
On Sunday, 19 February 2017 at 01:53:58 UTC, Timothee Cour wrote: Doesn't add indentation: with (module_!"std.stdio, std.traits") void fun(T)(File input, T value) if (isIntegral!T); * what is the implementation of `module_` ? `from` defined earlier doesn't allow for multiple modules as in fr

Re: syntax sugar: std.path::buildPath instead of from!"std.path".buildPath

2017-02-17 Thread Nick Treleaven via Digitalmars-d
On Friday, 17 February 2017 at 04:09:14 UTC, timotheecour wrote: * with(module_!"std.foo") is useful for scoping imports to cover several declarations and being DRY; at the expense of adding indentation/nesting and less nice syntax Doesn't add indentation: with (module_!"std.stdio, std.traits

Re: syntax sugar: std.path::buildPath instead of from!"std.path".buildPath

2017-02-15 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 15 February 2017 at 20:09:46 UTC, Timothee Cour wrote: This thread completely diverged from the original post, which was propsing `::` instead of `from!`: ``` void fun(T)(std.stdio::File input, T value) if (std.traits::isIntegral!T) {...} ``` instead of: ``` void fun(T)(Module

Re: Workaround for DIP 1005

2017-02-10 Thread Nick Treleaven via Digitalmars-d
On Thursday, 9 February 2017 at 05:40:01 UTC, Jonathan M Davis wrote: auto func(alias pred, R)(R range) if(from!"std.range.primitives".isInputRange!R && is(typeof(pred(range.front)) == bool)) {...} but you can't import std.range.primitives.front to make dynamic arrays work, whereas w

Re: memcpy() comparison: C, Rust, and D

2017-02-03 Thread Nick Treleaven via Digitalmars-d
On Thursday, 2 February 2017 at 20:37:32 UTC, Random D user wrote: What if d had a -safe-defaults switch? It should be ok, since safe is stricter than unsafe right? Yes, we need this because module-level '@safe:' doesn't allow inferrence of @system. This way old/existing code would compile f

Re: memcpy() comparison: C, Rust, and D

2017-02-01 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 31 January 2017 at 18:21:02 UTC, Jack Stouffer wrote: On Tuesday, 31 January 2017 at 01:30:48 UTC, Walter Bright wrote: 2. The return value is derived from s1. 4. Copies of s1 or s2 are not saved. Actually I didn't know either of those things from looking at the signature because

Re: Interior pointers and fast GC

2017-01-21 Thread Nick Treleaven via Digitalmars-d
On Saturday, 14 January 2017 at 15:30:42 UTC, Rainer Schuetze wrote: In addition, you need to lookup the pool anyway to figure out if the pointer points to non-managed memory (stack, global data, malloc'd memory). Makes me wonder about a GC'd language where each pointer is actually a member o

Re: std.traits vcs __traits

2017-01-19 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 17 January 2017 at 18:22:06 UTC, Nordlöw wrote: https://github.com/dlang/phobos/pull/5038 This makes (at least) UnsignedTypeOf unused in Phobos, and it's undocumented but public. There are LREFs in the std.traits docs under the SomethingTypeOf section - none of these links go any

Re: Multiple return value as requirements for safety and performance

2017-01-02 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 20 December 2016 at 18:51:05 UTC, Brad Anderson wrote: Could the comma expression be contextually removed? Specifically in return expressions as discussed initially in this post? Back in May a change was introduced to issue a deprecation message for uses of the comma operator outs

Re: wrong isInputRange design

2016-12-03 Thread Nick Treleaven via Digitalmars-d
On Saturday, 3 December 2016 at 16:37:21 UTC, Jerry wrote: Also "string" is just an alias of an array, "immutable(char)[]". So an array should have "front" defined. Can you post more code? You still have to `import std.range.primitives : front`, even for arrays.

Re: Don't truncate forum titles, use multiple lines instead

2016-11-21 Thread Nick Treleaven via Digitalmars-d
On Sunday, 20 November 2016 at 13:19:41 UTC, qznc wrote: For mobile I would prefer it to use the whole width for the title and convert the other two columns into "subtitle text" below. +1, that'd avoid the other columns taking up too much empty vertical space vs. if the title column was wrapp

Re: If Statement with Declaration

2016-11-07 Thread Nick Treleaven via Digitalmars-d
On Sunday, 6 November 2016 at 05:07:10 UTC, Andrei Alexandrescu wrote: if (auto variable = fun(); variable != 42) { ... } Why does the word "variable" need to appear twice? It seems simpler to allow punctuation around existing syntax: // possible future D if ((auto variable = fun()) != 42)

Re: If Statement with Declaration

2016-11-04 Thread Nick Treleaven via Digitalmars-d
On Friday, 4 November 2016 at 13:56:57 UTC, Andrea Fontana wrote: If you don't like indentation you can simply ignore it or you can use old goto :) { int i = someFunc(); if (i < 0) goto outer; // your code here } outer: BTW there is a trick to avoid goto+label: switch (true) { defau

Re: RC buffer

2016-11-02 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 2 November 2016 at 05:00:23 UTC, Andrei Alexandrescu wrote: In order to make opAssign safe, a language change will be necessary. Technically, it should be possible with runtime checks: https://forum.dlang.org/post/aeeffshzkfjbrejzt...@forum.dlang.org The checking overheads disap

Re: Pattern matching in D?

2016-11-02 Thread Nick Treleaven via Digitalmars-d
On Friday, 28 October 2016 at 11:53:16 UTC, Nick Treleaven wrote: In the unittest, using with(Color) should help, but I couldn't get that to compile (visit thinks invalid lambdas are being passed). https://issues.dlang.org/show_bug.cgi?id=16655

  1   2   3   >