Re: task can't take a class method

2018-11-19 Thread helxi via Digitalmars-d-learn
On Monday, 19 November 2018 at 17:18:14 UTC, John Chapman wrote: 1) task() Thanks, that helped.

Re: task can't take a class method

2018-11-19 Thread helxi via Digitalmars-d-learn
On Monday, 19 November 2018 at 16:10:15 UTC, helxi wrote: ... Oh wait never mind I was missing a bracket: auto proc = task!(ddCall.dd()); Now I have another thing to worry about: ddcall.dd() cannot be read at compile time.

task can't take a class method

2018-11-19 Thread helxi via Digitalmars-d-learn
I want to create a task out of an object's method. My Class is: public class Calldd { private: const string tmpFileName = "/tmp/nixwriter.progress.txt"; string deviceName, sourceFileName; public: this(in string sourceFileName, in string deviceName) { this.sourceFileName

Re: Reading into the output of a long running shellExecute

2018-11-12 Thread helxi via Digitalmars-d-learn
On Saturday, 10 November 2018 at 15:54:07 UTC, JN wrote: On Saturday, 10 November 2018 at 15:05:38 UTC, helxi wrote: Hi. I have not done any multi-threaded programming before. What I basically want is to read into the output of a long shellExecute function each second. In details, I am

Re: How does calling function pointers work?

2018-11-12 Thread helxi via Digitalmars-d-learn
On Monday, 12 November 2018 at 16:25:13 UTC, Rene Zwanenburg wrote: Idk where you got that syntax from, but there's no syntactic difference between calling normal functions and function pointers: import std.stdio; import std.concurrency; import core.thread; void worker(int firstNumber) {

Re: How does calling function pointers work?

2018-11-12 Thread helxi via Digitalmars-d-learn
On Monday, 12 November 2018 at 16:08:28 UTC, helxi wrote: Line 12 was meant to print 1234. Line 13 was meant to print 1234 too, but for a different reason. Correction, it was meant to print 12304. My bad.

How does calling function pointers work?

2018-11-12 Thread helxi via Digitalmars-d-learn
As far as I understand, calling a function pointer with an argument in D looks like: call(, argTofn0, argTofn1, argTofn3); This immediately struck me a very weak syntax to me so I decided to explore my concerns. I made a function pointer that takes an indefinite number of arguments.

Reading into the output of a long running shellExecute

2018-11-10 Thread helxi via Digitalmars-d-learn
Hi. I have not done any multi-threaded programming before. What I basically want is to read into the output of a long shellExecute function each second. In details, I am calling shellExecute("pkexec dd if=/path/to/file of=/dev/sdx status=progress && sync"); It's a long running process and dd

Re: Exception slipping through the catch block?

2018-11-08 Thread helxi via Digitalmars-d-learn
On Thursday, 8 November 2018 at 15:41:11 UTC, Adam D. Ruppe wrote: On Thursday, 8 November 2018 at 15:08:40 UTC, helxi wrote: Shouldn't the catch block in the function catch the exception? You caught Exception, but it throws Error. They have separate inheritance trees. The common ancestor

Exception slipping through the catch block?

2018-11-08 Thread helxi via Digitalmars-d-learn
How does exception work? I am inside a function that calls a constructor. Inside the constructor, an exception is thrown. However even though I have wrapped the body of the function inside a try/catch block, the program crashes from inside that constructor. Shouldn't the catch block in the

Re: Where do I learn to use GtkD

2018-10-31 Thread helxi via Digitalmars-d-learn
On Tuesday, 30 October 2018 at 14:38:53 UTC, Michelle Long wrote: On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote: Gtk3 from python3 has got I nice book with examples that are not so advanced but enough to get you doing real work(from a beginner point of view). GtkD seem to have

Re: Where do I learn to use GtkD

2018-10-29 Thread helxi via Digitalmars-d-learn
On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote: Gtk3 from python3 has got I nice book with examples that are not so advanced but enough to get you doing real work(from a beginner point of view). GtkD seem to have changed the API structure compared to python3 Gtk3 and the demo

Re: Prevent opening binary/other garbage files

2018-10-01 Thread helxi via Digitalmars-d-learn
On Sunday, 30 September 2018 at 03:19:11 UTC, Adam D. Ruppe wrote: On Saturday, 29 September 2018 at 23:46:26 UTC, helxi wrote: Thanks. Would you say https://dlang.org/library/std/encoding/get_bom.html is useful in this context? Eh, not really, most text files will not have one. Hi, I

Re: Prevent opening binary/other garbage files

2018-09-29 Thread helxi via Digitalmars-d-learn
On Saturday, 29 September 2018 at 16:01:18 UTC, Adam D. Ruppe wrote: On Saturday, 29 September 2018 at 15:52:30 UTC, helxi wrote: I'm writing a utility that checks for specific keyword(s) found in the files in a given directory recursively. What's the best strategy to avoid opening a bin file

Prevent opening binary/other garbage files

2018-09-29 Thread helxi via Digitalmars-d-learn
I'm writing a utility that checks for specific keyword(s) found in the files in a given directory recursively. What's the best strategy to avoid opening a bin file or some sort of garbage dump? Check encoding of the given file? If so, what are the most popular encodings (in POSIX if that

Re: D vs nim

2018-04-13 Thread helxi via Digitalmars-d
On Friday, 10 April 2015 at 18:42:20 UTC, Timothee Cour wrote: Nim looks very promising. Is there any comprehensive comparison against D somewhere (if possible recent) ? Nim is way more expressive than D afaik. Consider the following imaginary function: proc fn[A : int | float; N; B :

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

2018-04-09 Thread helxi via Digitalmars-d-learn
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 'sumtype' on code.dlang.org. You can replace

Is std.variant.visit not @nogc?

2018-04-08 Thread helxi via Digitalmars-d-learn
import std.variant, core.stdc.stdio; Algebraic!(T, string) fib_nth(T)(T n) { return n % 15 ? n % 5 ? n % 3 ? Algebraic!(T, string)(n) : Algebraic!(T, string)("Fizz") : Algebraic!(T,

Re: std.variant Is Everything Cool About D

2018-04-03 Thread helxi via Digitalmars-d-announce
On Thursday, 29 March 2018 at 14:10:39 UTC, Mike Parker wrote: Jared Hanson (a.k.a Meta and MetaLang around these parts) was inspired by an article titled "std::visit is everything wrong with modern C++" to contrast it with D's std.variant.visit. The result is this well-written post for the D

What is the equivalent of C++'s std::optional and std::nullopt in D?

2018-04-02 Thread helxi via Digitalmars-d-learn
For reference: https://en.cppreference.com/w/cpp/utility/optional

Re: Dynamic Bindings to libui (x-platform GUI)

2018-01-08 Thread helxi via Digitalmars-d-announce
On Tuesday, 24 May 2016 at 20:52:54 UTC, extrawurst wrote: Hey folks, libui is a crossplatform GUI lib written in C. This makes it a perfect candidate to be used in D! What they say about libui on their site: "Simple and portable (but not inflexible) GUI library in C that uses the native

Re: Avoiding default generic types, and allocator awareness

2017-12-30 Thread helxi via Digitalmars-d-learn
On Saturday, 30 December 2017 at 15:00:32 UTC, helxi wrote: As an exercise in http://ddili.org/ders/d.en/pointers.html, I was implementing a very stripped down version of singly linked list like below: struct Node(T) { T item; Node!T* next_item; } [...] Correction, I meant: If I

Avoiding default generic types, and allocator awareness

2017-12-30 Thread helxi via Digitalmars-d-learn
As an exercise in http://ddili.org/ders/d.en/pointers.html, I was implementing a very stripped down version of singly linked list like below: struct Node(T) { T item; Node!T* next_item; } string to_string(T)(in Node!T node) { import std.format; return node.nextItem ? "%s ->

Curiously Recurring Template Pattern Example

2017-12-25 Thread helxi via Digitalmars-d-learn
Hi, Is there any blogs that discuss CRTP, or even Policy based/introspection based design in idiomatic D? I would love to see the strategies used to tackle the overhead involving dynamic dispatch by emulating static polymorphism. Thanks.

Re: Post about comparing C, C++ and D performance with a real world project

2017-12-09 Thread helxi via Digitalmars-d
On Friday, 8 December 2017 at 15:40:08 UTC, Steven Schveighoffer wrote: On 12/7/17 8:11 PM, Mengu wrote: On Thursday, 7 December 2017 at 22:39:44 UTC, Daniel Kozak wrote: The other slowdown is caused by concatenation. Because std::string += is more simillar to std.array.(Ref)Appender wait, i

Seperating class methods in a different module

2017-12-06 Thread helxi via Digitalmars-d-learn
1. How can I separate class methods from the declaration block? And how can I implement them in a separate module? module frame; class Test { public: int x; this(); } Test.this() { x = 34; } // does not work In this scenario I would like to take the constructor to a

Re: Optimizing a bigint fibonacci

2017-12-06 Thread helxi via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 10:00:48 UTC, Biotronic wrote: On Wednesday, 6 December 2017 at 09:12:08 UTC, helxi wrote: [...] Here's my version:, based on fast squaring: auto fib(ulong n) { import std.bigint : BigInt; import std.meta : AliasSeq; import std.typecons : tuple;

Re: GtkD 3.7.0 released, GTK+ with D.

2017-12-06 Thread helxi via Digitalmars-d-announce
On Tuesday, 5 December 2017 at 18:38:06 UTC, aberba wrote: On Saturday, 2 December 2017 at 08:17:24 UTC, helxi wrote: [...] I wanted to do this using some examples I have whilst learning it. Its at the bottom of my list of things I love to do. its not difficult though. It's quite close to

Optimizing a bigint fibonacci

2017-12-06 Thread helxi via Digitalmars-d-learn
This is question not directly related to language concepts, it's got more to do with the application. I would appreciate if anyone would point to me how I could optimize this bit of code auto fib(const int n) { import std.bigint; if (n == 0) return BigInt(0);

Using enum types

2017-12-04 Thread helxi via Digitalmars-d-learn
Why can't enums be used as types in this (simplified) example? enum Positivity { Positive, Negative } struct Wave { public: Positivity slope; } enum Waves { Sin = Wave(Positivity.Positive), Cos = Wave(Positivity.Negative) } int nth_value(T : Waves)(int

Re: GtkD 3.7.0 released, GTK+ with D.

2017-12-02 Thread helxi via Digitalmars-d-announce
On Sunday, 15 October 2017 at 20:18:37 UTC, Mike Wey wrote: GtkD is a D binding and OO wrapper of Gtk+ and is released on the LGPL license. Apart form the biannual update to the latest glib/gtk version, this release adds bindings for Gstreamer Mpegts and Gstreamer AppSink. Full changelog:

Template specialisation, "Generic type locking", offline stdlib docs and case-based template question

2017-11-30 Thread helxi via Digitalmars-d-learn
1. Template specialisation. Why is this useful?: T getResponse(T = int)(string question); And how does it differ from int getResponse(string question); ? Context: http://ddili.org/ders/d.en/templates.html : Section: "Default template parameters" 2. "Generic locking". Is it possible to

Re: Private imports and Objects

2017-11-30 Thread helxi via Digitalmars-d-learn
On Thursday, 30 November 2017 at 06:44:43 UTC, Jonathan M Davis wrote: On Thursday, November 30, 2017 06:29:43 helxi via Digitalmars-d-learn wrote: [] I don't understand the question. You're asking whether casting from a base class to a derived class creates overhead? Or are you asking

Private imports and Objects

2017-11-29 Thread helxi via Digitalmars-d-learn
1. Why are imports visible from outside the package when you do selective imports? //mod.d module mod; import std.stdio : writeln; public void greet() { writeln("Hello"); } //app.d import mod; void main() { mod.greet(); writeln("You should not be seeing this."); }

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:34:32 UTC, helxi wrote: On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M Davis wrote: On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: Hi. What function signature should I use for receiving a constant reference of an r

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M Davis wrote: On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj

Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj)? I want to: 1. Take a constant reference of the object, not copy them 2. The object itself may be const or non const.

opCast'ing strings

2017-11-12 Thread helxi via Digitalmars-d-learn
struct Fraction { private: int numerator = 1, denominator = 1; public: string opCast(T : string)() const { import std.conv : to; return numerator.to!string() ~ "/" ~ denominator.to!string(); } } void main() { import

Inclusion of Serve-d langserver.org

2017-10-07 Thread helxi via Digitalmars-d
I would like to open a pull request in https://github.com/langserver/langserver.github.io to include serve-d (https://github.com/Pure-D/serve-d). However I would like to know which of the following is provided by any of DCD and Dscanner and whether it's implemented: Formatting => dfmt

Can't get expected strings

2017-07-18 Thread helxi via Digitalmars-d-learn
import std.stdio, std.datetime, std.conv, std.algorithm; void main() { immutable DEADLINE = DateTime(2017, 7, 16, 23, 59, 59).to!SysTime; immutable NOW = Clock.currTime; immutable INTERVAL = (DEADLINE - NOW) .abs .to!string;

Current state of the Garbage Collector

2017-07-08 Thread helxi via Digitalmars-d
First off, let me admit that I am no expert on Garbage Collector Technology or Language implementation. I made this thread only to know if there is any attempt being done to improve the current GC's efficiency. As the Garbage Collection techniques are becoming more efficient, how is

Re: [BEGINNER] reccurence! and sequence!

2017-07-06 Thread helxi via Digitalmars-d-learn
On Thursday, 6 July 2017 at 00:21:44 UTC, Ali Çehreli wrote: On 07/05/2017 04:38 PM, helxi wrote: >> [...] > > Oh thank you. Just 2 follow-up questions: >> [...] > 1. In the last example of reccurence, what does n in (a,n) refer to? n is "the index of the current value". Each time the lambda

Re: [BEGINNER] reccurence! and sequence!

2017-07-05 Thread helxi via Digitalmars-d-learn
On Monday, 26 June 2017 at 10:34:22 UTC, ag0aep6g wrote: On 06/26/2017 11:51 AM, helxi wrote: [...] `a` is a tuple of the run-time arguments you pass to `sequence`. In this example, no arguments are passed (empty parens at the end of the call), so `a` is empty. [...] a[0] = 1 a[1] = 2

[BEGINNER] reccurence! and sequence!

2017-06-26 Thread helxi via Digitalmars-d-learn
Can someone give me a very watered-down explanation of what std.range's recurrence! and sequence! do? auto tri = sequence!((a,n) => n*(n+1)/2)(); /** okay, it's a triangular number array * I understand n is the index number, the nth term * However where does this 'a' go? */ auto odds =

O(1) sum

2017-06-11 Thread helxi via Digitalmars-d-learn
Is it possible to sum an array in O(1)?

Re: byLine(n)?

2017-06-11 Thread helxi via Digitalmars-d-learn
On Sunday, 11 June 2017 at 12:49:51 UTC, Cym13 wrote: print each line byLine doesn't reall all input at once. Using byline and take you are effectively reading only the right amount of lines and not reading the rest. You already have what you want, what makes you think the contrary? Oh it

Re: byLine(n)?

2017-06-11 Thread helxi via Digitalmars-d-learn
On Sunday, 11 June 2017 at 06:28:18 UTC, Stanislav Blinov wrote: On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: I was writing a program that reads and prints the first nth lines to the stdout: import std.stdio; void main(string[] args) { import std.algorithm, std.range; import

byLine(n)?

2017-06-10 Thread helxi via Digitalmars-d-learn
I was writing a program that reads and prints the first nth lines to the stdout: import std.stdio; void main(string[] args) { import std.algorithm, std.range; import std.conv; stdin.byLine.take(args[1].to!ulong).each!writeln; } As far as I understand the

Re: Input interrupt

2017-05-28 Thread helxi via Digitalmars-d-learn
On Sunday, 28 May 2017 at 22:14:46 UTC, Adam D. Ruppe wrote: On Sunday, 28 May 2017 at 22:07:12 UTC, helxi wrote: So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1 The readln docs for D say it returns null on end of file. The example given is:

Input interrupt

2017-05-28 Thread helxi via Digitalmars-d-learn
Hello, I just wrote a mock-up of Unix's $cat. However unlike the actual $cat, when input interrupt (Cntrl+D) is pressed the following program does not stop. So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1 //... if (args.length < 2) {

foreach, is and pointer

2017-03-26 Thread helxi via Digitalmars-d-learn
What's the difference between 1. string x = "abcd"; foreach(character; x) write(character); and string x = "abcd"; foreach(character; x[0..$]) write(character); 2. is and == 3. pointer and address and reference?

Re: Gnome Builder IDE

2017-03-22 Thread helxi via Digitalmars-d
On Wednesday, 4 May 2016 at 13:51:13 UTC, WebFreak001 wrote: ok I asked in the IRC right now. There is a plugins directory where it dynamically loads it from. However nobody in there actually knew how to do it with anything else than Python. Gonna try to get it to work somehow Have you made

Sorting Assosiative Arrays and Finding Largest Common Substring

2017-03-16 Thread helxi via Digitalmars-d-learn
I was looking for ways to find the largest common substring between two given substrings and have learnt 1. .length is of type ulong 2. writing string[int] will not give me a sorted array 3. ulong cannot be sorted by sorted What's the trick to sort the associative array by their keys? Code

Re: Best ways to declare associative arrays

2017-03-12 Thread helxi via Digitalmars-d-learn
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: return def; I meant return arg_array;

Best ways to declare associative arrays

2017-03-12 Thread helxi via Digitalmars-d-learn
How would an experienced programmer declare an associative array of strings that has 2 keys? My initial impression was string[string][2] my_array; which does not seem to work. Here is a snippet of the code I am working on: import std.string; import std.stdio; string[string] change(ref

Setting up Vim

2017-02-26 Thread helxi via Digitalmars-d
Any vim users here? I've been trying to set up Vim to get started with D. I was going to install Dutyl plugin but DCD is not working. Neovim's deoplete-d doesn't seem to work either. I'm not sure about how to set up importpath. Can anyone share .vimrc? Also, if anyone gave me a step by step

Re: [Beginner]Variable length arrays

2017-02-25 Thread helxi via Digitalmars-d-learn
On Saturday, 25 February 2017 at 14:34:31 UTC, rikki cattermole wrote: On 26/02/2017 3:31 AM, helxi wrote: I am trying to create an array which has a user defined size. However the following program is not compiling: import std.stdio; void main(){ write("Enter your array size: ");

[Beginner]Variable length arrays

2017-02-25 Thread helxi via Digitalmars-d-learn
I am trying to create an array which has a user defined size. However the following program is not compiling: import std.stdio; void main(){ write("Enter your array size: "); int n; readf(" %s", ); int[n] arr; //<-Error: variable input cannot be read at compile time