Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-05 Thread Mathias Lang via Digitalmars-d-learn
On Friday, 6 March 2020 at 04:56:28 UTC, Marcone wrote: Is it possible change compile time errors to runtime errors in Dlang? If yes, how can I make it? No it's not possible, D is a statically typed language. Why would you want errors that can be caught at compile time to happen at runtimes ?

DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-05 Thread Marcone via Digitalmars-d-learn
Is it possible change compile time errors to runtime errors in Dlang? If yes, how can I make it?

Re: akePureMalloc cannot be interpreted at compile time

2020-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 20:13:11 UTC, Adnan wrote: auto d = some!(some!int(9)); My guess would be this line is causing your trouble. That is trying to pass an instance as a value at compile time, thus triggering ctfe. Since you use the `Array` object inside and that uses malloc

akePureMalloc cannot be interpreted at compile time

2020-03-05 Thread Adnan via Digitalmars-d-learn
The following program produces an error message and it is not clear exactly what line causes this error: module maybe; @nogc: private import std.container : Array; struct MayBe(T) { Array!T data; this(T datum) { data.reserve(1); data.insert(datu

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: Implement this for free functions i would do something like this void dispatch(alias fn, ARGS...)(Handle handle, ARGS args) Why do you need an `alias fn` like that? My sugg

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 14:46:24 UTC, Steven Schveighoffer wrote: On 3/5/20 9:24 AM, wjoe wrote: but how can I call fn in the context of an object instance? You could do it with delegates. But it's ugly: import std.stdio; class C { void foo() { writeln("Yup");} } void main() {

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: Implement this for free functions i would do something like this void dispatch(alias fn, ARGS...)(Handle handle, ARGS args) Why do you need an `alias fn` like that? My suggestion would be to just use the `opDispatch` magic method that gi

Re: spawn a function with object as arg?

2020-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 18:10:11 UTC, Martin Brezel wrote: Unfortunately the documentation page for core.thread is currently not available. the official docs are lame, use my fork doc website instead: http://dpldocs.info/experimental-docs/core.thread.html

Re: spawn a function with object as arg?

2020-03-05 Thread Martin Brezel via Digitalmars-d-learn
On Thursday, 5 March 2020 at 03:04:10 UTC, Adam D. Ruppe wrote: You can also not use `spawn` and instead give `new Thread` a try from core.thread. Thanks for the hint, I didn't notice core.thread at all. I will definitely try it out. Unfortunately the documentation page for core.thread is curr

Re: Converting Lua source to D

2020-03-05 Thread AB via Digitalmars-d-learn
On Thursday, 5 March 2020 at 07:44:21 UTC, Jesse Phillips wrote: I am making an attempt convert Lua to D. This is less about the conversion and more about exploring the tooling to make it happen. I have chosen to do this file by file and attempting to start with linint. I wanted to make use o

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/20 9:24 AM, wjoe wrote: but how can I call fn in the context of an object instance? You could do it with delegates. But it's ugly: import std.stdio; class C { void foo() { writeln("Yup");} } void main() { alias f = C.foo; auto c = new C; void delegate() dg; dg.func

How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread wjoe via Digitalmars-d-learn
Consider a Factory that creates instances of various different resource object instances, all of which have a common interface, and returns a handle to them. class Factory { struct Handle{} Handle create(R: Resource, ARGS...)(ARGS args) { auto r = new R(args); //...

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
On Thursday, 5 March 2020 at 13:31:14 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 11:03:30 UTC, mark wrote: I want to use the Porter stemming algorithm. There's a D implementation here: https://tartarus.org/martin/PorterStemmer/d.txt I think I (or ketmar and I stole it from him) po

Re: converting to/from char[]/string

2020-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 11:03:30 UTC, mark wrote: I want to use the Porter stemming algorithm. There's a D implementation here: https://tartarus.org/martin/PorterStemmer/d.txt I think I (or ketmar and I stole it from him) ported that very same file before: https://github.com/adamdruppe

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
I suspect the problem is using .length rather than some other size property.

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
I changed int to size_t and used const(char[]) etc. as suggested. It ran but crashed. Each crash was a range violation, so for each one I put in a guard so instead of if ( ... m_b[m_k]) I used if (m_k < m_b.length && ... m_b[m_k) I did this kind of fix in three places. The result is that it

Re: converting to/from char[]/string

2020-03-05 Thread Dennis via Digitalmars-d-learn
On Thursday, 5 March 2020 at 11:31:43 UTC, mark wrote: I've now got Martin Porter's own Java version, so I'll have a go at porting that to D myself. I don't think that's necessary, the errors seem easy to fix. src/porterstemmer.d(197,13): Error: cannot implicitly convert expression s.length o

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
On Thursday, 5 March 2020 at 11:12:24 UTC, drug wrote: On 3/5/20 2:03 PM, mark wrote: [snip] Your code and errors seem to be not related. OK, it is probably that the D stemmer is 19 years old! I've now got Martin Porter's own Java version, so I'll have a go at porting that to D myself.

Re: converting to/from char[]/string

2020-03-05 Thread drug via Digitalmars-d-learn
On 3/5/20 2:03 PM, mark wrote: I want to use the Porter stemming algorithm. There's a D implementation here: https://tartarus.org/martin/PorterStemmer/d.txt The main public function's signature is: char[] stem(char[] p, int i, int j) But I work entirely in terms of strings (containing indivi

converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
I want to use the Porter stemming algorithm. There's a D implementation here: https://tartarus.org/martin/PorterStemmer/d.txt The main public function's signature is: char[] stem(char[] p, int i, int j) But I work entirely in terms of strings (containing individual words), so I want to add a

Re: What does assigning void mean?

2020-03-05 Thread mark via Digitalmars-d-learn
On Thursday, 5 March 2020 at 08:35:52 UTC, drug wrote: On 3/5/20 10:47 AM, mark wrote: In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the fi

Re: What does assigning void mean?

2020-03-05 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 5 March 2020 at 08:35:52 UTC, drug wrote: On 3/5/20 10:47 AM, mark wrote: In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the fi

Re: What does assigning void mean?

2020-03-05 Thread drug via Digitalmars-d-learn
On 3/5/20 10:47 AM, mark wrote: In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the first line; could someone explain please? In D all vars