Re: How do I check if this field is of this template struct?

2021-03-19 Thread Panke via Digitalmars-d-learn

On Friday, 19 March 2021 at 07:14:46 UTC, Jack wrote:
give below template struct, how can I list the members x, y and 
z? I've tried something with OriginalType and TemplateOf but no 
luck... it seems if I do foo!"str1" the "str1" became "part of 
type"? give .stringof from typeof(__traits(getMember, foo, 
field)) I thought the type would be foo!string or something.


Template parameter cannot only be types but also values, 
including strings. If you instantiate a template with different 
values you get different types.


--
struct foo(T) { }
struct bar(string s) {}

alias a = foo!string; // type of a is foo!string
alias b = bar!"str1"; // type of b is bar!"str1"
alias c = bar!"str2"; // typo of c is bar!"str2"
static assert (!is(typeof(c) == typeof(b)));
--


Re: SIGUSR1, SIGUSR2

2020-12-11 Thread Panke via Digitalmars-d-learn

On Friday, 11 December 2020 at 17:32:54 UTC, Adam D. Ruppe wrote:

On Friday, 11 December 2020 at 17:29:12 UTC, Panke wrote:
But somehow my process gets signalled with USR1 and USR2 all 
the time. If I do


The garbage collector uses sig usr1/2 to pause threads so it 
can do its collection work.


When debugging just ignore them. My .gdbinit has these lines:

handle SIGUSR1 noprint
handle SIGUSR2 noprint

since most D programs will have these.


For lldb

breakpoint set -n _Dmain --auto-continue true -N OnMain
breakpoint command add -o "pro hand -p true -s false -n false 
SIGUSR1 SIGUSR2" OnMain


does the trick.


Re: SIGUSR1, SIGUSR2

2020-12-11 Thread Panke via Digitalmars-d-learn

On Friday, 11 December 2020 at 17:32:54 UTC, Adam D. Ruppe wrote:

On Friday, 11 December 2020 at 17:29:12 UTC, Panke wrote:
But somehow my process gets signalled with USR1 and USR2 all 
the time. If I do


The garbage collector uses sig usr1/2 to pause threads so it 
can do its collection work.


When debugging just ignore them. My .gdbinit has these lines:

handle SIGUSR1 noprint
handle SIGUSR2 noprint

since most D programs will have these.


Thanks, good to know!


SIGUSR1, SIGUSR2

2020-12-11 Thread Panke via Digitalmars-d-learn
I have as vibe.d application that opens some websockets, reads 
messages and does something with them (currently mostly writing 
them to disk).


The processing happens in background threads started with 
runWorkerTask, the websocket code runs as a normal task 
(runTask), everything is synchronized over a central circular 
buffer.


But somehow my process gets signalled with USR1 and USR2 all the 
time. If I do


  $ strace -etrace=epoll_wait

the disruptions of epoll by SIGUSR1/2 just scroll down. According 
to the strace output I got new, the source of the signals is the 
process itself. This happens if I do not install a signal handler 
myself.


While this makes debugging a pain, at least the program seems to 
work. If I install signal handlers for USR1/USR2 via eventcore 
than vibe.d never seems to be able to establish the websocket 
connection. The same happens if I do signal(SIGUSR1, SIG_IGN).


Maybe some kind of deadlock (all threads seem to be waiting on 
some condition variables or a in a spinlock). Does anyone have a 
idea what's going on here?







Re: Using Vibe.d for not HTTP

2020-05-25 Thread Panke via Digitalmars-d-learn

On Monday, 25 May 2020 at 12:04:12 UTC, Russel Winder wrote:


Now I need to find out how to spawn a task that can send out 
data even when the connection handler is blocked awaiting 
something to read.



https://vibed.org/api/vibe.core.core/runTask ?




Re: Using Vibe.d for not HTTP

2020-05-24 Thread Panke via Digitalmars-d-learn

On Sunday, 24 May 2020 at 16:14:58 UTC, Russel Winder wrote:

On Sun, 2020-05-24 at 17:01 +0100, Russel Winder wrote:



[…]

connection.read(buffer, IOMode.once);

What an idiot I am, this call returns the read count, which 
makes it fine.


Progress now being made.


I had a look. Documentation could be better. I think the other 
call does not return it, because it always reads until the buffer 
is filled.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Panke via Digitalmars-d-learn

On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
I'd like to have application as small as possible with a simple 
Command Line Window.
I'd use that Window to output notices, log information and the 
like.


Would this require GUI library and how can this be achieved?


If you do not want to create the library yourself, you could 
spawn a terminal application like konsole or kitty and start a 
simple cli app.


You'd need to have some form of inter process communication setup 
for this though.


Does anyone have gdb pretty printers for buildin types like associative arrays?

2020-03-15 Thread Panke via Digitalmars-d-learn
At least on my installation they are printed as just a pointer. 
Should this just work and by box is not correctly configured or 
do I need some pretty printers? If so, has someone already made 
them?


Re: Typescript with vibe.d

2020-03-09 Thread Panke via Digitalmars-d-learn

On Monday, 9 March 2020 at 09:42:16 UTC, GreatSam4sure wrote:
I want to know if it is possible to use typescript with the 
vibe.d since typescript is a superset of javascript. I will 
appreciate any example if it is possible


What do you want to do?


best practices for a new project

2020-02-17 Thread Panke via Digitalmars-d-learn
When I start a new project is there anything that I should get 
right from the start? Like using a specific set of compiler flags 
(e.g. -dip1000)?


Is there an overview over the status of upcoming language changes 
(-preview=?), e.g. what about -preview=rvaluerefparam? Should I 
use it?


Re: std.variant.Algebraic, self referential types and delegate members

2015-11-08 Thread Panke via Digitalmars-d-learn
On Sunday, 8 November 2015 at 11:28:05 UTC, Jonathan M Davis 
wrote:
On Sunday, November 08, 2015 10:31:11 Panke via 
Digitalmars-d-learn wrote:

import std.variant, std.stdio;

---
struct NodeTypeA(T) { T[] children; }
struct NodeTypeB(T) { Tree children; }
struct Leaf(T) { T delegate() dg; }

alias Tree = Algebraic!(Leaf, NodeTypeA!This, NodeTypeB!This);

void main()
{
   Tree t;
}
---

yields

tmp.d(6): Error: functions cannot return opaque type This by 
value

tmp.d(8): Error: template instance tmp.Leaf!(This) error
instantiating

This limitation seems arbitrary to me. What's the reason here?


Okay. Several things here. For starters, NodeTypeA, NodeTypeB, 
and Leaf are not actually types. They're templates for types. 
If you want a type, you have to instantiate them. So, something 
like Algebraic!Leaf doesn't make any sense. You need an 
instantiation of Leaf - e.g. Algebraic!(Leaf!int) - rather than 
just Leaf.


My failure, I've played with the code while crafting the post. 
I've used

---
alias Tree = Algebraic!(Leaf!This, NoteTypeA!This, NoteTypeB!This)
---

So no templates, just types.

Next, you have a recursive template instantiation going on 
here. Tree depends on knowing what a NodeTypeB looks like, 
because it's using it in its instantiation of Algebraic. 
Algebraic!(Foo, Bar) is told to hold either a Foo or a Bar, 
which means that it needs to know their definitions - not just 
their names. You need to be using pointers if you want to be 
able to avoid having to know the actual definition of the type. 
So, when you tell NodeTypeB to hold a Tree when a Tree holds a 
NodeTypeB, it's impossible to figure out what the actual layout 
of those types. You have a recursive expansion.


If you want to have a recursive type definition, you _must_ use 
pointers so that the actual definition of the type is not 
required.


Thing is that delegate is nothing more than a glorified pair of 
pointers.


Also, I have no idea what the deal with the This in your code 
is. IIRC, there's a feature involving This with template 
definitions, but you're just using it outside of a template 
definition, so I don't know if that's legal.


It's a recent feature of Algebraic to allow recursive 
definitions. I'd assume that it uses pointers under the hood.


Older compiler but same error message: http://goo.gl/P0wmqe


std.variant.Algebraic, self referential types and delegate members

2015-11-08 Thread Panke via Digitalmars-d-learn

import std.variant, std.stdio;

---
struct NodeTypeA(T) { T[] children; }
struct NodeTypeB(T) { Tree children; }
struct Leaf(T) { T delegate() dg; }

alias Tree = Algebraic!(Leaf, NodeTypeA!This, NodeTypeB!This);

void main()
{
  Tree t;
}
---

yields

tmp.d(6): Error: functions cannot return opaque type This by value
tmp.d(8): Error: template instance tmp.Leaf!(This) error 
instantiating


This limitation seems arbitrary to me. What's the reason here?


dbgVerifySorted is not nothrow

2015-11-08 Thread Panke via Digitalmars-d-learn

I've updated my compiler and ran into this regression:

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

Code:

---
import std.algorithm, std.container;

void main()
{
static bool compare(P a, P b)
{
return a.curColumn < b.curColumn;
}
Array!P a = make!(Array!P);
sort!compare(a[]);
}

struct P
{
int curColumn = 0;
}
---

Result:
/usr/include/dlang/dmd/std/algorithm/sorting.d(982): Error: 
template instance std.range.assumeSorted!(compare, 
RangeT!(Array!(P))) error instantiating
tmp.d(10):instantiated from here: sort!(compare, 
cast(SwapStrategy)0, RangeT!(Array!(P)))

1 tobias@akela ~ [i] % dmd -debug tmp.d
/usr/include/dlang/dmd/std/range/package.d(7189): Error: 
'std.range.SortedRange!(RangeT!(Array!(P)), 
compare).SortedRange.dbgVerifySorted' is not nothrow
/usr/include/dlang/dmd/std/algorithm/sorting.d(982): Error: 
template instance std.range.assumeSorted!(compare, 
RangeT!(Array!(P))) error instantiating
tmp.d(10):instantiated from here: sort!(compare, 
cast(SwapStrategy)0, RangeT!(Array!(P)))


What I don't understand is, why dbgVerifySorted has to be nothrow 
in the first place. Is that an new requirement for contracts? I 
couldn't find any hint in the language spec.





Re: How to use std.experimental.logger?

2015-10-01 Thread Panke via Digitalmars-d-learn
Ah, I tried to format a custom struct that has a non-pure 
toString, because std.conv.to isn't pure either, sigh :(





How to use std.experimental.logger?

2015-10-01 Thread Panke via Digitalmars-d-learn
I tried it on Windows today using the latest DMD installer, all 
default logger and settings.


I get: safe function [...].logImplf cannot call system function 
'std.format.formattedWrite!(MsgRange, char, 
Result!()).formattedWrite'


How do I make formatted logging work?


Re: Printing an std.container.Array

2015-04-16 Thread Panke via Digitalmars-d-learn

On Thursday, 16 April 2015 at 19:55:53 UTC, Bayan Rafeh wrote:


How am I supposed to interpret this?


The array contains two elements. The first equals one and the 
second equals two.


What happens under the hood is that Array does no provide a 
toString method, instead a default is used. This results in your 
first output. For ranges - and the slice of the array is a range 
while the array is not - writeln prints the elements as a special 
case which leads to your second output.


Re: Printing an std.container.Array

2015-04-16 Thread Panke via Digitalmars-d-learn


Yep, but problem is almost no one expect this, or know this. We 
definitely

should do better.


How?


Re: How to generate a random string ...

2015-03-17 Thread Panke via Digitalmars-d-learn

On Monday, 16 March 2015 at 13:33:55 UTC, Robert burner Schadek
wrote:
... from all Unicode characters in an idiomatic D way? 
(std.interal.unicode_*)


```
T genUnicodeString(T)(size_t minChars, size_t maxChars) 
if(isSomeString!T) {

...
}
```


You'll need two things. A uniform distribution of { 0 ... 113,020
}, this should be easy using phobos. And a mapping of { 0 ...
113,020 } - unicode ( or UTFX directly ). Since the unicode
planes or not connected, this might involve some kind of table.

Then just generate your uniform distribution and apply the
mapping.