How to make project with main application and cli application in the same folder?

2024-04-21 Thread alex via Digitalmars-d-learn
Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get an error that I can't have more then 1 main function. I already asked chatGPT, and it replied that I need to use

Re: How to make project with main application and cli application in the same folder?

2024-04-25 Thread alex via Digitalmars-d-learn
On Sunday, 21 April 2024 at 16:41:08 UTC, Mike Parker wrote: On Sunday, 21 April 2024 at 08:44:38 UTC, alex wrote: Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get

Re: Abstract classes vs interfaces, casting from void*

2019-08-10 Thread Alex via Digitalmars-d-learn
On Saturday, 10 August 2019 at 08:20:46 UTC, John Colvin wrote: On Friday, 9 August 2019 at 13:39:53 UTC, Simen Kjærås wrote: Thanks for the extra detail. Is there a solid reason to ever use an interface over an abstract class? (Other than multiple inheritance). I'm such a noob at anythin

Re: Abstract classes vs interfaces, casting from void*

2019-08-10 Thread Alex via Digitalmars-d-learn
On Saturday, 10 August 2019 at 14:29:03 UTC, John Colvin wrote: On Saturday, 10 August 2019 at 10:11:15 UTC, Alex wrote: On Saturday, 10 August 2019 at 08:20:46 UTC, John Colvin wrote: On Friday, 9 August 2019 at 13:39:53 UTC, Simen Kjærås wrote: Thanks for the extra detail. Is there a sol

Re: Passing nested template function

2019-08-10 Thread Alex via Digitalmars-d-learn
On Saturday, 10 August 2019 at 17:45:43 UTC, Prateek Nayak wrote: A nested function can be passed to another function evident from this example: https://run.dlang.io/is/6waRkB However if the nested function is a template function, it raises an error https://run.dlang.io/is/PQhkwl The error be

Re: Abstract classes vs interfaces, casting from void*

2019-08-11 Thread Alex via Digitalmars-d-learn
On Sunday, 11 August 2019 at 13:09:43 UTC, John Colvin wrote: Ok. What would go wrong (in D) if I just replaced every interface with an abstract class? I think there's some confusion here, because B.foo is not abstract. abstract on a class is not inherited by its methods. https://dlang.org/sp

Re: Abstract classes vs interfaces, casting from void*

2019-08-11 Thread Alex via Digitalmars-d-learn
On Sunday, 11 August 2019 at 16:05:20 UTC, John Colvin wrote: I'm trying to narrow down exactly what patterns work with each and how they overlap. What I was trying to get at with the abstract method thing is that abstract class C { void foo(); } is an abstract class with a non-abstract

Re: Abstract classes vs interfaces, casting from void*

2019-08-11 Thread Alex via Digitalmars-d-learn
On Sunday, 11 August 2019 at 20:32:14 UTC, John Colvin wrote: As I see this, everything you wrote is correct. :) But you compared abstractness with interface usage, initially. So... I would say, interfaces are more like the abstract method case without any function body. But then, you will hav

Re: What the abstrac final class mean?

2019-08-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 August 2019 at 08:54:56 UTC, lili wrote: Hi: Why need defined an abstract final class? see https://github.com/Rikarin/Trinix/blob/master/Kernel/arch/amd64/gdt.d From what I saw, all members are static. So, this is a kind of utility class, which is not supposed to be ins

Re: need this for name of type string

2019-09-10 Thread Alex via Digitalmars-d-learn
On Tuesday, 10 September 2019 at 10:32:29 UTC, Andre Pany wrote: Hi, following coding is throwing compiler error: need this for name of type string The error disappears if I delete method0. My gut feeling is, this is a compiler bug? --- class C { static this() { getT!(typeof(

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Alex via Digitalmars-d-learn
On Friday, 20 September 2019 at 20:26:03 UTC, Ron Tarrant wrote: Hi guys, I've been banging my head on the screen with this one for the last week or so. For whatever reason, I'm having major problems understanding how to implement a doubly-linked list in D. I don't know if it's because I'm lo

Re: how to determine if a function exists in a class?

2019-10-01 Thread Alex via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 06:06:20 UTC, TodNaz wrote: Hello everyone! I have a question: how to determine if a function exists in a class? Is this possible with @pointer tagging? Do you mean, like in examples of https://dlang.org/library/std/traits/has_member.html ?

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 October 2019 at 19:38:50 UTC, mipri wrote: On Monday, 7 October 2019 at 19:16:31 UTC, IGotD- wrote: On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in

Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Alex via Digitalmars-d-learn
On Saturday, 2 November 2019 at 17:49:09 UTC, Luh wrote: Hello, When trying to pass a D function to the C callback, the compiler says: 'Error: cannot implicitly convert expression &this.onProcessCb of type extern (C) bool delegate(const(short*) a, ulong b, void* c) to extern (C) bool functi

Re: Splitting a stream of data on based on data change.

2019-11-21 Thread Alex via Digitalmars-d-learn
On Thursday, 21 November 2019 at 21:36:08 UTC, Taylor R Hillegeist wrote: I was looking through the standard library for a good way to split a range into several ranges based on value changes in the stream: AAABB would be split on the AB transition into: AAA BB I just couldn't

Re: Simple casting?

2019-11-25 Thread Alex via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 05:17:54 UTC, Taylor R Hillegeist wrote: On Tuesday, 26 November 2019 at 05:05:48 UTC, Taylor R Hillegeist wrote: I'm attempting to do a segment group. details: alias ProbePoint[3]=triple; triple[] irqSortedSet = UniqueTriples.keys

Re: Intersection of two sets

2019-12-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 13:43:26 UTC, Jan Hönig wrote: It seems i don't google the right keywords. What i want to do: I have two sets. (I didn't find how to do sets, so i have two associative boolean arrays `bool[]`). And i want to join them, via an intersection. I know how to code t

Re: array of functions/delegates

2019-12-24 Thread Alex via Digitalmars-d-learn
On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote: I am trying to create an array of functions inside a struct. struct S { void f1() {} void f2() {} alias Func = void function(); immutable Func[2] = [&f1, &f2] } What I got: Error: non-constant expression '&f1' Tried also with

Re: Multi-threaded sorting of text file

2020-01-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 January 2020 at 07:51:49 UTC, MGW wrote: Need help: There' s a large text file (hundreds of thousands of lines). The structure is as follows: 2345|wedwededwedwedwe .. 872625|rfrferwewweww . 23|rergrferfefer It is necessary to sort this file by the fir

Re: What type does byGrapheme() return?

2020-01-06 Thread Alex via Digitalmars-d-learn
On Monday, 6 January 2020 at 08:39:19 UTC, Robert M. Münch wrote: On 2020-01-05 04:18:34 +, H. S. Teoh said: At a minimum, I think we should file a bug report to investigate whether Grapheme.opSlice can be implemented differently, such that we avoid this obscure referential behaviour that

Re: need help to get member function const address

2020-03-18 Thread Alex via Digitalmars-d-learn
On Thursday, 19 March 2020 at 04:30:32 UTC, Calvin P wrote: I use this code to get member function address on runtime: = struct A { this(){}; } auto ctor = (&__traits(getMember, A.init,"__ctor")).funcptr; = my question is, how to get it in compile time like static funct

Re: Option and Result [was Integration tests]

2020-04-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 16:30:15 UTC, Russel Winder wrote: On Mon, 2020-04-20 at 20:19 +, aliak via Digitalmars-d-learn wrote: […] [0]: https://github.com/aliak00/optional Rust has Option and Result, and most languages are rapidly introducing at least Option if not Result – and y

Re: Type sniffing at runtime

2020-05-15 Thread Alex via Digitalmars-d-learn
On Saturday, 16 May 2020 at 05:22:49 UTC, n0den1te wrote: [...] For example, like this: ´´´ import std; alias types = AliasSeq!( bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real, char, wchar, dchar ); void main() { static foreach(type; types) {

template evaluation

2018-04-14 Thread Alex via Digitalmars-d-learn
Hi all, I must overlook something, but given this: ´´´ void main(){} static assert(isMatching!(D, S!(D, true))); // place 1: works as expected. struct D { auto static s = S!(typeof(this), true).init; } enum bool isMatching(T, U) = (){ bool b; s

Re: template evaluation

2018-04-14 Thread Alex via Digitalmars-d-learn
Ok, trying to reduce my example a little bit, I arrived at this: ´´´ void main(){} struct D { size_t dummy; auto static s = S!D.init; } struct S(alias container = null) { pragma(msg, container); static if(__traits(compiles, __traits(allMembers, container

Re: "%s"-format template function arguments

2018-04-15 Thread Alex via Digitalmars-d-learn
On Sunday, 15 April 2018 at 12:04:19 UTC, vladdeSV wrote: Hello people of D-land. In a template function, I want to format all arguments as if it was an array. Se this snippet of code: foo(1,2,3); void foo(T...)(T args) { writefln("expected: %s", [1,2,3]); writefl

Re: Assoc. Array and struct with immutable member

2018-04-15 Thread Alex via Digitalmars-d-learn
On Sunday, 15 April 2018 at 17:59:01 UTC, Dgame wrote: How am I supposed to insert a struct with immutable members into an assoc. array? Reduced example: struct A { immutable string name; } A[string] as; as["a"] = A("a"); // Does not work Via a static this() it would work. But

Re: Assoc. Array and struct with immutable member

2018-04-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 11:07:55 UTC, bauss wrote: Even though it works in static this, then it still looks like a bug if you ask me, because the associative array itself isn't immutable. Yeah... I'm not sure, if this behavior is wanted, too... If you argue, that an absent field in in

Re: Getting the overload set of a template

2018-04-19 Thread Alex via Digitalmars-d-learn
On Thursday, 19 April 2018 at 13:57:04 UTC, Simen Kjærås wrote: Currently, there is no way (that I've found, at least) to do this. If you have a workaround, that's great, but there really should be a way - probably __traits(getOverloads). Having __traits(getOverloads) return templates as well s

Re: Getting the overload set of a template

2018-04-21 Thread Alex via Digitalmars-d-learn
On Thursday, 19 April 2018 at 17:55:47 UTC, Simen Kjærås wrote: Your first example defines two templates (which are overloads of the same name), the second only one. There's no ambiguity there. So, do you mean, that the constraint belongs to the interface of a template?

Re: Getting the overload set of a template

2018-04-21 Thread Alex via Digitalmars-d-learn
On Saturday, 21 April 2018 at 19:51:05 UTC, Simen Kjærås wrote: On Saturday, 21 April 2018 at 11:23:33 UTC, Alex wrote: So, do you mean, that the constraint belongs to the interface of a template? Not necessarily - it depends on what you want to achieve. The only thing I mean is that the code

Re: Getting the overload set of a template

2018-04-22 Thread Alex via Digitalmars-d-learn
On Sunday, 22 April 2018 at 18:25:29 UTC, Simen Kjærås wrote: No lowering occurs here. A lowering is when the compiler takes one piece of syntax and replaces it with a different one, usually one that's more verbose. In a way, it's kind of like a template being instantiated, in that you write

Re: Getting the overload set of a template

2018-04-22 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 00:26:23 UTC, Simen Kjærås wrote: // tuple("Has foo1_A") pragma(msg, __traits(getAttributes, foo1!"a")); // tuple("Has foo1_A") pragma(msg, __traits(getAttributes, foo2!"a")); // tuple("Has foo1_B") pragma(msg, __traits(getAttributes, foo1!"b")); // tuple("Has foo1_B")

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 07:49:39 UTC, Simen Kjærås wrote: On Monday, 23 April 2018 at 04:58:38 UTC, Alex wrote: On Monday, 23 April 2018 at 00:26:23 UTC, Simen Kjærås wrote: There is a limited set of lowerings, and they are defined in the language, not in user code. They include operator o

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 10:57:59 UTC, Simen Kjærås wrote: There is no official definition. That's because some natural rewrite rules are implied, which are very general, I assume... How official do you want it to be? That's the only definition in common use by others in the context of comp

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 14:22:13 UTC, Simen Kjærås wrote: As with all things D, the only real spec is the compiler source code. :p :( :p Proving that two templates are equivalent is in general impossible, since any amount of wasted computation could be performed before the end result is

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 15:44:10 UTC, Simen Kjærås wrote: Ah, but I'm not looking to instantiate the templates, but to learn about them - how many parameters do they take? Are their UDAs different, so that I should warn the programmer? Must I wrap them in different ways? So... Do I have

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 16:16:09 UTC, Arafel wrote: ``` import std.meta; void main() { pragma(msg, __traits(getMember, A, "Foo1").stringof); // Foo1(int N) if (N & 1) pragma(msg, __traits(getAttributes, __traits(getMember, A, "Foo1"))[0]); // tuple("int", "odd") alias f1a = Ins

Re: Getting the overload set of a template

2018-04-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 April 2018 at 17:46:10 UTC, Arafel wrote: You could also argue that function overloads are just semantically equivalent to a single function with variadic arguments. It is not. As there are exact known, distinct, finite numbers and types of arguments of functions, which can be

Re: Troubles with template constraints on string and static if

2018-04-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 April 2018 at 15:06:49 UTC, sungal wrote: I have this piece of code and I can't understand why the `static if` conditionals are always false. ``` import std.digest.sha; import std.file; import std.stdio; void main() { auto hash1 = produceHash!string("prova.d"); auto has

Re: Template to retrieve compile-time enum member from run-time enum member?

2018-04-27 Thread Alex via Digitalmars-d-learn
On Friday, 27 April 2018 at 13:43:47 UTC, Timoses wrote: `instantiateWith` gets called in three variations (menum.A, menum.B and menum.C). This causes instantiateWith to return TempStruct for each case of Temp... However, I was under the impression that a templated function will exist multi

Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-04 Thread Alex via Digitalmars-d-learn
Hi I just installed D on my windows 10 and want to try to compile a hello world. My source is a classical import std.stdio; void main() { writeln("Hello, World!"); } And I try to compile and get C:\D>dmd hello.d Error: module `hello` is in file 'hello.d' which cannot be read import path[0] =

Re: Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-05 Thread Alex via Digitalmars-d-learn
Thank you for you for your quick answer. I think I allready tryed this, before asking, but ... C:\>cd D\dmd2\sources C:\D\dmd2\sources>dmd hello.d Error: module `hello` is in file 'hello.d' which cannot be read import path[0] = C:\D\dmd2\windows\bin\..\..\src\phobos import path[1] = C:\D\dmd2\w

Re: Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-05 Thread Alex via Digitalmars-d-learn
On Saturday, 5 May 2018 at 12:26:20 UTC, Bauss wrote: Try to add module hello; To the top of the file Still not working. I tryed both module hello; and module 'hello'; C:\D\dmd2\sources>dmd hello.d Error: module `hello` is in file 'hello.d' which cannot be read import path[0] = C:\D\dmd2\w

Re: Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-05 Thread Alex via Digitalmars-d-learn
On Saturday, 5 May 2018 at 17:13:08 UTC, IntegratedDimensions wrote: You need to make sure hello.d is in the current dir dir C:\D does hello.d show up? If not, then dmd can't find it and you have to tell it where it is or be in the right location. type dmd ThereIsNowFileHere12342123242231

pointer to object resolution

2018-05-11 Thread Alex via Digitalmars-d-learn
Hi all, I'm sure, I didn't find something obvious, but: Given this: ´´´ void main() { auto s = S(); s.operator; assert(s.myOp(42)); assert(42 in s); auto sptr = new S(); sptr.operator; assert(sptr.myOp(42)); //assert(42 in sptr);

Re: pointer to object resolution

2018-05-11 Thread Alex via Digitalmars-d-learn
On Friday, 11 May 2018 at 15:24:08 UTC, Steven Schveighoffer wrote: On 5/11/18 8:53 AM, Alex wrote: This behaves differently, w.r.t. to an arbitrary method, like "operator". Why? Is there any workaround? operators don't follow pointers. Imagine if you had a struct that overloads "+" and th

Re: Can I infer the type from this?

2018-05-19 Thread Alex via Digitalmars-d-learn
On Sunday, 20 May 2018 at 01:41:03 UTC, Dr.No wrote: I'd like to pass a symbol as paramater (class static member0 and at same time get the type of this, something like this: template myTemp(alias s) { enum myTemp = templateFunction!(??)(s.stringof); } the templateFunction has this sign

Re: Can I infer the type from this?

2018-05-20 Thread Alex via Digitalmars-d-learn
On Sunday, 20 May 2018 at 03:16:39 UTC, Dr.No wrote: Oh, my bad: I totally forgot a crucial thing on question: I want this to work with a static member, for example, call myTemp like this myTemp!(C.a) I don't mind if I to pass the type as parameter somehow, like myTemp!(C, C.a) or myTemp!(C)

Re: Locking data

2018-05-22 Thread Alex via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 21:45:07 UTC, IntegratedDimensions wrote: an idea to lock data by removing the reference: class A { Lockable!Data data; } The idea is that when the data is going to be used, the user locks the data. The trick here is that data is a pointer to the data and the poi

each & opApply

2018-05-23 Thread Alex via Digitalmars-d-learn
This is a question is about usage of ´each´ https://dlang.org/phobos/std_algorithm_iteration.html#each with a type where different opApply overloads are defined. Say, I have something like this: ´´´ void main() { import std.stdio : writeln; import std.algorithm : each;

Re: each & opApply

2018-05-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 23 May 2018 at 13:49:45 UTC, Steven Schveighoffer wrote: Right, but not foreach(el1, el2; c), which is the equivalent of your each call. Yes. I tried this in the first place and get a compiler error. But it seemed logical to me, that if I define two opApply overloads, which bo

Re: each & opApply

2018-05-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 23 May 2018 at 14:19:31 UTC, Steven Schveighoffer wrote: On 5/23/18 9:59 AM, Alex wrote: On Wednesday, 23 May 2018 at 13:49:45 UTC, Steven Schveighoffer wrote: Right, but not foreach(el1, el2; c), which is the equivalent of your each call. Yes. I tried this in the first place

Re: each & opApply

2018-05-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 23 May 2018 at 14:24:18 UTC, Alex wrote: Ah... ok. Then, let me file a bug... Bug filed. https://issues.dlang.org/show_bug.cgi?id=18898

Re: UDA and static struct fields

2018-05-24 Thread Alex via Digitalmars-d-learn
On Thursday, 24 May 2018 at 08:48:30 UTC, Andrea Fontana wrote: This line: mixin("alias tmp = " ~ s ~ ";"); There's no mention of Symbol in there. If you change it to this: mixin("alias tmp = Symbol" ~ s ~ ";"); then suddenly things work. -- Simen What? a dot is missing,

Re: Any way to override base type with dervived in derived type

2018-05-24 Thread Alex via Digitalmars-d-learn
On Thursday, 24 May 2018 at 20:24:32 UTC, IntegratedDimensions wrote: class T; class TT : T; interface I { @property T t(); } abstract class A { T _t; @property T t() { return _t; } } class C : A { // Stuff below uses t as TT but compiler, of course, treats t as T ... } Th

Re: range simple toy problem

2018-06-01 Thread Alex via Digitalmars-d-learn
On Friday, 1 June 2018 at 17:00:45 UTC, Xiaoxi wrote: import std.range; import std.algorithm; import std.string; import std.stdio; void main() { auto s = "1 2 3 4 5 6 7 8 9"; auto iter = s.split(" ").drop(2); // How to find the unconsumed/not-split part of s here? // i.e. "3 4 5

Re: determining if array element is null

2018-06-05 Thread Alex via Digitalmars-d-learn
On Tuesday, 5 June 2018 at 14:52:28 UTC, Timoses wrote: Does `int[4] nums = void` work? Work for what? If you avoid initialization, then the variable(s) are not initialized. https://dlang.org/spec/declaration.html#void_init However, an int is not nullable and always contains a value.

comparing nullables

2018-06-15 Thread Alex via Digitalmars-d-learn
Hi all, do you see any valid reason why the last line yields an error: import std.typecons; void main() { void* ptr1; void* ptr2; assert(ptr1 is null); assert(ptr2 is null); assert(ptr1 == ptr2); Nullable!uint val1; Nullable!uint val2;

Re: comparing nullables

2018-06-15 Thread Alex via Digitalmars-d-learn
On Friday, 15 June 2018 at 16:49:47 UTC, bauss wrote: https://github.com/dlang/phobos/pull/6583 Thanks a lot.

template recursion

2018-06-26 Thread Alex via Digitalmars-d-learn
Hi all, I have a strange case of template recursion, which I don't know how to solve: ´´´ import std.range; void main() { T.member.tarr.length = 42; //put(T.member, 4); // line 6 T.member.put(4); // line 7 } struct T { void put(Type)(Type t){} // line 13

Re: template recursion

2018-06-26 Thread Alex via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 10:01:06 UTC, ag0aep6g wrote: On line 23, you're apparently trying to call std.range.put (which would in turn call tarr[t].put). But being in a method that is itself called "put", that line is instead interpreted as a recursive call (which fails). To refer to std.ran

Re: anyway to pass the context of an inner type to a template so it can be constructed?

2018-06-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 12:02:10 UTC, aliak wrote: === The use case is for a non-nullable type, where I want to guarantee that the value inside will never be null. I can't do it for inner classes though. And I can't allow the user to do something like: void main() { class C {}

Re: Getting the underlying range from std.range.indexed, with elements in swapped order, when Indexed.source.length == Indexed.indices.length

2018-06-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote: Title says it all. Is there a trivial way to do this? There are https://dlang.org/library/std/algorithm/mutation/reverse.html and https://dlang.org/library/std/range/retro.html both require a bidirectional range, which Indexed, luckily

Re: Getting the underlying range from std.range.indexed, with elements in swapped order, when Indexed.source.length == Indexed.indices.length

2018-06-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 14:29:33 UTC, Uknown wrote: On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote: On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote: Title says it all. Is there a trivial way to do this? There are https://dlang.org/library/std/algorithm/mutation/reverse.

Re: Getting the underlying range from std.range.indexed, with elements in swapped order, when Indexed.source.length == Indexed.indices.length

2018-06-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 15:07:57 UTC, Uknown wrote: On Wednesday, 27 June 2018 at 14:50:25 UTC, Alex wrote: On Wednesday, 27 June 2018 at 14:29:33 UTC, Uknown wrote: On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote: On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote: [...]

Re: Why tuples are not ranges?

2018-06-28 Thread Alex via Digitalmars-d-learn
On Thursday, 28 June 2018 at 14:35:33 UTC, Mr.Bingo wrote: Seems like it would unify things quite a bit. Yeah... this is, because you can't popFront on a tuple, as the amount of entries is fixed. You can, however, popFront on every range. But as Timoses wrote you can easily make a range out

Re: Why tuples are not ranges?

2018-06-28 Thread Alex via Digitalmars-d-learn
On Thursday, 28 June 2018 at 19:02:51 UTC, Ali Çehreli wrote: On 06/28/2018 11:08 AM, Mr.Bingo wrote: > Thanks, why not add the ability to pass through ranges and arrays and > add it to phobos? Makes sense. It needs an enhancement request at http://issues.dlang.org/, a good implementation, and

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Alex via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:19:50 UTC, vino.B wrote: Hi Timoses, Thank you very much, can you help me on how to rewrite the below using Variadic template Passing function as a parameter to another function: void ptFun(T)(T function(string, string, int) coRoutine, Array!string Dirlst, )

Re: ranges.chunks and map! does not work

2018-07-05 Thread Alex via Digitalmars-d-learn
On Thursday, 5 July 2018 at 09:47:32 UTC, Andre Pany wrote: Is it correct that I need to call ".map!(c => c.array)"? Kind regards André Well, no. It depends on how you define the formatting string. This would also work: ´´´ import std.experimental.all; void main() { double[] timestamps

Re: 'is(T==return)' How does is expression with return keyword as TypeSpecialization

2018-07-05 Thread Alex via Digitalmars-d-learn
On Thursday, 5 July 2018 at 10:32:01 UTC, Timoses wrote: int fun(T)(T i) { static assert(is(typeof(return) == T)); //true pragma(msg, is(T == return)); // false static if (is(T ReturnType == return)) pragma(msg, ReturnType); // does not enter re

Re: 'is(T==return)' How does is expression with return keyword as TypeSpecialization

2018-07-05 Thread Alex via Digitalmars-d-learn
On Thursday, 5 July 2018 at 11:37:16 UTC, Timoses wrote: I think it refers to this section: https://dlang.org/spec/expression.html#is_expression I don't remember where I read this usage (think it was in a book), but I noted it down and now I wonder how it can be used. I saw some usage cases,

Re: Outside array bounds

2018-07-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 July 2018 at 08:09:51 UTC, vino.B wrote: Hi All, Request you help, on the below code import std.stdio: writeln; void process(T ...)(string ID, T args) { if (ID == "I1") { writeln(args.length, "\t", args[0]); } else if (ID == "I2") { writeln(args.length, "\t", args[1]);} } voi

Re: Outside array bounds

2018-07-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 July 2018 at 08:24:21 UTC, Timoses wrote: Interesting.. Looks like the compiler does some boundschecking during compile time. You could circumvent this: void process(T ...)(string ID, T args) { if (ID == "I1") { writeln(args.length, "\t", args[0]); } static i

Re: Outside array bounds

2018-07-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 July 2018 at 11:22:38 UTC, Timoses wrote: Aw, got it. So args is actually a tuple type where accessing beyond the defined tuple (T) is invalid? auto a = [1, 2, 4]; // works pragma(msg, typeof(a[3])); auto t = tuple(3, 4, 5.3); // ERROR: // p

Re: guard clause style static if

2018-07-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 July 2018 at 12:54:03 UTC, kdevel wrote: On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote: On 08/07/2018 12:40 AM, kdevel wrote: Interesting alternative That was not an alternative. That is what your code was doing. What my original code was supposed to do. Bu

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-08 Thread Alex via Digitalmars-d-learn
On Sunday, 8 July 2018 at 18:46:31 UTC, vino.B wrote: Request you help, in the below code we pass the function "Testfun" as a parameter to another function "process" in order for the function "process" to work we have to specify the type of the parameter that is passed to the function "(T fun

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-09 Thread Alex via Digitalmars-d-learn
On Monday, 9 July 2018 at 15:40:53 UTC, vino.B wrote: On Sunday, 8 July 2018 at 19:10:24 UTC, Alex wrote: On Sunday, 8 July 2018 at 18:46:31 UTC, vino.B wrote: Request you help, in the below code we pass the function "Testfun" as a parameter to another function "process" in order for the func

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-09 Thread Alex via Digitalmars-d-learn
On Monday, 9 July 2018 at 17:26:30 UTC, vino.B wrote: Request Help: void process(alias coRoutine, T...)(Array!string Dirlst, T params) { ReturnType!coRoutine rData; / This line is not working alias scRType = typeof(coRoutine(string.init, T.init)); auto PFresult = task

Re: Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

2018-07-10 Thread Alex via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 14:38:03 UTC, vino.B wrote: Hi Alex, The reason the I am storing the output of "PFresult.toRange" to another array "rData" is that the output of the PFresult.toRange is different each time we execute the code.(Data is correct) but the way the it output is differ

Re: Check whether a range is empty

2018-07-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 July 2018 at 13:59:45 UTC, Gary Willoughby wrote: I thought every range at the lowest level has an `empty` property. So, in this case, it would be: if (PFResutl.toRange.empty) { writeln("Empty"); } Yeah, but it seems, that PFResutl is a range of ranges, and the OP has the

Re: HMAC and toHexString

2018-07-18 Thread Alex via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 05:54:48 UTC, Nicholas Wilson wrote: ... string key = "blahblahblah"; auto mac = hmac!SHA256(key.representation); string s = ...,t=...u=...,v=...; foreach(w;AliasSeq!(s,t,u,v)) mac.put(w.representation); ubyte[32] s = mac.finish; string sig = toHexString!

merging a group result

2018-07-23 Thread Alex via Digitalmars-d-learn
Hi all, I'm looking for a d-ish way to solve a basic "split-apply-combine" workflow. The idea is described (and solved) here: https://stackoverflow.com/questions/39922986/pandas-group-by-and-sum So, given a structure with some fields, say ´´´ struct S { string s; int i; } ´´´

Re: merging a group result

2018-07-23 Thread Alex via Digitalmars-d-learn
On Monday, 23 July 2018 at 12:07:37 UTC, Seb wrote: You could use chunkBy: auto res = sarr.chunkBy!((a, b) => a.s == b.s).map!(a => tuple(a.front.s, a.map!(b => b.i).sum)); https://run.dlang.io/is/TJOEmf Ha... This helps! Thanks a lot! :)

Re: trait to get the body code of a function?

2018-07-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 July 2018 at 07:32:19 UTC, Mr.Bingo wrote: If all you need is the string you can write a template function that imports the file and searches for the function and returns it's body. It's not very robust but it can work for some cases. D really should allow one to get the funct

Re: trait to get the body code of a function?

2018-07-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 July 2018 at 11:54:39 UTC, Mr.Bingo wrote: The string itself could be useful however... Whatever OP has in mind with this string... Having a code block is useful in many ways simply because not having it is the most limiting case. If one doesn't have it and requires it then

Re: Question about template argument matching with alias this

2018-07-29 Thread Alex via Digitalmars-d-learn
On Sunday, 29 July 2018 at 16:43:08 UTC, Johannes Loher wrote: I have a question about template argument matching in combination with implicit conversion and alias this. Consider the following code: interface SomeInterface { } class SomeClass : SomeInterface { } struct SomeStruct { Some

Re: Newbie: out-of-source builds with "dub"?

2018-07-30 Thread Alex via Digitalmars-d-learn
On Monday, 30 July 2018 at 01:50:23 UTC, CC wrote: Before starting with D programming, most of my projects have configured their build systems with Autotools or CMake, and git for source control. With those systems, it's usually considered best practice to store all files generated during con

Re: Question about template argument matching with alias this

2018-07-30 Thread Alex via Digitalmars-d-learn
On Sunday, 29 July 2018 at 23:03:27 UTC, Johannes Loher wrote: Yeah, I know that it possible to implement the template like this, but that is not the point here. I would like to know why it does not work the way I described it. To me it seems very strange, that `S : T` has different semantics i

Re: Disabling opAssign in a type disabled all the opAssigns of an aliased type?

2018-07-30 Thread Alex via Digitalmars-d-learn
On Monday, 30 July 2018 at 18:30:16 UTC, aliak wrote: Is this a bug? If not is there a workaround? I would like for the alias this to function as a normal A type unless B specifically disables certain features, but it seems weird that disabling one opAssign disables all of them inside the al

Re: Disabling opAssign in a type disabled all the opAssigns of an aliased type?

2018-07-30 Thread Alex via Digitalmars-d-learn
On Monday, 30 July 2018 at 19:33:45 UTC, aliak wrote: On Monday, 30 July 2018 at 18:47:06 UTC, Alex wrote: On Monday, 30 July 2018 at 18:30:16 UTC, aliak wrote: [...] What happens if you omit the @disable line? Compiles ok then. So... is this a valid workaround? ;)

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

2018-08-03 Thread Alex via Digitalmars-d-learn
On Friday, 3 August 2018 at 16:58:26 UTC, kdevel wrote: What does auto std.stdio.File.ByChunkImpl byChunk ( ulong chunkSize ); on https://dlang.org/library/std/stdio/file.by_chunk.html mean? Is that a (forward) declaration of a function named byChunk taking a single ulong argument na

Compiler build error

2018-08-04 Thread Alex via Digitalmars-d-learn
I'm a little bit confused by following situation: I have code, say around 8000 lines. Now, I'm facing a build error which just says dmd failed with exit code -11, (same for ldc2, with some lines of stack information, which do not belong to my code) 0 ldc2 0x000106f

Re: Compiler build error

2018-08-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 August 2018 at 12:21:36 UTC, Alex wrote: Ok. Dustmite finished. But the result is again an empty file... :(

Re: Compiler build error

2018-08-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 August 2018 at 13:26:01 UTC, Nicholas Wilson wrote: 0 ldc2 0x000106fcc4e7 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37 1 ldc2 0x000106fcb9ea llvm::sys::RunSignalHandlers() + 83 2 ldc2 0x000106fcc90e

Re: Compiler build error

2018-08-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 August 2018 at 13:29:36 UTC, kinke wrote: You're most likely hitting an ICE in the front-end (as both compilers crash). What you can always do is invoke the compiler in a GDB session. That's especially useful with an LDC CI build (download: https://github.com/ldc-developers/ldc/

Re: Compiler build error

2018-08-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 August 2018 at 22:50:49 UTC, kinke wrote: On Saturday, 4 August 2018 at 18:12:05 UTC, Alex wrote: /snap/ldc2/78/bin/ldc2(_start+0x29)[0x8b7ee9] You haven't specified the DMD version you are using. Your LDC is 'outdated', so make sure to first check whether it still fails with

Re: Compiler build error

2018-08-05 Thread Alex via Digitalmars-d-learn
On Sunday, 5 August 2018 at 01:15:07 UTC, Nicholas Wilson wrote: On Saturday, 4 August 2018 at 18:12:05 UTC, Alex wrote: On Saturday, 4 August 2018 at 13:26:01 UTC, Nicholas Wilson That is a very long stacks trace and combined with the very short stack trace on OSX, this is probably a stack ove

Re: @nogc closures

2018-08-05 Thread Alex via Digitalmars-d-learn
On Sunday, 5 August 2018 at 09:20:21 UTC, vit wrote: It's possible create something like this without errors? void main()@nogc{ //Error: function `app.main` is `@nogc` // yet allocates closures with the GC import std.experimental.all; const int j = 2; int i =

Re: foreach on a tuple using aliases

2018-08-05 Thread Alex via Digitalmars-d-learn
On Sunday, 5 August 2018 at 14:07:30 UTC, Steven Schveighoffer wrote: I have found something that looks like a bug to me, but also looks like it could simply be a limitation of the foreach construct. Consider this code: struct Foo {} enum isFoo(alias x) = is(typeof(x) == Foo); void main() {

  1   2   3   4   5   6   >