Re: strip in stdin

2020-12-04 Thread Paul Backus via Digitalmars-d-learn
On Friday, 4 December 2020 at 06:51:32 UTC, MGW wrote: string[] m = stdin.byLineCopy.array; How to make strip() for each line in an expression ... To apply a function to each element of a range, use the `map` algorithm: import std.algorithm: map; string[] m = stdin.byLineCopy.map!strip.arr

Re: D Bindings for C Opaque Pointers

2020-12-02 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 3 December 2020 at 00:30:06 UTC, Kyle Ingraham wrote: // EDSDKTypes.h typedef struct __EdsObject* EdsBaseRef; typedef EdsBaseRef EdsCameraListRef; // [...] // edsdk.d struct EdsBaseRef; alias EdsBaseRef EdsCameraListRef; You've dropped a level of indirection here. In the C hea

Re: IsTuple returns true for Nullable!SomeTuple

2020-12-02 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 2 December 2020 at 05:25:09 UTC, Ben Jones wrote: This seems like very surprising behavior to me. Is it a bug? import std.typecons; alias NT = Nullable!(Tuple!(int, double)); pragma(msg, isTuple!NT); //prints true! No, this is not a bug, because Nullable!T currently has an impl

Re: How to unit-test a phobos module?

2020-11-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 26 November 2020 at 00:17:26 UTC, Q. Schroll wrote: One of the issues is, I don't know what DRuntime really is. As far as I understand on the surface-level, it's functionality one would expect to be implemented by the compiler, but actually implemented in plain D code. A low-leve

Re: How to unit-test a phobos module?

2020-11-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 21:16:06 UTC, Q. Schroll wrote: On Wednesday, 25 November 2020 at 21:11:24 UTC, Paul Backus wrote: On Wednesday, 25 November 2020 at 20:58:20 UTC, Q. Schroll wrote: My setup: * A fresh DMD installed a few minutes ago. * Clone of my Phobos fork with up-to-date c

Re: How to unit-test a phobos module?

2020-11-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 20:58:20 UTC, Q. Schroll wrote: My setup: * A fresh DMD installed a few minutes ago. * Clone of my Phobos fork with up-to-date changes from dlang/phobos/master. Do you have clones of dmd and druntime too? If not, try following these instructions: https://wi

Re: Simulating computed goto

2020-11-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 18:44:52 UTC, NonNull wrote: How good is optimization in ldc2, gdc, dmd at compiling chained jumps into one jump each time? The easiest way to find the answer to a question like this is to use the compiler explorer: https://d.godbolt.org/

Re: Article about Ranges

2020-11-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 11:13:24 UTC, ddcovery wrote: Months ago I read an Andrei article explaining why Ranges (comparing with C++). I remember article introduction included a python "false" quick-sort algorithm. I'm really interested in a more detailed read of the article, but I c

Re: How Performance down slow it is using UFCS friendly function?

2020-11-20 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 21 November 2020 at 00:26:03 UTC, Marcone wrote: // Função receive() char[] receive(Socket socket, int size = 8192) nothrow { try { char[] buffer; buffer.length = size; int rq = socket.receive(buffer); return buf

Re: lambdas with types

2020-11-20 Thread Paul Backus via Digitalmars-d-learn
On Friday, 20 November 2020 at 14:08:23 UTC, jmh530 wrote: Doing something like below fails because I don't seem to be able to make a templated lambda that just takes types. Is the only way to do something similar to create a separate function to handle the condition, or is there some other way

Re: implementing default opCmp

2020-11-18 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 22:29:17 UTC, Steven Schveighoffer wrote: I have a struct like this: struct S { int x; int y; } and I want a default comparison. The problem is, that comparison doesn't have a default, and requires I implement opCmp. While this is useful for the compile

Re: Executing AWS commands

2020-11-17 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 17 November 2020 at 19:07:42 UTC, Vino wrote: auto pid = execute(["/usr/bin/aws ec2 describe-images --filters 'Name=state,Values=available' --query 'Images[*].[ImageId]'"]); [...] auto pid = execute(["/usr/bin/aws ec2 describe-images --filters 'Name=state,Values=available' --query '

Re: .d files without a module statement? Required to be absent?

2020-11-14 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 14 November 2020 at 17:55:13 UTC, WhatMeWorry wrote: I was poking around the dmd code just to "learn from the best" and I came across some files that ended with the .d extension which did not have the module statement. (I was under the naive impression that all .d files must have

Re: Unclear error message

2020-11-10 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 01:05:21 UTC, SealabJaster wrote: Please see the code at https://run.dlang.io/is/Yjidek As I understand the error is caused by trying to provide a delegate when there's no context to provide. Not complaining about that. However what I am complaining about is

Re: Generic comparison

2020-11-10 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 20:32:40 UTC, Paul Backus wrote: alias isOrderingComparableWith(T, U) = __traits(compiles, (T t, U u) => t < u); My bad, should be `enum`, not `alias`.

Re: Generic comparison

2020-11-10 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 17:19:09 UTC, Ola Fosheim Grøstad wrote: Interesting, so "auto ref T" is the go-to type specifier for generic code then? I guess I also should conditionally add things like pure, nogc, nothrow... I assume I would have to test the comparison operator. I actuall

Re: Generic comparison

2020-11-10 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 16:55:11 UTC, Ola Fosheim Grøstad wrote: I want to implement a generic function for "a < f(x) < b" that will give the same result as "(a < f(x)) && (f(x) < b)" for any conceivable mix of types. Except if that "f(x)" should only be evaluated once. Is it sufficie

Re: C++ or D?

2020-11-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: Anyone have any thoughts how C++ and D compare? Broadly speaking: D has a better core language, and C++ has a much better library and tooling ecosystem.

Re: Value based overload resolution?

2020-11-09 Thread Paul Backus via Digitalmars-d-learn
On Monday, 9 November 2020 at 22:04:55 UTC, kdevel wrote: It appears to me that the overload resolution may depend on the /value/ of the function argument. According to [1] the type of 1 is int and that of 1L is long. Thus I would have expected foo!int and foo!long being called in those cases.

Re: How exactly does Tuple work?

2020-11-07 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 7 November 2020 at 18:02:26 UTC, Jan Hönig wrote: I have a simple question. How exactly does Tuple work? In detail, I am interested in expand and opSlice. A Tuple is a struct whose members are generated by type sequence instantiation: https://dlang.org/articles/ctarguments.html

Re: Implicit conversion to templatized type

2020-11-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 November 2020 at 15:01:21 UTC, Andrey Zherikov wrote: But how can I achieve the same result if S1 is a template "struct S1(T) {}" and S2 should be convertible to S1!T with any T? Also why neither "opCast" struct S2 { S1 opCast(T)() const if(is(T == S1)) { return S1(); } }

Re: Return values from auto function

2020-11-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: I can make it work if I add a type to `failure` function but this remove brevity in usage: - auto failure(T)(string error) { return Result!T(Result!T.Failure(error)); } auto f(int i) { return i > 0 ? succe

Re: Json output to container

2020-10-30 Thread Paul Backus via Digitalmars-d-learn
On Friday, 30 October 2020 at 19:07:20 UTC, Vino wrote: Requirement: parse the json string and store the output to a container. From, Vino.B Here's a working version of the code from your original post: import asdf : parseJson; import std.algorithm; import std.container.array; import std.s

Re: Json output to container

2020-10-30 Thread Paul Backus via Digitalmars-d-learn
On Friday, 30 October 2020 at 10:23:22 UTC, Vino wrote: Hi, Request your help on the below code [...] .filter!(a => a.(["items"].byElement)) What exactly are you trying to accomplish with this `a.(stuff)` syntax? As I'm sure you've discovered, it is not valid D, but it appea

Re: Looking for a Simple Doubly Linked List Implementation

2020-10-29 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 29 October 2020 at 18:10:28 UTC, IGotD- wrote: Is this what you are looking for? https://dlang.org/phobos/std_container_dlist.html I'm pretty sure the post you replied to is spam.

Re: Empty functions

2020-10-29 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 29 October 2020 at 09:06:21 UTC, Jan Hönig wrote: On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: This would mean, that this one should work as well. It does not work as I intended, as `() => {}` has not the return type of `void`. (I don't know how to print: `Ret

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:15:40 UTC, Paul wrote: per the D sample wc2.d size_t[string] dictionary; <-is printed by... . foreach (word1; dictionary.keys.sort) writef etc I want to print the dictionary sorted by value not key. I can write an algorithm but is there a librar

Re: is type checking in D undecidable?

2020-10-22 Thread Paul Backus via Digitalmars-d-learn
On Friday, 23 October 2020 at 00:53:19 UTC, Bruce Carneal wrote: When you write functions, the compiler helps you out with fully automated constraint checking. When you write templates you can write them so that they look like simple functions, in which case you're on pretty solid ground. You

Re: is type checking in D undecidable?

2020-10-22 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 October 2020 at 19:24:53 UTC, Bruce Carneal wrote: On a related topic, I believe that type functions enable a large amount of code in the "may be hard to prove decidable" category (templates) to be (re)written as clearly decidable code. Easier for the compiler to deal with and,

Re: Does the default opEquals include padding in the comparison? If so, how can the problems that arise with C++ interoperabilty be solved?

2020-10-21 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 19:23:43 UTC, Simon van Bernem wrote: The only explanation I can think of is that D memcmps the entire struct including the padding. Is this correct? If so, what can I do about this? Why doesn't the opEquals get modified appropriately even though the struct is

Re: Compiler is calling `_memset64` in betterC

2020-10-19 Thread Paul Backus via Digitalmars-d-learn
On Monday, 19 October 2020 at 14:07:38 UTC, matheus wrote: On Sunday, 18 October 2020 at 19:24:28 UTC, Ferhat Kurtulmuş wrote: I plan to start a project in reasonable size, I wonder if I should really use betterC... if I encounter a bug like this, will I be stuck at it? The bug report says, i

Re: Compiler is calling `_memset64` in betterC

2020-10-18 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 18 October 2020 at 16:04:55 UTC, Koro wrote: I'm writing a 'betterC' program and the compiler is generating a call to '_memset64' if I have an array literal where the elements are the same. It's a known bug: https://issues.dlang.org/show_bug.cgi?id=17778 My guess is that the reaso

Re: Why is `Appender._data` a pointer to its `Data`-store?

2020-10-16 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 17 October 2020 at 00:06:31 UTC, Steven Schveighoffer wrote: Appender is ref counted IIRC. -Steve It's not; it uses the GC.

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Paul Backus via Digitalmars-d-learn
On Friday, 16 October 2020 at 15:19:51 UTC, Paul Backus wrote: On Friday, 16 October 2020 at 13:12:04 UTC, tchaloupka wrote: So when the exception is thrown within Foo destructor (and it's bad on it's own but can easily happen as destructors aren't nothrow @nogc by default). Is this behavior

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Paul Backus via Digitalmars-d-learn
On Friday, 16 October 2020 at 13:12:04 UTC, tchaloupka wrote: So when the exception is thrown within Foo destructor (and it's bad on it's own but can easily happen as destructors aren't nothrow @nogc by default). Is this behavior expected? This is a compiler/language bug. It was fixed in DMD

Re: universal alpha?

2020-10-16 Thread Paul Backus via Digitalmars-d-learn
On Friday, 16 October 2020 at 13:27:57 UTC, Imperatorn wrote: https://forum.dlang.org/post/e5ghnv$2bns$1...@digitaldaemon.com On Tuesday, 30 May 2006 at 04:29:51 UTC, BCS wrote: Does anyone have a link to a definition of universal alpha as used in the DMD docs? (see: http://www.digitalmars.co

Re: How can I use class and wasm?

2020-10-15 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 15 October 2020 at 22:02:11 UTC, Jack wrote: can I make it work? the code (see below) result in link error: lld: error: wasm.o: undefined symbol: _D4wasm1C7__ClassZ lld: error: wasm.o: undefined symbol: _d_allocclass Error: linking with LLD failed command line: ldc2 --d-debug -m

Re: Why was new(size_t s) { } deprecated in favor of an external allocator?

2020-10-15 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 15 October 2020 at 06:39:00 UTC, Patrick Schluter wrote: On Wednesday, 14 October 2020 at 20:32:51 UTC, Max Haughton wrote: On Wednesday, 14 October 2020 at 20:27:10 UTC, Jack wrote: What was the reasoning behind this decision? Andrei's std::allocator talk from a few years ago at

Re: malloc(s)[0..s] vs cast(T)malloc(s)

2020-10-14 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 14 October 2020 at 20:15:39 UTC, Jack wrote: What's the difference between: import core.stdc.stdlib : malloc; auto x = malloc(s)[0..s]; and auto x = cast(T)malloc(s); ? I have been using the last but I saw in some code examples, like this[1] the first being used. What's the d

Re: If and isType with arrays

2020-10-07 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 7 October 2020 at 16:25:33 UTC, DMon wrote: Can isType be used as a condition in an if statement with arrays? import std.stdio; import std.traits; void main() { int[5] a = [1,2,3,4,5]; // Something like this: if (a == isType!(int[5])) { write("true"); }

Re: cannot call impure function

2020-10-04 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote: Dear all, Sorry for the potentially stupid question, but I'm a complete newbie to D. Why does compiling the following trivial code fail? import std.stdio; void main() { writeln(3.14); } Works fine for me using DMD 2.094.0 on Lin

Re: static foreach over constant range in @nogc block

2020-10-03 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 3 October 2020 at 14:17:45 UTC, tspike wrote: On Saturday, 3 October 2020 at 14:12:21 UTC, Paul Backus wrote: https://issues.dlang.org/show_bug.cgi?id=18439 Perfect! Thanks for getting back to me so quickly. FYI I am not Timon Gehr, the person who originally replied to you, but

Re: static foreach over constant range in @nogc block

2020-10-03 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 3 October 2020 at 14:02:08 UTC, tspike wrote: On Saturday, 3 October 2020 at 12:43:01 UTC, Timon Gehr wrote: It's a compiler bug, the same as this one: @nogc: void main(){ static immutable x = { int[] a; a~=1; return a; }(); } Ah, thank you for the quick reply! Do you know i

Re: How does alias exactly work

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 01:46:56 UTC, Ruby The Roobster wrote: I thought alias could work like this with classes: alias test = MyClass(3,"H",9.1); //Assume the constructor parameters for MyClass are (int,string,double). Can anybody fix this code? `alias` lets you create a new name

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Monday, 28 September 2020 at 13:45:30 UTC, Ruby The Roobster wrote: On Monday, 28 September 2020 at 13:00:43 UTC, Paul Backus wrote: Can you give some examples of inputs and corresponding outputs for this, like you would for a unit test? I don't understand exactly what you're asking, and it

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:11:13 UTC, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in gener

Re: How to hide a function return type in order to wrap several functions into an associated array?

2020-09-27 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 27 September 2020 at 18:54:11 UTC, tastyminerals wrote: This is rather a generic implementation question not necessarily related to D but I'd like to get some opinions. I have a collection of functions that all have the same input, a string. The output however is different and dependi

Re: Why is "delete" unsafe?

2020-09-23 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 04:15:51 UTC, mw wrote: On Saturday, 27 October 2012 at 01:08:12 UTC, Jonathan M Davis wrote: Yes. But using core.memory.GC.free is unsafe for the same reasons that delete is. It's just that it's a druntime function instead of a part of the language, so it's l

Re: Resolve dub dependency

2020-09-21 Thread Paul Backus via Digitalmars-d-learn
On Monday, 21 September 2020 at 19:16:17 UTC, JN wrote: I am trying to use bindbc-sdl and bindbc-wgpu at the same time. The error is: Unresolvable dependencies to package bindbc-loader: bindbc-sdl 0.19.1 depends on bindbc-loader ~>0.3.0 bindbc-sdl 0.19.1 depends on bindbc-loader ~>0.3.0 b

Re: Cannot call @system funciton (stdout)

2020-09-19 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 19 September 2020 at 13:56:53 UTC, Anonymouse wrote: On Saturday, 19 September 2020 at 13:32:07 UTC, Paul Backus wrote: http://dpldocs.info/experimental-docs/std.stdio.File.setvbuf.1.html Thanks. I don't have a clone of druntime/Phobos available to me right now, so some follow-

Re: Cannot call @system funciton (stdout)

2020-09-19 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 19 September 2020 at 13:23:29 UTC, Anonymouse wrote: On Tuesday, 18 August 2020 at 06:25:31 UTC, Kagamin wrote: On Sunday, 16 August 2020 at 18:13:07 UTC, Anonymouse wrote: Just as a drive-by comment, the main stdio thing I came across that I couldn't do from within @safe was stdo

Re: get element index when using each!(x)

2020-09-16 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 17 September 2020 at 03:14:08 UTC, JG wrote: Perhaps there are other ways, but you can use enumerate. For example --- import std.algorithm; import std.range; import std.stdio; void main() { string s = "hello"; s.enumerate.each!(x=>writeln(x[0],":",x[1])); } Worth knowi

Re: Why is BOM required to use unicode in tokens?

2020-09-14 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 01:49:13 UTC, James Blachly wrote: I wish to write a function including ∂x and ∂y (these are trivial to type with appropriate keyboard shortcuts - alt+d on Mac), but without a unicode byte order mark at the beginning of the file, the lexer rejects the tokens.

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 18:24:01 UTC, mw wrote: But, I'd reflect on my experience so far on compile-time meta-programming in D as a novice user, the big problems are: -- in D, there are too many choices, with no clear guideline which one is *THE* one to use for a particular purpose: l

Re: Call C variadic function from D variadic function

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 17:23:42 UTC, Steven Schveighoffer wrote: On 9/13/20 12:55 PM, James Blachly wrote: ```     /// Add a single line to an existing header     auto addLine(T...)(RecordType type, T kvargs)     if(kvargs.length > 0 && isSomeString!(T[0]))     {     static as

Re: passing a parrameter read-only ref?

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 13:35:15 UTC, Martin wrote: Hi, i would like to create a function which takes the first parameter as a reference to a struct - but assure the calle that the reference is read-only. Can this be done? Yes, you can do this with `ref const`.

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 07:00:36 UTC, mw wrote: Here it is: D wrapper for https://ta-lib.org/ https://github.com/mingwugmail/talibd I end up using C macro to generate D functions, the single template is this one: https://github.com/mingwugmail/talibd/blob/master/source/talibd.h#L117

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 12 September 2020 at 19:31:57 UTC, mw wrote: (I'm asking for a more general solution, e.g. what if we have 3, or N sets of variadic parameters?) Looks like we can only pass 1 variadic parameters, then the question is what's the best way to divide it? Is there any special mark

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 12 September 2020 at 18:16:51 UTC, mw wrote: Now, let me expand this challenge: suppose we need to add a new set of variable length extra parameters in parallel to the arrays, i.e: [...] Now the question is how to pass & handle 2 sets of variadic parameters? void fun(Args...)(

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 12 September 2020 at 03:19:23 UTC, mw wrote: I.e. I want to learn the generic meta-programming way to assemble such parameter list (&(x[i], &(y[j])) at compile time, it is possible? It's possible if you use a helper function. Here's how: import std.meta: allSatisfy; import std.tr

Re: Named parameters in function call

2020-09-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 13:28:22 UTC, Cecil Ward wrote: I wonder if there is any way in which we could combine this with strong typing of some sort (how?) to detect errors such as int xcoord; int ycoord; myfunc( x : ycoord, y : xcoord, color : blue )[3] where the

Re: Range checked assignment

2020-09-08 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 14:18:14 UTC, Cecil Ward wrote: I assumed I would have to create a struct type definition and handle various operators. How many will I have to handle? I would of course make it a template so I can reuse this otherwise horribly repetitive code. You can see a fu

Re: Why is there no throws, @gc, impure, mutable ?

2020-09-07 Thread Paul Backus via Digitalmars-d-learn
On Monday, 7 September 2020 at 11:25:15 UTC, wjoe wrote: It's easy to declare the entire module @safe and functions which can't be can be declared @system. However there is const, immutable, pure, @nogc and nothrow but no mutable, impure, @gc and throws. Why is that ? Mostly because nobody's

Re: tupleof seems to break encapsulation

2020-09-04 Thread Paul Backus via Digitalmars-d-learn
On Friday, 4 September 2020 at 18:23:09 UTC, H. S. Teoh wrote: On Fri, Sep 04, 2020 at 07:36:00PM +0200, Jacob Carlborg via Digitalmars-d-learn wrote: [...] It's useful for serialization and, as you can see in your example, for debugging as well. `writeln` will print the values of the fields in

Re: I think Associative Array should throw Exception

2020-09-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 18:20:17 UTC, Jesse Phillips wrote: This is going to be a hard one for me to argue but I'm going to give it a try. Today if you attempt to access a key from an associative array (AA) that does not exist inside the array, a RangeError is thrown. This is similar

Re: Tuple poilerplate code

2020-09-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 02:08:54 UTC, JG wrote: Is there anyway to remove the boilerplate code of dealing with tuples: I find myself having to write things like this fairly often auto someRandomName = f(...); //where f returns a tuple with two parts auto firstPart = someRandomName[0

Re: Template argument deduction fails with alias

2020-09-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 02:48:08 UTC, Ben Jones wrote: Thanks all. I tried using alias this at first and then I get errors trying to construct AliasType objects: auto pi = Payload!int(5); auto pe = ParseError("error"); alias PRType = ParseResult!(Payload!int, ParseError); auto pr =

Re: Template argument deduction fails with alias

2020-08-31 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 01:11:35 UTC, Ben Jones wrote: I have an alias that looks like static if(...){ alias AliasType = SumType!(...); } which I use in a template constraint for a function template: bool func(T: AliasType!Args, Args...)(T t){ ... } When I try to call func with an

Re: Types of lambda args

2020-08-26 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 26 August 2020 at 15:57:37 UTC, Cecil Ward wrote: Ah! That’s the vital missing piece - I didn’t realise it was like a template - I just thought it was an ordinary plain anonymous function, not a generic. All makes sense now. Fun fact: you can see the "de-sugared" version of man

Re: AliasSeq!() deletes item in type list

2020-08-22 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 22 August 2020 at 21:45:35 UTC, data pulverizer wrote: Hi all, just wandering if this is a bug, I certainly didn't expect the output: ```d alias AliasSeq(T...) = T; alias Nothing = AliasSeq!(); template MyTemplate(S, Args...) { pragma(msg, "Args: ", Args); } void main() { a

Re: Disjoint slices of an array as reference

2020-08-19 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 20 August 2020 at 02:21:15 UTC, data pulverizer wrote: ``` double[] y; y ~= x[0..5]; y ~= x[9..14]; ``` But the act of appending results in array copying - breaks the reference with the original array. The only other thing I have considered is creating an array of references to ea

Re: Autodecode?

2020-08-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 16 August 2020 at 20:53:41 UTC, JN wrote: Related to this thread: https://forum.dlang.org/post/xtjzhkvszdiwvrmry...@forum.dlang.org I don't want to hijack it with my newbie questions. What is autodecode and why is it such a big deal? From what I've seen it's related to handling Uni

Re: I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote: I just discovered that the is-operator can be used as in template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias ElementType = T; else alias ElementType = void; } . Very powerful. Is this

Re: arrays in srucs

2020-07-31 Thread Paul Backus via Digitalmars-d-learn
On Friday, 31 July 2020 at 17:02:46 UTC, Andy Balba wrote: The above code, compiles and runs ok .. but sometimes I get run runtime errors using the same paradym, which disappear when I substitute (img.p)[i] Any explanation for this ? Can you show an example where it doesn't work?

Re: Using D within a rust codebase

2020-07-26 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 26 July 2020 at 21:18:19 UTC, powerboat9 wrote: I have an existing rust project, and I'm trying to rewrite part of it in D. However, I'm not sure how to get rust -> dlang interop working. I've looked into rust -> c -> dlang interop, but I'm not sure how to get c -> dlang interop work

Re: Result and Option types

2020-07-25 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 25 July 2020 at 18:06:51 UTC, powerboat9 wrote: Does dlang have an analog to Result or Option types from rust? In addition to Nullable in the standard library, there are some packages on dub you might find useful: * optional: an option type that can also function as a range, for

Re: How spand array for use with functions arguments like tuple?

2020-07-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 July 2020 at 17:59:06 UTC, Marcone wrote: On Sunday, 19 July 2020 at 23:05:45 UTC, Marcone wrote: How spand array for use with functions arguments like tuple? expand* If the array is a compile-time constant, you can use aliasSeqOf [1]. Otherwise, you can't. [1] http://dpldoc

Re: std.process - avoid interaction with parent shell

2020-07-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 July 2020 at 21:44:31 UTC, Steven Schveighoffer wrote: I think you might be right. I don't know how it's accessing my terminal, but clearly it can keep doing so even without any handles open. Probably /dev/tty

Re: alias restriction??!

2020-07-19 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 19 July 2020 at 16:00:28 UTC, Basile B. wrote: On Sunday, 19 July 2020 at 15:00:59 UTC, Paul Backus wrote: On Sunday, 19 July 2020 at 12:42:47 UTC, Carl Sturtivant wrote: On Sunday, 19 July 2020 at 12:08:07 UTC, Paul Backus wrote: Easiest workaround: ref inout(long) Second() inout

Re: alias restriction??!

2020-07-19 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 19 July 2020 at 12:42:47 UTC, Carl Sturtivant wrote: On Sunday, 19 July 2020 at 12:08:07 UTC, Paul Backus wrote: Easiest workaround: ref inout(long) Second() inout { return second.one; } Was trying to avoid this for performance reasons. In fact what are the performance implicatio

Re: alias restriction??!

2020-07-19 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 18 July 2020 at 18:46:16 UTC, Carl Sturtivant wrote: Here's a toy version of a problem in the wild. struct S { long first; union T { long one; double two; } T second; alias First = first; alias Second = second.one; } void main() { S x;

Re: getopt: How does arraySep work?

2020-07-14 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 14 July 2020 at 13:40:44 UTC, Steven Schveighoffer wrote: The whitespace separator doesn't get to your program. args is: ["sample", "--modelicalibs", "a", "b"] There is no separator in the parameter to --modelicalibs, it's just "a". What you need to do is: dmd -run sample.d --m

Re: What's the point of static arrays ?

2020-07-09 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 9 July 2020 at 18:02:02 UTC, IGotD- wrote: Static arrays are great because as already mentioned, they are allocated on the stack (unless it is global variable something, then it ends up in the data segment or TLS area). As C/C++ now allows dynamically sized static arrays (for st

Re: What is up with Vibe-d

2020-07-09 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 9 July 2020 at 18:16:58 UTC, CraigDillabaugh wrote: So is Vibe-d still being actively maintained? I noticed there have been no new releases in a while, and the forums are a bit of a disaster (unless you love porn I suppose): https://forum.rejectedsoftware.com/groups/rejectedsoft

Re: Working with pointers/adresses

2020-07-09 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 9 July 2020 at 16:16:53 UTC, Quantium wrote: I have one more question. I tested the programm, as you said, it worked rarely because of OS restrictions. If I compile that code to dll, and run it through dll launcher, should it work? The OS restrictions don't care whether your progr

Re: Working with pointers/adresses

2020-07-08 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 19:48:07 UTC, Quantium wrote: I'm learning now memory usage in D, and I have the problem that I can't solve. The problem is (The third step): 1) Programm gets number (In int format) as input data. 2) Integer is converted to HEX 3) Programm gets the data in 0x memory

Re: opApply and attributes

2020-07-07 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 7 July 2020 at 00:20:40 UTC, solidstate1991 wrote: See implementation of data structure here: https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/treemap.d#L565 If I try to compile this code, it'll fail, limiting it's usecase: @safe pure unittest {

Re: D Plugin for Visual Studio Code [was Re: Visual D 1.0.0 released]

2020-07-04 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 4 July 2020 at 17:11:47 UTC, Arafel wrote: On 4/7/20 17:42, Rainer Schuetze wrote: Indeed, this is Windows only. Visual Studio Code is a different platform than Visual Studio. Not sure why Microsoft named them so that they are easily confused. (Moving to the learn forum, sinc

Re: isInputRange not satisfied even if all individual conditions are satisfied

2020-06-26 Thread Paul Backus via Digitalmars-d-learn
On Friday, 26 June 2020 at 13:53:46 UTC, Johannes Loher wrote: Am 26.06.20 um 15:35 schrieb ag0aep6g: `isInputRange!R` fails because it has no knowledge of your free `empty` function. Without `empty`, `R` is obviously not a range. Ah, OK, that makes sense. It's kind of sad though because it

Re: Iterators in structs

2020-06-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 June 2020 at 18:47:42 UTC, repr-man wrote: struct ChunksOf(R) { Chunks!R iter; this(R r, size_t width) { this.iter = r.chunks(width); assert(is(typeof(iter) == Chunks!R)); } } This works, only if I change the declaration of x in main() to: au

Re: Flagging special conditions on return from a function call

2020-06-23 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 23 June 2020 at 16:14:20 UTC, Denis wrote: by presenting an interface that only compiles when both cases are covered, like fun().match((T t) => t, () => Error()). A complete solution wrapped in a tidy package -- I like it. Thanks for sharing. If you're open to using Dub packages,

Re: called copy constructor in foreach with ref on Range

2020-06-23 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 23 June 2020 at 03:52:23 UTC, Jonathan M Davis wrote: It is extremely common to wrap ranges in other ranges (and in fact, you basically have to in order to have lazy ranges). That really doesn't work very well - if at all - if you can't copy the range. It might be possible with a

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Paul Backus via Digitalmars-d-learn
On Monday, 22 June 2020 at 21:33:08 UTC, H. S. Teoh wrote: Jonathan is coming from the POV of generic code. The problem with move leaving the original range in its .init state isn't so much that it will crash or anything (even though as you said that does indicate a flaw in the range's imple

Re: Reading text (I mean "real" text...)

2020-06-19 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 20 June 2020 at 01:35:56 UTC, Denis wrote: THE OBJECTIVE The objective is to read a file one line at a time (reading each line into a string), while checking for human-readable text character by character. Invalid characters (control and UTF-8) should generate an exception. Un

Re: Should the compiler be failing to infer template args here?

2020-06-19 Thread Paul Backus via Digitalmars-d-learn
On Friday, 19 June 2020 at 16:16:55 UTC, SealabJaster wrote: If you take a look at this code here: https://godbolt.org/z/4T3uLh You can see that when using a templated alias, the compiler fails to infer the T template parameter, but only when using the function that also asks for the alias, i

Re: Finding out ref-ness of the return of an auto ref function

2020-06-12 Thread Paul Backus via Digitalmars-d-learn
On Friday, 12 June 2020 at 14:56:41 UTC, Arafel wrote: Hi all, I'm hitting a problem that it's making crazy... is there any way to find out if the return of an `auto ref` function is actually ref or not? So, according to the documentation [1] it depends on the return expressions... however

Re: What is the current stage of @property ?

2020-06-11 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 11 June 2020 at 05:41:25 UTC, H. S. Teoh wrote: Ironically, just today I ran into this corner case where @property actually became a solution to a real problem: //-module1.d-- auto someGenericFunc(T)(T t) { ... static if (is

Re: What is the current stage of @property ?

2020-06-10 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 23:03:21 UTC, Adam D. Ruppe wrote: On Wednesday, 10 June 2020 at 22:50:17 UTC, Paul Backus wrote: static assert(isInputRange!S); // passes isInputRange doesn't check it but others do. std.random.isSeedable requires @property on front for example. Nope: struct

Re: What is the current stage of @property ?

2020-06-10 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 23:26:35 UTC, Paul Backus wrote: On Wednesday, 10 June 2020 at 23:03:21 UTC, Adam D. Ruppe wrote: On Wednesday, 10 June 2020 at 22:50:17 UTC, Paul Backus wrote: static assert(isInputRange!S); // passes isInputRange doesn't check it but others do. std.random.isSe

Re: What is the current stage of @property ?

2020-06-10 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 21:41:54 UTC, H. S. Teoh wrote: There are a few places where it's needed (like satisfying the range API, which implicitly checks for it) That may have been true at one point, but it isn't true now: struct S { bool empty() { return false; } int front() { re

<    1   2   3   4   5   6   7   8   9   >