Re: SLF4D - A proposal for a common logging interface for Dub projects

2023-02-24 Thread Tobias Pankrath via Digitalmars-d-announce

On Wednesday, 22 February 2023 at 21:46:32 UTC, Andrew wrote:
I've been spending some time in the last few weeks to prototype 
a logging framework that's inspired by 
[SLF4J](https://www.slf4j.org/). To that end, I've created 
[SLF4D](https://github.com/andrewlalis/slf4d), which provides a 
common logging interface, and a pluggable architecture to allow 
third-parties to handle log messages generated by any logger in 
an application.




Why not std.experimental.logger?


Re: I like dlang but i don't like dub

2022-03-21 Thread Tobias Pankrath via Digitalmars-d-learn
On Monday, 21 March 2022 at 10:29:53 UTC, Alexandru Ermicioi 
wrote:

On Friday, 18 March 2022 at 21:04:03 UTC, H. S. Teoh wrote:
On Fri, Mar 18, 2022 at 11:16:51AM -0700, Ali Çehreli via 
Digitalmars-d-learn wrote:
tldr; I am talking on a soap box with a big question mind 
hovering over on my head: Why can't I accept pulling in 
dependencies automatically?


Because it's a bad idea for your code to depend on some 
external resource owned by some anonymous personality 
somewhere out there on the 'Net that isn't under your control.


True, and because of that you can try and have local/company 
wide dub registry (if not, should be added support for), in 
which packages are verified by you/your company, eliminating 
the problem of net not being under control.


Best regards,
Alexandru.


That's actually possible right now, in the easiest case you can 
have a directory of package zip files.


Isn't that best practice in all language eco systems.


Re: I like dlang but i don't like dub

2022-03-21 Thread Tobias Pankrath via Digitalmars-d-learn

On Monday, 21 March 2022 at 09:25:56 UTC, Dadoum wrote:

On Friday, 18 March 2022 at 04:13:36 UTC, Alain De Vos wrote:

Dlang includes some good ideas.
But dub pulls in so much stuff. Too much for me.
I like things which are clean,lean,little,small.
But when i use dub it links with so many libraries.
Are they really needed ?
And how do you compare to pythons pip.
Feel free to elaborate.


Personally I use CMake, it allows me to access to C and C++ 
libraries while still being able to use small Dub libraries. 
Also everyone knows how to build a project with CMake nowadays.


I do the same with meson and I wish dub would be easier to 
integrate into third party build systems.


The first problem with dub is, that it doesn't really let you 
decide where it puts stuff. There is `--cache`, but that doesn't 
accept an path either and does not guarantee that afterwards 
everything you need is there. For example if you `dub fetch A 
--cache=local` and some dependencies of A are already under 
$HOME/.dub, you won't have them locally afterwards.


There is a workaround for this though: `HOME=. dub fetch A`.

A second problem is that `dub describe` returns paths to the 
packages directories not to the actual build directories, thus 
you can only use one compiler and the last `dub build` wins. 
Although there are custom build directories per compiler and half 
of the code to integrate dub packages in meson is to find and use 
the correct build directory (instead of just calling `dub 
describe`).


This would be much easier, if there were a `dub provide` (or 
whatever) that builds all deps for a project, installs them into 
a given prefix/path and makes them usable from `dub describe` 
afterwards, so that dub describe works more or less like 
pkg-config afterwards.


Re: I like dlang but i don't like dub

2022-03-18 Thread Tobias Pankrath via Digitalmars-d-learn

On Friday, 18 March 2022 at 04:13:36 UTC, Alain De Vos wrote:

Dlang includes some good ideas.
But dub pulls in so much stuff. Too much for me.
I like things which are clean,lean,little,small.
But when i use dub it links with so many libraries.
Are they really needed ?
And how do you compare to pythons pip.
Feel free to elaborate.


Dub is fantastic at some places, e.g. if you need to just execute 
something from code.dlang.org via `dub run`, or single file 
packages (https://dub.pm/advanced_usage) are great to write small 
cmdline utilities with dependencies.


I don't like it as a build system and it is notoriously hard to 
integrate into existing build systems. You can look at meson 
(which had some D related bug fixes recently) or reggae for that. 
Or just do `dmd -i` as long as compile times are low enough.


Re: Mixin a function into a struct only if no member with that name already exists

2021-12-29 Thread Tobias Pankrath via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 10:21:07 UTC, Stanislav Blinov 
wrote:
On Wednesday, 29 December 2021 at 10:14:13 UTC, Tobias Pankrath 
wrote:



How do I mixin a function only if it is not already present?


Perhaps use opDispatch?


That's a great idea and I'll look into it.


Mixin a function into a struct only if no member with that name already exists

2021-12-29 Thread Tobias Pankrath via Digitalmars-d-learn
I am trying to implement the builder pattern for some structs. 
Currently I am auto implementing all methods by mixing them into 
the builder, but now I need some custom logic for some of the 
fields and I figured I just write them down by hand and mixin the 
rest.


I tried checking if it is contained in the FieldNameTuple, but 
that (understandably) creates a circular reference: 
https://run.dlang.io/is/Xih7yP


How do I mixin a function only if it is not already present?


Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Tobias Pankrath via Digitalmars-d-learn

On Tuesday, 28 December 2021 at 21:19:29 UTC, rempas wrote:
I would like to know if that's possible. Actually I would like 
to do something like the following:


```
extern (C) void main() {
  void print_num(int num, comp_time_type int mul) {
static if (is(mul == ten)) {
  printf("%d\n", num * 10);
} else static if (is(mul == three)) {
  printf("%d\n", num * 3);
} else {
  printf("%d\n", num);
}
  }

  int multi = 211;
  print_num(10, 3); // Ok, accept this
  print_num(10, multi); // Error, do not accept this
}
```

So I want to have "mul" only accept values that can be 
calculate at compile time so I can use it with things like 
"static if". Is this possible?


I think you have to make 'mul' a template parameter.


Re: D Language Foundation Quarterly Meeting, October 2021

2021-11-08 Thread Tobias Pankrath via Digitalmars-d-announce

On Monday, 8 November 2021 at 12:02:43 UTC, Atila Neves wrote:

On Saturday, 6 November 2021 at 15:46:57 UTC, JN wrote:

On Friday, 5 November 2021 at 13:19:24 UTC, zjh wrote:

D can aim at `experts`, especially `meta programming users`.
On this point,`rust` can't compete.
`Silky general meta programming`.
Use my `strengths` to attack theirs weaknesses.



This is much less of a strength than you think. For 90% of 
cases, lack of metaprogramming is resolved by putting a Python 
script in build step that autogenerates the necessary code.


Python has no idea about D syntax or semantics (or any other 
language not called Python), and therefore can't even do 
something as simple as "what are all the D structs in module 
x". You'd have to invent a templating language on top of the 
code you're already writing, then write some Python code to 
parse and generate on top of *that*.


To me, that's like saying that C/Fortran aren't that big of a 
deal compared to assembly. Who needs for loops, amirite?


What C# does and what's probably easier for tooling and newbes is 
to let users hook into the compilation step and generate code on 
the fly given full compiler knowledge to the already existing 
code prior to generation.


Re: Mir Ion and Asdf benchmakrs

2021-05-16 Thread Tobias Pankrath via Digitalmars-d-announce

On Sunday, 16 May 2021 at 09:50:21 UTC, 9il wrote:
mir-ion and Asdf JSON libraries have been added to the 
Kostya/benchmarks.


https://github.com/kostya/benchmarks#json

If we exclude parsers with inaccurate number parsing then the 
top will be


1. C++, simdjson
2. Rust, Serde
3. Dlang, Mir Amazon's Ion DOM
4. Dlang, Mir Asdf DOM
5. C++ RapidJSON (Precise)

Mir Ion has been inspired by simdjson and Amazon's Ion binary 
format, which is used as DOM. Thus the mir-ion DOM for the 112 
MiB file costs 16 MiB comparing with 176 MiB DOM in simdjson.


Kind regards,
Ilya


Great work! What makes simdjson faster?


Re: EMSI Containers and HashMap of HashMaps

2021-05-05 Thread Tobias Pankrath via Digitalmars-d-learn

On Sunday, 2 May 2021 at 07:38:03 UTC, Tobias Pankrath wrote:


For your convenience: https://run.dlang.io/is/gHSlu1

I am using Refcounted() because HashMap itself is not 
copy-able. Is there another way to have HashMaps as values of 
HashMaps?


I've figured it out and filed an PR 
https://github.com/dlang-community/containers/pull/169. Would be 
great if we can get a new version out with this.





Re: EMSI Containers and HashMap of HashMaps

2021-05-02 Thread Tobias Pankrath via Digitalmars-d-learn

On Sunday, 2 May 2021 at 08:59:15 UTC, Imperatorn wrote:



```d
HashMap!(int, RefCounted!Map) mapOfMaps = HashMap!(int, 
RefCounted!Map)(1024);

```


That only fixes it, because you are avoiding the rehash with the
initial size.



Re: EMSI Containers and HashMap of HashMaps

2021-05-02 Thread Tobias Pankrath via Digitalmars-d-learn

On Sunday, 2 May 2021 at 08:59:15 UTC, Imperatorn wrote:

On Sunday, 2 May 2021 at 07:38:03 UTC, Tobias Pankrath wrote:




```d
HashMap!(int, RefCounted!Map) mapOfMaps = HashMap!(int, 
RefCounted!Map)(1024);

```


Is HashMap.init a broken state? That makes using them hard as 
struct members :/


EMSI Containers and HashMap of HashMaps

2021-05-02 Thread Tobias Pankrath via Digitalmars-d-learn

The following code segfaults, when the outer hashmap rehashes,
and I am not yet sure why.

```d
module tests.refcounted_hashmap_test;

import containers;
import std.typecons;

struct Map
{
HashMap!(int, int) theMap;
}

unittest
{
HashMap!(int, RefCounted!Map) mapOfMaps;
foreach (i; 0 .. 1000)
{
RefCounted!Map val;
if (i == 0) val.theMap.getOrAdd(i, i);
mapOfMaps.getOrAdd(i, val);
}
}
```

For your convenience: https://run.dlang.io/is/gHSlu1

I am using Refcounted() because HashMap itself is not copy-able. 
Is there another way to have HashMaps as values of HashMaps?





Re: GC memory fragmentation

2021-04-13 Thread Tobias Pankrath via Digitalmars-d-learn

On Tuesday, 13 April 2021 at 12:30:13 UTC, tchaloupka wrote:


Some kind of GC memory dump and analyzer tool as mentioned 
`Diamond` would be of tremendous help to diagnose this..


You could try to get the stack traces of the allocating calls via 
eBPF. Maybe that leads to some new insights.






Re: noobie question, dub or meson?

2021-03-18 Thread Tobias Pankrath via Digitalmars-d-learn

On Thursday, 18 March 2021 at 02:28:56 UTC, Chris Piker wrote:

Hi D

I've started a D layer for one of my C libraries that's adds 
some new functionality and a bit of an interface upgrade.  In 
turn I'm using this combined code-base as a dependency for D 
"scripts".  Since my software is used by a few outside groups 
in my field, it seems I should get used to packaging D modules, 
even if those packages never make it to the central dub repo.


Given that source code for the combined library is some D but 
mostly C, would you recommend that I:


  1) Keep the D sources and C sources in separate projects?
  2) Use meson to create a combined package?
  3) Use dub to create a combined package?
  4) Some other option?

The D code is useless without it's C core, so a dub package 
that just includes the D parts would be disappointing.  The 
library's not huge, only about 25K lines, but I don't think I 
have time for a straight conversion of the whole thing to D at 
this point.


Thanks for your opinions on the matter,


The D support from meson is not perfect, but for your use case 
I'd go for it, esp. if you have do not have many dependencies on 
dub packages.


One problem with meson is that it goes the separate compilation 
route by default. I recommend just to -I your dependencies and 
build with -i, to avoid the hit in your compile times.


Re: rdmd and D equivalent for PYTHONPATH?

2021-03-17 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 17 March 2021 at 19:33:26 UTC, Chris Piker wrote:

So, if I could do the equivalent of:

  dub add-path

via an environment variable (not a permanent change under 
~/.dub), or have some environment variable that tells dub where 
to read a "system-level" local-packages.json file and merge 
it's paths in with any personal settings, that would likely 
handle our internal code sharing needs.


For scripts this could be a good way, but it does not really work 
with

most dub packages:

1. put all your dependencies into a single location, like 
/home//dstuff
2. add -I /home//dstuff to your call to rdmd/dmd (or put 
into /etc/dmd.conf

3. add -i (lowercase) to your call of rdmd/dmd
4. profit

-i automatically adds all modules that are imported to the 
compilation, i.e. all your dependencies are compiled together 
with your code, when they are needed. It searches for them where 
-I points to.


To make this work the dependencies must have the correct project 
layout, e.g. sources should be in the top-level project directory 
and not in a subdirectory source. This rules out most dub 
packages :/




Re: Our community seems to have grown, so many people are joining the Facebook group

2020-12-29 Thread Tobias Pankrath via Digitalmars-d-announce

On Wednesday, 30 December 2020 at 02:31:36 UTC, Murilo wrote:
On Tuesday, 29 December 2020 at 15:06:07 UTC, Ola Fosheim 
Grøstad wrote:
No, the OP clearly stated that he made the group "official". 
That is a deliberate attempt to fracture.
I'm sorry you see it like this but my intention when I created 
the group was to expand Dlang by bringing it to places people 
couldn't find it yet. The whole point of the FB group is to 
aggregate people into our community, to bring more people to 
Dlang and make Dlang famous. My whole intention was to help our 
community grow, not fracture.


No need to be sorry. Keep up the good work.

There is a tendency around here to kill the good that is for the 
better that never will be. Don't get discouraged by this. If I 
had facebook, I'd join.


Re: Our community seems to have grown, so many people are joining the Facebook group

2020-12-29 Thread Tobias Pankrath via Digitalmars-d-announce
On Tuesday, 29 December 2020 at 11:34:38 UTC, Ola Fosheim Grøstad 
wrote:


Not quite, if you split up then each community might have 
stronger social bonding, but in terms of aggregating helpful 
advice you will be worse off. It would be suitable for 
geographic groups (e.g. for a country/city).


For instance slashdot is very poor in social boding terms, but 
much better than the dlang forums for aggregating helpful 
advice. So the "learn" forum is beneficial socially, but does 
erode the slashdot presence.


You have a valid point, but still I am sure the facebook group is 
a net positive for the community. I'd see it as a digital version 
of a local user group.


Would be useful to have the option to post D.learn questions 
automatically on stack overflow as well.




Re: Truly algebraic Variant and Nullable

2020-12-20 Thread Tobias Pankrath via Digitalmars-d-announce

On Sunday, 15 November 2020 at 04:54:19 UTC, 9il wrote:
Truly algebraic Variant and Nullable with an order-independent 
list of types.


Thanks for sharing it!

Could you give a (very short) explanation on why sumtype could 
not meet your requirements? I am just starting a new D project 
and have to choose between sumtype and your solution.




The work has been sponsored by Kaleidic Associates and Symmetry 
Investments.


Much appreciated!




Re: Using multiple mixin templates to implement operator overloading

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote:
Functions from different mixin templates can't overload each 
other. The reason for this is that, when you mix in a mixin 
template, it does not *actually* add the declarations inside it 
to a current scope: instead, it adds them to a new scope, and 
then (essentially) "imports" them into the current scope.

Much appreciated! Exactly the explanation I needed.




Using multiple mixin templates to implement operator overloading

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn
I want to wrap e.g. an int and implement basic arithmetic. In the 
provided example [1] I use  two mixin templates to separately 
implement scaling (multiplication with int/double) and addition 
and subtraction with the type itself.


In the end I want to have several distinct wrappers and allow 
specific operations between them and int / double. It's important 
that the return values are typed correctly, otherwise I could use 
std.typecons.Proxy.


My problem is that both overloads of opBinary work, but not at 
the same time. As soon as I mixin both templates, they stop to 
work. If I just paste the implementation into the body of 
WrapInt, they work both at the same time though.


Could someone explain the mechanics behind it?

Thanks!

[1] https://run.dlang.io/is/WbG987




Re: regex: ] in a character class

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 12 December 2020 at 12:03:49 UTC, kdevel wrote:

I don't have a suggestion for better wording yet.

[1] https://dlang.org/phobos/std_regex.html


This [1] is how I would word it.

[1] https://github.com/dlang/phobos/pull/7724



Re: regex: ] in a character class

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 12 December 2020 at 12:03:49 UTC, kdevel wrote:

In some situations a ] must be escaped as in

   auto re = regex(`^[a\]]$`); // match a and ] only

Unfortunately dmd/phobos does not warn if you forget the 
backslash:


   auto re = regex(`^[a]]$`); // match a]

This leads me to the documentation [1] which says

   \c where c is one of [|*+?() Matches the character c itself.

] must be added to this list since \] obviously matches ]. 
Additionally

the statement

   any character except [{|*+?()^$ Matches the character 
itself.


is not true since ] does not match itself when ] denotes the 
end of
a character class. I don't have a suggestion for better wording 
yet.


[1] https://dlang.org/phobos/std_regex.html


As I understand it, the statement is indeed true and a regex 
`]]]` would match and only match the string `]]]`. What should be 
added somewhere is


  Inside character classes the character ']' has to be written 
as '\]'.


Re: dub: standard project: how to build the unittest (the thing `dub test` runs)

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 12 December 2020 at 12:18:47 UTC, Andre Pany wrote:


In any case you should have configurations in your dub json.


Thank you for your detailed reply and I am sure I can make it 
work in the way you described.


But I don't think my use case is invalid and dub should improve 
its usability here.


Either it is indeed necessary to provide configuration even for 
very simple projects. Than dub should generate them on `dub 
init`. Or dub allows one to just build the test without running 
them. I'd propose `dub build test` or `dub build --test` for it.


What do you think?



dub: standard project: how to build the unittest (the thing `dub test` runs)

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn
Whenever I come back to some D, I seem to be stumbling over dub. 
Somehow dub and I don't align:


$ dub init dubtest && cd dubtest
$ dub test
-> creates executable `dubtest` (saying Falling back to "dub -b 
unittest".)


$ touch source/lib.d
dub test
-> creates executable dubtest-test-library

Question is: How do I build the `dubtest-test-library` without 
running the tests?


If no explicit configuration is given, an existing "unittest" 
configuration will be preferred for testing. If none exists, 
the first library type configuration will be used, and if that 
doesn't exist either, the first executable configuration is 
chosen.


I've tried

$ dub test -b unittest -c library

but that re-creates ./dubtest not ./dubtest-test-library.



Re: Can I convert string to expression somehow?

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 12 December 2020 at 09:05:19 UTC, Godnyx wrote:
I'm trying to create a cool function that will let us do 
formatting sorter and faster. The function will work like that:


outln("My name is {name} and my age is {age}");

this will be equivalent to:

writeln("My name is ", name, " and my age is ", age);

or:

writefln("My name is %s and my age is %d", name, age);



There was a DIP to bring something akin to this into the 
language, but

there were also some decent counter proposals.

See for example here: 
http://dpldocs.info/this-week-in-d/Blog.Posted_2019_12_16.html





Re: Concatenation/joining strings together in a more readable way

2019-12-25 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote:
Are there any other ways to join two strings without Tilde ~ 
character?
I can't seems to find anything about Tilde character 
concatenation easily, nor the alternatives to it. Can someone 
share some knowledge on this or at least point out useful 
links/resources?


Tilde operator is documented under cat expression: 
https://dlang.org/spec/expression.html#cat_expressions


An alternative would be std.algorithm.joiner: 
https://dlang.org/phobos/std_algorithm_iteration.html#.joiner


Re: Bug or Feature: unsigned integer overflow

2019-12-14 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 14 December 2019 at 10:32:10 UTC, berni44 wrote:
On Saturday, 14 December 2019 at 09:33:13 UTC, Tobias Pankrath 
wrote:

See: https://dlang.org/spec/lex.html#integerliteral

What I am aiming at: Is the spec wrong or am I 
misunderstanding it and did this change recently?


You are right. The implementation does not do what the specs 
tell here.
I filed a bug report: 
https://issues.dlang.org/show_bug.cgi?id=20449


Thank you!


Re: Bug or Feature: unsigned integer overflow

2019-12-14 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 14 December 2019 at 07:44:37 UTC, berni44 wrote:
On Saturday, 14 December 2019 at 07:09:30 UTC, Tobias Pankrath 
wrote:

void main()
{
auto x = 9223372036854775808; // long.max + 1
}


You need to tell, that this is an unsigned long literal, else 
the compiler treats it as an int:


void main()
{
auto x = 9223372036854775808UL; // long.max + 1
}


As far as I understand the spec, the type is inferred from the 
value range:



Literal Type
Usual decimal notation
0 .. 2_147_483_647 int
2_147_483_648 .. 9_223_372_036_854_775_807 long
9_223_372_036_854_775_808 .. 18_446_744_073_709_551_615 ulong


See: https://dlang.org/spec/lex.html#integerliteral

What I am aiming at: Is the spec wrong or am I misunderstanding 
it and did this change recently?


Bug or Feature: unsigned integer overflow

2019-12-13 Thread Tobias Pankrath via Digitalmars-d-learn

void main()
{
auto x = 9223372036854775808; // long.max + 1
}


onlineapp.d(3): Error: signed integer overflow


According to spec x should be of type ulong and this should 
compile? It indeed compiles if I add the uL postfix.


Is this a bug or indented behaviour?


Re: during: a io_uring wrapper library

2019-12-08 Thread Tobias Pankrath via Digitalmars-d-announce

On Sunday, 8 December 2019 at 10:35:24 UTC, tchaloupka wrote:
Main difference with C liburing echo server is that we're using 
preregistered IO buffer so the kernel has less work with it. 
Otherwise it should perform similarly.


[1] https://github.com/tchaloupka/during
[2] https://github.com/axboe/liburing
[3] 
https://github.com/tchaloupka/during/tree/master/examples/echo_server


I like the range interface.


Re: dud: A dub replacement

2019-11-18 Thread Tobias Pankrath via Digitalmars-d-announce

On Monday, 18 November 2019 at 19:54:38 UTC, Russel Winder wrote:

Probably yes. Though Cargo has taken many different decisions 
to Dub and mostly I think Cargo took better decisions.


Could you elaborate a bit, please? I am not familiar with Cargo 
though.


Use my private phobos version in dub project

2019-11-18 Thread Tobias Pankrath via Digitalmars-d-learn

Hi,

I wanted to hack a bit on phobos and wondered what the best way 
is to use my own version in a project managed by dub.


I have used the dlang/tools/setup.sh and got ../d/dmd, 
../d/phobos/ ../d/druntime etc. Now I want to hack on phobos and 
use that version in a project of mine to test the changes. What's 
the best way to do this? I've searched the wiki, but didn't find 
anything useful.


Thanks!




No UFCS with nested functions?

2019-11-04 Thread Tobias Pankrath via Digitalmars-d-learn
Why does the following not work? It works, if I move the 'prop' 
out of 'foo'.


---
struct S {
ubyte[12] bar;
}

bool foo (ref S s)
{
   static bool prop(const(ubyte)[] f) {
  return f.length > 1;
   }
return s.bar[].prop;
}
---

Thanks!




Re: Documentation: is it intentional that template constraints are displayed after the signature?

2019-11-01 Thread Tobias Pankrath via Digitalmars-d-learn

On Friday, 1 November 2019 at 09:17:03 UTC, Dennis wrote:
Template constraints are not allowed before the signature in 
the language, so it can be expected the documentation does not 
swap that order.


On Thursday, 31 October 2019 at 13:34:35 UTC, Tobias Pankrath 
wrote:

I was confused at first by the trailing

 if (!is(T == struct) && !is(T == interface) && !is(T == 
class) && !__traits(isStaticArray, T));


Or are you confused by the newline between the ) and the if?
I do think the indentation is a bit confusing, but I don't know 
a better one.
I always have difficulty myself when trying to cleanly format 
long signatures of template functions.


Ah yes, now I see it.


Documentation: is it intentional that template constraints are displayed after the signature?

2019-10-31 Thread Tobias Pankrath via Digitalmars-d-learn

e.g. here: https://dlang.org/library/object/destroy.html

I was confused at first by the trailing

 if (!is(T == struct) && !is(T == interface) && !is(T == class) 
&& !__traits(isStaticArray, T));


after I somehow managed to completely parse that page without 
recognizing all other constraints.


Re: std.container.array: Error: unable to determine fields of Test because of forward references

2019-10-31 Thread Tobias Pankrath via Digitalmars-d-learn

On Thursday, 31 October 2019 at 12:37:55 UTC, user1234 wrote:

struct S
{
 S*[] children;
}

because otherwise when you declare the array the compiler has 
not finished the semantic ana of S.


---
struct Test
{
Test[] t;
}
---

Works today. Putting pointers into the container (and thus having 
another indirection) is not an option, though.


std.container.array: Error: unable to determine fields of Test because of forward references

2019-10-31 Thread Tobias Pankrath via Digitalmars-d-learn

My Problem:

--- (https://run.dlang.io/is/CfLscj)
import std.container.array;
import std.traits;

struct Test
{
   Test[] t;
}

struct Test2
{
   Array!Test2 t;
}

int main()
{
return FieldTypeTuple!Test.length + FieldTypeTuple!Test2;
}
---

I've found https://issues.dlang.org/show_bug.cgi?id=19407 but I 
am not using separate compilation, just `dmd test.d`.


I want to have a tree structure like

---
struct S
{
S[] children;
}
---

but I do not want to rely on the GC and thus wanted to use a 
custom array type. What's the best way to do this?


Re: How Different Are Templates from Generics

2019-10-11 Thread Tobias Pankrath via Digitalmars-d-learn

On Friday, 11 October 2019 at 14:43:49 UTC, Just Dave wrote:
I come from both a C++ and C# background. Those have been the 
primary languages I have used.


Probably the D templates relate to C# generics the same way that 
C++ templates do.


Re: Functional Programming in D

2019-10-10 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 9 October 2019 at 18:57:01 UTC, SrMordred wrote:

https://garden.dlang.io/


This should be more prominent. Very nice.


Re: Blog Post: Beating std::visit Without Really Trying

2019-10-06 Thread Tobias Pankrath via Digitalmars-d-announce
On Sunday, 6 October 2019 at 00:52:38 UTC, Andrei Alexandrescu 
wrote:
Anyhow, currently we would have to name it differently (e.g. 
dts - https://github.com/wilzbach/dts). Maybe the upcoming 
SAoC project will change this and allow multiple versions of a 
library to co-exist in a binary.


Adding it as a new facility is a possibility, but only if the 
challenges of keeping the existing interface are too large.


I just want to chime in as a returning D user, who stumbled upon 
Nullable, Typedef and Algebraic.


I think is is important to have high quality and well supported 
versions of these kinds of type constructors in the standard 
library, because to really shine support for them has to be 
pervasive. I could roll my own (or use some package from 
code.dlang.org), but one of the key features have to be that they 
'just work'. I want to std.conv.to them [1], use them in a json 
serialization library out of the box, etc, etc.


[1] https://issues.dlang.org/show_bug.cgi?id=11704


Re: Using enforce or assert to check for fullness when appending to fixed length array container

2019-10-04 Thread Tobias Pankrath via Digitalmars-d-learn

On Friday, 4 October 2019 at 10:00:08 UTC, Per Nordlöw wrote:
Is the usage of `enforce` to check for out of bounds (fullness) 
idiomatic D or should an `assert()` be used instead?


I'd say it should follow -boundscheck: 
https://dlang.org/dmd-linux.html#switch-boundscheck


Does that set an version identifier?


Re: How to get the address of an instance of a class

2019-09-25 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 25 September 2019 at 17:32:25 UTC, dokutoku wrote:
I wrote the following code to get the address of a class 
instance, but it doesn't work.
Please let me know if there is a way to write it to work 
properly.


private import std;

```
class C
{
C* this_pointer()
{
return this;
}
}

void main()
{
C Z = new C();
writeln( == Z.this_pointer());
}
```


Classes are always references. I think you can just cast 'Z' to 
void* to get the address.


Conversely  should be an address on the stack.



Re: Inspecting __traits(isDeprecated) and deprecation warnings

2019-09-25 Thread Tobias Pankrath via Digitalmars-d-learn

On Tuesday, 24 September 2019 at 17:01:46 UTC, Anonymouse wrote:
I want to write a piece of code that reflects on the names of 
members of a passed struct, where some are depreacted.


https://run.dlang.io/is/P9EtRG

struct Foo
{
string s;
int ii;
bool bbb;

deprecated("Use `s`")
string ;
}

template longestMemberLength(T)
{
enum longestMemberLength = ()
{
size_t maxLength;

foreach (immutable i, immutable name; 
__traits(allMembers, T))

{
static if (!__traits(isDeprecated, 
__traits(getMember, T, name)))

{
maxLength = max(maxLength, name.length);
}
}

return maxLength;
}();
}

static assert (longestMemberLength!Foo == "bbb".length);

onlineapp.d(23): Deprecation: variable `onlineapp.Foo.` is 
deprecated - Use s


Is there any way to inspect the deprecated-ness of a member 
this way? I only have what __traits(allMembers) gives me.


Does your code work or does it not? I don't seem to unterstand 
neither what the question here is nor what the desired result is. 
Is the problem that the static reflections triggers the 
deprecation warning?


Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Tobias Pankrath via Digitalmars-d-learn

On Saturday, 21 September 2019 at 09:03:13 UTC, Ron Tarrant wrote:
Ah! Thanks, ag0aep6g. I was wondering about that when I was 
writing the code. (If I already knew this, I'd forgotten.) I 
did as you suggested, took out all '*' and '&' and it works 
perfectly.


Is this what you want?
---
current.setPrev(current);
---


dub with sub packages: sub package with targetType "executable" builds with configuration ""

2019-09-21 Thread Tobias Pankrath via Digitalmars-d-learn

Hi,

I've got a dub package with the following configuration file

---
{
   "description": "A minimal D application.",
   "license": "proprietary",
   "authors": [
  "me"
   ],
   "copyright": "Copyright © 2019, me",
   "name": "test",
   "targetType"  : "none",

   "dependencies": {
   "test:mylib"  : "*"
  ,"test:myexe1" : "*"
   },

   "subPackages": [
  {
  "name": "mylib"
 ,"targetType"  : "library"
 ,"sourcePaths" : ["mylib/source"]
 ,"importPaths" : ["mylib/source"]
  }
  ,{
  "name"   : "myexe1"
 ,"targetType" : "executable"
 ,"sourcePaths": ["myexe1/source"]
 ,"importPaths": ["myexe1/source"]
 ,"dependencies": {
   "test:mylib" : "*"
 }
  }
   ]
}
---

when building this, dub gives me

---
 dub build --force
Performing "debug" build using /usr/bin/dmd for x86_64.
test:mylib ~master: building configuration "library"...
test:myexe1 ~master: building configuration ""...
Linking...
---

Note that the configuration of myexe1 is "". I want it to be 
'application', just like this:


---
% dub build test:myexe1
Building package test:myexe1 in /home/tobias/projects/test/
Performing "debug" build using /usr/bin/dmd for x86_64.
test:mylib ~master: target for configuration "library" is up to 
date.

test:myexe1 ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
---

Background: the project will contain multiple executables that 
use vibe-d. If they are not build as 'application' the version 
VibeDefaultMain seems to have no effect.


What's the best way to configure this?


Re: Line numbers in backtraces (2017)

2017-11-02 Thread Tobias Pankrath via Digitalmars-d-learn
Including Phobos? Your posted backtrace looks to me like 
templates instantiated within Phobos, so I think you'd need 
Phobos with debug symbols for those lines.


---
int main(string[] argv)
{
  return argv[1].length > 0;
}
---


~ [i] % rdmd -g -debug test.d
core.exception.RangeError@test.d(3): Range violation



No difference when I compile with 'dmd -g -debug' and run in 
manually.




Re: Line numbers in backtraces (2017)

2017-11-01 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 31 October 2017 at 11:21:30 UTC, Moritz Maxeiner 
wrote:
On Tuesday, 31 October 2017 at 11:04:57 UTC, Tobias Pankrath 
wrote:

[...]
??:? pure @safe void 
std.exception.bailOut!(Exception).bailOut(immutable(char)[], 
ulong, const(char[])) [0xab5c9566]
??:? pure @safe bool std.exception.enforce!(Exception, 
bool).enforce(bool, lazy const(char)[], immutable(char)[], 
ulong) [0xab5c94e2]



I've found this StackOverflow Question from 2011 [1] and if I 
remember correctly this could be fixed by adding 
-L--export-dynamic which already is part of my dmd.conf


[...]

[1] 
https://stackoverflow.com/questions/8209494/how-to-show-line-numbers-in-d-backtraces


Does using dmd's `-g` option (compile with debug symbols) not 
work[1]?


[1] This is also what the answer in your linked SO post suggest?


Of course I've tried this.


Line numbers in backtraces (2017)

2017-10-31 Thread Tobias Pankrath via Digitalmars-d-learn

Hi,

I'm using ArchLinux and the recent DMD from the Arch repositories 
and my backtraces show no line numbers. I now that is an old 
issue, but I'm back to D after a long pause and I thought that 
this used to work out of the box.


My backtraces look likes this:

??:? pure @safe void 
std.exception.bailOut!(Exception).bailOut(immutable(char)[], 
ulong, const(char[])) [0xab5c9566]
??:? pure @safe bool std.exception.enforce!(Exception, 
bool).enforce(bool, lazy const(char)[], immutable(char)[], 
ulong) [0xab5c94e2]



I've found this StackOverflow Question from 2011 [1] and if I 
remember correctly this could be fixed by adding 
-L--export-dynamic which already is part of my dmd.conf


cat /etc/dmd.conf

[Environment32]
DFLAGS=-I/usr/include/dlang/dmd -L-L/usr/lib32 
-L--export-dynamic -fPIC


[Environment64]
DFLAGS=-I/usr/include/dlang/dmd -L-L/usr/lib -L--export-dynamic 
-fPIC


which is in fact read by dmd:

% dmd -v
DMD64 D Compiler v2.076.1
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright

Documentation: http://dlang.org/
Config file: /etc/dmd.conf


How do I get useful back traces back?


Thanks,
Tobias

[1] 
https://stackoverflow.com/questions/8209494/how-to-show-line-numbers-in-d-backtraces


[std.regex] Set operations with unicode properties.

2017-10-30 Thread Tobias Pankrath via Digitalmars-d-learn

Greetings,

I need to match any character, except control characters and some 
other exceptions and thought this would be a good usecase to use 
character classes and set operations.


Can I combine this with unicode properties?, e.g: any Charactor 
that is not a control character and not ';' or ':'?

---
string regex = "[\p{Any}--\p{Control}--[;:]]";
---

Is this possible somehow?

Thanks,
- Tobias


Re: Deprecation of implicit string concatenation

2017-04-02 Thread Tobias Pankrath via Digitalmars-d

On Sunday, 2 April 2017 at 09:22:38 UTC, Johan Engelen wrote:

Did we lose the ability to break strings across lines?


[1] 
https://dlang.org/changelog/2.072.0.html#deprecated_implicit_cat


Delimited strings are the way to go.

http://dlang.org/spec/lex.html#StringLiteral


Re: Researcher question – what's the point of semicolons and curly braces?

2016-05-04 Thread Tobias Pankrath via Digitalmars-d

On Wednesday, 4 May 2016 at 08:48:58 UTC, deadalnix wrote:

It should be obvious that curly braces are a symbol of 
femininity, and it is why it is often unfairly neglected by 
community of programmers that perpetuate societal schema of 
patriarchal oppression.


Attributing a redundant element of the grammar to femininity just
demonstrates your inherent sexism and the sexism ingrained into
you due to your upbringing in the patriarch. Please check your
privileges and refrain from playing the "ally" while 
simultaneously

occupying space and attention that rightfully should belong to
true feminists.


Re: Walter's Famous German Language Essentials Guide

2016-04-27 Thread Tobias Pankrath via Digitalmars-d

On Wednesday, 27 April 2016 at 02:57:47 UTC, Walter Bright wrote:
To prepare for a week in Berlin, a few German phrases is all 
you'll need to fit in, get around, and have a great time:


1. Ein Bier bitte!
2. Noch ein Bier bitte!
3. Wo ist der WC!


That makes cologne so tourist friendly. The waitress will refill 
your beer until you put a beermat on your glass. So only #3 is 
necessary.


Re: Collections question

2015-11-30 Thread Tobias Pankrath via Digitalmars-d
On Monday, 30 November 2015 at 16:06:43 UTC, Steven Schveighoffer 
wrote:

MyCollection!(int) c1;
auto c2 = c1;
c1 ~= 1;

assert(c2.contains(1)); // pass? fail?

BTW, I third Jonathan's and Timon's suggestion -- go with an 
external factory function. Use IFTI to its fullest!


-Steve


That should throw, because you're using an uninitialised 
reference (c1). It's the equivalent to:


Class C { .. }

C c1;
C c2 = c1;
c1.foo(); // call via nullptr

Or it needs to pass, but that's probably not worth it.


Re: Collections question

2015-11-28 Thread Tobias Pankrath via Digitalmars-d
On Friday, 27 November 2015 at 20:14:21 UTC, Andrei Alexandrescu 
wrote:
There's this oddity of built-in hash tables: a reference to a 
non-empty hash table can be copied and then both references 
refer to the same hash table object. However, if the hash table 
is null, copying the reference won't track the same object 
later on.


Fast-forward to general collections. [...]

Andrei


I'd prefer the factory method and we shouldn't allow lazy 
initialization. That's only confusing, if it sometimes works and 
sometimes won't work. Null container should throw.


Re: emplace, immutable members and undefined behaviour

2015-11-15 Thread Tobias Pankrath via Digitalmars-d-learn


this compiles and runs fine. Because emplace expects a typed 
pointer, it actually modifies (*p).x and (*p).y

As far as I understand, this causes undefined behavior.

Are there any (safe) alternatives to this code other than 
making the immutable members mutable?


As long as there are no other references to the immutable members 
and you can guarantee that they are indeed in mutable memory 
(both guaranteed by malloc) you are safe. If you really don't 
want to write to any immutable member, you could do this:


struct Point {
double a;
double b;
}

Point* p = (allocate memory from somewhere);
emplace!Point(p, 1, 2);

immutable(Point)* immutableP = cast(immutable(Point)*) p;


Re: emplace, immutable members and undefined behaviour

2015-11-15 Thread Tobias Pankrath via Digitalmars-d-learn
On Sunday, 15 November 2015 at 10:59:43 UTC, Tobias Pankrath 
wrote:


Point* p = (allocate memory from somewhere);
emplace!Point(p, 1, 2);

immutable(Point)* immutableP = cast(immutable(Point)*) p;


You could also use the emplace version that takes untyped memory: 
http://dlang.org/phobos/std_conv.html#.emplace The last one.


Re: my first D program (and benchmark against perl)

2015-11-12 Thread Tobias Pankrath via Digitalmars-d-learn

or with ~ operator:

import std.stdio;

[...]


Did anyone check that the last loop isn't optimized out? Could 
also be improved further if you make the function take an output 
range and reuse one appender for every call, but that might be to 
far off the original perl solution.


Re: Difference between input range and forward range

2015-11-12 Thread Tobias Pankrath via Digitalmars-d
On Thursday, 12 November 2015 at 15:43:50 UTC, Jonathan M Davis 
wrote:
On Thursday, 12 November 2015 at 15:29:19 UTC, Steven 
Schveighoffer wrote:

(and diabolically, 99% of the time it DOES do what you want).


_This_ is the big problem. It wouldn't surprise me in the least 
if the vast majority of range-based code out there does not 
actually work properly with ranges which aren't implicitly 
saved when they're copied. I mean, technically, you have to do 
stuff like haystack.save.startsWith(needle) instead of 
haystack.startsWith(needle) if you want your code to work right 
with all forward ranges, but almost no one does that. And 99% 
of the time the code works - but not always.


- Jonathan M Davis


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


Re: String interpolation

2015-11-10 Thread Tobias Pankrath via Digitalmars-d-learn

On Tuesday, 10 November 2015 at 10:21:32 UTC, tired_eyes wrote:

Hi,
The only example of string interpolation I've found so far is 
on Rosetta Code:


void main() {
import std.stdio, std.string;

"Mary had a %s lamb.".format("little").writeln;
"Mary had a %2$s %1$s lamb.".format("little", 
"white").writeln;

}

Is this a "proper" way of string interpolation in D? This looks 
a little clumsy. Are there any better approaches? Quick 
skimming through the docs didn't give anything.


std.string.format and std.format are the standard options. What 
are you missing?


Re: Tree datatype

2015-10-14 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 14 October 2015 at 14:42:31 UTC, Namal wrote:

Hello,

I don't remember exactly but I think when I first saw D code 
there was tree datatype implemented without pointers. Is it 
possible to make a tree struct without pointers?


struct Tree {
   Tree[] children;
}

That works quite well as long as you don't have to change the 
tree.


Re: Today's programming challenge - How's your Range-Fu ?

2015-04-18 Thread Tobias Pankrath via Digitalmars-d
Also another issue is that lower case letters and upper case 
might have different size requirements or look different 
depending on where on the word they are located.


For example, German ß and SS, Greek σ and ς. I know Turkish 
also has similar cases.


--
Paulo


While true, it does not affect wrap (the algorithm) as far as I 
can see.


Re: Today's programming challenge - How's your Range-Fu ?

2015-04-18 Thread Tobias Pankrath via Digitalmars-d
Wait, I thought the recommended approach is to normalize first, 
then do

string processing later? Normalizing first will eliminate
inconsistencies of this sort, and allow string-processing code 
to use a
uniform approach to handling the string. I don't think it's a 
good idea
to manually deal with composed/decomposed issues within every 
individual

string function.



1. Problem: Normalization is not closed under almost all 
operations. E.g. concatenating two normalized strings does not 
guarantee the result is in normalized form.


2. Problem: Some unicode algorithms e.g. string comparison 
require a normalization step. It doesn't matter which form you 
use, but you have to pick one.


Now we could say that all strings passed to phobos have to be 
normalized as (say) NFC and that phobos function thus skip the 
normalization.


Re: Today's programming challenge - How's your Range-Fu ?

2015-04-18 Thread Tobias Pankrath via Digitalmars-d
Isn't this solved commonly with a normalization pass? We should 
have a normalizeUTF() that can be inserted in a pipeline.


Yes.

Then the rest of Phobos doesn't need to mind these combining 
characters. -- Andrei


I don't think so. The thing is, even after normalization we have 
to deal with combining characters because in all normalization 
forms there will be combining characters left after normalization.




Re: Interlocked (compare) exchange

2015-04-17 Thread Tobias Pankrath via Digitalmars-d-learn

On Friday, 17 April 2015 at 10:36:33 UTC, Szymon Gatner wrote:

Hi,

are there equivalents of Interlocked.Exchange [1] and 
Interlocked.CompareExchange [2] in D? I can't find it in teh 
docs?


[1] 
https://msdn.microsoft.com/en-us/library/f2090ex9(v=vs.110).aspx


[2] 
https://msdn.microsoft.com/en-us/library/h7etff8w(v=vs.110).aspx


[2] sounds like compare-and-swap from 
http://dlang.org/phobos/core_atomic.html


Re: How D could gain more traction?

2015-04-15 Thread Tobias Pankrath via Digitalmars-d
On Wednesday, 15 April 2015 at 13:40:36 UTC, Ola Fosheim Grøstad 
wrote:

On Wednesday, 15 April 2015 at 13:18:55 UTC, Panke wrote:
There will always be a better solution in the future than the 
implementation included in the standard library today. However 
that is no argument against the kitchen sink.


That's dodging the foundational issue which is that different 
application areas have different needs. So then you either have 
to settle for a standard library that is heavily biased or that 
is only suitable for prototyping.


No. We were talking about parts of e.g. the python standard 
library that have been completely superseded by third party 
solutions at least for new projects.


Re: More Libraries - sub-forum request

2015-04-04 Thread Tobias Pankrath via Digitalmars-d

On Saturday, 4 April 2015 at 16:43:45 UTC, ParticlePeter wrote:

Hi,
there is this nice new link to More libraries link, but there 
is no place to discuss usage, exchange experiences or ask 
questions regarding these libraries ( unless I am missing 
something ). A sub-forum here would be very nice.


Or would this here be the right place ?

I am trying out dimgui on win8, dmd 2.066.1 and now 2.067. Got 
16 warnings, no error, BUT: Building .dub\lib\imgui_d.lib 
failed!


How to debug this ?

Regards, ParticlePeter


Tag your post with [library name]. If threads with such tags 
get overboard we can consider a forum.


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-28 Thread Tobias Pankrath via Digitalmars-d
D has documented unittests (they appear in the docs as if part 
of the Examples section).  The only excuses for example code in 
Phobos to be untested are supposed to be that it is an 
incomplete fragment or that it is old code from before we had 
the feature.


 — David


I added some just recently, because it wasn't possible to add 
unittest to the module level.


https://github.com/D-Programming-Language/phobos/blob/master/std/container/package.d


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-27 Thread Tobias Pankrath via Digitalmars-d
Looked also in the source code to find out that startsWith is 
locale sensitive, something ignored in phobos.


Why would I need a locale for startsWith? Please file a bug, if 
that's actually needed for unicode strings.


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-27 Thread Tobias Pankrath via Digitalmars-d

[skip]
I'm not a native English speaker, but a range can start with a 
needle? Where is the haystack? :)


Yes the output is awful, but that does not imply some kind of 
concepts is needed to make the documentation easier to 
understand. And Python's startsWith makes no use of a protocol. 
See here http://www.rafekettler.com/magicmethods.html for an 
explanation.


Now that we're talking about creating your own sequences in 
Python, it's time  to talk about protocols. Protocols are 
somewhat similar to interfaces in other  languages in that 
they give you a set of methods you must define. However, in  
Python protocols are totally informal and require no explicit 
declarations to  implement. Rather, they're more like 
guidelines.


It's similar to what we have, just with even less help from the 
language. (We can at least statically check that some arguments 
is e.g. a range).


Anyway, in the Python built-in lib I didn't find any 
levenshtheinDistance
Please calculate the levenshtein distance of aaabc and ababc 
both in python and D.


Then come back and tell me it was too hard in D compared to 
Python.


, boyermooreFinder or 
schschchcscshshscscshshscscssscsshcswarzSort.


Both are well known and useful algorithms. You might not know 
them but that's actually no argument not to include them in 
phobos. Their presence does not make the documentation any harder 
to understand or harder to find a startsWith function.


I don't buy this There is a function I don't know, it's so hard 
to understand thing. That's like saying: I only need XML, don't 
put JSON in the stdlib because I will get confused! How should I 
anticipate that I don't need std.json when I just want to parse 
XML? I cannot even google that for me.







Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-27 Thread Tobias Pankrath via Digitalmars-d
Regarding the scscscshghshshshhswarzThing, here we discuss the 
readability and accessibility of the documentation, not the 
power of the library. Every other language will use a variation 
of  sortBy instead of the scscshwcwscThing. I'm happy that D 
has in the default lib functions like levenshteinDistance, but 
this will not attract the average or just starting to learn 
developer. On the contrary, sorting correctly some names is a 
more common task than calculating the Levenshtein distance, but 
there is no function for it in phobos.


You may have a point that schwartzSort has a bad name (I 
disagree), but putting another algorithm does not make the 
documentation worse per se. Dunno, what problem you have with the 
levenshteinDistance.


On the contrary, sorting correctly some names is a more common 
task than calculating the Levenshtein distance, but there is no 
function for it in phobos.


What do you mean by correct? http://unicode.org/reports/tr10/? 
We even have something obscure like levenshteinDistance but no 
implementation for the unicode collation algorithm, which all 
newcomers are looking for! is a) a questionable comparison 
between a relative simple algorithm and a monster and b) wrong, 
because 99% of programmers don't even know about the algorithm 
itself, thus they aren't looking for it.


BTW. python's startwith does the Köln example wrong. Kö and 
Ko\u0308 dont match.


Re: Advise for syntax highlighting

2015-03-27 Thread Tobias Pankrath via Digitalmars-d

On Friday, 27 March 2015 at 15:23:56 UTC, Jacob Carlborg wrote:

On 2015-03-27 16:04, Dicebot wrote:

not at all. The fact it is reserved is already denoted by __, 
otherwise

it is just another vairable/symbol.


Doesn't this symbol also have special semantics?


A more pragmatical view would be:

if(__ctf ... Was it __ctfe or __ctfe__?

Easily answered if it has special highlighting.


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Tobias Pankrath via Digitalmars-d




I think it would be a good addition. Would we want to allow 
specifying the inclusion like below:


auto between(string inclusion = [])(int v, int a, int b) {


+1


Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 25 March 2015 at 14:40:28 UTC, Per Nordlöw wrote:

On Wednesday, 25 March 2015 at 13:55:29 UTC, bearophile wrote:

Nordlöw:

I have graph traversal algorithm that needs to keep track of 
the N best node visit.


std.algorithm.topNCopy?

Bye,
bearophile


Notice that, ideally, I would like my list of top-nodes to have 
a fixed size during the whole algorithm (99.9 % of time) as 
soon it has reached the length of N.


What's wrong with binary heaps?


Re: Making byLine faster: we should be able to delegate this

2015-03-23 Thread Tobias Pankrath via Digitalmars-d
I made the same test in C# using a 30MB plain ASCII text file. 
Compared to fastest method proposed by Andrei, results are not 
the best:


D:
readText.representation.count!(c = c == '\n') - 428 ms
byChunk(4096).joiner.count!(c = c == '\n') - 1160 ms

C#:
File.ReadAllLines.Length - 216 ms;

Win64, D 2.066.1, Optimizations were turned on in both cases.

The .net code is clearly not performance oriented 
(http://referencesource.microsoft.com/#mscorlib/system/io/file.cs,675b2259e8706c26), 
I suspect that .net runtime is performing some optimizations 
under the hood.


Does the C# version validate the input? Using std.file.read 
instead of readText.representation halves the runtime on my 
machine.


Re: Contributing to Phobos Documentation

2015-03-22 Thread Tobias Pankrath via Digitalmars-d-learn
On Saturday, 21 March 2015 at 17:48:41 UTC, Craig Dillabaugh 
wrote:

Motivated by this thread:

http://forum.dlang.org/thread/measc3$qic$1...@digitalmars.com

I was hoping to see if I could do some work on the Phobos 
documentation, but I am curious to know what the easiest way 
for someone with limited/no ddoc experience to get involved in 
this would be.  I checked the CONTRIBUTING.md file in phobos 
and it is a bit on the 'light' side.





http://wiki.dlang.org/Building_DMD


Re: A few notes on choosing between Go and D for a quick project

2015-03-21 Thread Tobias Pankrath via Digitalmars-d

Well then write that answer.


Not true, right now.



Re: Lazy functions, lazy arrays

2015-03-20 Thread Tobias Pankrath via Digitalmars-d-learn

On Friday, 20 March 2015 at 12:15:22 UTC, Dennis Ritchie wrote:

On Friday, 20 March 2015 at 10:38:17 UTC, John Colvin wrote:
I don't understand what you mean. You mean a function that 
isn't compiled if it isn't used anywhere?


Yes. That's exactly what I mean.


Use case?


Re: Lazy functions, lazy arrays

2015-03-20 Thread Tobias Pankrath via Digitalmars-d-learn
Now I am totally confused. lazy and eager evaluation are 
unrelated to compile time  and run time.


Re: A few notes on choosing between Go and D for a quick project

2015-03-20 Thread Tobias Pankrath via Digitalmars-d
You may want to answer there, not here. I've also posted a 
response.


Andrei


Nitpick: Your solutions that use readText validate their input 
and the python version probably doesn't. You could mention that 
(I cannot comment on SO).


Interestingly readText is faster than byChunck.joiner regardless.

Nitpick 2: http://www.unicode.org/versions/Unicode7.0.0/ch05.pdf 
(chapter 5.8) splitLines is still incomplete, missing to break on 
U+0085, U+000B, U+000C. Would a PR for this be accepted?


I'd say the coolest answer to this question would have been: D 
has not only one of the fastest, but the only correct solution to 
this that works with UTF8, UTF16 and UTF32 at the same time.


DMD build is broken

2015-03-20 Thread Tobias Pankrath via Digitalmars-d

I'm on master.

make -f posix.mak
- make -C src -f posix.mak
- dmd idgen.d
- lots of errors regarding druntime.

Reason is that my HOST_DC reads in src/dmd.conf which in turn 
points to the ~master druntime which is incompatible with my 
dmd-v2.66.




Re: DMD build is broken

2015-03-20 Thread Tobias Pankrath via Digitalmars-d

On Friday, 20 March 2015 at 18:01:35 UTC, Tobias Pankrath wrote:

I'm on master.

make -f posix.mak
- make -C src -f posix.mak
- dmd idgen.d
- lots of errors regarding druntime.

Reason is that my HOST_DC reads in src/dmd.conf which in turn 
points to the ~master druntime which is incompatible with my 
dmd-v2.66.


Ah, nevermind, that dmd.conf was placed there by myself when dmd 
wasn't used to build dmd m(


Re: How to use UFCS and std.algorithm.sort?

2015-03-10 Thread Tobias Pankrath via Digitalmars-d-learn

.array
.sort


buildin arrays have a .sort-property that is called.


Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Tobias Pankrath via Digitalmars-d-learn



I have three questions?

If I change the iterator which I get from algorithm, the owner 
data will change or not?


How to use std.algorithm.fill with char types?

What is the type of char array holds why it does not matches 
char?


Regards
Kadir Erdem


I have no time to dig into this, but:

is(typeof(arr.front = 'a')) does _not_ check if arr.front is of 
type char. It is true if you can assign an 'a' to arr.front.


is(typeof(_expr_)) is another way to write __traits(compiles, 
_expr).


So, either the range returned by until has elements that are not 
assignable or the reason is that until returns a range of dchar, 
because all string types are treated as ranges of dchar.




Re: Error instantiating std.container.Array

2015-03-02 Thread Tobias Pankrath via Digitalmars-d-learn

I'm really clueless... :P


Something is wrong with your Material class, but you'll need to 
show us a reduced example.


Re: Shouldn't std.conv.emplace be @nogc?

2015-03-02 Thread Tobias Pankrath via Digitalmars-d-learn

On Monday, 2 March 2015 at 12:37:33 UTC, drug wrote:
I guess the reason why std.conv.emplace is not @nogc-ed is that 
nobody added it yet? I didn't see using of gc in the emplace 
sources.


It's a template and an instance will be @nogc, if possible.


Re: Error instantiating std.container.Array

2015-03-02 Thread Tobias Pankrath via Digitalmars-d-learn
On Monday, 2 March 2015 at 14:08:29 UTC, Francesco Cattoglio 
wrote:
I'm trying to instantiate a std.container.Array of a given 
class (named Material), by a simple

Array!Material _myStuff;
I get two compile errors stating the following:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(85):
Error: template std.algorithm.initializeAll cannot deduce 
function from argument types !()(Material[]), candidates are:

  C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(1502):
std.algorithm.initializeAll(Range)(Range range)
if (isInputRange!Range
   hasLvalueElements!Range
   hasAssignableElements!Range)
  C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(1530):
std.algorithm.initializeAll(Range)(Range range)
if (is(Range == char[]) || is(Range == wchar[]))
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(825): 
Error: template std.algorithm.copy cannot deduce function from 
argument types !()(Range, Range), candidates are:

  C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(7808):
std.algorithm.copy(Range1, Range2)(Range1 source, Range2 
target)
if (isInputRange!Range1  isOutputRange!(Range2, 
ElementType!Range1))


Any idea about what might be happening? I can't give a quick 
minimal example of the code since it is quite complex (and I 
failed at using dustmite trying to minimize it)


Try to reduce your Material class for a small failing example. 
It's probably your constructors or opAssign or something like 
that. Anyway, it's a bug if template errors from the 
implementation bubble up, so please file a report.


Re: D constness: head tail

2015-03-02 Thread Tobias Pankrath via Digitalmars-d-learn

On Monday, 2 March 2015 at 10:15:00 UTC, ketmar wrote:
or, tl;dr: `const` in D is working as it was designed to work. 
there are
no changes planning for it, and it will not be turned to 
c++-like const.


It's working as it's designed to work, although the design is 
somewhat lacking:


https://github.com/D-Programming-Language/phobos/blob/master/std/container/array.d#L505


Re: Error instantiating std.container.Array

2015-03-02 Thread Tobias Pankrath via Digitalmars-d-learn
On Monday, 2 March 2015 at 15:14:49 UTC, Francesco Cattoglio 
wrote:

On Monday, 2 March 2015 at 15:01:55 UTC, Tobias Pankrath wrote:

I'm really clueless... :P


Something is wrong with your Material class, but you'll need 
to show us a reduced example.


After a really long time I finally found what was wrong.

http://dpaste.dzfl.pl/16d202b7124d

Wow, I honestly could have NEVER foreseen this.
This is all it takes for a class being unusable in a 
std.container.Array

class MyClass
{
void init();
}


.init is a special property of every type: 
http://dlang.org/property.html#init




Re: Cannot instantiate a std.container.Array of a class with a init() function member.

2015-03-02 Thread Tobias Pankrath via Digitalmars-d
On Monday, 2 March 2015 at 15:46:28 UTC, Francesco Cattoglio 
wrote:

Taken from
http://forum.dlang.org/thread/gjrbmskictrbcyedu...@forum.dlang.org

trying to instantiate an Array!MyClass fails with a rather 
obscure error message if the MyClass has a member function 
void init():


http://dpaste.dzfl.pl/16d202b7124d

Is this a std library bug, or should this be considered a 
mistake on the library user side to name a member function 
init?


I consider both your type and the library buggy. The type because 
.init is a property of every type with a special meaning, which 
is violated by your class. The library because it emits such a 
useful error message. Please file a bug report.


Re: Opening temporary files for std.process.spawnProcess input/output

2015-02-25 Thread Tobias Pankrath via Digitalmars-d-learn

On Wednesday, 25 February 2015 at 13:56:06 UTC, wobbles wrote:

Hi,
Any reason why the following wont work?

void main(string[] args)
{
auto pidIn = File.tmpfile();
auto pidOut = File.tmpfile();
auto pid = spawnProcess([ls, ./], pidIn, pidOut, 
std.stdio.stdout, null, Config.newEnv);


if(wait(pid) == 0)
writefln(%s, pidOut.readln());
}

The pidOut.readln() throws this exception:
object.Exception@/usr/include/dmd/phobos/std/stdio.d(1377): 
Attempt to read from an unopened file.


I figured tmpfile() would be open for read/write by default?
Also, theres no way to pass in args to File.tmpfile() to make 
them read/write.


Any ideas?


maybe only for writing: 
http://www.cplusplus.com/reference/cstdio/tmpfile/


DList.Range magically becomes empty.

2015-02-25 Thread Tobias Pankrath via Digitalmars-d-learn

import std.container;
import std.stdio;


void main()
{
   DList!int list;
   Array!(DList!int.Range) stack;
   foreach(i; 0 .. 4)
   {
  list.stableInsertBack(i);
  stack.insertBack(list[]);
   }

   writefln(list: %s, list[]); // fine
   writefln(stack: %s, stack[]); //fine

   foreach(s; stack[])
  writefln(s: %s, s); // all s are empty?

   writefln(stack: %s, stack[]); //not fine
}

It prints:

list: [0, 1, 2, 3]
stack: [[0], [0, 1], [0, 1, 2], [0, 1, 2, 3]]
s: []
s: []
s: []
s: []
stack: [[], [], [], []]


Re: Mac Apps That Use Garbage Collection Must Move to ARC

2015-02-24 Thread Tobias Pankrath via Digitalmars-d

I suspect it would be a terrible performance hit.


It would be nice to have some numbers backing this up.



This the approach taken by Active Oberon and Modula-3.

Pointers are GC by default, but can be declared as untraced 
pointers in code considered @system like in D.




Do they have concurrent gc and emit barriers for each write to a
default pointer? Do they have precise scanning and don't scan the
untraced pointers? Are the meaningful performance comparisons
between the two pointer types that would enable us to estimate
how costly emitting those barriers in D would be?


Re: Mac Apps That Use Garbage Collection Must Move to ARC

2015-02-24 Thread Tobias Pankrath via Digitalmars-d
The latest implementation had a concurrent incremental 
generational GC.


https://modula3.elegosoft.com/cm3/doc/help/cm3/gc.html



According to this they never had a concurrent or incremental GC 
on x86.




Re: Struct inheritance

2015-02-24 Thread Tobias Pankrath via Digitalmars-d-learn

On Tuesday, 24 February 2015 at 12:05:51 UTC, amber wrote:

Hi,

Is it possible in D to have inheritance using value types, i.e. 
structs?


No runtime polymorphism, but a kind of sub typing via alias this.

struct S { void foo() { writeln(S.foo); }
struct T { S s; alias s this; }

T t;
t.foo(); // prints S.foo


Also I don't quite understand how copy ctors work in D. Do I 
need to implement opAssign(S other) {}, or this(this) {} and 
what's the difference between these two?


If available, opAssign will be used in an assignment like x = y;
You're custom opAssign can take arbitrary parameter types, so 
typeof(y) does not have to be typeof(x).


postblit is used for copy construction. This could be assignment 
if no opAssign is provided (not sure about this), but also e.g. 
passing parameter by value or returning from a function.


Re: Mac Apps That Use Garbage Collection Must Move to ARC

2015-02-24 Thread Tobias Pankrath via Digitalmars-d

On Tuesday, 24 February 2015 at 12:31:06 UTC, Paulo  Pinto wrote:
Sorry about the caps, couldn't find a better way to emphasis. 
Not sure where you found out the information about x86, or why 
it should matter.


I found an (apparently older) version of the documentation 
earlier that looked exactly the same, so I didn't mind to read 
your link carefully enough.


The current collector is, by default, INCREMENTAL and 
GENERATIONAL. The interruptions of service should be very 
small, and the overall performance should be better than with 
the previous collectors.


Yes, however from your page now:


Now @M3novm is the default.


And if you follow the link:


@M3novm implies @M3noincremental and @M3nogenerational.


Maybe, that's an documentation error. This was the place where 
the other version

mentioned that x86 is not supported.

While I like that you constantly remind us about achievements of 
older programming languages, you'll often do it with a that 
problem was solved in Language X 20 years ago-attitude, but 
almost never elaborate how that solution could be applied to D. 
When taking a closer look, I often find that those languages 
solved an similar but different problem and the solution do not 
apply to D at all. For example the last time in the discussion on 
separate compilation, templates and object files you blamed the C 
tool chain and pointed to pascal/delphi. But they didn't solved 
the problem, because they didn't faced it in the first place, 
because they didn't had the template and meta-programming 
capabilities of D.


At the problem at hand: I don't see how Module3's distinction 
between system and default pointer types or the lessons they 
learned help in any way to improve the current D GC.






Re: strings and array literal mutability

2015-02-24 Thread Tobias Pankrath via Digitalmars-d-learn

On Tuesday, 24 February 2015 at 22:12:57 UTC, Freddy wrote:

Why are strings immutable but array literals are not?


Because string is an alias for immutable(char).


Re: Mac Apps That Use Garbage Collection Must Move to ARC

2015-02-23 Thread Tobias Pankrath via Digitalmars-d
Urgh. Product types masquerading as sum types. Give me a break 
will ya. -- Andrei


1. The product solution is more pleasant to work with, if you 
have no sugar for sum types like pattern matching.


2. It's the same as with exception specifications: Product types 
make ignoring the error path easier thus are more popular.


Re: Mac Apps That Use Garbage Collection Must Move to ARC

2015-02-23 Thread Tobias Pankrath via Digitalmars-d
On Monday, 23 February 2015 at 08:27:52 UTC, Ola Fosheim Grøstad 
wrote:
On Monday, 23 February 2015 at 01:41:17 UTC, Adam D. Ruppe 
wrote:

On Monday, 23 February 2015 at 01:38:35 UTC, Manu wrote:
All my ref counting types fiddle with the ref in every 
assignment, or every function call and return.


Hmm, the optimizer could potentially tell inc X; dec X; is 
useless and remove it without knowing what it is for.


INPUT:

try{
nonsharedobj._rc++;
…
}
finally {
nonsharedobj._rc--;
if(nonsharedobj._rc==0) destroy…
}

OPTIMIZED:

try{
…
}
finally {
if(nonsharedobj._rc==0) destroy…
}


Thanks to the messed up modular arithmetics that D has chosen 
you cannot assume the a non-shared live object does not have a 
rc==0 due to wrapping integers, in the general case.


You mean when there are more than 2^64 references to the object?


Re: Searching for Elements in Containers

2015-02-22 Thread Tobias Pankrath via Digitalmars-d-learn

On Sunday, 22 February 2015 at 13:53:51 UTC, Nordlöw wrote:
Is there some function similar to std.algorithm.find() which 
returns an element index instead of a range? I guess 0 means no 
hit and 1, 2, 3 means hits at indexes 0, 1, 2 etc.


I want this to avoid having to create ranges ([]) when 
searching for a specific element in std.container.Array.


You could use a range and countUntil.


  1   2   3   4   >