Re: Getting nice print of struct for debugging

2017-02-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 February 2017 at 16:04:17 UTC, Martin Tschierschke wrote: Hello, I have a little program where I am filling a struct with values from an regex match. Now I want to display the content of the struct for debugging purpose. I believe the easiest way to do this is to define a

Re: Calling std.variant.visit from a pure function

2016-11-04 Thread Paul Backus via Digitalmars-d-learn
On Friday, 4 November 2016 at 23:38:47 UTC, sarn wrote: I suggest trying it with the latest dmd and filing a bug report. Taking a quick look at the library code (https://github.com/dlang/phobos/blob/master/std/variant.d), it *seems* like everything uses templates and functions returning

Re: Unable To Install Debian Package on Deepin Linux (Debian Jessie)

2016-11-16 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 16 November 2016 at 02:24:26 UTC, azzuwan wrote: It seems that /usr/bin/dman is currently used by deepin-manual. Is there anyway to get around this? Take a look at dpkg-divert(1)

Calling std.variant.visit from a pure function

2016-11-03 Thread Paul Backus via Digitalmars-d-learn
As a learning exercise, I'm writing a simple AST evaluator for arithmetic expressions in D. (See https://gist.github.com/ckirkendall/2934374) In order to get a feel for functional programming in D, I decided to try and implement my solution in a functional style, using algebraic data types

Re: not callable error

2016-11-03 Thread Paul Backus via Digitalmars-d-learn
On Friday, 4 November 2016 at 02:28:17 UTC, bluphantom91 wrote: Hello, I am trying to finish up a group project but I am running into a small problem. I keep getting an error about fgetc not being callable. The purpose of my program is to count the number of characters in a file. Any bit of

Re: Creating a template mixin for explicit casts.

2018-05-17 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 17 May 2018 at 15:25:37 UTC, Sjoerd Nijboer wrote: I want to make a template mixin that is able to cast one of these generic structs to the other explicitly. I have a bunch of these structs and therefore I thought it would make sense to do it by template mixin. I just don't know

Re: pipeProcess failing

2018-06-03 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 3 June 2018 at 15:07:07 UTC, DigitalDesigns wrote: I'm calling pipe process using pipeProcess([AliasSeq!args], Redirect.stdout | Redirect.stdin); where args is a tuple. Everything works when I pass each argument individually. If I combine any args using a space it fails or if I

Re: New programming paradigm

2018-06-03 Thread Paul Backus via Digitalmars-d-learn
On Monday, 4 September 2017 at 03:26:23 UTC, EntangledQuanta wrote: Take a variant type. It contains the "type" and the data. To simplify, we will treat look at it like (pseudo-code, use your brain) enum Type { int, float } foo(void* Data, Type type); The normal way to deal with this is a

Re: How do I make this function thread safe?

2018-05-31 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 31 May 2018 at 19:26:12 UTC, Dr.No wrote: My application create some HTML which is then converted to PDF by wkhtmltopdf library. I'm trying to figure out how make the PDF generation run parallel, currently, it's running linearly. It looks like wkhtmltopdf does not support

Re: Error: variable foo conflicts with struct foo

2018-01-04 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 4 January 2018 at 17:45:35 UTC, Stijn wrote: Why is it not allowed for a variable name to match a type name? The following example fails with "Error: variable foo conflicts with struct foo" struct foo {} foo foo; Imagine if you then tried to write something like

Re: Templates for DRY code

2018-01-06 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 6 January 2018 at 03:38:35 UTC, codephantom wrote: or even.. a.append( s.to!ConvertToElementType(a) ); That's not valid code of course, but the semantics are all contained in that single chunk. This works: import std.range.primitives: ElementType; a ~=

Re: free func "front" is not picked up as a candidate when doing range.front(...)

2018-02-07 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 7 February 2018 at 19:25:01 UTC, aliak wrote: import std.range: iota; 0.iota.front(100).writeln; // Error: inout method std.range.iota!(int, int).iota.Result.front is not callable using a mutable object import std.algorithm: filter; auto arr = [0, 1];

Re: Zip with range of ranges

2018-02-25 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 25 February 2018 at 16:22:19 UTC, ARaspiK wrote: Instead of passing std.range.zip a set of ranges as different arguments, is it possible to hand the m a range of ranges, and get them to zip together each element of every subrange? `std.range.transposed` does this, but it requires

Re: @nogc closures

2018-08-05 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 5 August 2018 at 12:23:17 UTC, vit wrote: Yes, it isn't possible. I modify filter a and map from std.algorithm: void main()@nogc{ import std.experimental.all; const int j = 2; int i = 0; const int[3] tmp = [1, 2, 3]; tmp[]

Re: GC and void[N] in struct

2018-08-06 Thread Paul Backus via Digitalmars-d-learn
On Monday, 6 August 2018 at 20:22:36 UTC, vit wrote: On Monday, 6 August 2018 at 19:56:03 UTC, Steven Schveighoffer wrote: BTW, is there a reason you aren't just using Algebraic? https://dlang.org/phobos/std_variant.html#.Algebraic -Steve primarily visit for Algebraic isn't pure, @nogc,

Re: Convert output of map() to array of strings

2018-08-15 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 13:53:02 UTC, Andrey wrote: Hello, I have the following code: string[] list; string text; // ... enum pattern = ctRegex!`^[0-9]+$`; list = text.split('\n').map!(line => line.matchFirst(pattern).hit); Compiler says that it can't convert result of map function

Re: is this a betterC bug ?

2018-08-14 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:01:57 UTC, learnfirst1 wrote: enum string[] a = ["a"]; extern(C) void main() { int i = 0; auto s = a[i]; } --- Error: TypeInfo cannot be used with -betterC Workaround: https://run.dlang.io/is/NZykl0 Source:

Re: write a function template specialisation that tests if an argument is known at compile time

2018-08-11 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 11 August 2018 at 05:17:51 UTC, Cecil Ward wrote: T myfunc(T)( T x, uint mask ) if ( mask == 3 ) { return fast_func( x, mask ); } but of course this doesn't work because mask is not known at compile-time. so I wondered if there is a way to do something like static if

Re: templated lambda with {} cause GC

2018-08-10 Thread Paul Backus via Digitalmars-d-learn
On Friday, 10 August 2018 at 09:57:53 UTC, learnfirst1 wrote: import core.stdc.stdio; struct Test { string name ; } void T(alias pred, A...)(){ __gshared t = Test(A) ; pred(t); } extern(C) void main(){ T!(t => printf("test 1 name = %s\n".ptr, t.name.ptr), "test") ;

Re: templated lambda with {} cause GC

2018-08-10 Thread Paul Backus via Digitalmars-d-learn
On Friday, 10 August 2018 at 11:10:55 UTC, learnfirst1 wrote: Still, if my first example is use GC, why dmd not throw error at compile time, instead at link time report symbols is missing. Is this a bug ? If you make your main function @nogc, you will get a compile-time error.

Re: write a function template specialisation that tests if an argument is known at compile time

2018-08-11 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 12 August 2018 at 00:15:37 UTC, Cecil Ward wrote: Paul, what would the calls look like? I am about to misunderstand things completely so here goes :-) It would be a bit kludgy having to switch from one calling syntax to another, putting the mask argument in the template parameters

Re: write a function template specialisation that tests if an argument is known at compile time

2018-08-11 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 12 August 2018 at 02:17:21 UTC, Cecil Ward wrote: I was thinking about reflection and powerful things like traits. Would a test to see if a static if compile do the trick ? You ask the question using traits : "does the following compile? : { static if ( mask == 3 ) { }; }" - any

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

2018-08-08 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 17:08:57 UTC, vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? Short answer: no. Long answer: https://issues.dlang.org/show_bug.cgi?id=17628

Re: Patterns to avoid GC with capturing closures?

2018-08-24 Thread Paul Backus via Digitalmars-d-learn
On Friday, 24 August 2018 at 15:18:13 UTC, Peter Alexander wrote: I can write scaleAll like this: auto scaleAll(int[] xs, int m) @nogc { return repeat(m).zip(xs).map!(mx => mx[0] * mx[1]); } So that repeat(m) stores m, but it is quite hacky to work like this. Here's a spoonful of sugar to

Re: Solving the impossible?

2018-08-25 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 26 August 2018 at 02:26:58 UTC, Everlast wrote: The problem is, suppose one wants to specify A void print(T, int... A)(T t, A a) while tricks can be used, why doesn't D support such an obvious syntax? We can specify an arbitrary type but can't restrict it in an obvious way, in

Re: Patterns to avoid GC with capturing closures?

2018-08-26 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 26 August 2018 at 06:08:39 UTC, vit wrote: const x = iota(0, 10) .map!((x, i) => x*i)(a) ///map!((x) => x*a) .map!((x, i) => x*i)(b) ///map!((x) => x*b) .filter!((x, i) => x%i)(c)///filter!((x) => x%c) .any!(x => x % c); I think it's easier to

Re: Solving the impossible?

2018-08-28 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 19:09:38 UTC, Everlast wrote: Yeah, I see the link paul posted. The actual syntax seems a bit strange to me... We don't do A[] a So it is not "logical". foo(A...)(A a) but if A is a specific type we must do foo(int[] a ...) The actual syntax then looks

Re: Solving the impossible?

2018-08-28 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 20:37:05 UTC, Everlast wrote: Also, the biggest complaint is that when we use [] attached to a type it has a specific meaning as "an array of". e.g., int[] means an array of int's. But int[] a... then changes as we don't have an array of int's any more but

Re: Generically call a function on Variant's payload?

2018-08-19 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 00:27:04 UTC, Nick Sabalausky (Abscissa) wrote: Suppose I've wrapped a Variant in a struct/class which ensures the Variant *only* ever contains types which satisfy a particular constraint (for example: isInputRange, or hasLength, etc...). Is there a way to call a

Re: Deduce type of struct in function arguments

2018-08-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 09:23:27 UTC, Andrey wrote: Hello, I have a function and a struct: void foo(ref Data data) { ... } struct Data { int a; string text; } How to pass struct into function without naming its type? This doesn't work: foo({1234, "Hello!"}); Create an

Re: Make function alias

2018-08-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote: Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) { alias print(T...) = newline ? : _file.print(); text.print(); }

Re: Deduce type of struct in function arguments

2018-08-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 August 2018 at 12:33:34 UTC, Andrey wrote: On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote: Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data);

Re: How to pass alias as template parameter?

2018-08-27 Thread Paul Backus via Digitalmars-d-learn
On Monday, 27 August 2018 at 09:50:01 UTC, Andrey wrote: alias Pair(alias key, alias value) = AliasSeq!(key, value); alias Pairs = AliasSeq!(Pair!(Option.First, handler!(Option.First)), Pair!(Option.Second, handler!(Option.Second)), handler); You can't nest AliasSeqs. If you examine Pairs

Re: Solving the impossible?

2018-08-29 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 29 August 2018 at 19:56:31 UTC, Everlast wrote: One of the things that makes a good language is it's internal syntactic consistency. This makes learning a language easier and also makes remembering it easier. Determinism is a very useful tool as is abstraction consistency. To say

Re: Solving the impossible?

2018-08-29 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 29 August 2018 at 22:18:09 UTC, Everlast wrote: No it is not! you have simply accepted it to be fact, which doesn't make it consistent. If you take 100 non-programmers(say, mathematicians) and ask them what is the natural extension of allowing an arbitrary number of parameters

Re: taskPool.reduce vs algorithm.reduce

2018-07-11 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 11 July 2018 at 08:31:30 UTC, Dorian Haglund wrote: But it fails to compile (with gdc 8.1.0, dmd v2.081) complaining that template instance reduce!(f) cannot use local 'f' as parameter to non-global template reduce(functions...) Congratulations! You've just run into issue

Function template argument deduction

2018-04-06 Thread Paul Backus via Digitalmars-d-learn
I'm playing around with functional programming in D, and have run into a problem with the following code: --- list.d import std.variant: Algebraic, This, visit; import std.typecons: Tuple, tuple; struct Nil {} alias List(T) = Algebraic!( Nil, Tuple!(T, "head", This*, "tail") ); alias

Re: Function template argument deduction

2018-04-07 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 7 April 2018 at 05:46:07 UTC, Uknown wrote: I don't see the error you are talking about: https://run.dlang.io/is/XWPIc1 Are you using the latest compiler? Compile with -unittest. And yes; I'm using DMD 2.079.0.

Re: Function template argument deduction

2018-04-07 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 7 April 2018 at 06:26:24 UTC, Uknown wrote: What I did notice though is that when `string list2string(T)(List!T list)` was changed to `string list2string(T)(VariantN!(16LU, Nil, Tuple!(T, "head", This*, "tail")) list)` The compiler correctly deduce `T` to be `int` Interesting.

Re: Function template argument deduction

2018-04-07 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 7 April 2018 at 14:02:55 UTC, Paul Backus wrote: Interesting. Looks like this is an issue with aliases, because I get the error with this code too: --- test.d import std.typecons: Tuple, tuple; alias Pair(T) = Tuple!(T, T); void foo(T)(Pair!T p) { return; } unittest {

Re: toString contains null for struct with function/method

2018-04-08 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 8 April 2018 at 15:04:49 UTC, number wrote: the write() shows a 'null' if the struct has a function/method. why is that? ``` import std.stdio; void main() { struct S { int i; } S s; writeln(s);// S(0)

Re: Is std.variant.visit not @nogc?

2018-04-09 Thread Paul Backus via Digitalmars-d-learn
On Monday, 9 April 2018 at 07:07:58 UTC, Chris Katko wrote: On Monday, 9 April 2018 at 07:02:50 UTC, Hasen Judy wrote: IMO, this is one more reason why sum-types should be built into the language compiler, instead of being implemented in user-space. +1. Any time you have to "create" a

Re: Is std.variant.visit not @nogc?

2018-04-10 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 12:34:07 UTC, aliak wrote: Awesome! this is a neat trick: union { AliasSeq!(T0, T1) values; } Is that usage documented somewhere, or is it somewhere in phobos maybe? Also, can Algebraic be fully replaced with this version then or is there some functionality

Re: Using iteration / method chaining / etc on multi-dimensional arrays

2018-04-12 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 12 April 2018 at 20:34:40 UTC, Chris Katko wrote: But each doesn't return anything, it mutates, right? I think that's the problem I ran into with my attempt. With your code, I get an error about void: string []x = split(file.readln.idup, " "); x.each((ref s) => s.each((ref

Re: Is std.variant.visit not @nogc?

2018-04-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 00:22:18 UTC, helxi wrote: On Monday, 9 April 2018 at 15:59:32 UTC, Paul Backus wrote: On Monday, 9 April 2018 at 07:07:58 UTC, Chris Katko wrote: [...] I agree in general, but in this case it's actually completely doable. In fact, I've done it myself: check out

Re: #import mapi.h

2018-03-22 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 16:22:45 UTC, Martin Tschierschke wrote: Is there an step by step introduction how to convert a C header of an external lib into the right extern(C){} block? In addition to what others have said, I found the following article on the D Wiki useful:

Re: Error: variable 'xyz' has scoped destruction, cannot build closure

2018-10-05 Thread Paul Backus via Digitalmars-d-learn
On Friday, 5 October 2018 at 06:56:49 UTC, Nicholas Wilson wrote: On Friday, 5 October 2018 at 06:44:08 UTC, Nicholas Wilson wrote: Alas is does not because each does not accept additional argument other than the range. Shouldn't be hard to fix though.

Re: betterC generate dynamic array throw Error: TypeInfo cannot be used with -betterC

2018-10-17 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 07:01:21 UTC, test wrote: test1: module test1; import test2; enum X = getR(1,3); void main(string[] args){} test2: module test2; struct R { int i; } R[] getR(int a, int b){ R[] r; r ~=

Re: lazy variables

2018-10-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 October 2018 at 14:08:11 UTC, aliak wrote: On Wednesday, 17 October 2018 at 23:34:55 UTC, Paul Backus wrote: auto x = () { // do some heavy stuff }; if (condition) { func(x().y); // heavy stuff evaluated here } That would do heavy stuff everytime i wanted to get y

Re: lazy variables

2018-10-17 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: lazy S x = () { // do some heavy stuff }(); if (condition) { func(x.y); // heavy stuff evaluated here } auto x = () { // do some heavy stuff }; if (condition) { func(x().y); // heavy stuff evaluated here } If you want

Re: Using . notation abstractly

2018-10-12 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 10 October 2018 at 22:56:14 UTC, James Japherson wrote: The point of all this is because D does not allow nesting of enums which allows for nice use of . to separate hiearchies: enum A { enum B { X, } } A.B.X, rather than having to have one large flat enum and do

Re: anyway to set a const object after the fact?

2018-10-29 Thread Paul Backus via Digitalmars-d-learn
On Monday, 29 October 2018 at 21:50:32 UTC, aliak wrote: Hi, so if you have this piece of code: struct C { void f() { string[] others; const string[] restArgs; foreach (i, arg; args) { if (isValidArg(arg)) { restArgs = args[i + 1 .. $]; break; }

Re: Built-in array opSliceAssign

2018-10-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 October 2018 at 12:25:37 UTC, Eduard Staniloiu wrote: As I wrote in the comments above, I was expecting `a[] = b[]` to iterate the slices and assign the elements of b into a. What really happens is a memcpy: as you can see from godblot [0], this gets lowered to a call to

Re: Need help with calling a list of functions

2018-11-03 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 4 November 2018 at 01:17:01 UTC, Luigi wrote: I need to call a function that can create a function from an array of functions and calls them in reverse order. I am learning D any help would be import std.stdio; import std.algorithm; import std.array : array; import std.range;

Re: Creating InputRanges from strings, files etc.

2018-11-08 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 8 November 2018 at 13:58:55 UTC, Vinay Sajip wrote: Excuse my ignorance, but from looking at the documentation on std.range and a quick skim of the guides mentioned there near the top, I can't see what the simple way is of creating an InputRange!(ubyte) from strings, files etc. I

Re: Compile time sequences

2018-10-03 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 3 October 2018 at 07:57:07 UTC, drug wrote: According to https://dlang.org/articles/ctarguments.html compile time sequences "...allow a programmer to operate on types, symbols and values..." Phobos has `isType`/`isTypeTuple` traits, also `isExpressions` where expression may

Re: Copy parameters from function passed as an alias

2018-10-10 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 10 October 2018 at 12:10:06 UTC, bauss wrote: On Wednesday, 10 October 2018 at 08:16:11 UTC, Kagamin wrote: How do you want to use parameter names of an arbitrary function? What I want to do is pass a function to a template and that template creates a function with the same

Re: assumeNoGC works but can't get an assumePure to work

2018-09-03 Thread Paul Backus via Digitalmars-d-learn
On Monday, 3 September 2018 at 22:07:10 UTC, aliak wrote: Why does it work with nogc but not with pure? Cheers, - Ali You can't define an impure function inside a pure unittest. If you move `modify` outside the unittest block, and change the argument from a lambda to a function pointer, it

Re: Pass lambda into template

2018-09-03 Thread Paul Backus via Digitalmars-d-learn
On Monday, 3 September 2018 at 09:09:44 UTC, Andrey wrote: Hello, Here is a code with comments: https://run.dlang.io/is/BNl2Up. I don't understand how to pass lambda into template. I get an error: onlineapp.d(18): Error: template instance `qwerty!((i) => "arg" ~ i.to!string ~ "[0] == '?'",

Re: std.process.execute without capturing stderr?

2018-09-20 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 20 September 2018 at 07:24:52 UTC, berni wrote: I need to execute a program and capture stdout, which I hoped std.process.execute would do. But unfortunatly this command also captures stderr, which I need to be ignored. When looking at the implementation of std.process.execute I

Re: interrupting a function

2018-11-17 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 17 November 2018 at 06:19:25 UTC, Alex wrote: It can happen, that the input params are correct, however, the calculation lasts too long. Is there a way, to measure the execution time of foo (á la benchmark) and then, if some execution time limit is exceeded to interrupt the

Re: static foreach direct use of variables

2019-01-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote: auto foo(S s) { static foreach(k, p; [s, this]) for(int i = 0; i < p.length; i++) ... } The idea is to provide single for loop structure for each of the variables(in this case s and

Re: API Documentation

2019-01-20 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 20 January 2019 at 16:51:23 UTC, kdevel wrote: Online but not on a local installation I frequently land on pages under https://dlang.org/library/ (API Documentation). What is the reason for this duplicate docs? The API documentation looks much cleaner and better structured.

Re: Modulo that 'wraps' the number?

2019-01-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 21 January 2019 at 04:52:53 UTC, NaN wrote: On Sunday, 20 January 2019 at 18:51:54 UTC, Steven Schveighoffer wrote: On 1/20/19 1:28 PM, faissaloo wrote: In Python -1%3 == 2 however in D -1%3 == -1 Is there a standard library function or something that gives me the Python version of

Re: Can you move a disabled this struct in to a container type if it's an rvalue?

2018-12-12 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 12 December 2018 at 20:05:18 UTC, aliak wrote: Ie: struct S { @disable this(); this(int i) {} } struct Container(T) { T value; this(auto ref T value) { this.value = value; } } void main() { auto a = Container!S(S(3)); // can't do this. } The

Re: cannot use local f as parameter to non-global template

2018-12-10 Thread Paul Backus via Digitalmars-d-learn
On Monday, 10 December 2018 at 16:15:36 UTC, aliak wrote: Ah, that's a good way of breaking it down. But ok, so then the other version would be lowered to: template match(handlers...) { template match(T) { auto match(T holder) { return handlers[0](holder); }

Re: typeof function literals which define the types of its parameters but do not give their parameters names

2018-12-26 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 27 December 2018 at 03:52:52 UTC, Johannes Loher wrote: Hey all, I am a bit confused about the inferred types of function literals which do not name their parameters (something like `(int) {}`). The confusion arises from the fact that the inferred type sometimes is `void` (might

Re: is(ElementType!(char[2]) == dchar - why?

2018-12-11 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 11 December 2018 at 17:51:56 UTC, Denis Feklushkin wrote: import std.stdio; import std.range.primitives; void main() { writeln( typeid(ElementType!(char[2])) ); static assert(is(ElementType!(char[2]) == dchar)); // why? } ? https://run.dlang.io/is/Q74yHm

Re: Qualified class opEquals()

2018-12-24 Thread Paul Backus via Digitalmars-d-learn
On Monday, 24 December 2018 at 22:58:03 UTC, Per Nordlöw wrote: Is it in the following code possible to make the statement assert(car1 == car2); in the function testEqual() compile in a `@safe pure nothrow @nogc context`? No, because equality comparison between classes lowers to

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 13 December 2018 at 13:17:05 UTC, aliak wrote: Ah. Is there any case where you would not want to do that when you have a T value as parameter? And, what if it's "this()(auto ref T value)"? Then moving could be dangerous if the parameter was passed as a ref. Or maybe it just

Re: public imports

2018-12-05 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 5 December 2018 at 21:13:29 UTC, Sjoerd Nijboer wrote: A small question. Is it intended behaviour that public imports inside function calls fail with the message "Error: found public instead of statement", or is it an underdocumented feature? void foo() { public import bar;

Re: compile time sequence through dub config or commandline.

2018-12-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 December 2018 at 14:50:05 UTC, Sjoerd Nijboer wrote: The idea being that bar can be packed in a library and the program that includes this library can decide what parameters will be added to foo whitout any runtime overhead and ugly looking syntax. The normal way to do this

Re: dmd -unittest works poorly with executables

2018-12-08 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 8 December 2018 at 20:16:09 UTC, Andrew Pennebaker wrote: I think it's lame to have to use magical code like `version(unittest) {} else` to guard our main functions, when we run unit tests. Could D go ahead and do the right thing, automatically shadowing our main functions when

Re: cannot use local f as parameter to non-global template

2018-12-08 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 8 December 2018 at 09:57:29 UTC, aliak wrote: This compiles fine. However, if I change the match template to: template match(handlers...) { auto match(alias f)(Holder!f holder) { return handlers[0](holder); } } Notice the template parameter of the eponymous match

Re: changing the output of `std.stdio.write'

2019-01-03 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 3 January 2019 at 17:59:28 UTC, Manfred Nowak wrote: According to this tutorial https://wiki.dlang.org/Defining_custom_print_format_specifiers it seems easy to change the format of the output for `std.stdio.writef'. But why is there no example for changing the output when there

Re: Getting template parameters by its name

2019-01-10 Thread Paul Backus via Digitalmars-d-learn
On Friday, 11 January 2019 at 04:59:50 UTC, Yui Hosaka wrote: I want to do something like this: template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } You can get the arguments of a template instance as an AliasSeq using

Re: Variadic template with template arguments in pairs

2018-09-12 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 12 September 2018 at 15:12:16 UTC, Anonymouse wrote: void doByPair(Args...)(Args args) if (Args.length) { foreach (pair; args.pairwise) { static assert(is(typeof(pair[0]) == string)); static assert(isPointer!(pair[1])); assert(pair[1] !is null);

Re: array to string functional?

2018-09-15 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 15 September 2018 at 20:04:36 UTC, berni wrote: Anotherone I'm not getting to work: From some output with newlines I want to discard all lines, that start with a # and select part of the other lines with a regex. (I know the regex r".*" is quite useless, but it will be replaced by

Re: array to string functional?

2018-09-14 Thread Paul Backus via Digitalmars-d-learn
On Friday, 14 September 2018 at 20:43:45 UTC, SrMordred wrote: What you want is std.range.chunks auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0]; a.map!(to!string) .join("") .chunks(4) .map!(to!string) //don´t know why the chunks are not already strings at this point ;/

Re: array to string functional?

2018-09-15 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 15 September 2018 at 05:39:48 UTC, berni wrote: Oh, thanks. What I didn't know about was join. Now I wonder how I could have found out about it, without asking here? Even yet I know it's name I cannot find it, nighter in the language documentation nor in the library documentation.

Re: Cannot use UFCS in lambda?

2018-09-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 16 September 2018 at 10:55:43 UTC, berni wrote: The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ (search for UFCS in the

Re: Am I missing with ref in this code?

2019-01-24 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 24 January 2019 at 16:04:06 UTC, Suliman wrote: Error: static assert: "Cannot convert arguments '(MyUrl)' to function arguments '(MyUrl*)'." You've forgotten to change the call site to pass a pointer. However, it turns out that even if you do that, vibe will not allow you to

Re: Why is creating of if Expressions not allowed?

2019-03-24 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 24 March 2019 at 16:18:49 UTC, sighoya wrote: Why auto GenIf()() { return mixin("if(true) { return true;} else {return false;}"); } public bool testFunction2() { GenIf!(); } gives me: onlineapp.d-mixin-3(3): Error: expression expected, not if onlineapp.d(8): Error:

Re: Using opOpAssign, cannot assign sequence

2019-04-05 Thread Paul Backus via Digitalmars-d-learn
On Friday, 5 April 2019 at 13:59:27 UTC, Alex wrote: class X(T) void opOpAssign(string op)(T d) If T has more than length of one then x += We can work around this but it seems to me that we should be able to get it to work in some way x += Alias!(a,b,c) fails to package it up

Re: Simultaneously assigning to all values in a tuple

2019-03-30 Thread Paul Backus via Digitalmars-d-learn
On 3/27/19 8:29 PM, Jamie wrote: > Is it possible to assign to all values in a tuple at once if they are > the same type? > I.e. > > Tuple!(double, "x", double, "y") t; > t[] = 1.0; > foreach (ref member; t.expand) { member = 1.0; }

Re: What's the correct way to interface with a intptr_t?

2019-04-07 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 7 April 2019 at 12:19:10 UTC, bauss wrote: On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote: On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent?

Re: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()`

2019-04-07 Thread Paul Backus via Digitalmars-d-learn
On 4/7/19 1:30 AM, Nicholas Wilson wrote: > On Sunday, 7 April 2019 at 05:24:38 UTC, Alex wrote: >> Error: template instance `Reflect!(type)` cannot use local `type` as >> parameter to non-global template `Reflect(Ts...)()` >> >> mixin(`import `~moduleName!(T)~`;`);    >> mixin(`alias X =

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-07 Thread Paul Backus via Digitalmars-d-learn
On 4/6/19 11:47 PM, Alex wrote: > What you need to tell me is why using .stringof is bad. You have simply > conjured up a rule and are stating it but not giving any reason why it > is not a good idea to follow when, in fact, not following can be shown > to be beneficial. I'm not Adam, but I've

Re: What's the correct way to interface with a intptr_t?

2019-04-06 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? The correct equivalent is `intptr_t` from `core.stdc.stdint`.

Re: Compile Time Fun Time

2019-02-25 Thread Paul Backus via Digitalmars-d-learn
On Monday, 25 February 2019 at 06:51:20 UTC, Yevano wrote: I am writing a domain specific language of sorts in D for the lambda calculus. One of my requirements is that I should be able to generate expressions like this: new Abstraction(v1, M) like this: L!(x => M) A word of caution: this

Re: How to call other variadic function with the same arguments?

2019-02-24 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 24 February 2019 at 13:09:15 UTC, Victor Porton wrote: Let f be a variadic function: Result f(...); How to implement variadic function g which calls f with the same arguments as one it receives? Result g(...) { // ... } If you must use C-style variadic arguments, then your

Re: Can't make inout work.

2019-03-16 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 March 2019 at 11:55:56 UTC, spir wrote: I think (but may be wrong) that you don't need inout here, since a plain 'ref' will (and does) work. This is accepted by me (I added vars to make the code clearer to myself): struct S(T) { T value = T.init; } auto ref make(T)(ref T

Re: Can't make inout work.

2019-03-17 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 17 March 2019 at 10:49:03 UTC, aliak wrote: Ah! Thanks! So next problem with that: import std.stdio; struct S(T) { T value; } auto make(T)(inout auto ref T val) { return inout(S!T)(val); } void main() { writeln(make("hello") == S!string("hello")); } Error: Error:

Re: Why this template code does not compile?

2019-03-13 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 13 March 2019 at 17:38:02 UTC, Victor Porton wrote: Why this template code does not compile? /// module runnable; import std.meta; import std.typecons; template FieldInfo(argT, string argName) { template FieldInfo(Nullable!argT argDefault = Nullable!argT()) { } }

Re: Block statements and memory management

2019-03-15 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make

Re: Can't make inout work.

2019-03-15 Thread Paul Backus via Digitalmars-d-learn
On Friday, 15 March 2019 at 23:57:15 UTC, aliak wrote: Anyone knows how to make this work? You need an explicit `inout` on the return value of `make`: auto ref make(T)(inout auto ref T value) { return inout(S!T)(value); }

Re: Array of byLineCopy ranges behaves as they are byLine

2019-03-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 March 2019 at 17:33:31 UTC, HaraldZealot wrote: Ah yes, I forget about laziness of `map`. BTW, I have found other solution, which is more fit to my initial intention. ```d ReturnType!(std.stdio.File.byLineCopy!(char, immutable(char)))[] ranges; foreach(filename; args[1 .. $]) {

Re: this is null

2019-03-09 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 9 March 2019 at 19:18:38 UTC, ANtlord wrote: Hello everyone! I've encountered the problem which I already encountered before. Unfortunately, I had no time in the previous time to report and to talk about it. So I decided to play making my own "malloc" function in pure D (betterC)

Re: How to use dproto for removing and element from a repeated field

2019-02-06 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 6 February 2019 at 10:07:06 UTC, Sudhi wrote: Hi, I have been using dproto to work with protocol buffers. I have below proto structure message Person { required string name = 1; required string id = 2; repeated string emailId = 3; } Where a person can have multiple

Re: Generators in D

2019-02-19 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote: Hi there, is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? Regards Generally speaking, things that are generators in Python are implemented as ranges [1] in D.

  1   2   3   4   5   >