Re: D for scripting?

2017-01-20 Thread Edwin van Leeuwen via Digitalmars-d

On Friday, 20 January 2017 at 03:59:12 UTC, 岩倉 澪 wrote:
I keep my scripts in ~/scripts so that I can just pull them 
from github and go on my merry way, with symlinks in 
/usr/local/bin, but rdmd doesn't -I the real directory, it does 
-I/usr/local/bin, and if I symlink a script.d as 
/usr/local/bin/script, it can't find the module.

I can pass -I/home/mio/scripts on the shebang line at least...


FYI dub also has a script option, which would allow you to 
include any dub projects in your script, e.g.:

https://github.com/Abscissa/scriptlike/blob/master/USAGE.md#a-basic-script-in-d

Of course then you'd have to turn the included .d files into a 
dub project.


Re: Learning resources for std.experimental.allocator

2017-01-05 Thread Edwin van Leeuwen via Digitalmars-d

On Thursday, 5 January 2017 at 11:09:01 UTC, xtreak wrote:
Can someone explain me the actual benefits of using this and if 
so any benchmarks explaining the advantage.


Benefits compared to what? Compared to using the GC?


Re: Terminix Year In Review

2017-01-02 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 2 January 2017 at 13:35:21 UTC, Mike Parker wrote:

On Monday, 2 January 2017 at 00:53:04 UTC, Gerald wrote:
Terminix is a GTK 3 tiling terminal emulator that has been 
designed following the GNOME Human Interface Guidelines. The 
project started just over a year ago at the start of 2016 and 
I thought it would be fun to look back at the project history, 
highlights, low-lights and goals for 2017.


https://gnunn1.github.io/terminix-web/news/year-in-review/


https://www.reddit.com/r/programming/comments/5ll9j8/terminix_year_in_review_looking_back_on_a_tiling/


It was also posted to:
https://www.reddit.com/r/linux/comments/5liblz/terminix_year_in_review/


Re: drepl fails because of missing lib linenoise

2016-12-08 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 8 December 2016 at 12:31:01 UTC, Nordlöw wrote:

drepl fails to build as

https://github.com/drepl/drepl/issues/58

Any ideas why?


Looks like you don't have liblinenoise installed.

Some basic notes on how to install on linux/macosx can be found 
here:

https://github.com/BlackEdder/todod#linenoise


Re: Tutorial: Form upload in vibe.d

2016-12-07 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Tuesday, 6 December 2016 at 22:28:04 UTC, aberba wrote:

https://aberba.github.io/2016/form-upload-in-vibe-d/


Thanks for the tutorial! Please keep them coming.


Re: Compiling and linking libraries

2016-11-16 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 16 November 2016 at 14:27:41 UTC, Darren wrote:

Hey all,

This is a very beginner problem, but not one I know how to do 
on my own.  Could anyone give a step-by-step guide on how to 
compile libraries, and then use them in my project with DUB?


If you are happy to use dub I would just add the GL library as a 
dependency to my dub.json file. Then if you call dub it will 
download and compile the necessary file.


Example dub.json file:
```
{
"name": "myWindow",
"authors": [
"Darren"
],
"description": "A minimal D application.",
"copyright": "Copyright © 2016, Darren",
"dependencies": {
"derelict-gl3": "~>2.0.0-alpha.2"
}
}
```

This will build the necessary library into your library though, 
so it is not the same as using a static library.


Also see the "Creating an own project" section on 
https://code.dlang.org/getting_started


Re: PDF generation in D?

2016-11-11 Thread Edwin van Leeuwen via Digitalmars-d

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


Personally I would generate markdown and use a command line tool 
(pandoc) to compile it to pdf. Of course ggplotd can save figures 
in pdf format (using cairod)


Re: problem with isnan

2016-11-11 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Thursday, 10 November 2016 at 23:45:01 UTC, Charles Hixson 
wrote:
you might try using std.math.isNaN instead and see what it 
does.



It was default initialized by the class instance:

classCell
...
floatcurActivation;
...

The this method doesn't have any mention of a few variables 
that are supposed to be default initialized, or which 
curActivation is one.



std.math.isNaN should work for the default initialization (at 
least it does for doubles)




Re: Combining "chunkBy" and "until" algorithms

2016-11-04 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Friday, 4 November 2016 at 08:04:12 UTC, Jacob Carlborg wrote:
Currently I'm using a standard for loop iterating over the 
lines. I'm always looking at the current line and the next 
line. When the current line is the standard pattern and the 
next line is is not, I do a separate loop until I see a 
standard pattern again, collecting the lines with the 
non-standard pattern in an array.


Could you filter [1] for the non standard pattern? Filter is 
lazy, so will only start looking for the next when the current 
one has been "handled".


[1] https://dlang.org/phobos/std_algorithm_iteration.html#.filter



Re: Linux Kernel in D?

2016-11-01 Thread Edwin van Leeuwen via Digitalmars-d

On Tuesday, 1 November 2016 at 12:12:29 UTC, Heisenberg wrote:
Just an idea. Do you think it would have any advantage compared 
to the one that is written in C?


There have been a number of projects working on this. For example:
https://github.com/Vild/PowerNex


Re: Avoiding GC

2016-10-26 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 08:18:07 UTC, hardreset wrote:
Is there a page somewhere on how to program D without using the 
GC? How do I allocate / free structs / classes on the heap 
manually? New would be GCed memeory wouldnt it? Delete is being 
depreciated?


thanks.


There is the following:
https://wiki.dlang.org/Memory_Management


Re: From Python to Dlang

2016-10-18 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 18 October 2016 at 12:03:54 UTC, Alfred Newman wrote:

Hello and greetings,

I'm a brand new D developer coming from Python.

So, can you pls guys suggest me any resource like "D for a 
Python Developer" or so ? BTW, I just ordered the "D 
Programming Language" book from AA.


Cheers


Another great book, available for free online:
http://ddili.org/ders/d.en/index.html


Re: Tuple enhancement

2016-10-17 Thread Edwin van Leeuwen via Digitalmars-d
On Monday, 17 October 2016 at 13:35:12 UTC, Steven Schveighoffer 
wrote:


Why not something like this:

Val get(T, Val)(auto ref T item, string memberName, Val 
defaultValue)

{
   switch(memberName)
   {
   foreach(n; __traits(allMembers, T))
   {
  static if(is(typeof(__traits(getMember, item, n)) : Val))
case n: mixin("return item." ~ n ~ ";");
   }
   default:
 return defaultValue;
   }
}


I like the general solution, although I probably would just 
expect it to fail compiling if no member is present or return 
Val.init if no defaultValue is passed.




Re: [OT] Re: Mir GLAS vs Intel MKL: which is faster?

2016-09-26 Thread Edwin van Leeuwen via Digitalmars-d

On Monday, 26 September 2016 at 11:59:57 UTC, Johan Engelen wrote:
On Monday, 26 September 2016 at 11:56:39 UTC, Edwin van Leeuwen 
wrote:


Ah, I was not aware that DMD support was dropped completely. I 
think that is a real shame, and it makes it _much_ less likely 
that I will use mir in my own projects, let alone as a 
dependency in another library.


"_much_"
:'( :'(  Please don't write that to LDC devs.


I love LDC, I just also tend to use DMD for testing and won't 
force people to use ldc over dmd if they want to use a library I 
build.


Re: Mir GLAS vs Intel MKL: which is faster?

2016-09-26 Thread Edwin van Leeuwen via Digitalmars-d

On Monday, 26 September 2016 at 11:46:19 UTC, Johan Engelen wrote:
On Monday, 26 September 2016 at 11:11:20 UTC, Joseph Rushton 
Wakeling wrote:


The broader topic of what compiler features Mir GLAS uses 
could be the topic of an entire blog post in its own right, 
and might be very interesting.


I guess this is my terrain. I'll think about writing that blog 
post :)


Specific LDC features that I see in GLAS are:

- __traits(targetHasFeature, ...)  , see 
https://wiki.dlang.org/LDC-specific_language_changes#targetHasFeature


- @fastmath, see 
https://wiki.dlang.org/LDC-specific_language_changes#.40.28ldc.attributes.fastmath.29


- Modules ldc.simd and ldc.intrinsics.

- Extended allowed sizes for __vector (still very limited)

To get an idea of what is different for LDC and DMD, this PR 
removed support for DMD: https://github.com/libmir/mir/pull/347


-Johan


Ah, I was not aware that DMD support was dropped completely. I 
think that is a real shame, and it makes it _much_ less likely 
that I will use mir in my own projects, let alone as a dependency 
in another library.


Re: Mir GLAS vs Intel MKL: which is faster?

2016-09-26 Thread Edwin van Leeuwen via Digitalmars-d
On Monday, 26 September 2016 at 11:36:11 UTC, Edwin van Leeuwen 
wrote:
On Monday, 26 September 2016 at 11:32:20 UTC, Ilya Yaroshenko 
wrote:

Updated:
Mir is LLVM-Accelerated Generic Numerical Library for Science 
and Machine Learning. It requires LDC (LLVM D Compiler) for 
compilation.


It doesn't really require LDC though, it just requires it to 
get good performance? I can still use DMD for quick testing?


I would say something like:

For optimal performance it should be compiled using LDC.


Re: Mir GLAS vs Intel MKL: which is faster?

2016-09-26 Thread Edwin van Leeuwen via Digitalmars-d
On Monday, 26 September 2016 at 11:32:20 UTC, Ilya Yaroshenko 
wrote:

Updated:
Mir is LLVM-Accelerated Generic Numerical Library for Science 
and Machine Learning. It requires LDC (LLVM D Compiler) for 
compilation.


It doesn't really require LDC though, it just requires it to get 
good performance? I can still use DMD for quick testing?






Re: polar coordinates with ggplotd

2016-09-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Sunday, 18 September 2016 at 22:13:35 UTC, brocolis wrote:

Found an error in ys line. Thanks.


Does that mean you solved it?

Currently there is no special support for other coordinate 
systems, but I recently added Guides for x/y coordinates which 
should make this relatively straightforward to implement and is 
next on the list. Not sure when I'll get a chunk of time to 
implement it though.


For now you will have to convert the coordinates yourself, before 
plotting them.




Re: Draw math formulas with ggplotd

2016-09-17 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Saturday, 17 September 2016 at 11:57:17 UTC, John Colvin wrote:
On Saturday, 17 September 2016 at 11:45:07 UTC, Edwin van 
Leeuwen wrote:

But I assumed he meant adding the formula onto the plot.


Hah, yes, I should have read the question better.


Rereading the question I am actually not sure which of us 
interpreted the question correctly :)


Do you support embedding outside images? When I wanted nice 
mathematical notation generated quickly in D I have used pyd to 
call matplotlib's builtin math rendering (much quicker than a 
full latex roundtrip).


You can draw onto any cairo surface, so this should be possible. 
You'd just need to figure out how to cast/convert a matplotlib 
image to a cairo image.


Re: Draw math formulas with ggplotd

2016-09-17 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Saturday, 17 September 2016 at 11:22:04 UTC, John Colvin wrote:

On Saturday, 17 September 2016 at 02:41:15 UTC, brocolis wrote:
How do I draw math formulas programmatically? I want to do on 
screen what latex does on .pdf.


And I want to draw a math formula in the image generated with 
ggplotd.


Generate data from those formulas (I like to do this with 
something like iota(0, 10, 0.05).map!(x => sqrt(x) / (1 + 
sin(x)^^2)) and then plot that.


For this part ggplotd does have a helper function:

http://blackedder.github.io/ggplotd/ggplotd/stat.html#statFunction

auto gg = statFunction(x => sqrt(x) / (1 +
  sin(x)^^2), 0.0, 10).geomLine().putIn(GGPlotD());

But I assumed he meant adding the formula onto the plot.


Re: Draw math formulas with ggplotd

2016-09-17 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Saturday, 17 September 2016 at 09:56:09 UTC, Edwin van Leeuwen 
wrote:

On Saturday, 17 September 2016 at 02:41:15 UTC, brocolis wrote:
How do I draw math formulas programmatically? I want to do on 
screen what latex does on .pdf.


And I want to draw a math formula in the image generated with 
ggplotd.


You can't at the moment. Parsing latex equations is not a 
trivial task.


When I say you can't I meant that this is not explicitly 
supported by ggplotd.


Re: Draw math formulas with ggplotd

2016-09-17 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Saturday, 17 September 2016 at 02:41:15 UTC, brocolis wrote:
How do I draw math formulas programmatically? I want to do on 
screen what latex does on .pdf.


And I want to draw a math formula in the image generated with 
ggplotd.


You can't at the moment. Parsing latex equations is not a trivial 
task.


One possible approach would be to convert part of the equations 
(greek alphabet etc.) to utf and use geomLabel to "simulate" 
sub/super script. One caveat with this is that I am not sure how 
well cairo(d) supports utf.


Re: colour lib needs reviewers

2016-09-12 Thread Edwin van Leeuwen via Digitalmars-d
On Monday, 12 September 2016 at 19:55:57 UTC, Guillaume Piolat 
wrote:
- I've wanted a function like colorFromString many times. It's 
especially nice with the added #RGBA and #RRGGBBAA syntax that 
eg. SVG lacks.


What happens when the string is invalid? Does it throw an error?


Re: colour lib needs reviewers

2016-09-12 Thread Edwin van Leeuwen via Digitalmars-d

On Monday, 12 September 2016 at 15:06:29 UTC, Manu wrote:
One of my first port-of-calls after this work would be a 
graph/plot library... I'd use the hell out of that. I 
constantly want to output data visualisations!


Just for your information. ggplotd currently uses an old version 
of your library on the backend. I'm planning on porting it soon 
to the latest (dub) version.


Re: Checking all elements are unique.

2016-08-31 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund 
wrote:

Hello,

I have an array of objects of class C which contain a id member.
I want to figure out if all the id members are unique using 
functional primitives.


For example, if I have:

class C
{
  int id;
}

and an array of C 'Cs';

My idea was to do:

auto ids = Cs.map!(c => c.id);
assert(equal(ids.sort().uniq(), ids.sort()));

But it doesn't compile because I can't can call sort on ids.

Any idea why ? and how to solve my initial problem, which is to 
check all ids are unique.


Regards,

Dorian


Sort require an indexable array. You can convert an insertRange 
to an indexable array with .array:

ids.array.sort()

You can also directly sort on id
Cs.array.sort!((a,b) => a.id < b.id);



Re: dub test

2016-08-24 Thread Edwin van Leeuwen via Digitalmars-d
On Wednesday, 24 August 2016 at 06:32:54 UTC, Jacob Carlborg 
wrote:
Sure, but one might not figure why a test is failing after only 
a single run. One might use "dub test" to run integration tests 
that depends on some external dependency that is causing the 
test to fail.


I always considered dub test to be only for running unittests and 
not really suited for integration tests, but if that is a use 
case then fair enough.



There are many reasons to run the test without recompiling.


I might be dense, but the only other thing than integration tests 
that I can think of is if you use random data for testing, but 
that would be more correctly solved by using more random data 
during the unittests. Nothing is worse than tests that only 
sometimes fail.



What is the point of recompiling when nothing has changed?


I'd be all for for dub to analyse whether there are any changes, 
but AFAIK dub's focus is as a packaging system, not as a build 
system. In that case I'd prefer it to ere on the side of caution 
and recompile more often in case there might be a change. Maybe 
the key would be to replace dub's limited build system by an 
external build system such as reggea.


Re: dub test

2016-08-23 Thread Edwin van Leeuwen via Digitalmars-d
On Tuesday, 23 August 2016 at 17:55:41 UTC, Andrei Alexandrescu 
wrote:
Why does "dub test" rebuild the library? It should just re-run 
unittests. -- Andrei


To be honest I prefer it to rebuild it. Why would you want to 
rerun the tests without a rebuild? It should give the same 
failure/success as last time.


Re: Check out blog post on vibe.d

2016-08-22 Thread Edwin van Leeuwen via Digitalmars-d

On Monday, 22 August 2016 at 15:47:34 UTC, karabuta wrote:
I made a blog post on vibe.d for people who might be into 
node.js and other web frameworks. Its not meant for everybody 
especially not for softwares engineers or hardcore coders :) 
Please let me know what you think.


Sounds good, but where is it :)


Re: ggplotd version 1.0.0 released

2016-08-21 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Sunday, 21 August 2016 at 12:32:11 UTC, ZombineDev wrote:
I've worked extensively with data-viz UI components for WPF/SL 
and ASP.NET and I have to say that, after a quick glance at the 
readme, I really like the API of your library! Nice work!


Thanks! Although I must give most of the props to ggplot2 (the R 
package), because it is inspired by their API :)





Re: ggplotd version 1.0.0 released

2016-08-20 Thread Edwin van Leeuwen via Digitalmars-d-announce
On Saturday, 20 August 2016 at 16:37:29 UTC, Edwin van Leeuwen 
wrote:
I just wanted to announce the 1.0.0 version release of ggplotd 
[1]. The main addition is support for legends. Other than that 
the release focused on cleaning up/refactoring the code. It 
should still be backwards compatible though.




Forgot to add what ggplotd actually is :)

ggplotd is a plotting library, which uses cairo to do the actual 
for drawing. It supports saving as svg, pdf and png file. It also 
has basic support for drawing to gtk. The library design is 
inspired by ggplot2 for R, which in turn is based on a book 
called: grammar of graphics (hence gg(plot)). It supports 
plotting lines/points, histograms(2d) and density(2d) plots. It 
is written in such a way that it is easy to add your own type of 
plots (see the README).


ggplotd version 1.0.0 released

2016-08-20 Thread Edwin van Leeuwen via Digitalmars-d-announce
I just wanted to announce the 1.0.0 version release of ggplotd 
[1]. The main addition is support for legends. Other than that 
the release focused on cleaning up/refactoring the code. It 
should still be backwards compatible though.


As always I also released a new version of plotcli (the 
commandline plotting tool), which now also supports legends [2]. 
I am afraid there is currently no prebuild plotcli version with 
gtk support available OSX due to a linker error with gtkd on OSX 
[3]. I don't have a mac, so have been unable to solve this. Any 
input would be appreciated :)


[1] https://github.com/BlackEdder/ggplotd
[2] https://github.com/BlackEdder/plotd
[3] https://github.com/gtkd-developers/GtkD/issues/162



Re: Serialize/Deserialize Tuple

2016-08-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Friday, 19 August 2016 at 09:55:32 UTC, Steve Biedermann wrote:
I'm trying to send data over the network. On the receiving 
side, I need a tuple of the sent values. Is there any way to 
achieve this?


Depends on the format the data is send in. There are a number of 
serialization/deserialization libraries:


binary:
https://github.com/atilaneves/cerealed

Others:
http://code.dlang.org/search?q=serial+painlessjson+cerealed



Re: Command Line Utility Library

2016-08-16 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 16 August 2016 at 13:32:26 UTC, Jacob Carlborg wrote:

On 2016-08-16 11:37, Seb wrote:


Manual work? O_o
Just open code.dlang.org and either hit CTRL-F or use the 
search bar
(Martin added elastic search two months ago) as the packages 
usually

have a very low PageRank.


It's a bit problematic when you don't know what to search for. 
Not all projects have a descriptive name ;)


Does it only search the description or also the README?


Re: Command Line Utility Library

2016-08-16 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 15 August 2016 at 07:29:58 UTC, UDW wrote:

Hi,

I would like some options for a library, preferably json 
configurable, that helps with command line tool development. 
Doesn't have to be in D specifically.




I am using:
http://code.dlang.org/packages/docopt

It's not really json configurable, but that shouldn't be to 
complex to implement yourself.


Re: Decimal/Currency Type

2016-08-09 Thread Edwin van Leeuwen via Digitalmars-d

On Tuesday, 9 August 2016 at 10:48:50 UTC, Zane wrote:
Is there such a thing build into D? If not, is there any plans 
to add it? It seems like this would be something needed by many 
applications (especially anything dealing with currency).


I don't think there is anything in the standard library, but 
there is a dub library:

https://github.com/qznc/d-money


Re: Battle-plan for CTFE

2016-07-29 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Friday, 29 July 2016 at 11:30:20 UTC, Stefan Koch wrote:

I have fresh performance statistics:


Is there any improvement in memory usage?



Re: Autotesting dub packages with dmd nightly

2016-07-18 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 18 July 2016 at 18:47:28 UTC, Jacob Carlborg wrote:

On 2016-07-18 11:55, Sebastiaan Koppe wrote:

Like I said I am aiming really low. On purpose. I have a wife 
and two

kids and I need to keep the scope limited.


In that case, go with something that already exists.


I think Martin Nowak has some sort of automated setup for testing 
a limited number of dub packages against each release, but I 
can't find the relevant post at the moment.


Re: Using external libraries the correct way

2016-07-17 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Sunday, 17 July 2016 at 17:52:59 UTC, solidstate1991 wrote:
Up to this day, I have to use them by dragging the source into 
my project. When I tried to import imageformats, the compiler 
looks up for the file imageformats.d and fails to finish the 
program.


I'm not using command line for compiling, I use Xamarin with 
mono-D instead.


I tend to use dub for all my external libraries:
http://code.dlang.org

Not sure how that ties in with mono-D though.


Re: Docs for `Group` type

2016-07-12 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 12 July 2016 at 11:40:48 UTC, Bahman Movaqar wrote:

On 07/12/2016 01:01 PM, Mike Parker wrote:

Do you have some sample code that shows the error?


Yes.  I'm working on Stockman[1] a playground to learn D.
In file `etl.d`, line 110 [2], if I change the line to
auto refInvoice = group[1].takeOne();
the file will not compile.  I have attached the compile error 
to this

message.

Thanks,


What does group.writeln; output? That should give you a good 
sense of what is going on.


Re: local const functions - bug ?

2016-07-07 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 7 July 2016 at 10:33:39 UTC, Basile B. wrote:

this compiles without error:


struct Foo
{
int i;
void bar()
{
void foo() const
{
i = 1;
}
foo;
}
}

In this case "const" seems to be a noop. Do you think it's a 
bug ? Shouldn't "const" be applied, despite of foo() 
inaccessibility ?


Is this related to:
https://issues.dlang.org/show_bug.cgi?id=1983


Re: daffodil, a D image processing library

2016-07-04 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 4 July 2016 at 15:10:30 UTC, Manu wrote:
On 1 July 2016 at 18:19, Edwin van Leeuwen via 
Digitalmars-d-announce <digitalmars-d-announce@puremagic.com> 
wrote:

On Friday, 1 July 2016 at 08:11:37 UTC, Benjamin Schaaf wrote:


On Friday, 1 July 2016 at 01:24:55 UTC, rikki cattermole 
wrote:


On 01/07/2016 9:35 AM, Benjamin Schaaf wrote:

Doesn't use allocators or Manu's color work, yup yup not 
interested.



In terms of std.experimental.color, one of the things I 
focused on was extensibility.



Also, the only way currently to use Manu's color work is to 
install his phobos branch. The dub package will throw unittest 
errors and loads of deprecation warnings.


Really? Nobody ever mentioned that before.
I don't use dub, so I didn't notice... but I thought the code 
there

was up to date...?


Maybe I am confused. I am talking about the code/package here:
https://github.com/TurkeyMan/color
which hasn't seen an update since november.

Relevant issue:
https://github.com/TurkeyMan/color/issues/5
I had a look at the unittest, but couldn't immediately figure out 
why it wasn't working, so didn't look further into it.





Re: daffodil, a D image processing library

2016-07-01 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Friday, 1 July 2016 at 08:11:37 UTC, Benjamin Schaaf wrote:

On Friday, 1 July 2016 at 01:24:55 UTC, rikki cattermole wrote:

On 01/07/2016 9:35 AM, Benjamin Schaaf wrote:

Doesn't use allocators or Manu's color work, yup yup not 
interested.


In terms of std.experimental.color, one of the things I focused 
on was extensibility.


Also, the only way currently to use Manu's color work is to 
install his phobos branch. The dub package will throw unittest 
errors and loads of deprecation warnings.




Re: Garbage Collector

2016-06-15 Thread Edwin van Leeuwen via Digitalmars-d

On Wednesday, 15 June 2016 at 17:03:21 UTC, Konstantin wrote:

On Wednesday, 15 June 2016 at 13:56:09 UTC, Jack Stouffer wrote:
Has anyone thought about taking GC from .NET and reusing it 
in D?

Two words: write barriers.
What about them? You mean not all D’s target platforms support 
them?


I think he meant that the .NET GC (and most GC designs) rely on 
write barriers, but D does not have write barriers, since D is 
meant to be a proper systems language.


Re: Button: A fast, correct, and elegantly simple build system.

2016-06-15 Thread Edwin van Leeuwen via Digitalmars-d-announce
On Wednesday, 15 June 2016 at 15:39:47 UTC, Andrei Alexandrescu 
wrote:

On 06/15/2016 08:05 AM, John Colvin wrote:
On Wednesday, 15 June 2016 at 11:47:00 UTC, Walter Bright 
wrote:

On 6/15/2016 4:07 AM, Edwin van Leeuwen wrote:

How about using reggae?

https://github.com/atilaneves/phobos/blob/reggae/reggaefile.d


I haven't studied either.


If you do study that reggae file, remember that it's a 
deliberate
transliteration of the makefile and therefore is a lot more 
verbose than
it *could* be if done from a clean slate or as a proper 
translation.
IIRC it was done to show that reggae could do literally 
everything the

makefile does, in the same way.


Does it do -j? -- Andrei


It can work with multiple backends (make/tup/ninja), which all 
support -j. There is also a binary backend (creates an 
executable), not sure if that supports -j natively.


Re: Button: A fast, correct, and elegantly simple build system.

2016-06-15 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 13 June 2016 at 00:27:47 UTC, Walter Bright wrote:

On 5/30/2016 12:16 PM, Jason White wrote:

Here is an example build description for DMD:

https://github.com/jasonwhite/dmd/blob/button/src/BUILD.lua

I'd say that's a lot easier to read than this crusty thing:

https://github.com/dlang/dmd/blob/master/src/posix.mak


Yes, the syntax looks nice.


How about using reggae?

https://github.com/atilaneves/phobos/blob/reggae/reggaefile.d


Re: Beta release DUB 1.0.0-beta.1

2016-06-07 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Tuesday, 7 June 2016 at 09:54:19 UTC, Sönke Ludwig wrote:
DUB 1.0.0 is nearing completion. The new feature over 0.9.25 is 
support for single-file packages, which can be used to write 
shebang-style scripts on Posix systems:


#!/usr/bin/env dub
/++ dub.sdl:
name "colortest"
dependency "color" version="~>0.0.3"
+/



I love that as a feature! Thanks for adding that.



Re: mir.random - my GSoC project

2016-06-02 Thread Edwin van Leeuwen via Digitalmars-d

On Thursday, 2 June 2016 at 10:56:36 UTC, Martin Nowak wrote:

On 04/23/2016 04:17 PM, Seb wrote:
This project is about adding non-uniform random generators to 
mir and hopefully eventually to Phobos.


I just happen to need a gaussian random number generator right 
now. Is there already some WIP code, or would you have an 
intermediate recommendation?


I tend to use rNorm from dstats:
https://github.com/dsimcha/dstats/blob/master/source/dstats/random.d#L266


Re: Trying to get type and name at compile time

2016-05-24 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 24 May 2016 at 18:44:45 UTC, ag0aep6g wrote:


Seems to be a problem in ApplyLeft:


import std.meta: AliasSeq, ApplyLeft;
alias addType(T, string name) = AliasSeq!(T, name);
alias addTypeInt = ApplyLeft!(addType, int);
alias FullyInstantiated = addTypeInt!"foo";


Fails with: "std/meta.d(1114): Error: cannot interpret int at 
compile time".


I've filed an issue:
https://issues.dlang.org/show_bug.cgi?id=16070



Thanks! I've worked around it for now with some recursion :)

Using `is(...)` with an AliasSeq of only types is ok. But you 
can't use it when there's a non-type in the sequence.


That makes sense.

Thanks for the help, Edwin



Re: Trying to get type and name at compile time

2016-05-24 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 24 May 2016 at 15:09:43 UTC, Adam D. Ruppe wrote:
On Tuesday, 24 May 2016 at 15:01:33 UTC, Edwin van Leeuwen 
wrote:

// I expected AliasSeq!(double,"x")???
pragma(msg,test); // tuple((double), "x")


What Phobos calls AliasSeq is called tuple inside the compiler. 
They are the same thing, just different names.


That's what I assumed at first.. So why does the following fail 
with: cannot interpret double at compile time? I assumed 
staticMap would automatically flatten the resulting AliasSeqs.


```
import std.meta : AliasSeq, ApplyLeft, staticMap;

struct Point { double x; double y; }

template addType(T,alias name)
{
alias addType = AliasSeq!( typeof(__traits(getMember, Point, 
name)),

name );
}

alias test3 = addType!( Point, "x" );

// I expected AliasSeq!(double,"x")???
pragma(msg,test3); // tuple((double), "x")

//static assert(is(test == AliasSeq!(double,"x")));
alias ts = AliasSeq!("x","y");
alias addTypeP = ApplyLeft!(addType,Point);
alias mapped = staticMap!(addTypeP,ts);

pragma(msg,mapped);

void main() {
}
```

Looking at it now, I guess it is because staticMap does not work 
with alias values, only with actual type lists. Is that correct? 
Any ideas on how to do this?





static assert(is(test == AliasSeq!(double,"x")));


AliasSeq is not comparable as a type. You can test the 
individual pieces of it (`is(test[0] == double) && test[1] == 
"x"`) or wrap it in a struct or something.


I thought so, but a lot of the documentation does seem to compare 
it (see the example here):

https://dlang.org/library/std/meta/static_map.html





Trying to get type and name at compile time

2016-05-24 Thread Edwin van Leeuwen via Digitalmars-d-learn

Hi all,

I am trying to get the type and name of a field at compile time, 
but can't get the following to work. Anyone any idea of why test 
is not of the type AliasSeq!(double, "x")?



```
import std.meta : AliasSeq;

struct Point { double x; double y; }

alias test = AliasSeq!(
typeof(__traits(getMember, Point, "x")),
"x"
);

// I expected AliasSeq!(double,"x")???
pragma(msg,test); // tuple((double), "x")

static assert(is(test == AliasSeq!(double,"x")));

void main() {}
```

Cheers, Edwin


Re: matrix library

2016-05-23 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 23 May 2016 at 23:08:46 UTC, Vlad Levenfeld wrote:
Now I am thinking that the best way to orthogonalize (sorry) my 
efforts with respect to mir and scid.linalg is to use them as 
backend drivers, maintain this wrapper for the crowd that isn't 
as familiar with blas/lapack, or wants to write slightly more 
concise top-level code, and forward the relevant bug reports 
and pull requests to mir and scid.


You might be interested in joining the gitter channel where the 
mir developers hang out:

https://gitter.im/libmir/public


Re: matrix library

2016-05-23 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 23 May 2016 at 20:27:54 UTC, Vlad Levenfeld wrote:

On Monday, 23 May 2016 at 20:11:22 UTC, Vlad Levenfeld wrote:

...


On first glance it looks like 
https://github.com/DlangScience/scid/blob/master/source/scid/matrix.d has most of what my matrix implementation is missing. Not sure how to put them together yet.


There is also mir, which is working towards being a full 
replacement for blas:

https://github.com/libmir/mir

It is still under development, but I think the goal is to become 
the ultimate matrix library :)




Re: static member and/or @property ?

2016-05-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 19 May 2016 at 15:12:44 UTC, Edwin van Leeuwen wrote:

On Thursday, 19 May 2016 at 15:04:00 UTC, chmike wrote:
The only viable solution I found so far is by using distinct 
member names. In the interface we define name as a property, 
and in the class we define the static member with another 
name. Is it possible to avoid the different names ?


Can you use identifier!(typeof(this)) or something along those 
lines. I am not sure how it behaves with inheritance.


https://dlang.org/spec/traits.html#identifier


Sorry I meant __traits(identifier, typeof(this)).


Re: static member and/or @property ?

2016-05-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 19 May 2016 at 15:04:00 UTC, chmike wrote:
The only viable solution I found so far is by using distinct 
member names. In the interface we define name as a property, 
and in the class we define the static member with another name. 
Is it possible to avoid the different names ?


Can you use identifier!(typeof(this)) or something along those 
lines. I am not sure how it behaves with inheritance.


https://dlang.org/spec/traits.html#identifier


Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 16:37:48 UTC, TheDGuy wrote:

On Wednesday, 18 May 2016 at 16:13:35 UTC, Seb wrote:
May I ask why you need to get tango working? It has been 
deprecated a long time ago and phobos (the standard library) 
or alternatively other packages on dub have a look of features 
:)


Okay, it looks like 'onyx' is a library which handles serial 
communication in D. So tried to create a new project with DUB 
and add onyx as dependency but there are still some errors:


http://pastebin.com/4eRBt6XX

Any idea what i do wrong?


The onyx README seems to suggest it only works for POSIX. Did you 
try serial-port by any chance:

http://code.dlang.org/packages/serial-port

That does mention Windows as supported. It is quite old though, 
the latest github activity is from a year ago.


ggplotd v0.9: Added geomDensity and geomDensity2d support. Documentation improvements

2016-05-18 Thread Edwin van Leeuwen via Digitalmars-d-announce
I’d like to announce a new release of the ggplotd plotting 
library.

https://github.com/BlackEdder/ggplotd

Main changes are:

User visible change:

- geomDensity and geomDensity2D (kernel smoothed hist and hist2d)
- Browseable api documentation using harbored-mod
- Updates to documentation
- Some deprecations due to moving/renaming
- mergeRange moved to ggplotd.range
- geomHist3D renamed to geomHist2D

Other changes:

- Addition of ggplotd.stat module
- Split some geom functions into separate geom and stat part
- Many refactors




Plotcli: https://github.com/BlackEdder/plotd

A new version of plotcli has also been released, which depends on 
the new ggplotd version. As a result plotcli can now also create 
density and density2d plots (which are basically smoothed 
histograms).


Re: PropertyType

2016-05-17 Thread Edwin van Leeuwen via Digitalmars-d
On Tuesday, 17 May 2016 at 14:24:09 UTC, Steven Schveighoffer 
wrote:

I have this little helper in my iopipe library:

template PropertyType(alias x)
{
static if(is(typeof(x) == function))
alias PropertyType = typeof(x());
else
alias PropertyType = typeof(x);
}



FYI: In painlesstraits we use a different approach, where we test 
whether it is a function (with isSomeFunction) and then test for 
the property attribute:


https://github.com/msoucy/painlesstraits/blob/master/source/painlesstraits.d#L173
```
static if (isSomeFunction!(T))
{
return (functionAttributes!(T) & 
FunctionAttribute.property);

} else
return false;
```



Re: The D language online tour - tour.dlang.org

2016-05-16 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 16 May 2016 at 17:32:06 UTC, André wrote:

Hi,

after another round of polishing, bug fixing, very useful user 
contributions and suggestions, I'd like to present the new home 
of the D language online tour:


http://tour.dlang.org/

Thank you very much to the D foundation for hosting this 
service!


If you would like to report errors or have suggestions, please 
use GitHub:


https://github.com/stonemaster/dlang-tour

Thanks & regards,
André


Nice work. Will this be mentioned/linked too in the Learn section 
of the dlang.org?


Re: static import (v2.071.0)

2016-05-11 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 11 May 2016 at 14:24:03 UTC, Chris wrote:

I was wondering if

`static import std.file;`

`if (exists(file))`

will only import `std.file.exists` or the whole lot of 
`std.file`? I want to find out what the best strategy for 
imports is now.


I tend to do specified imports, although (AFAIK) it doesn't make 
a difference for the imported code:


private import std.file : exists;

if (exists(file))




Re: ggplotd - curve colour

2016-05-09 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 9 May 2016 at 02:29:47 UTC, brocolis wrote:

Is this correct usage?
auto gg = GGPlotD().put( geomLine( Aes!(typeof(xs), "x", 
typeof(ysfit), "y", string, "colour")( xs, ysfit, "red") ) );


The output is a blank png file.

Full source:
import ggplotd.ggplotd;
import ggplotd.geom;
import ggplotd.aes;
import ggplotd.axes;

void main()
{
import std.array : array;
import std.algorithm : map;
import std.range : iota;
import ggplotd.colour;

auto f = (double x) { return x; };
auto xs = iota(-5, 5, 0.1 ).array;
auto ysfit = xs.map!((x) => f(x)).array;
auto gg = GGPlotD().put( geomLine( Aes!(typeof(xs), "x", 
typeof(ysfit), "y", string, "colour")( xs, ysfit, "red") ) );


gg.put( xaxisOffset( 0) ).put( yaxisOffset( 0) );
gg.save( "axes.png", 500, 300 );
}


The problem there is that colour also needs to be an InputRange. 
This is so that different points can have a different colours 
associated with it, which is particularly useful if you want to 
plot some data and have different types of data plotted as 
different colours.


In your example you can either do:

```
auto colour = "red".repeat( xs.length );
auto gg = GGPlotD().put( geomLine( Aes!(typeof(xs), "x",
 typeof(ysfit), "y", typeof(colour), "colour")( xs, ysfit, 
colour) ) );

```

Or use the mergeRange function mentioned before, which will 
automatically repeat if one argument is a single element.


```
auto aes = Tuple!( string, "colour" )( "red" ).mergeRange( 
Aes!(typeof(xs), "x",

 typeof(ysfit), "y" )( xs, ysfit ) );
```


Re: ggplotd - curve colour

2016-05-08 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Sunday, 8 May 2016 at 01:50:38 UTC, brocolis wrote:

How do I set the color of a curve with ggplotd?
Thanks.


Also see the below example on how to merge Colour with an 
existing range of points using mergeRange:


(Copied from http://blackedder.github.io/ggplotd/stat.html)

void main()
{
  /// http://blackedder.github.io/ggplotd/images/function.png
  import std.random : uniform;
  import std.typecons : Tuple;
  import ggplotd.stat : statFunction;
  import ggplotd.ggplotd : GGPlotD;
  import ggplotd.geom : geomLine, geomPoint;
  import ggplotd.aes : mergeRange;

  auto f = (double x) { return x / (1 + x); };

  auto aes = statFunction(f, 0.0, 10);
  auto gg = GGPlotD().put(geomLine(aes));

  // Generate some noisy points
  auto f2 = (double x) { return x / (1 + x) * uniform(0.75, 
1.25); };

  auto aes2 = f2.statFunction(0.0, 10, 25);

  // Show points in different colour
  auto withColour = Tuple!(string, 
"colour")("aquamarine").mergeRange(aes2);

  gg = gg.put(withColour.geomPoint);

  gg.save("function.png");
}



Re: ggplotd - curve colour

2016-05-08 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Sunday, 8 May 2016 at 01:50:38 UTC, brocolis wrote:

How do I set the color of a curve with ggplotd?
Thanks.


You can set colours by name:
https://github.com/BlackEdder/ggplotd/blob/master/source/ggplotd/colour.d#L20

Alternatively you can pass through the RGB value (see the link 
above for the specification).


Finally if you have multiple curves and don't want to specify 
specific colours you can just give them a different identifier 
(e.g. different double/int value (any type should do)) and it 
will chose the colours according to the colourgradient used. 
There is an example on how to specify your own gradient in the 
hist3D.svg example:

http://blackedder.github.io/ggplotd/ggplotd.html


Re: Computer Vision Library in D

2016-04-28 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Thursday, 28 April 2016 at 11:32:25 UTC, Michael wrote:
And I would also like to see some more scientific libraries 
make it into D. Though I understand that including it in the 
standard library can cause issues, it would be nice to at least 
get some Linear Algebra libraries in experimental or over with 
the rest of the science libraries.


As I understand it that is part of the goal of mir:
https://code.dlang.org/packages/mir

Not sure if you were aware, but there is also a group with the 
aim to promote scientific dlang work:

https://gitter.im/DlangScience/public


Re: DUB and pragma lib - OSX

2016-04-20 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 20 April 2016 at 05:53:28 UTC, Joel wrote:

How do I get this C stuff working with DUB?


Mind posting your dub configuration file?



Re: JSONValue floating and 42

2016-04-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 19 April 2016 at 13:44:08 UTC, Andre wrote:
-> I need to analyze every value whether it is a floating or an 
integer?


This is the correct option. Something like:

double f;
if (j["value"].type == JSON_TYPE.INTEGER)
  f = j["value"].integer.to!float;
else
  f = j["value"].floating;

There are also a number of libraries available that make dealing 
with json a bit easier:

code.dlang.org/search?q=json


Re: Command line utilities for tab-separated value files

2016-04-12 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Tuesday, 12 April 2016 at 07:17:05 UTC, Jon D wrote:


I'd certainly like to make it available via dub, but I wasn't 
sure how to set it up. There are two issues. One is that the 
package builds multiple executables, which dub doesn't seem to 
support easily. More problematic is that quite a bit of the 
test suite is run against the executables, which I could 
automate using make, but didn't see how to do it with dub.


If there are suggestions for setting this up in dub that'd be 
great. An example project doing something similar would be 
really helpful.


Dub is indeed not ideal for building multiple executables. You 
can either use subConfigurations or subPackages. In your case I 
would probably go the subPackages route, with the root dub file 
depending on all the executables. Never done that before though, 
so not exactly sure if that would work. If it works though then 
I'd think dub test in the root would run the tests for each 
subPackage.


Re: Official dub packages for Debian and Ubuntu

2016-04-11 Thread Edwin van Leeuwen via Digitalmars-d-announce

On Monday, 11 April 2016 at 14:21:46 UTC, Matthias Klumpp wrote:
And porting Python code to D was incredibly easy. I'll likely 
blog about my experience with D).


That would be great. Do you have a link to your blog (and its rss 
feed)?


As part of that work, the dub package an build management 
system is now available in Debian, and I will ensure it works 
well.


Nice, that will make it a lot easier, for people that are not 
using D, to install D programs/packages


Re: simple range question

2016-04-08 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Friday, 8 April 2016 at 18:27:59 UTC, Laeeth Isharc wrote:
suppose I have a forward or random access range.  what's the 
best way to compare each element with the element 4 elements 
prior to that element?  I could map each element to a tuple of 
the element and the element 4 bars previously and do it that 
way.  any neater way ?


I'd do it like this, but I guess that is what you mean with 
mapping it to a tuple:


zip( r, r[4..$] ).map!((t) => t[0] == t[1]);


Re: is std.algorithm.joiner lazy?

2016-04-07 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 7 April 2016 at 09:55:56 UTC, Puming wrote:

When compiled, I get the error:

Error: open path skips field __caches_field_0
source/app.d(19, 36): Error: template instance 
std.algorithm.iteration.cache!(MapResult!(__lambda1, int[])) 
error instantiating


That seems like a bug to me and you might want to submit it to 
the bug tracker. Even converting it to an array first does not 
seem to work:


import std.stdio : writeln;
import std.algorithm : map, cache, joiner;
import std.array : array;

auto read(int a) {
   return [0, a]; // second level
}

auto mkarray(int a) {
  return [-a, a].map!(x=>read(x)).cache.joiner; // to avoid 
calling read twice

}

void main() {
  auto xs = [1,2 ,3, 4];
  auto r = xs.map!(x=>mkarray(x)).array;

  // Both lines below should be equal, but second does not compile
  [[0, -1, 0, 1], [0, -2, 0, 2], [0, -3, 0, 3], [0, -4, 0, 
4]].cache.joiner.writeln;

  r.cache.joiner.writeln;
}

Above results in following error:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(326): 
Error: one path skips field __caches_field_0
/d617/f62.d(19): Error: template instance 
std.algorithm.iteration.cache!(Result[]) error instantiating


Re: is std.algorithm.joiner lazy?

2016-04-07 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 7 April 2016 at 08:17:38 UTC, Puming wrote:
On Thursday, 7 April 2016 at 08:07:12 UTC, Edwin van Leeuwen 
wrote:


OK. Even if it consumes the first two elements, then why does 
it have to consume them AGAIN when actually used? If the 
function mkarray has side effects, it could lead to problems.


After some testing it seems to get each element twice, calls 
front on the MapResult twice, on each element. The first two 
mkarray are both for first element, the second two for the 
second. You can solve this by caching the front call with:


xs.map!(x=>mkarray(x)).cache.joiner;


Re: is std.algorithm.joiner lazy?

2016-04-07 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 7 April 2016 at 07:07:40 UTC, Puming wrote:

Hi:

when I use map with joiner, I found that function in map are 
called. In the document it says joiner is lazy, so why is the 
function called?


say:

int[] mkarray(int a) {
   writeln("mkarray called!");
   return [a * 2]; // just for test
}

void main() {
   auto xs = [1, 2];
   auto r = xs.map!(x=>mkarray(x)).joiner;
}

running this will get the output:

mkarray called!
mkarray called!

I suppose joiner does not consume?

when I actually consume the result by writlen, I get more 
output:


mkarray called!
mkarray called!
[2mkarray called!
mkarray called!
, 4]

I don't understand


Apparently it works processing the first two elements at 
creation. All the other elements will be processed lazily.


Even when a range is lazy the algorithm still often has to 
"consume" one or two starting elements, just to set initial 
conditions. It does surprise me that joiner needs to process the 
first two, would have to look at the implementation why.


Re: how to parse a string into a phobos datatype with additional logic

2016-04-07 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 7 April 2016 at 07:45:06 UTC, yawniek wrote:

what is the way one is supposed to parse e.g. a
double of unixtime (as delived by nginx logs) into a SysTime?

currently i'm creating a wrapper struct around SysTime with 
alias this as:


https://gist.github.com/yannick/6caf5a5184beea0c24f35d9d4a4c7783

really ugly imho.

is there a better way to do this?


You can try this library:
https://code.dlang.org/packages/dateparser


Re: Read only delegate

2016-04-04 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 4 April 2016 at 11:39:55 UTC, Kagamin wrote:

On Monday, 4 April 2016 at 11:32:23 UTC, Rene Zwanenburg wrote:

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


Bug 1983 is about usage of delegates after creation, 
restrictions during creation are enforced. AIU, OP wants to 
have const check during creation.


I think the underlying issue is the same. The problem seems to be 
that:
Unfortunately, there is no way to declare a const delegate (by 
which I mean, a delegate whose context pointer is typed const).


I actually discovered the problem, due to the hole it leaves in 
the const system, where I got different results calling a const 
method multiple times. The const method in question called a 
delegate that changed its context pointer, resulting in changes 
during calls.




Re: Read only delegate

2016-04-04 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 4 April 2016 at 11:32:23 UTC, Rene Zwanenburg wrote:
On Monday, 4 April 2016 at 08:10:10 UTC, Edwin van Leeuwen 
wrote:
Is there a way to make sure a delegate only reads state, 
without changing it? I tried annotating the delegate as const, 
but that does not seem to work.

```


Yeah this is a nasty old issue. The underlying problem is that 
a delegate's function and context pointers are completely 
untyped.


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


Thanks for the reference, hopefully this will be resolved at some 
point :)




Re: Read only delegate

2016-04-04 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 4 April 2016 at 08:10:10 UTC, Edwin van Leeuwen wrote:
Is there a way to make sure a delegate only reads state, 
without changing it? I tried annotating the delegate as const, 
but that does not seem to work.




Note that annotating with pure also doesn't help. As a result we 
can have a pure delegate that returns different results every 
time it is called.


```D
void main()
{
import std.stdio : writeln;
auto r = [0,1,2,3];

auto f = delegate() const pure
{
import std.array : front, popFront;
r.popFront;
return r.front;
};

r.writeln; // [0,1,2,3]
auto f1 = f();
r.writeln; // [1,2,3]
assert( f() == f1 ); // Throws
}
```



Read only delegate

2016-04-04 Thread Edwin van Leeuwen via Digitalmars-d-learn
Is there a way to make sure a delegate only reads state, without 
changing it? I tried annotating the delegate as const, but that 
does not seem to work.


```D
void main()
{
import std.stdio : writeln;
auto r = [0,1,2,3];

auto f = delegate() const // Compiles even though we are 
changing r

{
import std.array : popFront;
r.popFront;
};

r.writeln; // [0,1,2,3]
f();
r.writeln; // [1,2,3]
}
```




Re: infer type argument in classe constructor?

2016-03-29 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 29 March 2016 at 10:13:28 UTC, Puming wrote:

Hi,

I'm writing a generic class:

```d

struct Message { ... }

class Decoder(MsgSrc) {
}
```

When using it, I'd have to include the type of its argument:

```
void main() {
   Message[] src = ...;

   auto decoder = new Decoder!(Message[])(src);

   ...
}
```

Can it be inferred so that I only need to write?

```d
auto decoder = new Decoder(src); // you can infer the type from 
src.

```


You can't directly. This is (AFAIK) because this()() can also be 
templated, making it impossible to just derive. The common way in 
D to deal with this/work around it is to create a helper function 
that can infer it:


```D
auto decoder(T)(T src)
{
  return new Decoder!T(src);
}

auto dec = decoder(src)
```

This pattern is widely used in phobos (e.g. tuple and Tuple)


Re: Usage of custom class with JSONValue

2016-03-24 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 24 March 2016 at 11:39:13 UTC, arturg wrote:

isnt alias this supposed to do this implicitly?

convert this
auto jsValue = JSONValue(new MyClass());

into this
auto jsValue = JSONValue((new MyClass())._data);


Good point, I did not catch that. That indeed should work and 
seems to be a bug. Does it work if _data is a base type (string 
or int, etc..)




Re: Usage of custom class with JSONValue

2016-03-24 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 24 March 2016 at 08:15:12 UTC, Andre wrote:

Hi,

I have a class which has already an alias this to a string 
array,

so I can use it in a foreach loop.

class MyClass
{
string[] _data;
alias _data this;
// ...
}

void main()
{
import std.json;
auto jsValue = JSONValue(new MyClass());
}

For some generic code I need an implicit conversion of MyClass 
so I can
use it for a JSONValue. For the coding above I receive a 
compiler error:

static assert  "unable to convert type "MyClass" to json"



JSONValue only works with the build in types, not with user 
defined types. Either you define a specific function for the 
class that returns a JSONValue. Easiest way to do that would be 
to build an associative array with strings as keys with the 
names, and JSONValues as values and turn that into JSONValue, 
i.e. (untested):

class MyClass
{
string[] _data;
alias _data this;
// ...
   JSONValue toJSON()
  {
JSONValue[string] aa;
JSONValue[] dataJSON = _data.map!((a) => JSONValue(a)).array;
aa["data"] = JSONValue(dataJSON);
return JSONValue(aa);
  }
}

Alternatively there are multiple serialization libraries that 
will allow you to turn any user defined type from and to 
JSONValues.


https://code.dlang.org/packages/painlessjson
https://code.dlang.org/packages/jsonizer

Cheers, Edwin


Re: iota result as member variable

2016-03-24 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 24 March 2016 at 06:54:25 UTC, Alex wrote:

Hi everybody,
doing some optimization on my code, I faced some strange 
question:

how to save a iota result in a class member?

Say I have
class A
{
??? member;

auto testIter4()
{
return iota(0,5);
}
}

void main()
{
A a = new A();
a.member = testIter4();
}

how would I declare the member?



Yeah this is one of the downsides of voldermort types. In these 
cases typeof and ReturnType are your friend. It often takes me a 
couple of tries to get it right, but the following seems to work:


import std.traits : ReturnType;
import std.range : iota;
class A
{
ReturnType!(A.testIter4) member;
auto testIter4()
{
return iota(0,5);
}
}

void main()
{

 A a = new A();
 a.member = a.testIter4();

}


Re: Some crazy ideas from a high level perspective

2016-03-22 Thread Edwin van Leeuwen via Digitalmars-d

On Tuesday, 22 March 2016 at 15:50:15 UTC, Basile B. wrote:
On Tuesday, 22 March 2016 at 15:33:04 UTC, Edwin van Leeuwen 
wrote:
On Tuesday, 22 March 2016 at 15:19:10 UTC, rikki cattermole 
wrote:

Idea 1:

Sigh I do wish the author of gl3n had given permission for 
relicense for Phobos. Would do what you want.


Idea 3:

My goal is get windowing/image library into Phobos. Now that 
is not a UI toolkit but you can atleast get a window up and 
show an image like a graph.

Kinda everything you want.


Any tips on how easy it will be to plot a cairo surface to a 
window ?


Very easy.

- wrap a context in a Canvas with the methods for drawing.
- BLIT the cairo surface.


Thanks!



It also works with simple bitmaps, so image proceduraly 
rendered.

Actually I've started to work on this at the end of 2015.

(https://github.com/BBasile/kheops/blob/master/src/kheops/bitmap.d#L396)


That looks interesting. Would you say kheops is stable enough to 
be relied upon  by other projects? Any plans to make it into a 
dub package?


Since kheops is vector based it would be even nicer to be able to 
convert a cairo svg/pdf surface to kheops.


While it was planned to make a native D UI, using it to plot 2D 
data would require very few work. There's also a OO wrapper 
called cairoD or something like that which is for sure very 
easy to use to render bitmap proceduraly.


cairoD is indeed what ggplotd uses to produce the plot. And 
saving svg/png/pdf to disk is indeed very easy with cairo.





Re: Some crazy ideas from a high level perspective

2016-03-22 Thread Edwin van Leeuwen via Digitalmars-d

On Tuesday, 22 March 2016 at 15:19:10 UTC, rikki cattermole wrote:

Idea 1:

Sigh I do wish the author of gl3n had given permission for 
relicense for Phobos. Would do what you want.


Idea 3:

My goal is get windowing/image library into Phobos. Now that is 
not a UI toolkit but you can atleast get a window up and show 
an image like a graph.

Kinda everything you want.


Any tips on how easy it will be to plot a cairo surface to a 
window? ggplotd currently relies on gtkd for that, but would be 
great if there is a D based solution.


I'm especially interested in plotting image of the below type in 
a window:


CAIRO_FORMAT_ARGB32[1]
each pixel is a 32-bit quantity, with alpha in the upper 8 bits, 
then red, then green, then blue. The 32-bit quantities are stored 
native-endian. Pre-multiplied alpha is used. (That is, 50% 
transparent red is 0x8080, not 0x80ff.)


[1] cairographics.org/manual-1.2.0/cairo-Image-Surfaces.html


Re: Something wrong with GC

2016-03-22 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 22 March 2016 at 13:46:41 UTC, stunaep wrote:

public class Example2 {

private int one;
private int two;

public this(int one, int two) {
this.one = one;
this.two = two;
}
}


in a tree map and list of some sort. Neither of the above work 
whether they are classes or structs and it's starting to become 
quite bothersome...


Is there a particular reason why you don't want to use the 
standard ranges?


public class Example2 {

private int one;
private int two;

public this(int one, int two) {
this.one = one;
this.two = two;
}
}

void main()
{
auto myExamplesList = [ new Example2( 6,3 ), new Example2(7,5) ];

// Note that if you do a lot of appending then using 
Appender is more performant than ~=

myExamplesList ~= new Example2(9,1);
}

For trees there is also redBlackTree




Re: Gdmd compiling error

2016-03-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 16 March 2016 at 12:17:42 UTC, Orkhan wrote:

On Tuesday, 15 March 2016 at 18:26:48 UTC, Ali Çehreli wrote:

I don't know where from shpuld I get help. Thanks.


Is the xcomm library available somewhere, maybe if we had a link 
to the original documentation we could help.




Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote:



void printVars(Args...)()
if (Args.length > 0)
{
import std.stdio : writefln;

foreach (i, arg; Args) {
writefln("%s\t%s:\t%s", typeof(Args[i]).stringof, 
Args[i].stringof, arg);

}
}

void main() {
int abc = 3;
string def = "58";
float ghi = 3.14f;
double jkl = 3.14;

printVars!(abc,def,ghi,jkl)();
}


Interesting, any idea if it is possible to do assignment within 
template.. Either:


printVars!(int abc=5,string def="58")();
or something like
printVars!("abc","def",ghi)(5,"58");



Re: Obtaining argument names in (variadic) functions

2016-03-18 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Thursday, 17 March 2016 at 13:53:00 UTC, JR wrote:


Interesting, any idea if it is possible to do assignment 
within template.. Either:


printVars!(int abc=5,string def="58")();
or something like
printVars!("abc","def",ghi)(5,"58");


What would the use-cases for those be?

I don't think the first is valid grammar, and I'm not sure what 
you want the second to do. Resolve symbols by string literals 
of their names? That might need a string mixin as they wouldn't 
be in scope when in the called template function, but I've 
never tried it.


Both use cases are when you want a named parameter, without 
having to assign it first. I know the first is not valid grammar, 
was just wondering if you might be smarter than me and see a way 
to make it valid :)


Second one is another possible alternative that I have been 
thinking about.


Basically, say I want to have the named (optional) parameters x 
and y. In your initial example I would be required to do:


```
int x = 1;
string y = "2";
doSomethingWithNamedPars!(x,y)();
```

I just hoped to shorten that to a one liner similar to:

```
doSomethingWithNamedPars!(x=1,y="2")();
```

or alternatively

```
doSomethingWithNamedPars!("x","y")(1,"2");
```

(where doSomethingWithNamedPars's behaviour depends on which 
named parameters it is passed)


Just as a reference, my current approach (in ggplotd) is with 
named tuples, but that is slightly more verbose than I had hoped:


```
doSomethingWithNamedPars( Tuple!(int, "x", string, "y")( 1, 2 ) );
```


Re: dmd-built dmd is faster that ldc-built dmd or gdc-built dmd?

2016-03-11 Thread Edwin van Leeuwen via Digitalmars-d
On Friday, 11 March 2016 at 14:46:59 UTC, Vladimir Panteleev 
wrote:
Thanks :) After changing that to version(all), LDC is faster 
now. Doesn't build with GDC though (multiple definitions)...


How much faster is LDC?


Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 9 March 2016 at 15:39:55 UTC, rcorre wrote:

On Wednesday, 9 March 2016 at 14:28:11 UTC, cym13 wrote:

Still curious as to why it fails; maybe the range is getting 
copied at some point? I guess I need to step through it.


I did try different SwapStrategies with no luck.


Since you are adapting phobos anyway you could try commenting out 
the assert and see what the result of the sort is. That might 
give you some clue:


//assert(isSorted!lessFun(r), "Failed to sort range of type " ~ 
Range.stringof);



Also I notice the line numbering is different in my sorted.d 
file. Did you test the latest version of dmd/phobos?





Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 9 March 2016 at 13:04:31 UTC, rcorre wrote:
On Wednesday, 9 March 2016 at 12:31:18 UTC, Edwin van Leeuwen 
wrote:

On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote:
If you are looking for a lazy uniq that works on non sorted 
ranges, I implemented one not to long ago:

http://github.com/BlackEdder/ggplotd/blob/master/source/ggplotd/range.d


That sounds like the kind of thing I was looking for. I'll 
take a look, thanks!


Well that one does allocate, because it keeps track of which 
values have already been seen.


Yup, just noticed that >.<


Of course it only allocates when the actual result is used, so 
this will probably be more efficient if you only need a small 
number of unique results or need to keep the unsorted range 
around/intact. Sorting without allocating and then using uniq 
should indeed be more efficient in other cases.


Did you try different SwapStrategy values in your original?


Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote:
If you are looking for a lazy uniq that works on non sorted 
ranges, I implemented one not to long ago:

http://github.com/BlackEdder/ggplotd/blob/master/source/ggplotd/range.d


That sounds like the kind of thing I was looking for. I'll take 
a look, thanks!


Well that one does allocate, because it keeps track of which 
values have already been seen.


Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 9 March 2016 at 03:05:52 UTC, rcorre wrote:
I was in a situation where I wanted to remove duplicates from 
an OnlyResult.
To do this with uniq, I needed to sort it. OnlyResult doesn't 
satisfy the template constraints of sort, but this seems easy 
enough to fix. I made front, back, and opIndex return by ref. 
With this, the following compiles:


assert(only(3,1,2).sort.equal(only(1,2,3)));

However, it fails with:

core.exception.AssertError@std/algorithm/sorting.d(1052): 
Failed to sort range of type OnlyResult!(int, 3LU)


So, if you have a range for which sort compiles, what does it 
take to make sorting actually work?


For reference, my two attempts were:

https://github.com/rcorre/phobos/commit/d89b3cfab7a0938e178a506b4ceb8faae6ecbfe2

https://github.com/rcorre/phobos/commit/512d9b8db6f311db6a9b6ccb077a691cec66ce70


I'm not sure why your fix didn't work, but generally I work 
around this by converting the OnlyResult into an array:


import std.array : array;
assert(only(3,1,2).array.sort.equal(only(1,2,3)));


If you are looking for a lazy uniq that works on non sorted 
ranges, I implemented one not to long ago:

http://github.com/BlackEdder/ggplotd/blob/master/source/ggplotd/range.d


Re: Named arguments via struct initialization in functions

2016-03-08 Thread Edwin van Leeuwen via Digitalmars-d
On Wednesday, 9 March 2016 at 07:30:31 UTC, Edwin van Leeuwen 
wrote:
I also added a merge function that will return a tuple 
containing merged named tuples:


Tuple!(double,"x",string,"colour")(-1, 
"black").merge(Tuple!(double,"x")(0.0))


returns:
Tuple!(double,"x",string,"colour")(0, "black");


Quick clarification. The merge function is used to merge the 
passed tuple, with the default values needed in the function. 
This way we don't have to worry about missing values.


Re: Named arguments via struct initialization in functions

2016-03-08 Thread Edwin van Leeuwen via Digitalmars-d

On Sunday, 6 March 2016 at 17:35:38 UTC, Seb wrote:

Hey all,

Using structs is not ideal, because one can't require 
parameters, but this can be solved by having those parameters 
as normal ones like `sliced(4, {allowDownsize: true})` and it 
creates some maybe unnecessary overhead.

However it is probably the easiest solution right now.


In ggplotd I often use named tuples as and "anonymoous" struct:
Tuple!(double,"x")( 0.0 )

I also added a merge function that will return a tuple containing 
merged named tuples:


Tuple!(double,"x",string,"colour")(-1, 
"black").merge(Tuple!(double,"x")(0.0))


returns:
Tuple!(double,"x",string,"colour")(0, "black");

As an aside the merge function also works with structs so you can 
do the following:


struct Point
{
  double x;
  double y;
}

Tuple!(double,"x",string,"colour")(-1, "black").merge(Point(1,2))

returns:
Tuple!(double,"x",double,"y",string,"colour")(1, 2, "black");

It works reasonably well, except that the tuples require a lot of 
typing.




Re: Memory Efficient HashSet

2016-03-08 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 8 March 2016 at 08:12:04 UTC, Nordlöw wrote:
Has anybody put together a memory-efficient D-implementation of 
a HashSet


Something like

sparse_hash_set<> contained in

https://github.com/sparsehash/sparsehash

but in D.


There is an implementation in:
code.dlang.org/packages/emsi_containers

But to be honest I got stuck trying to use it (copy constructor 
disabled), so I used this very minimal wrapper around associative 
array:


private struct HashSet(E) {
// TODO switch to proper implementation (not using AA)
bool put( E el )
{
if ( el in set )
return false;
set[el] = set.length;
return true;
}
size_t[E] set;
}

(I only needed put, since I used it to check whether we already 
encountered a value before in a lazy/non sorted implementation of 
uniq)


Re: Warning: statement is not reachable

2016-03-02 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 1 March 2016 at 21:30:44 UTC, Tamas wrote:

  foreach(attr; __traits(getAttributes, S)) {
static if (is(attr == Tag)) {
  return true;
}
  }
  return false;
}();
}

void main() {
  static @Tag struct MyStruct {}
  static struct VanillaStruct {}
  static assert(isTagged!MyStruct);
  static assert(!isTagged!VanillaStruct);
}


Sorry forgot to add the fix to the email. The following should 
work:


  bool tag = false;
  foreach(attr; __traits(getAttributes, S)) {
 static if (is(attr == Tag)) {
   tag = true;
 }
   }
   return tag;



Re: Warning: statement is not reachable

2016-03-02 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Tuesday, 1 March 2016 at 21:30:44 UTC, Tamas wrote:
My d code doesn't compile using ldc2 1.0.0-alpha or anything 
above DMD v2.068.0


Using these compilers I get a lot of "Warning: statement is not 
reachable". Then the both compiler crashes.


ldc2 -w reach.d
dmd -w reach.d

reach.d:

struct Tag {}

template isTagged(S) {
  enum bool isTagged =
delegate() {
  foreach(attr; __traits(getAttributes, S)) {
static if (is(attr == Tag)) {
  return true;
}
  }
  return false;
}();
}

void main() {
  static @Tag struct MyStruct {}
  static struct VanillaStruct {}
  static assert(isTagged!MyStruct);
  static assert(!isTagged!VanillaStruct);
}


We had the same problem in painlessjson and you can find some 
more background (with our fix) on it here: 
https://github.com/BlackEdder/painlessjson/issues/49


As I understand it: if attr == Tag the code will look something 
like this:


   foreach(attr; __traits(getAttributes, S)) {
   return true;
   }
   return false;

and the return false is basically unreachable.


Re: Why file.exists of relative path on Linux always return false?

2016-02-29 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 29 February 2016 at 14:58:46 UTC, Alex Parrill wrote:

On Monday, 29 February 2016 at 14:50:51 UTC, Suliman wrote:

I am trying to check relative path on Linux for exists.

string mypath = "~/Documents/imgs";


~ is expanded by your shell. It is not a relative path, and 
system calls do not recognize it (same with environmental 
variables).


D can expand tilde with expandTilde:

import std.path : expandTilde;
string mypath = expandTilde("~/Documents/imgs");




Re: Am I right understand the dub.json system?

2016-02-29 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 29 February 2016 at 12:45:36 UTC, Suliman wrote:
On Monday, 29 February 2016 at 12:34:02 UTC, Edwin van Leeuwen 
wrote:

Should it be like this?
http://www.everfall.com/paste/id.php?80k9jsgdx6o3

"versions": ["VibeCustomMain"],
"versions": ["USE_MYSQL"],



As far as I know all versions should be on one line:
 "versions": ["VibeCustomMain","USE_MYSQL"],


And by log it's again try to build sqllite.


What does the log actually say? Is it trying to bind to sqlite?



What happens if you also add

"subConfigurations": {
   "ddbc":"MySQL"
}


Re: Am I right understand the dub.json system?

2016-02-29 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Monday, 29 February 2016 at 12:27:04 UTC, Suliman wrote:
For example I have got app that depended on DDBC. In 
configuration section DDBC related on:


"libs-posix": [
"sqlite3",
"pq"
]

Does it's mean that it will try to find this 2 libs in any 
case? Even I do not use them.


If I do not need them what I should to do? Fix 
~/.dub/packages/ddbc and remove this strings from it, or what?


Reading the dub.json from ddbc it seems you can specify which 
version you want. So if you only need mysql support you add

"versions": ["USE_MYSQL"],
in your own dub.json file.


Re: Is DUB the best place to get examples of "Best of" D code?

2016-02-28 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Sunday, 28 February 2016 at 05:59:39 UTC, WhatMeWorry wrote:


If so, is there a way to do a global search of all projects in 
DUB?


If you just want to search through package names and descriptions 
you can use the search box at the top right of code.dlang.org.


If you want to search through code. Most packages are on github, 
so you could search there (limit by D projects).


  1   2   >