Re: vibe.d / experience / feedback

2020-10-13 Thread Robert M . Münch via Digitalmars-d-learn
On 13 Oct 2020 at 09:57:14 CEST, "aberba"  wrote:

> D is a great language that is capable of solving any problem 
> easier than what it'll take to do in equivalent languages.

Don't get me wrong, D is great, it has a lot of technically cool things on
board.

As said, those technical things won't be our major decision aspect. The
non-technical aspects are more important when looking from a company
perspective.

> D is a language you learn once and use every.

The question is: Which language and eco-system take how much time to learn to
become productive? As team? How to handle a code-base that requires multi-year
maintenance?

> Just hope the  ecosystem gets better to meet business needs... 

Well, from a business perspective "hope" is a very bad advisor.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




Re: vibe.d / experience / feedback

2020-10-13 Thread Robert M . Münch via Digitalmars-d-learn
On 12 Oct 2020 at 21:58:12 CEST, "Ola Fosheim Grøstad"
 wrote:

> On Monday, 12 October 2020 at 11:06:55 UTC, Robert M. Münch wrote:
>>  Go seems to be kept as simple as possible, even if you have to 
>>  write more code. Which is, in the long run, the cheaper and 
>>  smaller burden. No tricks, no surprises... that has a lot of 
>>  merits.
> 
> Btw, Go has some major weaknesses related to tricks and surprises:

I don't expect Go to be perfect and as with every language you need to get a
good sense of the dark corners. At least it looks like there are not so many
of them, and as long as you are doing "normal" stuff you won't be bitten too
frequent.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




Re: vibe.d / experience / feedback

2020-10-12 Thread Robert M . Münch via Digitalmars-d-learn
On 12 Oct 2020 at 13:13:27 CEST, "Ola Fosheim Grøstad"
 wrote:

> Yes, it is a good fit for web services with medium sized code 
> bases.

We don't have a lot of "big project" experience with Go yet, but we would use
it for a plain-old desktop application.

Even most people seem to use Go for the web services stuff, I think it might
be underrate for desktop apps.

Viele Grüsse.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




Re: vibe.d / experience / feedback

2020-10-12 Thread Robert M . Münch via Digitalmars-d-learn
On 11 Oct 2020 at 21:10:20 CEST, "tastyminerals" 
wrote:

> And I feel like you guys will just pick Go because it will get 
> stuff done.

That's the main focus from a company perspective. We try to waste as less time
& money as possible.

> When I just started learning about D ecosystem, vibe frequently 
> popped up as one of the popular frameworks available for the 
> language AND also a reason for ppl to jump in and try out D. 

I love D, like it a lot, follow it for many years, use it from time to time...
but it's not about me, but a team and a product we need to develop and
maintain. There are much more non-technical aspects important then
technical...

And, deciding about your tech-stack base is a path-dependent decision. Turning
to something else, has a very high cost impact.

> However, as time goes, I also pick up many complaints about vibe, 
> its performance and ease of use compared to competitors. This 
> post just solidifies the impression. Bad documentation is the 
> worst thing that can happen to a project which gets promoted as a 
> one of the gems of the language ecosystem and actually hurts the 
> language image much more than does good. Sigh...

Well... I expect a lot of people taking a look at D do it like we do with
other solutions: I take a list of things I want to try out and start the timer
to see how long I take to get it done. This gives a good impression of the
eco-system, etc.

Taking a step back, D looks a bit scattered. A lot of stuff is there, the
standard lib is pretty good, many half-done packages, many corners to take a
look at. D is a big language, with a lot of concepts to learn and building up
experience is not fast.

> I will never advice vibe to anyone because I know that better alternatives 
> exist. People will use Go, Python, Ruby, Rust whatever has better 
> docs to get it running fast and not risk wasting time.

I'm pretty sure Vide is suitable for all kind of applications today. But you
need to have a higher "experimentation" scope in what you do. Once you build
up experience with all this stuff, I think there is no big difference to other
approaches. But the question is how long is this? 1, 2, X years?

> Sadly, this is how some languages grow and some don't. And it's 
> not all about the corporate support, hype, GC or random luck, 
> it's about cases like the above.

I think less is more, and D is pretty huge tpday. And, it's an OS project, so
people do what makes fun.

Go is mostly driving from a corporate perspective and the OS part is a side
aspect. That has some merits too.

Viele Grüsse.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




Re: vibe.d / experience / feedback

2020-10-12 Thread Robert M . Münch via Digitalmars-d-learn
On 11 Oct 2020 at 16:46:13 CEST, "Ola Fosheim Grøstad"
 wrote:

> Ada, Java, Eiffel are supposed to.

Yes... beside Java, the other two are already in the exotic department...

> I'm not sure if Go is a success in that department either. I 
> suspect it tanks when programs get large.

Go seems to be kept as simple as possible, even if you have to write more
code. Which is, in the long run, the cheaper and smaller burden. No tricks, no
surprises... that has a lot of merits.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




Re: vibe.d / experience / feedback

2020-10-11 Thread Robert M . Münch via Digitalmars-d-learn
On 6 Oct 2020 at 10:07:56 CEST, "ddcovery" 
wrote:

> I found myself in a similar situation recently, and I can't help 
> but ask you: What technology do you use regularly?

Hi, well we use a couple of different things. Scripting languages, C, Lua,
..

> What drives/draws you to try dlang/vibe.d?

A prototype we wanted to build while evaluating D as our next tech stack
foundation.

> Do you have other alternatives to dlang/vibe.d for your project?

Yes. We are currently looking into Go as well.

> In my case we usually work in Node+js/ts (previously Scala+Play) 
> and I wanted to jump to something really performant for a new 
> project without losing code expressiveness and development speed. 
> Dlang seemed a good alternative (I like it much more than Go or 
> Rust).

Well, for us it's getting more and more clear, that a decision what to use in
the future will be based on less and less technical aspects.

The interesting thing about Go is, that their main focus is thinking from an
enterprise perspective, not only from a technical one. So, their focus is
getting stuff done, keeping maintainability in big, constantly changing teams
and stripping everything away, that reduces productivity in such an
environment... I don't know about any other language which puts all these
non-technical aspects on the top of the agenda.

Viele Grüsse.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




Re: vibe.d / experience / feedback

2020-10-03 Thread Robert M . Münch via Digitalmars-d-learn
On 3 Oct 2020 at 13:14:57 CEST, "0xEAB"  wrote:

> On Saturday, 3 October 2020 at 07:54:58 UTC, Martin wrote:
>>  On Friday, 2 October 2020 at 09:46:09 UTC, Denis Feklushkin 
>>  wrote:
>>>  Because standard implementation worse?
>> 
>>  What do you mean with "worse"?
> 
> It's said to be pretty slow…

Well, then it should be fixed... it doesn't make sense to spread N version
because everyone things, A or B is not fitting for such a code framework. 

And, this argument sounds like pre-mature optimization. Who has a real life
use-case where the std lib JSON thing is too slow? By how much?

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




vibe.d / experience / feedback

2020-10-01 Thread Robert M . Münch via Digitalmars-d-learn
Hi, we are currently using vibe.d for a prototype and I want to post some
experiences. I know one shouldn't only address the problems but provide some
solutions. 

However, our current use-case is that we want to get a job done, and not
creating a web-framework. 

1. For many things the docs are missing, or inconsistent, or wrong. So, it's
pretty hard to make your way through it. Or you just start reading the code
and reverse engineer vibe. => We are waisting a lot of time.

2. There are many inconsistencies / half-done implementations in vibe. Again,
this makes it hard to find out what works, what doesn't or which parts behave
differently. => Costs a lot of time.

3. Vibe can't handle GET & POST on the same URL... and the bad thing is, the
later route will just be ignored, so you don't get any hint or crash. The docs
don't mention this clearly. => We waisted a lot of time to find out, that this
doesn't work.

4. Vide uses an own JSON type, not the standard one. We don't understand why,
this just makes things much more complicated and one has to mess around with
this.

5. One can't access the raw HTTP request body, things must be go through
Vibe's JSON parser. To get access to the raw body, a lot of workarounds are
necessary.

So, overall... compared to other web-frameworks we know, there are many
pitfalls which just cost a lot of time... We think it's a good base, but there
needs to be much less magic, much better docs, much less complexity.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster




vibe / CTRL+C not terminating server

2020-06-13 Thread Robert M. Münch via Digitalmars-d-learn

After a CTRL+C I still have the server process running on OSX. Any idea?

[main() INF] Listening for requests on http://[::1]:8080/
[main() INF] Listening for requests on http://127.0.0.1:8080/
[main() INF] Please open http://127.0.0.1:8080/ in your browser.
^C
[main() INF] Received signal 2. Shutting down.

After this, the server is still running.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Are compile time generated, stable and unique IDs possible?

2020-05-08 Thread Robert M. Münch via Digitalmars-d-learn
Let's assume I have an GUI application and I want to record some 
user-actions which can be replayed.


And this replay should be possible even if the application layout 
changes. Hence, I somehow need to identify the run-time objects in a 
way that this identification stays the same while the app is further 
developed and between user sessions.


And I don't want to manually manage all IDs (initially) but use the 
compiler for this.


Is there any way to generate such stable unique IDs at compile-time? I 
can imagine that his maybe needs to be combined with a mixin that is 
used inside a constructor to get IDs into run-time objects.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: countUntil with negated pre-defined predicate?

2020-05-04 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-05-03 21:59:54 +, Harry Gillanders said:


I'm unsure as to which part is unclear,


Well, I was trapped by this formatting/syntax:

size_t drawableCharacterCount (CodePoints) (auto ref CodePoints 
codePoints)
if (isInputRange!CodePoints && is(ElementType!CodePoints : dchar))
{

and was wondering what the first line contributes... now understanding 
that it's the function signature and the following "if" line is 
template contraint (IIRC). So it's actually:


size_t drawableCharacterCount (CodePoints) (auto ref CodePoints 
codePoints)
if (isInputRange!CodePoints && is(ElementType!CodePoints : 
dchar))
{

However, I find this sytax a bit unfortunate because I can't spot 
quickly that this "if" is a tempalte constraint... but maybe I get more 
used to it.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: countUntil with negated pre-defined predicate?

2020-05-03 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-05-02 22:33:59 +, Harry Gillanders said:

This depends on what you classify as drawable, and what you consider to 
be a character (the joys of Unicode),


Absolutely... however, trying getting close to what works in most cases.


and why you want to search for them anyway.


I'm doing some cursor-movement in a text-field. So, need to find out 
where the cursor should be positioned.


One way (I haven't verified this) could be to check if any of the 
code-points within a grapheme are graphical[1], and not white-space 
(and are not any other code-point you consider non-drawable).


Yes, that makes sense. I wasn't aware about graphical category... so 
would have used the !isWhite approach only. Thanks.



Which could look like so:

import std.algorithm;
import std.range;
import std.uni;

size_t drawableCharacterCount (CodePoints) (auto ref CodePoints 
codePoints)


What does this line do?


if (isInputRange!CodePoints && is(ElementType!CodePoints : dchar))
{
bool isDrawableCodePoint (dchar c)
{
return c.isGraphical() && !c.isWhite();
}

return codePoints.byGrapheme().count!(
g => g[].any!isDrawableCodePoint
);
}


I want to identify spans of drawable and isWhite in a grapheme array. 
So, I think any! just gives the total count of the whole thing. But 
anyway, thanks for the input, helps to better understand the whole 
thing.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Idomatic way to guarantee to run destructor?

2020-05-03 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-05-02 20:43:16 +, Steven Schveighoffer said:

destroy sets all the values to the .init value. And it nulls the vtable 
pointer.


Ok, that makes sense. Thanks for all the deep internal details. There 
is always a lot to learn.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Idomatic way to guarantee to run destructor?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-05-02 18:18:44 +, Steven Schveighoffer said:


On 5/2/20 4:44 AM, Robert M. Münch wrote:

How would that help, because the class instance is now unusable anyway. 
So I have it around like a zombie and others might think: "Hey you look 
normal, let's get in contact" and then you are doomed...


The difference is that if you use it, you get an error and a crash. If 
you clean up the memory, that memory could be reallocated to something 
else with a completely different type, and now you have memory 
corruption.


I didn't thought about the "memory is re-used" case here...

And how is the instance made unusable so that a crash happens (which I 
prefer too!)? Does .destroy zero the memory? Just curious how the crash 
situation is detected.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



countUntil with negated pre-defined predicate?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn

This works:

countUntil!(std.uni.isWhite)("hello world"))

How can I switch this to (not working);

countUntil!(!std.uni.isWhite)("hello world"))

without having to write my own predicate?

Or is there an even better way to search for all "drawable unicode characters"?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Idomatic way to guarantee to run destructor?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-30 17:45:24 +, Steven Schveighoffer said:

No, auto is declaring that there's about to be a variable here. In 
actuality, auto does nothing in the first case, it just means local 
variable. But without the type name, the type is inferred (i.e. your 
second example). This does not do any automatic destruction of your 
class, it's still left to the GC.


Ok, that was my understand too. As said, I found some older posts and 
was a bit confused...


You can use scope instead of auto, and it will then allocate the class 
on the stack, and destroy it as Ben Jones said. There is danger there, 
however, as it's very easy to store a class reference elsewhere, and 
then you have a dangling pointer.


Ok. Can't this be combined with some "don't let the refrence escape my 
function" feature of D?



A safer thing to do is:

auto X = new MyClass();
scope(exit) destroy(X);

This runs the destructor and makes the class instance unusable, but 
does not free the memory (so any remaining references, if used, will 
not corrupt memory).


How would that help, because the class instance is now unusable anyway. 
So I have it around like a zombie and others might think: "Hey you look 
normal, let's get in contact" and then you are doomed...


If your concern is guaranteeing destructors are run, that's what I 
would pick. If in addition you want guaranteed memory cleanup, then use 
scope (and be careful).


Ok, thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Re: Idomatic way to guarantee to run destructor?

2020-05-02 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-30 17:04:43 +, Ben Jones said:

I think you want to use scope rather than auto which will put the class 
on the stack and call its destructor: 
https://dlang.org/spec/attribute.html#scope


Yes, thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Idomatic way to guarantee to run destructor?

2020-04-30 Thread Robert M. Münch via Digitalmars-d-learn
For ressource management I mostly use this pattern, to ensure the 
destructor is run:


void myfunc(){
 MyClass X = new MyClass(); scope(exit) X.destroy;
}

I somewhere read, this would work too:

void myfunc(){
 auto MyClass X = new MyClass();
}

What does this "auto" does here? Wouldn't

void myfunc(){
 auto X = new MyClass();
}

be sufficient? And would this construct guarantee that the destructor 
is run? And if, why does "auto" has this effect, while just using "new" 
doesn't guarantee to run the destructor?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Wich: opIndex overloading by return type

2020-04-19 Thread Robert M. Münch via Digitalmars-d-learn
Wouldn't it make a lot of sense to allow different opIndex 
implementations based on return type?


class myC {
myT1 opIndex(int x)
myT2 opIndex(int x)
}

Depending on the types involved myC[1] woudl return myT1 or myT2. 
Use-case: I have a geomentry object and in one case I get x0,y0,x1,y1 
and in the other case x,y,w,h


IMO that would make a lot of sense.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: __init unresolved external when using C library structs converted with dstep

2020-04-17 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-17 09:06:44 +, Dominikus Dittes Scherkl said:


On Friday, 17 April 2020 at 08:59:41 UTC, Robert M. Münch wrote:

How would that look like?

myStruct ms = void; // ???


Exactly.


Cool... never saw this / thought about it... will remember it, hopefully.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: __init unresolved external when using C library structs converted with dstep

2020-04-17 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-16 18:33:51 +, Basile B. said:


On Tuesday, 14 April 2020 at 17:51:58 UTC, Robert M. Münch wrote:
I use a C libary and created D imports with dstep. It translates the C 
structs to D structs.


When I now use them, everything compiles fine but I get an unresolved 
external error:


WindowsApp1.obj : error LNK2019: unresolved external symbol 
"myCstruct.__init" (_D7myCStruct6__initZ) referenced in function _Dmain


Any idea what this is about and how to fix it? I'm wondering why D 
tries to find the __init function in the C library and not compile it 
from the import.


One way to prevent the problem is to do void initialization each time 
you declare a variable of this type.


How would that look like?

myStruct ms = void; // ???

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: __init unresolved external when using C library structs converted with dstep

2020-04-16 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-15 15:18:43 +, Steven Schveighoffer said:

The difference is you are telling the compiler that it should generate 
any symbols for those types. If you just import them, then it's 
expecting something else to build those symbols.


Maybe I'm a bit confused, but that's quite different to a C compiler, 
right? If I include header and have a .lib things fit.


With D I have a .lib, I have the imports and still need the imports 
somehow compiled (included in project, or as a 2nd .lib) to make 
everything work. Do I understand that correct?


You could also build a library that builds those symbols, and link in 
that library instead.


That would be the 2nd .lib approach than. 



What's strange is, that for a dub project that uses the same imports, I 
didn't had to add them to the dub.json file. There, it just works 
without any problems.


dub builds all dependencies so this is like the library solution.


But I didn't include the library as a dub dependency. I just have the 
C/C++ compiled lib file and the D imports path for this lib.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Re: __init unresolved external when using C library structs converted with dstep

2020-04-15 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-14 18:44:55 +, Steven Schveighoffer said:


On 4/14/20 2:29 PM, Robert M. Münch wrote:

Ah, ok. That's why the problem went (temporarly) away when I did a: 
myCstruct a = {0,0}; for example?


I don't know what causes it to be emitted when. Sometimes it doesn't 
make a whole lot of sense to me.


Hu... I wouldn't expect this to behave arbitrary...


Yes, everything is "extern(C) :" for the complete import files.


Then apparently the compiler still expects to have initializers even 
for foreign language structs.


Which surprised me, or more precise, I don't understand why these are 
not done implicitly using the D basic-type initializers.


 This is not a huge issue though, as the structs are ABI compatible 
even if compiled in D.


Yes, fortunately.


Are you compiling the D file that contains the struct definition as well?


No. Is that the missing part?



Probably. I think the compiler expects whatever is compiling the 
imported file to provide the symbol. If you aren't compiling it 
separately, then you need to include it in the compilation.


The C lib contains the smybols and I thought that the compiler just 
needs the imports to get an idea about the structures, types, etc. and 
later on the links resolves everything.


But, it works when I explicitly add the import source files to the 
VisualD project. Not sure what difference this makes, because the 
source can be compiled without any problems with/without those files 
added. But it seems that the linker now sees different things.


What's strange is, that for a dub project that uses the same imports, I 
didn't had to add them to the dub.json file. There, it just works 
without any problems.


All a bit strange and confusing...

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: __init unresolved external when using C library structs converted with dstep

2020-04-14 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-14 18:23:05 +, Steven Schveighoffer said:


On 4/14/20 1:51 PM, Robert M. Münch wrote:
I use a C libary and created D imports with dstep. It translates the C 
structs to D structs.


When I now use them, everything compiles fine but I get an unresolved 
external error:


WindowsApp1.obj : error LNK2019: unresolved external symbol 
"myCstruct.__init" (_D7myCStruct6__initZ) referenced in function _Dmain


Any idea what this is about and how to fix it? I'm wondering why D 
tries to find the __init function in the C library and not compile it 
from the import.




__init is not a function, it's a static member variable. It's the 
`intializer` property inside TypeInfo used for initialization.


Ah, ok. That's why the problem went (temporarly) away when I did a: 
myCstruct a = {0,0}; for example?



Did you extern(C) the struct?


Yes, everything is "extern(C) :" for the complete import files.


Are you compiling the D file that contains the struct definition as well?


No. Is that the missing part?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



__init unresolved external when using C library structs converted with dstep

2020-04-14 Thread Robert M. Münch via Digitalmars-d-learn
I use a C libary and created D imports with dstep. It translates the C 
structs to D structs.


When I now use them, everything compiles fine but I get an unresolved 
external error:


WindowsApp1.obj : error LNK2019: unresolved external symbol 
"myCstruct.__init" (_D7myCStruct6__initZ) referenced in function _Dmain


Any idea what this is about and how to fix it? I'm wondering why D 
tries to find the __init function in the C library and not compile it 
from the import.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said:


struct S {
 float a;
 float b;

 S opOpAssign(string op)(ref S rhs) if (op == "+"){
 this.a += rhs.a;
 this.b += rhs.b;
 return this;
 }
}


If the struct is from some 3rd party source, how can I add such an 
operator overloading to it? Is it possible to "extend" a struct later?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said:

Probably I didn't understand what you mean. Sorry if this is not the 
case, but this one is easy.

...
struct S {
 float a;
 float b;

 S opOpAssign(string op)(ref S rhs) if (op == "+"){
 this.a += rhs.a;
 this.b += rhs.b;
 return this;
 }
}


void main()
{
 S a = {1, 5};
 S b = {2, 5};

 a += b;

 writeln(a);
}
...


Yes, sure, but in C++ I don't have to explicitly write this down. It 
just works. IMO that makes a lot of sense as long as all types fit. 
This just looks superfluously.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn

D doesn't have implicit operators for structs?

struct S {float a, float b};
S a = {1, 5};
S b = {2, 5);

a += b;
Error: a is not a scalar, it is a S

So I really have to write an overloaded operator for such cases?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Dynamically init a struct with values calculated from other values in the struct?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
I need to dynamically initialize a fixed number of entries of the form: 
(start, length) and iterate over them.


Hence, I think a struct makes sense:

struct S {
  s1, l1
, s2, l2
, s3, l3
}

Now I need to initialize the values like this:

S myS = {s1:0, l1:10, s2:(2*s1), ...};

So I somehow would like to reference the prior values to initialize the 
other members. I haven't found a way to do it. Is this possible at all? 
Or do I just init the struct empty and then set the entries?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: static foreach / How to construct concatenated string?

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-03-07 16:41:47 +, MoonlightSentinel said:


You can use an anonymous lambda to build the string in CTFE:

--

struct S {
 int a;
 bool b;
}

import std;

enum string sql = {
 string s = "CREATE TABLE data(";

 static foreach(f; FieldNameTuple!S) {
s ~= f ~ ",";
 }

s ~= ");";
 return s;
} ();

pragma(msg, sql);

--

This prints "CREATE TABLE data(a, b);"


You can get rid of the enum und the static and it will work too.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-03-07 12:10:27 +, Jonathan M Davis said:


I take it that you're asking why you don't get the time zone as part of the
string when you call one of the to*String functions?


The problem is, the from* functions give an error, that this is not an 
ISO date.


I get this in an XML response and extract the datetime:




But I have to do:

DateTime dt = 
DateTime.fromISOExtString(split("2018-11-06T16:52:03+01:00", 
regex("\\+"))[0]);


IMO such a string should be feedable directly to the function.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: static foreach / How to construct concatenated string?

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-03-07 16:41:47 +, MoonlightSentinel said:


On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote:

Is this possible at all?


You can use an anonymous lambda to build the string in CTFE:

--

struct S {
 int a;
 bool b;
}

import std;

enum string sql = {
 string s = "CREATE TABLE data(";

 static foreach(f; FieldNameTuple!S) {
s ~= f ~ ",";
 }

s ~= ");";
 return s;
} ();

pragma(msg, sql);

--

This prints "CREATE TABLE data(a, b);"


Nice... is the enum a so called "manifest constant" for which the 
initializer is evaluated at compile time?


OT: The pragma seems to print the string twice... at least here on my side.

OT2: Looks like I have to read through the language spec again... and 
most likely over and over again, to have all these tricks at my 
finger-tips.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-03-07 16:40:15 +, Adam D. Ruppe said:


Use regular foreach with a regular string. Put that inside a function.

Then simply use that function to initialize your other thing and enjoy 
the magic of CTFE!


Perfect! This implicit CTFE is a tricky thing to see/remember/... 
Feeling a bit dumb but, hey it works :-)


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
I want to create a "CREATE TABLE data (...)" where the columns are 
derived from struct member names. Something like:


string s = "CREATE TABLE data(";

static foreach(f; FieldNameTuple!myStruct) {
 s ~= f ~ ",";
}

s ~= ");";

Which of course doesn't work... I didn't find any reference how to 
build-up strings in a statif foreach loop.


Is this possible at all?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
It looks like std.datetime is not anticipating the +1:00 part of a date 
like: "2018-11-06T16:52:03+01:00"


Those dates are used all over on the internet and I'mm wondering why 
it's not supported. Any reason? Is this +01:00 not ISO conforming?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Dynamic array of Cycle buffers of size 2 which use a struct?

2020-02-22 Thread Robert M. Münch via Digitalmars-d-learn
I don't get how I can create a dynamic array of Cycle buffers of size 2 
which use a struct.


 struct ms {
   int a;
   int b;
 }
 ms[2] msBuffer;
 alias circularStructBuffersT = typeof(cycle(msBuffer));
 circularStructBuffersT[int] circularStructBuffers;

 int i = 2;
 auto x = circularStructBuffers.require(i, (){
   ms[2] t;
   return cycle(t,2);
 });

This give an error:

Error: template object.require cannot deduce function from argument 
types !()(Cycle!(ms[2])[int], int, Cycle!(ms[2]) function() pure 
nothrow @nogc @system), candidates are:
/Library/D/dmd/src/druntime/import/object.d(3225):require(K, 
V)(ref V[K] aa, K key, lazy V value = V.init)


Not sure if the `m[2] t` survives the scope exit in form of a closure 
(?) or if cycle takes a reference to it...


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



dub / use git branch

2020-02-16 Thread Robert M. Münch via Digitalmars-d-learn
I want to use a specific branch version if a package. I specified the 
branch version in a dub.selections.json file.


But it seems that dub requires a ZIP file that can be downloaded from 
code.dlang.org, which of course fails because the branch is only 
available on github.


Fetching rtree ~fix-#3 (getting selected version)...
Downloading https://code.dlang.org/packages/rtree/~fix-#3.zip failed 
with 404 (Not Found).


How am I supposed to switch to a branch version of a package to try a 
bug-fix version for example?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



How to explicitly state the expression in with(...)?

2020-02-01 Thread Robert M. Münch via Digitalmars-d-learn

I have quite often this pattern:

with(x.y.z){
xyzFunc();  // = x.y.z.xyzFunc()
myFunc(x.y.z, ...);
}

and it would be cool to write:

with(t = x.y.z){ // work like an implicit alias
xyzFunc();  // = x.y.z.xyzFunc()
myFunc(t, ...);
}

Is there anything which comes near this idea?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



How to use -profile when I initialize D-runtime myself?

2020-01-15 Thread Robert M. Münch via Digitalmars-d-learn

Hi, I had a related question in the "Does -profile need the D runtime?" thread.

Since D runtime is required for profile to work, the question is how 
can I use profile when initializing it myself?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: What is the difference between a[x][y] and a[x,y]?

2020-01-08 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-01-07 19:06:09 +, H. S. Teoh said:


It's up to you how to implement all of this, of course. The language
itself doesn't ship a built-in type that implements this, but it does
provide the scaffolding for you to build a custom multi-dimensional
array type.


Hi, thanks for your extensive answer! Helped a lot...

And the above paraghraph brings it to the core.

How can this be added to the D docs? I think adding such clear "this is 
the idea how you should use it" intros would help a lot to see the 
world from a d-ish perspective.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: What is the difference between a[x][y] and a[x,y]?

2020-01-07 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-01-07 17:42:48 +, Adam D. Ruppe said:


So [x][y] indexes an array of arrays.


Yes, that's what I understand. And both can be dynamic, so that I can 
have a "flattering" layout where not all arrays have the same length.



 [x,y] indexes a single array that has two dimensions.


Does this fix the dimension sizes? So I can't add a "row" or "column" 
at runtime?


What are the difference use-cases for these two? For example, I'm doing 
a grid widget but want to add/remove rows/columns. Can this only be 
done with a array-of-array? Is the memory continuous in the [x,y] case, 
whereas in the [x][y] this is not necessarily the case?



This can be kinda confusing because we often think of

int[4][4]

as being a 2d array, but the D language actually technically sees that 
as an array of arrays. So it is indexed with [x][y].


Yes, it's confusing as I don't understand the [x,y] case :-)

There is no built in multi-dimensional array, it is only syntax 
provided for library types to implement with the opIndexAssign 
overloads.


I don't get that sentence. Above you write "a single array that has two 
dimensions" which IMO is exactly a multi-dimensional array.


So the operator there like += or -= or *= etc become opAssign, whereas 
plain = is just plain Assign.


Got it. Thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

What is the difference between a[x][y] and a[x,y]?

2020-01-07 Thread Robert M. Münch via Digitalmars-d-learn
I read all the docs but I'm not toally sure. Is it that [x][y] is a 2D 
array-index, where as [x,y] is a slice?


But the example in docs for opIndexAssign uses the [x,y] syntax, which 
is confusing:


```
struct A
{
   int opIndexAssign(int value, size_t i1, size_t i2);
}

void test()
{
   A a;
   a[i,3] = 7;  // same as a.opIndexAssign(7,i,3);
}
```

And what is the difference between opIndexAssign and opIndexOpAssign?

Background: I have a class with a 2D array of some other class objects 
as memember and want to be able to use it as LHS and RHS.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: What type does byGrapheme() return?

2020-01-06 Thread Robert M. Münch via Digitalmars-d-learn

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 makes it hard to work with in complex
code. I'm not sure if this is possible, but IMO we should at least
investigate the possibilities.


Done... my first bug report :-) I copied togehter all the findings from 
this thread.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



decodeGrapheme & static array

2020-01-04 Thread Robert M. Münch via Digitalmars-d-learn

I have:

Grapheme[] gr;
dchar[1] buf;
encode(buf, cast(dchar)myData);
gr =~ decodeGrapheme(buf[]);

Which gives:

Error: template std.uni.decodeGrapheme cannot deduce function from 
argument types !()(dchar[]), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\uni.d(7164,10):
decodeGrapheme(Input)(ref Input inp)


I some how need an InputRange for buf and though that buf[] should 
work. But it doesn't seem to be an L-value... which I don't understand. 
I thought buf[] returns a temporary dynamic array initialized with the 
buf content.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: What type does byGrapheme() return?

2020-01-04 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-31 21:36:56 +, Steven Schveighoffer said:

The fact that a Grapheme's return requires you keep the grapheme in 
scope for operations seems completely incorrect and dangerous IMO (note 
that operators are going to always have a ref this, even when called on 
an rvalue). So even though using ref works, I think the underlying 
issue here really is the lifetime problem.


Thanks for all the answers, pretty enlighting even I'm not sure I get 
everything 100%.


So, what to do for now? File a bug-report? What needs to be fixed?

I'm using the ref approach for now, in hope it will be OK for my 
use-case, which is converting a wstring to a grapheme[], alter the 
array, and map it back to a wstring. Sounds like a lot of porcessing 
for handling unicode text, but I don't think it gets a lot simpler than 
that.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: What type does byGrapheme() return?

2019-12-29 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-27 19:44:59 +, H. S. Teoh said:


Since graphemes are variable-length in terms of code points, you can't
exactly *edit* a range of graphemes -- you can't replace a 1-codepoint
grapheme with a 6-codepoint grapheme, for example, since there's no
space in the underlying string to store that.


Hi, my idea was that when I use a grapheme range, it will abstract away 
that graphemes consist of different sized code-points. And the docs at 
https://dlang.org/phobos/std_uni.html#byGrapheme show an example using 
this kind of range:


auto gText = text.byGrapheme;

gText.take(3);
gText.drop(3);

But maybe I need to get a better understanding of the ranges stuff too...


If you want to add/delete/change graphemes, what you *really* want is to
use an array of Graphemes:

Grapheme[] editableGraphs;

You can then splice it, insert stuff, delete stuff, whatever.

When you're done with it, convert it back to string with something like
this:

string result = editableGraphs.map!(g => g[]).joiner.to!string;


I played around with this approach...

string r1 = "Robert M. Münch";
// Code-Units  = 16
// Code-Points = 15
// Graphemes   = 15

Grapheme[] gr1 = r1.byGrapheme.array;
writeln(" Text = ", gr1.map!(g => g[]).joiner.to!string);
//  Text = obert M. Münch
writeln("wText = ", gr1.map!(g => g[]).joiner.to!wstring);
//  wText = obert M. Münch
writeln("dText = ", gr1.map!(g => g[]).joiner.to!dstring);
//  dText = obert M. Münch

Why is the first letter missing? Is this a bug?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: What type does byGrapheme() return?

2019-12-29 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-27 17:54:28 +, Steven Schveighoffer said:

This is the rub with ranges. You need to use typeof. There's no other 
way to do it, because the type returned by byGrapheme depends on the 
type of Range.


Hi, ok, thanks a lot and IMO these are the fundamental important 
information for people using D (beginners, causual programmers, etc.) 
to understand how things fit together.



If you know what type Range is, it would be:

struct S
{
typeof(string.init.byGrapheme()) gText;
// or
alias GRange = typeof(string.init.byGrapheme());
GRange gText;
}


Ah... I didn't know that I can use a basic type "string" combined with 
".init" to manually build the type. Neat...


Subbing in whatever your real range for `string`. Or if it's the result 
of a bunch of adapters, use the whole call chain with typeof.


Ok, and these are good candidates for alias definitions to avoid 
re-typing it many times.


Why not just declare the real range type? Because it's going to be 
ugly, especially if your underlying range is the result of other range 
algorithms. And really, typeof is going to be the better mechanism, 
even if it's not the best looking thing.


I think I got it... thanks a lot.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



What type does byGrapheme() return?

2019-12-27 Thread Robert M. Münch via Digitalmars-d-learn

I love these documentation lines in the D docs:

auto byGrapheme(Range)(Range range)

How should I know what auto is? Why not write the explicit type so that 
I know what to expect? When declaring a variable as class/struct member 
I can't use auto but need the explicit type...


I used typeof() but that doesn't help a lot:

gText = [Grapheme(53, 0, 0, 72057594037927936, [83, , 1)]Result!string

I want to iterate a string byGrapheme so that I can add, delete, change 
graphemes.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: D-ish way to work with strings?

2019-12-27 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-23 15:05:20 +, H. S. Teoh said:

On Sun, Dec 22, 2019 at 06:27:03PM +0100, Robert M. Münch via 
Digitalmars-d-learn wrote:

Want to add I'm talking about unicode strings.

Wouldn't it make sense to handle everything as UTF-32 so that
iteration is simple because code-point = code-unit?

And later on, convert to UTF-16 or UTF-8 on demand?

[...]

Be careful that code point != "character" the way most people understand
the word "character".


I know. My point was that with UTF-8 code-points (not being a 
character) have different sizes. Which you need to take into account if 
you want to iterate by code-points.


The word you're looking for is "grapheme". Which, unfortunately, is 
rather complex and very slow to handle in

Unicode. See std.uni.byGrapheme.


Yes, that's when we come to "characters". And a "grapheme" can consists 
of several code-points. Is grapheme handling just slow in D or in 
general? If it's the latter, well, than that's just how it is.



Usually you want to just stick with UTF-8 (usually) or UTF-16 (for
Windows and Java interop). UTF-32 wastes a lot of space, and *still*
doesn't give you what you think you want, and Grapheme[] is just dog
slow because of the amount of decoding/recoding needed to manipulate it.


I need to handle graphemes when things are goind to be rendered and edited.


What are you planning to do with your strings?


Pretty simple: Have user editable content that is rendered using 
different fonts supporting unicode.


So, all editing functions: insert, replace, delete at all locations in 
the string supporting all unicode characters.


Viele Grüsse.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: D-ish way to work with strings?

2019-12-27 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-22 18:45:52 +, Steven Schveighoffer said:

switch to using char[]. Unfortunately, there's a lot of code out there 
that accepts string instead of const(char)[], which is more usable. I 
think many people don't realize the purpose of the string type. It's 
meant to be something that is heap-allocated (or as a global), and 
NEVER goes out of scope.


Hi Steve, thanks for the feedback. Makes sense to me.

It really depends on your use cases. strings are great precisely 
because they don't change. slicing makes huge sense there.


My "strings" change a lot, so not really a good fit to use string.

Again, use char[] if you are going to be rearranging strings. And you 
have to take care not to cheat and cast to string. Always use idup if 
you need one.


Will do.

If you find Phobos functions that unnecessarily take string instead of 
const(char)[] please post to bugzilla.


Ok, will keep an eye on it.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: D-ish way to work with strings?

2019-12-22 Thread Robert M. Münch via Digitalmars-d-learn

Want to add I'm talking about unicode strings.

Wouldn't it make sense to handle everything as UTF-32 so that iteration 
is simple because code-point = code-unit?


And later on, convert to UTF-16 or UTF-8 on demand?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



D-ish way to work with strings?

2019-12-22 Thread Robert M. Münch via Digitalmars-d-learn
I want to do all the basics mutating things with strings: append, 
insert, replace


What is the D-ish way to do that since string is aliased to immutable(char)[]?

Using arrays, using ~ operator, always copying, changing, combining my 
strings into a new one? Does it make sense to think about reducing GC 
pressure?


I'm a bit lost in the possibilities and don't find any "that's the way 
to do it".


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Strange casting error when using lamdas

2019-12-05 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-04 19:23:07 +, Steven Schveighoffer said:

Is one a delegate and one a function pointer? This can easily happen 
for untyped lambdas.


Not sure if the code-snippets already give an explanation but the 
differences I have are:


1. Working case

template filter(alias pred)
{
auto filter(TObservable)(auto ref TObservable observable)
{
static struct FilterObservable
{
...
}

return FilterObservable(observable);
}
}

2. Non-Working case

template filter(alias pred)
{
   auto filter(TObservable)(auto ref TObservable observable)
   {
   return FilterObservable!(pred, TObservable)(observable);
   }
}

struct FilterObservable(alias pred, TObservable)
{
...
}

The constructor has the same implementaion in both cases.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Strange casting error when using lamdas

2019-12-05 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-04 19:23:07 +, Steven Schveighoffer said:

Is one a delegate and one a function pointer? This can easily happen 
for untyped lambdas.


That's a very good point and hint. A function pointer will be 8LU and a 
delegate 16LU, right? This is a strong argument that this is really the 
problem.


How can I find out? That's why I used a pragma to get the type of the 
alias. So, the alias needs to become a delegate. No clue how to write 
this down.



--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Strange casting error when using lamdas

2019-12-04 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-03 16:34:43 +, Robert M. Münch said:


I have very strange casting error I don't understand:

alias typeof(windows_message_streams[WM_MOUSEMOVE].filter!(win => 
(win.wParam & MK_LBUTTON))) WM_MOUSEMOVE_LBUTTON_TYPE;

WM_MOUSEMOVE_LBUTTON_TYPE WM_MOUSEMOVE_LBUTTON_STREAM;
pragma(msg,typeof(WM_MOUSEMOVE_LBUTTON_STREAM));


FilterObservable!(__lambda39, SubjectObject!(OS_State))


WM_MOUSEMOVE_LBUTTON_STREAM = 
cast(WM_MOUSEMOVE_LBUTTON_TYPE)(windows_message_streams[WM_MOUSEMOVE].filter!(win 
=> (win.wParam & MK_LBUTTON)));
pragma(msg,typeof(wstreams[WM_MOUSEMOVE].filter!(win => (win.wParam & 
MK_LBUTTON;



FilterObservable!(__lambda7, SubjectObject!(OS_State))


..\..\gui.d(317,104): Error: cannot cast expression 
filter(windows_message_streams[512u]) of type 
FilterObservable!(__lambda6, SubjectObject!(OS_State)) to 
FilterObservable!(__lambda39, SubjectObject!(OS_State)) because of 
different sizes

FilterObservable!(__lambda7, SubjectObject!(OS_State))

My code worked in the past but now it doesn't and I don't know why. I 
don't understand the "because of different sizes" message.


It looks like I have to explicitly create a lambda and re-use it. But 
how to do that?


So, it all boils down to a breaking change in the RX framework... which 
I still don't understand...


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Strange casting error when using lamdas

2019-12-03 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-12-03 16:34:43 +, Robert M. Münch said:


I have very strange casting error I don't understand:

alias typeof(windows_message_streams[WM_MOUSEMOVE].filter!(win => 
(win.wParam & MK_LBUTTON))) WM_MOUSEMOVE_LBUTTON_TYPE;

WM_MOUSEMOVE_LBUTTON_TYPE WM_MOUSEMOVE_LBUTTON_STREAM;
pragma(msg,typeof(WM_MOUSEMOVE_LBUTTON_STREAM));


FilterObservable!(__lambda39, SubjectObject!(OS_State))


WM_MOUSEMOVE_LBUTTON_STREAM = 
cast(WM_MOUSEMOVE_LBUTTON_TYPE)(windows_message_streams[WM_MOUSEMOVE].filter!(win 
=> (win.wParam & MK_LBUTTON)));
pragma(msg,typeof(wstreams[WM_MOUSEMOVE].filter!(win => (win.wParam & 
MK_LBUTTON;



FilterObservable!(__lambda7, SubjectObject!(OS_State))


..\..\gui.d(317,104): Error: cannot cast expression 
filter(windows_message_streams[512u]) of type 
FilterObservable!(__lambda6, SubjectObject!(OS_State)) to 
FilterObservable!(__lambda39, SubjectObject!(OS_State)) because of 
different sizes

FilterObservable!(__lambda7, SubjectObject!(OS_State))

My code worked in the past but now it doesn't and I don't know why. I 
don't understand the "because of different sizes" message.


It looks like I have to explicitly create a lambda and re-use it. But 
how to do that?


The first three lines are on module level, the second two lines are 
inside a class member function.


pragma(msg,WM_MOUSEMOVE_LBUTTON_STREAM.sizeof);


8LU


but

pragma(msg,windows_message_streams[WM_MOUSEMOVE].filter!(win => 
(win.wParam & MK_LBUTTON)).sizeof);



16LU


Why do these two things have different sizes even the declaration is 
exactly the same?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Strange casting error when using lamdas

2019-12-03 Thread Robert M. Münch via Digitalmars-d-learn

I have very strange casting error I don't understand:

alias typeof(windows_message_streams[WM_MOUSEMOVE].filter!(win => 
(win.wParam & MK_LBUTTON))) WM_MOUSEMOVE_LBUTTON_TYPE;

WM_MOUSEMOVE_LBUTTON_TYPE WM_MOUSEMOVE_LBUTTON_STREAM;
pragma(msg,typeof(WM_MOUSEMOVE_LBUTTON_STREAM));


FilterObservable!(__lambda39, SubjectObject!(OS_State))


WM_MOUSEMOVE_LBUTTON_STREAM = 
cast(WM_MOUSEMOVE_LBUTTON_TYPE)(windows_message_streams[WM_MOUSEMOVE].filter!(win 
=> (win.wParam & MK_LBUTTON)));
pragma(msg,typeof(wstreams[WM_MOUSEMOVE].filter!(win => (win.wParam & 
MK_LBUTTON;



FilterObservable!(__lambda7, SubjectObject!(OS_State))


..\..\gui.d(317,104): Error: cannot cast expression 
filter(windows_message_streams[512u]) of type 
FilterObservable!(__lambda6, SubjectObject!(OS_State)) to 
FilterObservable!(__lambda39, SubjectObject!(OS_State)) because of 
different sizes

FilterObservable!(__lambda7, SubjectObject!(OS_State))

My code worked in the past but now it doesn't and I don't know why. I 
don't understand the "because of different sizes" message.


It looks like I have to explicitly create a lambda and re-use it. But 
how to do that?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Template mixin / unresolved external / scope problem?

2019-11-29 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-11-28 16:36:36 +, Jacob Carlborg said:

Are you using the latest version, 2.089.0? It might be fixed in that 
version [1].


[1] https://dlang.org/changelog/2.089.0.html#mixin_template_mangling


Ha! Thanks Jacob, that looks like the root-cause. Didn't expect to use 
a feature which was just fixe in the newest compiler release...


Using it now, but 2.089 broke some code using CAS... need to take a 
look into it first before I can tell if it works with the template 
mixin.


Thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Template mixin / unresolved external / scope problem?

2019-11-28 Thread Robert M. Münch via Digitalmars-d-learn

I have:

a.d:
extern (C) void myFuncA();

void myFuncB() {
myFuncA();
}

b.d:
public import a;

mixin template MYFUNCA() {
extern (C) void myFuncA() {...}
}

c.d:
import b;

mixin MYFUNCA;
...further code...


Compiling such a structure gives me an unresolved external in a.d/myFuncB

I assume this is because the mixin get's it's own scope. Is this 
correct? How can I solve such a setup?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: static assert(version(x)) ?

2019-11-28 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-11-27 18:50:07 +, Johan Engelen said:


On Tuesday, 26 November 2019 at 12:53:02 UTC, Jonathan M Davis wrote:

On Tuesday, November 26, 2019 4:29:18 AM MST S.G via Digitalmars-d-learn wrote:

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 accessbile from assert (different,
non-accessible namespace).


BTW D language designers are against boolean eval of version. It's not 
a technical restriction, it's just that they don't want this to work.


...
static if can be used instead of version blocks to get boolean 
conditions, and local version identifiers can be defined which combine 
some set of version identifiers, but such practices are discouraged for 
D programmers in general, and they're basically forbidden in official 
source code. The only case I'm aware of where anything like that is 
used in druntime or Phobos is for darwin stuff, since darwin isn't a 
predefined identifier.


`xversion` is a simple and effective and useful tool, used in dmd source:


That's pretty neat... going to try this.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



static assert(version(x)) ?

2019-11-26 Thread Robert M. Münch via Digitalmars-d-learn
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 accessbile from assert (different, non-accessible namespace).


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: std.json / nested key/value access?

2019-11-15 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-11-15 17:23:38 +, Steven Schveighoffer said:


On 11/15/19 12:05 PM, Robert M. Münch wrote:

JSONValue j = parseJSON(json_string).object;

 writeln(j); // works
 writeln(j["a"]); // works
 writeln(j["a"].object["b"]); // bombs


Maybe your "a" value is not an object?


Thanks, it's an array... why ever... I need to use:

writeln(j["a"][0]["b"]);

Wasn't that obvious, because it's a big JSON structure.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



std.json / nested key/value access?

2019-11-15 Thread Robert M. Münch via Digitalmars-d-learn

I have:

 JSONValue j = parseJSON(json_string).object;

 writeln(j);// works
 writeln(j["a"]); // works
 writeln(j["a"].object["b"]);   // bombs

Runtime error: std.json.JSONException@std/json.d(276): JSONValue is not 
an object


How can I access a nested JSON key/value using something that comes 
close to a path notation?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: csvReader & specifying separator problems...

2019-11-14 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-11-14 13:08:10 +, Mike Parker said:

Contents, ErrorLevel, Range, and Separator are template (i.e. 
compile-time) parameters. Input, delimiter, and quote are function 
(i.e. runtime) parameters.


Mike, thanks a lot... I feel like an idiot. As casual D programmer the 
template-syntax is not so easy to get used too because it's not so 
distinguishable.


However, your explanation helps a lot to make things much more clear now.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



csvReader & specifying separator problems...

2019-11-14 Thread Robert M. Münch via Digitalmars-d-learn
Just trying a very simple thing and it's pretty hard: "Read a CSV file 
(raw_data) that has a ; separator so that I can iterate over the lines 
and access the fields."


csv_data = raw_data.byLine.joiner("\n")


From the docs, which I find extremly hard to understand:


auto csvReader(Contents = string, Malformed ErrorLevel = 
Malformed.throwException, Range, Separator = char)(Range input, 
Separator delimiter = ',', Separator quote = '"')


So, let's see if I can decyphre this, step-by-step by trying out:

csv_records = csv_data.csvReader();

Would split the CSV data into iterable CSV records using ',' char as 
separator using UFCS syntax. When running this I get:


	std.csv.CSVException@/Library/D/dmd/src/phobos/std/csv.d(1283): Row 
1's length 0 does not match previous length of 1.


Which indicates some problem because not all fields are set in my CSV 
data. So let's ignore any error by specifying Malformed.ignore;


csv_records = csv_data.csvReader(Malformed.ignore);

And now I'm lost (just showing the first candidate):

Error: template std.csv.csvReader cannot deduce function from argument 
types !()(Result, Malformed), candidates are:
/Library/D/dmd/src/phobos/std/csv.d(327):csvReader(Contents = 
string, Malformed ErrorLevel = Malformed.throwException, Range, 
Separator = char)(Range input, Separator delimiter = ',', Separator 
quote = '"')

 with Contents = string,
  ErrorLevel = cast(Malformed)1,
  Range = Result,
  Separator = Malformed
 whose parameters have the following constraints:
 
   isInputRange!Range
   is(Unqual!(ElementType!Range) == dchar)
 > isSomeChar!Separator
 - !is(Contents T : T[U], U : string)
 

The docs state Malformed as 2nd parameter, since I use UFCS I assume 
that this becomes the first parameter. I don't understand what the 3rd 
parameter (Range) is about. 4th parameter is my separator, which I need 
to set to ';' somehow.


But from the error message, it looks like DMD tries to use 
Malformed.ignore as the 4th (!!) Parameter being the Separator.


I'm totally confused:

* What is used as the 3rd parameter by DMD? Where does it come from?
* How to specify a ';' separator?

This is all pretty confusing...

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Read Once then reset/init value?

2019-11-03 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-29 23:28:35 +, Simen Kjærås said:


On Tuesday, 29 October 2019 at 22:24:20 UTC, Robert M. Münch wrote:
I quite often have the pattern where a value should be read just once 
and after this reset itself. The idea is to avoid that others read the 
value by accident and get an older state, instead they get an 
"invalid/reset" value.


Is there a library function that can mimic such a behaviour?


Something like this?

T readOnce(T)(ref T value) {
 auto tmp = value;
 value = T.init;
 return tmp;
} unittest {
 int i = 3;
 assert(i.readOnce == 3);
 assert(i == 0);
}

If so, no, there is no library function for it, but feel free to use 
the above. You may very well have to change T.init to something more 
fitting for your use case, of course.


Hi, that looks very good. I forgot about the UFCS possibility. That's 
very good because it works on basic types too. Thanks :-)


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Accuracy of floating point calculations

2019-10-31 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-31 16:07:07 +, H. S. Teoh said:


Maybe you might be interested in this:


https://stackoverflow.com/questions/6769881/emulate-double-using-2-floats


Thanks, I know the 2nd mentioned paper.


Maybe switch to PPC? :-D


Well, our customers don't use PPC Laptops ;-) otherwise that would be cool.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Accuracy of floating point calculations

2019-10-31 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-30 15:12:29 +, H. S. Teoh said:


It wasn't a wrong *decision* per se, but a wrong *prediction* of where
the industry would be headed.


Fair point...

Walter was expecting that people would move towards higher precision, 
but what with SSE2 and other such trends, and the general neglect of 
x87 in hardware developments, it appears that people have been moving 
towards 64-bit doubles rather than 80-bit extended.


Yes, which is wondering me as well... but all the AI stuff seems to 
dominate the game and follow the hype is still a frequently used 
management strategy.



Though TBH, my opinion is that it's not so much neglecting higher
precision, but a general sentiment of the recent years towards
standardization, i.e., to be IEEE-compliant (64-bit floating point)
rather than work with a non-standard format (80-bit x87 reals).


I see it more of a "let's sell what people want". The CPU vendors don't 
seem able to market higher precision. Better implement a 
highly-specific and exploding command-set...



Do you mean *simulated* 128-bit reals (e.g. with a pair of 64-bit
doubles), or do you mean actual IEEE 128-bit reals?


Simulated, because HW support is lacking on X86. And PPC is not that 
mainstream. I exect Apple to move to ARM, but never heard about 128-Bit 
support for ARM.



I'm still longing for 128-bit reals (i.e., actual IEEE 128-bit format)
to show up in x86, but I'm not holding my breath.


Me too.

In the meantime, I've been looking into arbitrary-precision float 
libraries like libgmp instead. It's software-simulated, and therefore 
slower, but for certain applications where I want very high precision, 
it's the currently the only option.


Yes, but it's way too slow for our product.

Maybe one day we need to deliver an FPGA based co-processor PCI card 
that can run 128-Bit based calculations... but that will be a pretty 
hard way to go.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Accuracy of floating point calculations

2019-10-30 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-29 17:43:47 +, H. S. Teoh said:


On Tue, Oct 29, 2019 at 04:54:23PM +, ixid via Digitalmars-d-learn wrote:

On Tuesday, 29 October 2019 at 16:11:45 UTC, Daniel Kozak wrote:

On Tue, Oct 29, 2019 at 5:09 PM Daniel Kozak  wrote:

AFAIK dmd use real for floating point operations instead of double


Given x87 is deprecated and has been recommended against since 2003 at
the latest it's hard to understand why this could be seen as a good
idea.


Walter talked about this recently as one of the "misses" in D (one of
the things he predicted wrongly when he designed it).


Why should the real type be a wrong decision? Maybe the code generation 
should be optimized if all terms are double to avoid x87 but overall 
more precision is better for some use-cases.


I'm very happpy it exists, and x87 too because our app really needs 
this extended precision. I'm not sure what we would do if we only had 
doubles.


I'm not aware of any 128 bit real implementations done using SIMD 
instructions which get good speed. Anyone?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Read Once then reset/init value?

2019-10-29 Thread Robert M. Münch via Digitalmars-d-learn
I quite often have the pattern where a value should be read just once 
and after this reset itself. The idea is to avoid that others read the 
value by accident and get an older state, instead they get an 
"invalid/reset" value.


Is there a library function that can mimic such a behaviour?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-26 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-24 16:03:26 +, Dukc said:

We're planning to have our product preview program to calculate and 
suggest a price for the product displayed. There are a lot of variables 
to take into account, so it's essential the users can edit the price 
variables themselves.


Hi, maybe you want to take a look what we do.

We are creating price-predicting formulas for all kind of products. Our 
solution is used in B2B by sales, engineering and purchasing 
departments to predict prices for very complex parts and products 
mostly using 3 to 10 performance drivers.


So, it's very easy (and fast) for users to get a good idea about the 
target-price of a product. Our predictions have a very high precision.


Let me know if you want to get some more background information.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-26 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-25 15:20:21 +, Ali ‡ehreli said:


On 10/25/2019 07:34 AM, Robert M. Münch wrote:

 > If the compiler is a 1-pass one I see the problem, otherwise one could
 > first get a "total overview" and create the necessary vtbl entries after
 > everything is known. Maybe this is not "how a compiler is implemented"
 > but the problem sounds solvable for me.

Unfortunately, it's not the compiler but the linker that produces the 
program (dmd and others conveniently call the linker behind the scenes).


Yes, sure...

It's common to compile the compilation units e.g. with "dmd -c" and 
then link them together at the end. C++ has been suffering from the 
fact that linkers are language agnostic but the linker is a part of the 
operating system, so this is what we got.


Otherwise, I would agree with you. But even then, what about dynamic 
libraries? The library was built with 7 instances of a template but I 
have 8 instances in my program. This is related to the operating system 
'loader', which happens to be the sister of the 'linker'. :)


The thing here would be to "instrument" or generate other code if such 
a case shows up, so be prepared for the case when such a dynamic case 
shows up. However, I can imagine that at the end one ends with a VM, 
that provides an eco-system that abstracts all these problems away... 
but than you are no longer a system language and won't have the common 
C compatible ABI.


I'll live the with cicumstance and as you showed, there is a solution 
to the problem.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-25 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-24 19:45:42 +, Ali ‡ehreli said:

One practical reason is, the number of their instances cannot be known 
when the interface (or base class) is compiled.

...


Ali, first, thanks a lot for your answers.

If the compiler is a 1-pass one I see the problem, otherwise one could 
first get a "total overview" and create the necessary vtbl entries 
after everything is known. Maybe this is not "how a compiler is 
implemented" but the problem sounds solvable for me.


However, your solution works too. Thanks again.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-24 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-23 17:22:38 +, Ali ‡ehreli said:


On 10/23/2019 02:43 AM, Robert M. Münch wrote:

 >> Unfortunately, member function template instances are never virtual
 >> functions, so you can't override them.
 >
 > What I don't understand is:
 >
 > 1. The RX lib has a member function template and than an instance of it
 > using type Oberver!E.
 >
 > 2. I'm creating a new type and want to use the same pattern but now with
 > my type. But it seems that D reduces my own type which leads to the
 > ambigty of which function now to use. Whereas I would expect that D uses
 > the most specific type first.

That is exactly the case (for D, C++, etc.). However, the function must 
be virtual. Imagine an object is being accessed by it base interface, 
only the virtual function calls will be dispatched to the most specific 
type. Non-virtual functions will be called on the base type.


Yes, I know and the problem seems to be what you mentioned before: "But 
I think you have a member function template in the base class. 
Unfortunately, member function template instances are never virtual 
functions, so you can't override them."


Is there a reason why these type of functions are not virtual or can't 
be made virtual?


For that reason, even though I've managed to remove your compilation 
error below, you will not like how it behaves.


 > The pastbin is the minimal code example. And yes, I'm sure there is a
 > (simple) way out...

Replacing FilterSubject with the following removes the compilation error:

static class FilterSubject : SubjectObject!message {

   SI spitialIndex;

   this(){
 spitialIndex = new SI();
   }

   auto subscribe(T)(T t)
   if (!is (T == myWidget))
   {
 return typeof(super).subscribe(t);
   }

   Disposable subscribe(T)(T observer)
   if (is (T == myWidget))
   {
 spitialIndex.insert(observer.x, observer.y, 
cast(long)cast(void*)observer);


 return NopDisposable.instance;
   }
}


Ah, that's pretty neat. I think that is what I need. I have to get used 
to this template variant handling feature.



However...

   auto rx_message = new FilterSubject;

The type of rx_message is FilterSubject above. When one calls 
.subscribe() on it, only FilterSubject.subscribe templates will be 
involved. Perhaps that's exactly what you want.


Yes.


However... :)

Accessing rx_message through a base class interface will call a 
different set of .subscribe() functions (the ones on the base even for 
myWidget!):


   SubjectObject!message rx_message = new FilterSubject;

Now rx_message is the base type and only now you get "Hit!" printed.


Yes, that fits. Because only when thîs specific type is used the 
specialized implementation should be used.


Again, maybe this is exactly what you want but beware that different 
sets of functions will be called depending on what interface of the 
object you are using.


Yes, I understand and this is a very elegant way to keep the same 
interface but with different behaviour depending on the type. Very 
useful.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-23 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-22 20:59:41 +, Ali ‡ehreli said:


That says "private paste" for me.


Ups, sorry and thanks for letting me know.



But I think you have a member function template in the base class.


This the lib I use: 
https://github.com/lempiji/rx/blob/dev/source/rx/subject.d and which 
gives the error.


On lines 72ff it has:

   Disposable subscribe(T)(T observer)
   {
   return subscribe(observerObject!E(observer));
   }

   Disposable subscribe(Observer!E observer)
   {


Which looks exactly like what you mention, if I understand it correctly.

Unfortunately, member function template instances are never virtual 
functions, so you can't override them.


What I don't understand is:

1. The RX lib has a member function template and than an instance of it 
using type Oberver!E.


2. I'm creating a new type and want to use the same pattern but now 
with my type. But it seems that D reduces my own type which leads to 
the ambigty of which function now to use. Whereas I would expect that D 
uses the most specific type first.


I'm pretty sure there is a way out. Can you try showing minimal code 
again please.


The pastbin is the minimal code example. And yes, I'm sure there is a 
(simple) way out... for some advanced guys like you. Still learning a 
lot here...


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-22 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-21 18:02:06 +, Robert M. Münch said:


This now gives:

rx_filter_subject.d(66,23): Error: 
rx_filter_subject.FilterSubject.subscribe called with argument types 
(myWidget) matches both:


/Users/robby/.dub/packages/rx-0.13.0/rx/source/rx/subject.d(72,16):
rx.subject.SubjectObject!(message).SubjectObject.subscribe!(myWidget).subscribe(myWidget 
observer)


and:

rx_filter_subject.d(47,14): 
rx_filter_subject.FilterSubject.subscribe(myWidget observer)


So, now there is an ambiguty.


I'm really stuck on this which looks like a dead-lock to me. Adding 
"override" gives:


class myWidget : Observer!message {...}

class FilterSubject : SubjectObject!message {
 override Disposable subscribe(myWidget observer){...}
}

rx_filter_subject.d(47,23): Error: function Disposable 
rx_filter_subject.FilterSubject.subscribe(myWidget observer) does not 
override any function, did you mean to override template 
rx.subject.SubjectObject!(message).SubjectObject.subscribe(T)(T 
observer)?


rx_filter_subject.d(47,23):Functions are the only declarations 
that may be overriden


So, I can't override but when I use an alias I get an ambiguty error... 
now what?


The only solution I have is to use a different name, but that would 
change the interface and run against all the OOP ideas. The whole code 
can be found here: https://pastebin.com/5BTT16Ze



--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-21 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-21 07:04:33 +, John Chapman said:


This should work:

class FilterSubject : SubjectObject!message {
   alias subscribe = typeof(super).subscribe;
   Disposable subscribe(myWidget observer){...}
}


This now gives:

rx_filter_subject.d(66,23): Error: 
rx_filter_subject.FilterSubject.subscribe called with argument types 
(myWidget) matches both:


/Users/robby/.dub/packages/rx-0.13.0/rx/source/rx/subject.d(72,16):
rx.subject.SubjectObject!(message).SubjectObject.subscribe!(myWidget).subscribe(myWidget 
observer)


and:

rx_filter_subject.d(47,14): 
rx_filter_subject.FilterSubject.subscribe(myWidget observer)


So, now there is an ambiguty.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-20 Thread Robert M. Münch via Digitalmars-d-learn

I get this error message, which doesn't tell me a lot:

rx_filter_subject.d(38,8): Error: class rx_filter_subject.FilterSubject 
use of 
rx.subject.SubjectObject!(message).SubjectObject.subscribe(Observer!(message) 
observer) is hidden by FilterSubject; use alias subscribe = 
SubjectObject.subscribe; to introduce base class overload set


I have in file rx_filter_subject:

class myWidget : Observer!message {...}

class FilterSubject : SubjectObject!message {
 Disposable subscribe(myWidget observer){...}
}


I tried to add "alias subscribe = SubjectObject.subscribe;" in 
different places, but that didn't help. Nor do I have any how that 
should help...


I understand that my subscribe(myWidget observer) function seems to 
hide the base class subscribe function. But I don't care about the base 
class one. So, I want to hide it when a FilterSubject is used.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-11 18:09:01 +, Jacob Carlborg said:

No, I don't think that's the problem. I have the same setup and I don't 
have this problem.


Interesting... but the update seems to have solved the problem. Maybe 
some old DMD compiler stuff lying around got in the way.



What result do you get if you run the following command:

nm /usr/lib/system/libdyld.dylib | grep _dyld_enumerate_tlv_storage


=> nm /usr/lib/system/libdyld.dylib | grep _dyld_enumerate_tlv_storage
00017eca T _dyld_enumerate_tlv_storage


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-11 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-10-10 18:31:25 +, Daniel Kozak said:


What dmd version?


I think I had an older one like 2.085 or so. I updated to 2.088 and it 
now seems to work.



https://issues.dlang.org/show_bug.cgi?id=20019


I'm on OSX 10.14.6, so this might not be directly related to Catalina 
but maybe more to the XCode Version installed:


| => xcrun --show-sdk-version
10.15

So, it's possible to run 10.14 with SDK version 10.15 which seems to 
trigger the problem.


Thanks for the hints.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-10 Thread Robert M. Münch via Digitalmars-d-learn

I have two project I want to compile and both times get this error:

Undefined symbols for architecture x86_64:
 "_dyld_enumerate_tlv_storage", referenced from:
 __d_dyld_getTLSRange in libphobos2.a(osx_tls.o)

I'm wondering where this comes from as I didn't see it in the past. Any idea?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: vibe / self contained standalone executable?

2019-07-28 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-07-28 14:14:06 +, Sebastiaan Koppe said:

I am using https://dlang.org/spec/expression.html#import_expressions 
for text files. Don't know if it works on binary files as well.


And this works than good together with the vibe framework? So, it's not 
requiring or forcing one to use files or databases?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



vibe / self contained standalone executable?

2019-07-28 Thread Robert M. Münch via Digitalmars-d-learn
Is it possible to pack a complete "web-app" (serving web-pages and 
providing REST API) into a single executable so that no other files 
need to be accessed and everything is servered from something like a 
"virtual filesystem" which is in memory only?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Associative Array & different template types

2019-07-04 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-07-03 19:07:10 +, ag0aep6g said:


On 03.07.19 20:20, Robert M. Münch wrote:
So, I need to carry around the object from which a delegate was created 
from because it's not possible to query the delegate for the object 
later somewhere else in the code.


It is possible to get the context object out of a delegate:


class C { void method() {} }
void main()
{
 auto c = new C;
 void delegate() dg = 
 assert(cast(C) dg.ptr is c); /* passes */
}


You just have to know (or carry around) the type so that you can cast 
correctly.


Hmm... IIRC I once played around and it didn't work... seems I messed 
this up. Thanks for correcting my wrong perception here.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Associative Array & different template types

2019-07-03 Thread Robert M. Münch via Digitalmars-d-learn

I have something like:

template myStruct(T){
auto makeMyStruct(T,E)(T context, void delegate(E) myFunc){
static struct myObject {
this(T context, void delegate(E) myFunc){
_context = context;
_myFunc = myFunc;
}

private:
void delegate(E) _myFunc;
T _context;
}
}
}

class myClass {
void myClassFunc();
}

myClass mc = new myClass;

auto mo = makeMyStruct!myClass(mc, ); // mo = myObject

So, I need to carry around the object from which a delegate was created 
from because it's not possible to query the delegate for the object 
later somewhere else in the code.


Now, I want to keep several of the makeMyStruct!... created objects in 
an AA (or an other container) so that I can compare them with an object 
pointer. Like this (not working code, just pseudo code):



myObject[string] myObjectArray;

auto mo1 = makeMyStruct!myClassA(mcA, ); // mo1 = myObject
auto mo2 = makeMyStruct!myClassB(mcB, ); // mo2 = myObject

myObjectArray["1"] = mo1;
myObjectArray["2"] = mo2;

assert(mcA == mo1._context)
assert(mcA == myObjectArray["1"]._context)


I hope the idea is understandable. Of course this doesn't work because 
myObjectArray needs a template, which creates different types. But with 
different types I can't throw everything into on array. May claases, 
and inheritance from a non-template base type help here?


I would like to keep it as simple as possible...

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: assert in unittest has access to private member?

2019-07-01 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-30 17:47:27 +, a11e99z said:

Private means that only members of the enclosing class can access the 
member, or

vvv
members and functions in the same module as the enclosing class.
^^^
did you take it into account?


Of course not... still to much C++ in my head... Thanks for the 
clarification. I will remember it from now on.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



assert in unittest has access to private member?

2019-06-30 Thread Robert M. Münch via Digitalmars-d-learn
I have a case, with templates, where an assert in a unittest can access 
a private memember and I don't know how this can happen.


Before trying to creat an equivalent case, I want to cross-check, if 
assert has special semantics in a unittest so that it can access 
private memembers?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: How does this template work?

2019-06-18 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-17 20:53:28 +, aliak said:


Less typing for one. Otherwise you'd have to write:

auto observer = observerObject!int.observerObject(TestObserver());


Since code is many times more read than written I will never understand 
why the syntax is polluted to save some keystrokes, making it much 
harded for others who don't have 800 pages special cases in their mind 
to read the code.


One explicit alias or so would be OK too for cases where such a 
declaration is needed more than once.


But anyway, thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: How does this template work?

2019-06-17 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-16 15:14:37 +, rikki cattermole said:


observerObject is an eponymous template.

What this means (in essence) is the symbol inside the template block == 
template block.


Hmm... ok. Is there any reason to have these "eponymous templates"? I 
don't see any benefit...


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



How does this template work?

2019-06-16 Thread Robert M. Münch via Digitalmars-d-learn
How does the observerObject Template and function work? I'm struggling 
because both use the same name and how is the template parameter R 
deduced/where is it coming from? Looks like it's somehow implicitly 
deduced.



class ObserverObject(R, E...){...}

template observerObject(E)
{
   ObserverObject!(R, E) observerObject(R)(R range)
   {
   return new ObserverObject!(R, E)(range);
   }
}

struct TestObserver {...}

auto observer = observerObject!int(TestObserver());


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-15 16:19:23 +, Anonymouse said:

By design, I think: "delegate and function objects cannot be mixed. But 
the standard function std.functional.toDelegate converts a function to 
a delegate."


Your example compiles if the assignment is changed to dg = 
toDelegate(); (given appropriate imports).


https://tour.dlang.org/tour/en/basics/delegates

https://dlang.org/phobos/std_functional.html#.toDelegate


Hmm... but this here compiles:

void main()
{
   import std.stdio: write, writeln, writef, writefln;
   void foo(int a) {return; }

   void test()
   {
void delegate(int) dg;

   dg = 
   }
}

See: https://run.dlang.io/is/U7uhAX

Is it because inside main() there is a stack frame? And with a global 
function there is none? I'm a bit confused...


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread Robert M. Münch via Digitalmars-d-learn
Why does the follwing code give: Error: cannot implicitly convert 
expression & myFunc of type void function(int a) to void delegate(int)



void myFunc(int a){return;}

void main()
{
   void delegate(int) dg;
   dg = 
}

See: https://run.dlang.io/is/iTYo2L

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Elegant way to test if members of array A are present in array B?

2019-06-14 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-12 13:58:49 +, Meta said:


There are two versions of find that can find a range within another:

https://dlang.org/phobos/std_algorithm_searching.html#.find
https://dlang.org/phobos/std_algorithm_searching.html#.find.3


Thanks, that looks good. I read the find docs, but somehow didn't 
see/understand the forwardRange part. Not so easy to get...


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-11 17:34:00 +, Paul Backus said:


It's a space/time tradeoff. foreach with canFind is O(n^2) time and O(1) space.


Yes, that's why I asekd. They haystack is most likely >10 times larger 
than the needles. Speed has priority.



If you use an associative array or a set, it's O(n) time and O(n) space.


I don't see how this is the case. The AA itself has some overhead too. 
So, the checking loop is O(n) but the AA lookups not.


If you sort the arrays and use std.algorithm.setops.setDifference it's 
O(n*log(n)) time and either O(1) or O(n) space, depending on whether 
you use an in-place sorting algorithm.


I think I will need some testing to see the effect of different approaches...

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Elegant way to test if members of array A are present in array B?

2019-06-11 Thread Robert M. Münch via Digitalmars-d-learn
Is there a simple and elegant way to do this? Or is just using a 
foreach(...) with canFind() the best way?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: How to create a template class using foreach delegate to filter objects in a member function call?

2019-06-01 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-06-01 04:43:13 +, Alex said:


That's ok, but could you provide an example anyway? Is it like this?

´´´
void main(){
 auto target = new myClass!int();
 target.objects.length = 4;
 auto val = 42;
 put(target, val, testfunction); // does the test function enters here?
 put(target, val);
 auto f = myFilter!int; // where do you want to use this entity?
}
´´´


myClass shouldn't be subclassed, only just used.

The myFilter struct is the implementation which myClass.put() should 
use to iterate over all objects. All things being only examples. So, 
the idea is, that I can provide a delegate which foreach(...; 
myFilter(objects)) uses. Like a run-time plug-in.


Do you have control about the contained classes? If so, it is a hint to 
implement the testing inside them. Like:


/* probably inside a templated mixin */
bool testfunction(inputs){...}

class myOtherClass(/*probably templated*/){... mixin testfunction ... & 
provide a put function}


I thought about a mixin too. But this requires an understanding of how 
myClass works. Which I what I want to avoid.


* So, you are not totally against the idea of modifying the foreign 
library, but you want to keep modifications small?


Yes, because myClass is some external lib, which can be changed to 
support this approach here. But not more.


With the approach now, you could, for example, handle compile time 
blocks inside the put function in the myClass and dynamical ones inside 
the myOtherClasses. class myClass(E){/* inserted put function */ void 
put(...){static if put action is at all possible --> put. }}


As said, KISS and really just want to provide a plug-in which is used 
to iterate of a sequence I provide from the outside.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Dub dependencies / How to use own Github fork?

2019-06-01 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-05-30 18:29:44 +, Steven Schveighoffer said:

You can dub add-local your local fork, and it will use that instead of 
going out to code.dlang.org.


Ok, any chance to switch back and forth between local/remote versions?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: How to create a template class using foreach delegate to filter objects in a member function call?

2019-05-31 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-05-31 11:07:00 +, Alex said:


Not sure, if I understood your problem correctly.


I can imagine... I try my best :-)


It is meant that the class myClass defines an array of myOtherClass objects?


Yes. So there is one class having an array of other stuff.

The code does not compile and it does not provide an example, how you 
would apply the pattern, even in a non-compileable way...


The code is just to show the problem and not meant to compile. I 
couldn't get anything to compile...


However, commonly, a filter is a higher order function, which expects a 
predicate acting on each element of a set. Even if it's higher order, 
it is still a function, not a delegate. Therefore, it is unexpected, 
that you want to store something inside the filter.


I choose filter to give a hint what the idea is, not meant to be that I 
want to use a filter.


Said this, I for myself had a similar problem. I solved this by 
reversing the hierarchy: I templated my objects I wanted to use the 
filter on with the filter function and removed the need of the template 
parameter inside the filter.


The thing is, myClass is not under my control. It's coming from a 
library I don't maintain and I don't want to mess around with the code 
or if, as minimalistic as possible. That's why I was thinking about 
providing a put(T)... function.


My first idea was to sub-class myClass, but objects is private, so no 
chance to get access to it.


You could still write a general filter function in this case, if you 
want. For example, you could use mixins for this...


Then myClass needs to somehow get the mixin in.

So, to summurize the problem: Given a class that manages an array of 
things as an OutputRange how can I provide a put() function with 
something like a filter-predicate? I only want to put() to some of the 
things, not all.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



How to create a template class using foreach delegate to filter objects in a member function call?

2019-05-30 Thread Robert M. Münch via Digitalmars-d-learn
I have myClass and I want to add a way where I can provide a delegate 
to iterate over myClass.objects when a member function put(...) of 
myClass is called. The idea is that a user of myClass can provide 
something like an "iterator filter" so that the function is only called 
on a subset of myClass.objects.



myClass(E){
myOtherClass!E objects;

void put(E obj) {
.put(objects, obj);
}

void put(T)(E obj, T filter) {
foreach(o ; filter!E(objects)){
.put(o, obj);
}
}
}

struct myFilter {
myOtherClass!E object;

opApply(int delegate(E) foreach_body) const {
if(mytestfunc(object))
return(foreach_body(object));
}
}

But I'm struggeling how to write all this down with tempaltes, because 
E is not known in myFilter. But the filter code needs to be aware of 
the template type if myClass. I hope the idea want to do is 
understandable.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Dub dependencies / How to use own Github fork?

2019-05-30 Thread Robert M. Münch via Digitalmars-d-learn
Is there a best practice how I can use a fork if mine of a project that 
can be access via "dependencies": {...} so that my own code is used?


I think that would make it pretty easy to switch between different versions.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



  1   2   3   4   >