Re: how to enable safeD ? dmd.conf ? dmd switch ?

2021-06-08 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 8 June 2021 at 02:47:18 UTC, someone wrote: https://dlang.org/articles/safed.html https://dlang.org/dmd-linux.html#switches http://ddili.org/ders/d.en/functions_more.html Neither man dmd nor man dmd.conf appear to have a related/switch setting. Does it means safeD is achieved by

Re: Idiomatic D code to avoid or detect devision by zero

2020-07-31 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 31 July 2020 at 13:55:18 UTC, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than set c to an other value (d). (In the moment I

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Andrea Fontana via Digitalmars-d-learn
On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this property. Searching an array is O(n). Probably it should work if we're using a "SortedRange". int[] a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; auto

Re: How to sum multidimensional arrays?

2020-02-27 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: void main() { int[][] m1 = rndMatrix(10, 2, 3); int[][] m2 = rndMatrix(10, 2, 3); auto c = m1[] + m2[]; } I think you're trying to do this: int[][] m1 = rndMatrix(10, 2, 3); int[][] m2 = rndMatrix(10, 2, 3);

Re: Error on using regex in dmd v2.088.1

2020-02-03 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 3 February 2020 at 07:11:34 UTC, Dharmil Patel wrote: On Monday, 3 February 2020 at 07:03:03 UTC, Dharmil Patel wrote: In my code I am using regex like this: auto rgxComma = regex(r","); On compiling with dmd v2.076.1, it compiles successfully, but on compiling with dmd

Re: format with floating points GC allocating in DMD 2.090

2020-01-31 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 31 January 2020 at 08:45:55 UTC, bauss wrote: On Friday, 31 January 2020 at 07:20:17 UTC, cc wrote: char[4096] buf; writeln(GC.stats.usedSize); foreach (i; 0 .. 10) { sformat(buf, "%f", 1.234f); writeln(GC.stats.usedSize);

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 6 December 2019 at 12:34:17 UTC, realhet wrote: Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...} //static function struct V3f{ V3f max(in V2f b){...} //member function

Re: Slice/Substr [0..?lastIndexOf(".")] How refer itself without create a variable?

2019-12-05 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote: Simple example: writeln("Hi\nHow are you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]); How to refer to this string in lastIndexOf() without create a variable? Thank you. One solution: writeln( "Hello\nHow are

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 09:48:39 UTC, Basile B. wrote: You see what surprises me here is that we cannot express the special type that is `TypeNull` and that can only have one value (`null`) so instead we have to use `auto` or `typeof(null)`. You can still create an alias anyway :)

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 07:24:31 UTC, Basile B. wrote: A testA() { return alwaysReturnNull(); // Tnull can be implictly converted to A } still nice tho. Why not [1]? [1] typeof(null) alwaysReturnNull() { ... } Andrea

Re: static assert(version(x)) ?

2019-11-26 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch wrote: How can I write something like this to check if any of a set of specific versions is used? static assert(!(version(a) | version(b) | version(c)): The problem is that I can use version(a) like a test, and the symbol a is not

Re: Anything like HPPTOD out there?

2019-11-25 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 25 November 2019 at 16:35:21 UTC, ParticlePeter wrote: I would like to auto convert c++ header to d module. Is there some project aiming for this? I know of VisualD c++ to d conversion wizzard [1] and LLVM tooling based CPP2D [2], both of them aiming for whole cpp conversion. But

Re: What is the point of a synchronized lock on a single return statement?

2019-11-25 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 25 November 2019 at 09:24:43 UTC, Jonathan M Davis wrote: On Monday, November 25, 2019 1:22:17 AM MST Andrej Mitrovic via Digitalmars- d-learn wrote: From: https://github.com/dlang/phobos/blob/10b9174ddcadac52f6a1ea532deab3310d3a8 c03/std/concurrency.d#L1913-L1916: - /// final

Re: Meta question - what about moving the D - Learn Forum to a seperate StackExchange platform?

2019-10-18 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 18 October 2019 at 10:55:59 UTC, Martin Tschierschke wrote: Yes, it works as it is, but it is not the best solution to share know how. I agree. I think D.learn should be moved to stackoverflow and D.general should stay here.

Re: How does one cast to an array type?

2019-10-17 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 17 October 2019 at 12:19:03 UTC, Vinay Sajip wrote: Are arrays and objects part of a unified type system? Specifically, if I do void foo(Object x) { if (typeid(x) == typeid(Object[])) { auto a = cast(Object[]) x; } } I get a compilation error: onlineapp.d(3):

Re: How does D distnguish managed pointers from raw pointers?

2019-10-03 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 3 October 2019 at 14:13:55 UTC, IGotD- wrote: According to the GC documentation this code snippet char* p = new char[10]; char* q = p + 6; // ok q = p + 11; // error: undefined behavior q = p - 1; // error: undefined behavior suggests that char *p is really a "fat

Re: Using algorithms with ranges

2019-10-03 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 3 October 2019 at 05:33:04 UTC, mipri wrote: void main() { import std.range : iota; foreach (x; iota(1, 10).withHistory) writeln(x); } This doesn't work as expected, I think. auto r = iota(1,10).withHistory; writeln(r.front); writeln(r.front);

Re: Avoid gratuitous closure allocations

2019-09-20 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 20 September 2019 at 11:21:22 UTC, Ali Çehreli wrote: tl;dr Instead of returning an object that uses local state, return an object that uses member variables. Really good to know tips!

Re: How'd I store possible types for each item of a list of Variants ?

2019-09-20 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 20 September 2019 at 08:58:09 UTC, oleobal wrote: I'm kind of out of ideas at this point. Would anyone have an elegant solution to this problem? Thanks ! Is this ok for you: https://run.dlang.io/is/VllpJk ? Andrea

Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 18 September 2019 at 12:03:28 UTC, berni wrote: The following code doesn't compile: import std.stdio; void main() { import std.complex: abs, complex; import std.math: abs; auto a = complex(1.0,1.0); auto b = 1.0; writeln(abs(a)); writeln(abs(b)); } What

Re: Dynamic array + AA array

2019-09-17 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 17 September 2019 at 14:33:30 UTC, Brett wrote: The idea is to basically use a dynamic array for most of the items, then an array to get the rest. T[] Base; T[int] Rest; Then if Base has a max size(usually it might be fixed due to some algorithm) the Rest AA can pick up any

Re: Using CSS Data from Within My Code

2019-09-12 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant wrote: I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab {

Re: Meaning of Scoped! ??

2019-07-30 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 30 July 2019 at 09:33:04 UTC, Ron Tarrant wrote: Some things are almost impossible to research. For instance, in the GtkD wrapper code—specifically the Widget.d file—the following function definition appears: gulong addOnDraw(bool delegate(Scoped!Context, Widget) dlg,

Re: What is iota function full name

2019-06-21 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 21 June 2019 at 09:24:54 UTC, lili wrote: in dictionary iota means: a tiny or scarcely detectable amount the 9th letter of the Greek alphabet but this function is not that mean. Full answer: https://stackoverflow.com/questions/9244879/what-does-iota-of-stdiota-stand-for

Re: Simultaneously assigning to all values in a tuple

2019-04-01 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 1 April 2019 at 10:12:50 UTC, Simen Kjærås wrote: On Monday, 1 April 2019 at 09:46:34 UTC, Jacob Carlborg wrote: On 2019-03-28 01:29, 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[] =

Re: Tuple!(string, int))[] field_orders

2019-03-14 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 14 March 2019 at 15:29:28 UTC, Ozan wrote: Hi In vibe.d / data / mongo / collection I found the function * ensureIndex(Tuple!(string, int))[] field_orders) What could be the right way to use "Tuple!(string, int))[] field_orders"? I tried different ways like [Tuple!("a", 1),

Re: bug in doc?

2019-03-14 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 14 March 2019 at 14:22:52 UTC, spir wrote: https://dlang.org/spec/hash-map.html#static_initialization: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; If I'm right, you can't use this syntax with global array. Insted this works: void main() {

Re: local class instance (at module-level)

2019-03-14 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 14 March 2019 at 11:05:22 UTC, spir wrote: The most confusing error is: Error: variable `_base.c0` is a thread-local class and cannot have a static initializer. Use `static this()` to initialize instead. Error is reffering to: https://dlang.org/spec/module.html#staticorder

Re: Strange appender behavior

2019-03-13 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 13 March 2019 at 13:03:27 UTC, tchaloupka wrote: Is this expected?: ``` import std.stdio; import std.algorithm; import std.array; void main() { auto d = Appender!string(); //auto d = appender!string(); // works string[] arr = ["foo", "bar", "baz"];

Re: sort!("...") with template function?

2019-02-25 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 25 February 2019 at 12:37:31 UTC, Vladimirs Nordholm wrote: Hello. I wish to sort an array by calling a template function on a struct. In essence I want to do foos.sort!("a.get!Dummy < b.get!Dummy"); but I get the error message

Re: Weird const behavior

2018-12-20 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 20 December 2018 at 14:49:10 UTC, Marko wrote: But is this right? I mean if they are equal shouldn't they have the same behavior? I don't think so: float a = 1.0; long b = 1; writeln(a == b); writeln(a/2 == b/2);

Re: Reverse and sort array elements

2018-12-18 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:47:59 UTC, Andrey wrote: On Tuesday, 18 December 2018 at 12:32:35 UTC, angel wrote: On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote: Thank you everybody. Here was another problem that local variable 'array' shadows function 'array()' from

Re: D do not know which function to use apparently

2018-12-11 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 11 December 2018 at 15:17:10 UTC, Narxa wrote: Yes, it worked: --- int var = cast(int) floor(sqrt( cast(float) n )); I thought floor already returned an 'int' but I was mistaken. Thank you very much. I think you don't need floor. int var =

Re: Wrapping a Dub project inside Meson

2018-11-22 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 22 November 2018 at 02:46:03 UTC, Adnan wrote: Does anyone have experience with using meson to wrap around a dub project? I have a typical dub project, meaning I have a dub dependency but I want to use meson for two reasons: 1. I want to distribute the application in form of a

Re: Writing Postgresql extension in D

2018-11-15 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 15 November 2018 at 13:05:59 UTC, Ranjan wrote: This is my first time on the Dlang forum. I like the language but my usecase is a bit different. I want to write Postgresql extension in D. Currently extension can be written in C or C linked languages. Has anyone done this or can

Re: std.socket tutorials? examples?

2018-10-04 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 4 October 2018 at 08:32:13 UTC, Chris Katko wrote: I've been Google'ing and there's like... nothing out there. One of the top results for "std.socket dlang examples"... is for TANGO. That's how old it is. Socket paradigm is quite standard across languages. Anyway you can find a

Re: Private struct constructor

2018-10-04 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 4 October 2018 at 07:31:21 UTC, Ritchie wrote: Any reason why this works? https://run.dlang.io/is/TALlyw Why not?

Re: Template return type?

2018-10-03 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 October 2018 at 09:37:29 UTC, JN wrote: int i = returnDefault!int(); obviously works, but the point is I would like to skip the explicit type. See: https://forum.dlang.org/post/ufhibwmouxpivjylq...@forum.dlang.org

Re: How to implement D to HTML pages ?

2018-10-03 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 18:27:04 UTC, Aurélien Plazzotta wrote: Thank you both for all the links! I guess DiamondMVC is very powerful but I would rather avoid using such heavy artillery. I'm expecting the learning curve to be very long. I currently use two libraries I wrote to keep

Re: Weird compilation error only as static library

2018-09-28 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 19:08:45 UTC, Márcio Martins wrote: Hi! I am getting this error when compiling my code as a static library. It works fine as an executable. I have no idea what's happening. Has someone seen something like this before? What could be different? This is the

Re: std.process: spawnProcess

2018-09-07 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 7 September 2018 at 14:36:42 UTC, Russel Winder wrote: From what I can see, processes created with std.process: spawnProcess are not terminated when the creating process terminates, i.e. it seems Config.detached is the default for these process. Is there a way of all spawned

Re: Is there any reason to use non-ref foreach?

2018-09-04 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 07:06:43 UTC, Dukc wrote: On Monday, 3 September 2018 at 13:34:36 UTC, Andrea Fontana wrote: On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this:

Re: Is there any reason to use non-ref foreach?

2018-09-03 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: One good reason: https://forum.dlang.org/thread/dlhrrgvzmhladnphi...@forum.dlang.org

Re: DStep rocks [was Example of using C API from D?]

2018-09-03 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 3 September 2018 at 10:50:17 UTC, Russel Winder wrote: Interesting alternative to DStep. I came to D to avoid #include, but… I'll give it a whirl once I can get it compiled on Debian Sid. It seems the libclang-dev package does not install a libclang.so symbolic link, you have to be

Re: Pass lambda into template

2018-09-03 Thread Andrea Fontana 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: Why std.array : array needs pure postblit?

2018-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 15 June 2018 at 11:48:59 UTC, Andrea Fontana wrote: On Friday, 15 June 2018 at 11:25:49 UTC, Basile B. wrote: Hello, i've tested locally and it can works by making `Appender.reserve()` and `Appender.ensureAddable()` function templates. That was my idea too. But I wonder if

Re: Why std.array : array needs pure postblit?

2018-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 15 June 2018 at 11:25:49 UTC, Basile B. wrote: Hello, i've tested locally and it can works by making `Appender.reserve()` and `Appender.ensureAddable()` function templates. That was my idea too. But I wonder if pureness of reserve and ensureAddable have a particular reason.

Why std.array : array needs pure postblit?

2018-06-15 Thread Andrea Fontana via Digitalmars-d-learn
Check this code: https://run.dlang.io/is/PoluHI It won't work, because array appender requires a pure postblit. Why? Can we remove this limitation? Andrea

Re: Is DWT busted?

2018-06-09 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 8 June 2018 at 05:00:57 UTC, TheGag96 wrote: I'm sorry about bringing this into here instead of DWT's subforum, but it's somewhat dead and hasn't been getting a lot of attention. I decided to finally play around with DWT today and tried to build the example. It's a known bug. I

Re: how to define infix function

2018-06-04 Thread Andrea Fontana via Digitalmars-d-learn
On Saturday, 2 June 2018 at 23:17:48 UTC, Simen Kjærås wrote: unittest { import std.algorithm.comparison; alias min = Operator!(std.algorithm.comparison.min); assert(1 /min/ 3 == 1); } Why not: alias Δ = Operator!(std.algorithm.comparison.min); assert(1 /Δ/ 3 == 1); To improve

Re: UDA and static struct fields

2018-05-24 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 24 May 2018 at 10:23:41 UTC, Andrea Fontana wrote: On Thursday, 24 May 2018 at 09:17:10 UTC, Alex wrote: 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

Re: UDA and static struct fields

2018-05-24 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 24 May 2018 at 09:17:10 UTC, Alex wrote: 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

Re: UDA and static struct fields

2018-05-24 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 24 May 2018 at 07:59:08 UTC, Simen Kjærås wrote: On Thursday, 24 May 2018 at 07:47:54 UTC, Andrea Fontana wrote: Is this a bug or am I missing something? https://run.dlang.io/is/OGHJYX Andrea This line: mixin("alias tmp = " ~ s ~ ";"); There's no mention of Symbol in

UDA and static struct fields

2018-05-24 Thread Andrea Fontana via Digitalmars-d-learn
Is this a bug or am I missing something? https://run.dlang.io/is/OGHJYX Andrea

Re: Speed of math function atan: comparison D and C++

2018-03-06 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 5 March 2018 at 20:11:06 UTC, H. S. Teoh wrote: Walter has been adamant that we should always compute std.math.* functions with the `real` type T I don't understand why atan(float) returns real and atan(double) return real too. If I'm working with float, why does it return a

Re: single loop copy in D

2018-03-02 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 2 March 2018 at 09:44:20 UTC, psychoticRabbit wrote: trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: -- while ((*dst++ = *src++)) {} -- You can't use this syntax

Re: iota to array

2018-02-25 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit wrote: I would have preffered it defaulted java style ;-) System.out.println(1.0); // i.e. it prints 'what I told it to print'. System.out.println(1.0); // print 1.0 System.out.println(1.0); // print 1.0 So it doesn't print

Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit

2018-02-14 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 14 February 2018 at 11:16:25 UTC, Martin Tschierschke wrote: Ok, good to know! I started with 16.04 and made the initial mistake to take the 32 Bit version, do you use 32 or 64 Bit? 64bit of course! Andrea

Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit

2018-02-14 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 13 February 2018 at 22:21:18 UTC, Martin Tschierschke wrote: I will downgrade to 16.04., the dist-upgrade to 17.10 was a mistake, resulting in problems with startx and newer kernels so I have to use 4.10. In my experience dist-upgrade are long and messy :) Usually I create a

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

2017-12-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 December 2017 at 16:39:14 UTC, kdevel wrote: Then (*) works as expected. But why do I have to use the prefix "mymod.:" in the library case? Because module names are not relative to file path, but to import path / compile path afaik.

Re: Directory Size

2017-12-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 14:49:48 UTC, Vino wrote: Hi Andrea, Thank you very much, as your code is pretty good for our scenario, just one request, the above is a part of our main code where we have many such sub code and all of our sub code use the container

Re: Directory Size

2017-12-06 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 17:21:29 UTC, Vino wrote: Hi All, Is there any better ways to get the size of folders , The below code perfectly works , but i need return type as Array!(Tuple!(string, string)) rather then using the "Result.insertBack(d);

Re: Object oriented programming and interfaces

2017-12-05 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 07:47:32 UTC, Dirk wrote: What would be a good way to implement this? Did you tried to use introspection?

Re: Passing Function as an argument to another Function

2017-12-04 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 4 December 2017 at 08:27:10 UTC, rikki cattermole wrote: On 04/12/2017 8:22 AM, Vino wrote: Hi All,   Request your help on the below code, I want to send the name of the function ( First and Second) from main as an argument to another function(Mid) and the function "Mid" has to

Re: Decimal handling for currency (precision)

2017-11-23 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 23 November 2017 at 14:47:21 UTC, aberba wrote: Some suggest working with the lowest currency denomination to avoid decimal precision handling and only convert to the highest denominations (decimal) when displaying. I've also seen some use decimal value handling libraries. I'm

Re: reduce condition nesting

2017-11-23 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 23 November 2017 at 13:47:37 UTC, Adam D. Ruppe wrote: On Thursday, 23 November 2017 at 05:19:27 UTC, Andrey wrote: for instance in kotlin it can be replace with this: when { c1 -> foo(), c2 -> bar(), c3 -> ... else -> someDefault() } The `switch` statement

Re: reduce condition nesting

2017-11-23 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 23 November 2017 at 05:19:27 UTC, Andrey wrote: Hello, is there way to reduce this condition: if (c1) { foo(); } else { if (c2) { bar(); } else { if (c3) { ... } } } for instance in kotlin it can be replace with this: when { c1

Re: User defined type and foreach

2017-11-16 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 16 November 2017 at 08:03:48 UTC, Tony wrote: I made a stack data type and created an opIndex() so it could be turned into a dynamic array, and created empty() (unfortunate name), front() and popFront() methods, which I read allow it to be used with foreach. However, when I use

Re: Missing return value error not present with template

2017-11-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 08:43:01 UTC, Tony wrote: This code: class MyClass { public: int SomeMethod () { } } void main() { } gets a compile error: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int

Re: string version of array

2017-11-14 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 07:56:06 UTC, rikki cattermole wrote: On 14/11/2017 7:54 AM, Tony wrote: Is there an easy way to get the string representation of an array, as would be printed by writeln(), but captured in a string? struct Foo { int x; } void main() { Foo[]

Re: Writing some built-in functions for Bash, possible?

2017-10-18 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 03:48:01 UTC, Ky-Anh Huynh wrote: Hi, I'm using Bash heavily in my systems. Things become slow and slow when I have tons of scripts :) And sometimes it's not easy to manipulate data. You may have heard of recutils [1] which has a C extension to be loaded by

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-18 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 07:26:20 UTC, Nordlöw wrote: On Wednesday, 18 October 2017 at 07:01:19 UTC, Andrea Fontana wrote: If you try to use your data with chunkBy!"a != b+1", it does not work, as expected. What's the motivation behind this limitation? Without it chunkBy!"a + 1

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-18 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 06:45:37 UTC, Nordlöw wrote: On Tuesday, 17 October 2017 at 14:15:02 UTC, Andrea Fontana wrote: auto splitBy(alias F, R)(R range) Because of lazyness shouldn't it be named something with splitter, say splitterBy, instead? Yes but I think it is something

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread Andrea Fontana via Digitalmars-d-learn
More phobos-ized version: https://run.dlang.io/is/iwgeAl Andrea

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 13:09:18 UTC, Nordlöw wrote: I can't find any algorithm/range in Phobos that can be used to split (eagerly or lazily) a sequence using a binary predicate on adjacent elements as follows [1,2,3,5,10,11,12,13,20,21,100].splitBy!"a + 1 != b"() should evaluate to

Re: initializing a static array

2017-10-10 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:53:37 UTC, jmh530 wrote: double[n] bar; bar[] = 0; This works at runtime only for mutable arrays, anyway.

Re: initializing a static array

2017-10-10 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:36:56 UTC, Simon Bürger wrote: Is there a good way to set them all to zero? The only way I can think of is using string-mixins to generate a string such as "[0,0,0,0]" with exactly n zeroes. But that seems quite an overkill for such a basic task. I suspect I

Re: Does writing from NNTP work?

2017-10-04 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 14:18:52 UTC, Tristan B. Kildaire wrote: Does this work? No, I don't read you. Try again :)

Re: Struct bug?

2017-10-02 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 2 October 2017 at 09:08:59 UTC, Biotronic wrote: Not knowing what you're attempting to do, I'm not sure how to fix your problem. But if what I've described above does indeed cover it, initializing b in the constructor is the way to get it to work. -- Biotronic Obviusly real

Struct bug?

2017-10-02 Thread Andrea Fontana via Digitalmars-d-learn
Why this code doesn't write two identical lines? https://dpaste.dzfl.pl/e99aad315a2a Andrea

Re: Internal error mixing templates and CTFE

2017-09-15 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 15 September 2017 at 05:58:47 UTC, David Bennett wrote: Is this an error in dmd, and should I open a bug report? Internal error is always a bug, so it should be reported! Andrea

Re: I need library for QR codes generation.

2017-09-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 14:30:24 UTC, MGW wrote: I need library for generation of QR codes. Who knows, give the link. You can try to bind a c library like [1] using dstep. It should be easy. Andrea [1] https://github.com/fukuchi/libqrencode

Re: Problem with std.string.strip(): Can't use result in format routine

2017-09-05 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 13:40:18 UTC, Ky-Anh Huynh wrote: On Tuesday, 5 September 2017 at 13:17:34 UTC, Azi Hassan wrote: Maybe it has something to do with how you read from STDIN. Can you show that part of the code to see if I can reproduce the issue ? I used `lines(stdin)` as in

Re: replace switch for mapping

2017-09-05 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 4 September 2017 at 20:54:27 UTC, EntangledQuanta wrote: On Monday, 4 September 2017 at 09:23:24 UTC, Andrea Fontana wrote: On Thursday, 31 August 2017 at 23:17:52 UTC, EntangledQuanta wrote: Generally one has to use a switch to map dynamic components. Given a set X and Y one can

Re: replace switch for mapping

2017-09-04 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 31 August 2017 at 23:17:52 UTC, EntangledQuanta wrote: Generally one has to use a switch to map dynamic components. Given a set X and Y one can form a switch to map X to Y: [...] Does this work for you? https://dpaste.dzfl.pl/e2669b595539 Andrea

Re: How to make autocompletion for IDE?

2017-07-26 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 10:45:38 UTC, unDEFER wrote: On Tuesday, 25 July 2017 at 10:35:14 UTC, Andrea Fontana wrote: If you want to add UFCS suggestions to DCD it would be useful for your project and all other IDEs too! Andrea Thank you, I will think. But if it was easy, authors self

Re: How to make autocompletion for IDE?

2017-07-25 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 10:32:11 UTC, unDEFER wrote: Yes this project where "Not working: UFCS suggestions and That one feature that you REALLY needed".. I want to have all features that I really need :-) But If I will not find how do UFCS suggestions fast, I probably will use DCD for all

Re: How to make autocompletion for IDE?

2017-07-25 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 10:23:33 UTC, Andrea Fontana wrote: On Tuesday, 25 July 2017 at 10:06:47 UTC, unDEFER wrote: Any ideas? I think you should use/contribute to DCD project https://github.com/dlang-community/DCC Andrea Sorry, this is the right link:

Re: How to make autocompletion for IDE?

2017-07-25 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 10:06:47 UTC, unDEFER wrote: Any ideas? I think you should use/contribute to DCD project https://github.com/dlang-community/DCC Andrea

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote: Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. You can also use a queue to avoid recursion that should improve performances and readibility. Probably using ndslice library

Re: Check if a variadic argument is numeric?

2017-07-06 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 6 July 2017 at 12:15:56 UTC, Hamborg wrote: That compiles, but it returns false when I pass in a numeric value... :( I think you should provide a code snippet then. I think I missed something about your question. Andrea

Re: Check if a variadic argument is numeric?

2017-07-06 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 6 July 2017 at 08:22:44 UTC, Hamborg wrote: But how would I check _arguments[i]? When I do (isNumeric!_arguments[i]) I get an error saying: "Error: template instance isNumeric!(_arguments) does not match template declaration isNumeric(T)" or when I do

Re: Remove instance from array

2017-07-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 5 July 2017 at 16:17:29 UTC, Jolly James wrote: On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote: On Wednesday, 5 July 2017 at 15:56:45 UTC, Igor Shirkalin wrote: [...] Thank you! :) But why a containers so complicated in D? [...] Part of CoreCLR's 'List':

Re: Remove instance from array

2017-07-05 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote: WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i; How does one remove that instance 'i'? Maybe: http://dlang.org/phobos/std_algorithm_mutation.html#.remove ?

Re: if auto and method call

2017-04-18 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 09:05:10 UTC, Andrea Fontana wrote: On Tuesday, 18 April 2017 at 00:48:05 UTC, Jethro wrote: How to combine the need to localize a result for an if statement and have to call a method to get proper comparison: [...] which should simplify to if ((auto x =

Re: if auto and method call

2017-04-18 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 00:48:05 UTC, Jethro wrote: How to combine the need to localize a result for an if statement and have to call a method to get proper comparison: [...] which should simplify to if ((auto x = foo()).valid()) { } but this code does not work. [...] for(auto x =

Re: how to make interface with return auto

2017-04-03 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 3 April 2017 at 12:42:02 UTC, Eko Wahyudin wrote: I know it's imposible. is there's a way if i want to create an interface that have method with return type value is equals with return type of std.palallelism.task eg. interface IWorker{ auto activate(); //on implementation

Re: high performance client server solution in D?

2017-03-23 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 23 March 2017 at 13:07:54 UTC, biocyberman wrote: I would choose 'dlangui' and check 'vibe.d' for a start. However, I do not need to access the central server via web browsers. Hope that you can give some thoughts about this design, what GUI library to use, and what back-end

Re: first try

2017-03-17 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 17 March 2017 at 09:04:18 UTC, Andrea Fontana wrote: On Friday, 17 March 2017 at 00:35:32 UTC, Philip Miess wrote: This is my first 100+ line D program. https://gitlab.com/pmiess/101gamesDlangComputerGames/blob/master/ aceyducy.d Its a translation/refactor of aceyducy from 101 basic

  1   2   3   >