Re: std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn
It seems my lacking knowledge of C has gotten the best of me and 
longs in C only have a signed int range? It looks like in C, 
fseeko() is needed on linux and _fseeki64() is needed on windows, 
but I dont see either of these in stdc.stdio.





Re: std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn

On Monday, 14 March 2016 at 03:07:05 UTC, Nicholas Wilson wrote:

On Monday, 14 March 2016 at 00:12:46 UTC, stunaep wrote:
On Sunday, 13 March 2016 at 12:21:11 UTC, Nicholas Wilson 
wrote:

[...]


I'm on 64 bit but it needs to work on both. It works for 
anything between 0 and 2147483647.



[...]


that throws an error before reaching f.tell()


[...]


Also, seeking relative to the current position throws the same 
error as in the original post if it's over max signed int.



[...]


Hmm. If you're getting an errno exception ( as opposed to a 
conv) I really don't
think that theres anything you can do about it, as its a 
problem with the C standard

lib. What OS/version are you running?

what does the equivalent in C give you.
i.e.

FILE* f = fopen(...,"r");
fseek(f,0,SEEK_END);
printf("%ld",ftell(f));
printf("%d",errno);


I'm currently on windows 7. The code you gave me prints 022. It's 
weird because it always tries to convert longs to ints and I 
think that is weird because the function uses a c_long.

int fseek(FILE* stream, c_long offset, int whence)


It wont even compile if I try giving it a long
Error: function core.stdc.stdio.fseek (shared(_iobuf)* stream, 
int offset, int whence) is not callable using argument types 
(shared(_iobuf)*, long, int)


I also tried giving it a c_long, but this line

c_long test = 2147483649;

gives this error for some reason...
Error: cannot implicitly convert expression (2147483649L) of 
type long to int


It's like c_longs are not longs at all...


Re: Where do I learn to use GtkD

2016-03-13 Thread Gerald via Digitalmars-d-learn

On Sunday, 13 March 2016 at 19:53:35 UTC, karabuta wrote:

On Sunday, 13 March 2016 at 19:34:36 UTC, WebFreak001 wrote:
and in the (not quite complete) documentation you can find 
widgets you might want to use. Its a great place for getting 
ideas on which widgets to use imo. 
http://api.gtkd.org/src/gtk/AboutDialog.html


That thing really need some work to make it consumable :)


I contributed a script (makeddocs.sh) to generate the 
documentation in ddox instead of candydocs, ddox is miles better 
then candydocs and using it is way more efficient IMHO.





Re: Where do I learn to use GtkD

2016-03-13 Thread Gerald via Digitalmars-d-learn

On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote:
Any help on where I can get better leaning materials(GtkD)? 
Repo, blogs post, etc please


I starting learning both D and GTK back in October, I found that 
a combination of looking at an example D GtkD app, Grestful 
(https://github.com/Gert-dev/grestful), as well as examples in 
other languages worked fine for me. I started with a simple 
program as a learning example and then moved up from there. I'm 
still learning every day but it's coming along. I know you are 
already aware of Terminix but I have another, simpler app at 
https://github.com/gnunn1/vgrep as well.


Finally, I have some entries on my blog about using GtkD based on 
my experiences, you can check them out at http://www.gexperts.com.


Re: std.stdio.File.seek error

2016-03-13 Thread Nicholas Wilson via Digitalmars-d-learn

On Monday, 14 March 2016 at 00:12:46 UTC, stunaep wrote:

On Sunday, 13 March 2016 at 12:21:11 UTC, Nicholas Wilson wrote:

On Sunday, 13 March 2016 at 10:32:41 UTC, stunaep wrote:
I have a very large file I need to read data from at certain 
positions, but I have run into this error

[...]
when seeking to 6346890680. Seeking to smaller values such as 
3580720 work with no problem. The file is well over 8GB, so 
it must be able to read data at positions that high.


are you on a 32 or 64 bit system?
You could try 2 or more consecutive relative seeks in place of 
an absolute seek.

i.e.
File f = ... ;
f.seek(173445340 , SEEK_SET);
f.seek(173445340 , SEEK_REL);
also what does
f.seek(0,SEEK_END);
writeln(f.tell());
print?


I'm on 64 bit but it needs to work on both. It works for 
anything between 0 and 2147483647.



f.seek(0,SEEK_END);
writeln(f.tell());


that throws an error before reaching f.tell()

std.exception.ErrnoException@std\stdio.d(920): Could not seek 
in file `./file.dat' (Invalid argument)


0x00013FE67868 in @safe bool 
std.exception.errnoEnforce!(bool, "std\stdio.d", 
920uL).errnoEnforce(bool, lazy immutable(char)[])
0x00013FE4E7D3 in @trusted void std.stdio.File.seek(long, 
int)


Also, seeking relative to the current position throws the same 
error as in the original post if it's over max signed int.



f.seek(2147483647, SEEK_SET);
writeln(f.tell()); // prints 2147483647
f.seek(4, SEEK_CUR); // throws error


Hmm. If you're getting an errno exception ( as opposed to a conv) 
I really don't
think that theres anything you can do about it, as its a problem 
with the C standard

lib. What OS/version are you running?

what does the equivalent in C give you.
i.e.

FILE* f = fopen(...,"r");
fseek(f,0,SEEK_END);
printf("%ld",ftell(f));
printf("%d",errno);


Re: Programming in D vs The D Programming Language

2016-03-13 Thread Ali Çehreli via Digitalmars-d-learn

On 03/13/2016 02:40 PM, Saša Janiška wrote:

>> quality of the softcover by CreateSpace

> Have you seen this one:
>
> 
http://www.amazon.com/gp/customer-reviews/R1WWT9EIV3UDI0/ref=cm_cr_arp_d_rvw_ttl?ie=UTF8=0692599436


Yes, I had seen that one. It is unfortunate... :-/

>> I've gone all the trouble to also publish with IngramSpark and gave
>> the book stores a very big discount just so that users could return
>> their books. How about order your copy through your local book store
>> and see how it looks and whether the return process is pleasant.
>
> Well, I'm from Croatia and the D is too unpopular here, so there is no
> way to find the book in the local store.

I agree and I doubt that I will ever see PinD on a local bookshop shelf. 
What I meant was, IngramSpark makes it *possible* at all for a local 
bookshop to order the book for you and that you can return it for a full 
refund.


The differences are:

* Because they boycot CreateSpace due to its affiliation with Amazon, a 
local bookstore will not store books printed by CreateSpace. This is 
because the wholesale discount is too little from CreateSpace and local 
book stores do not agree with certain practices of Amazon's book business.


* They will still order for you a book by CreateSpace only if you pay up 
front and if you understand that the book is not returnable. (Because 
CreateSpace books are simply not returnable.) On the other hand, if the 
local book store orders the book from IngramSpark, then you need not 
prepay and you (and the bookstore) can return it.


So, I really think that your local bookstore will order one of the 
IngramSpark printing. And you will not pay for customs or shipping.


>> dinner in Berlin at DConf. ;) )
>
> Thank you for an invitation - I'm not sure I'll make it

11 hours by car to Berlin seems a little long for you but there must be 
trains in Europe. ;) I hope you and many others can make it. So many 
good friends here...


Ali



Re: std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn

On Sunday, 13 March 2016 at 12:21:11 UTC, Nicholas Wilson wrote:

On Sunday, 13 March 2016 at 10:32:41 UTC, stunaep wrote:
I have a very large file I need to read data from at certain 
positions, but I have run into this error
std.conv.ConvOverflowException@std\conv.d(1328): Conversion 
positive overflow
when seeking to 6346890680. Seeking to smaller values such as 
3580720 work with no problem. The file is well over 8GB, so it 
must be able to read data at positions that high.


are you on a 32 or 64 bit system?
You could try 2 or more consecutive relative seeks in place of 
an absolute seek.

i.e.
File f = ... ;
f.seek(173445340 , SEEK_SET);
f.seek(173445340 , SEEK_REL);
also what does
f.seek(0,SEEK_END);
writeln(f.tell());
print?


I'm on 64 bit but it needs to work on both. It works for anything 
between 0 and 2147483647.



f.seek(0,SEEK_END);
writeln(f.tell());


that throws an error before reaching f.tell()

std.exception.ErrnoException@std\stdio.d(920): Could not seek 
in file `./file.dat' (Invalid argument)


0x00013FE67868 in @safe bool 
std.exception.errnoEnforce!(bool, "std\stdio.d", 
920uL).errnoEnforce(bool, lazy immutable(char)[])
0x00013FE4E7D3 in @trusted void std.stdio.File.seek(long, 
int)


Also, seeking relative to the current position throws the same 
error as in the original post if it's over max signed int.



f.seek(2147483647, SEEK_SET);
writeln(f.tell()); // prints 2147483647
f.seek(4, SEEK_CUR); // throws error


Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread anonymous via Digitalmars-d-learn

On Sunday, 13 March 2016 at 22:34:54 UTC, Chris Wright wrote:
In theory, it can't be modified. As a practical matter, unions 
and casts will allow people to modify it.


Saying that it *can't* be modified is slightly besides the point, 
yeah. It *must* not be modified. Casting away const and then 
mutating will probably just work as expected much of the time. 
But it's not allowed by the language. One must not do it.


I think it's important not to give the impression that it's ok in 
practice to cast away const and then mutate.


By the way, I don't think unions are in the exact same boat as 
casts here. With a union of const and mutable types, I'd say it's 
perfectly fine to mutate the data through the mutable one. Such a 
union is similar to having const and mutable pointers to the same 
data. Unions of immutable and mutable types are weird, though.


Decorating your code with @safe is intended to prevent these 
holes (and other types of unsafe code).


But even in non-@safe code, the compiler doesn't just accept 
mutating through a const reference. It requires a cast, which is 
an explicit signal to just do what the programmer says. There's a 
similar signal for ignoring @safe: @trusted.


Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread Chris Wright via Digitalmars-d-learn
On Sun, 13 Mar 2016 21:14:59 +, anonymous wrote:

> On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:
>> ref const(Array!Type) view(){}
>>
>> Unless the result is explicitly cast later it can't me modified.
> 
> No, it can't be modified, period. Casting away const and then mutating
> is not allowed, it has undefined behavior.

In theory, it can't be modified. As a practical matter, unions and casts 
will allow people to modify it.

Decorating your code with @safe is intended to prevent these holes (and 
other types of unsafe code). In practice, @safe has some implementation 
flaws, but it will catch the straightforward cases -- and even some of 
the sneaky ones.


Re: Programming in D vs The D Programming Language

2016-03-13 Thread Saša Janiška via Digitalmars-d-learn
Ali Çehreli  writes:

> You may find that D has changed since TDPL was printed but it's still
> a great read. In some places it explains tradeoffs in language design
> in general.

Yeah, I like, based on what I've seen some portions which explains
'why'.

> PiD starts as a tutorial to novices but can also be used a D language
> (not Phobos) reference because it includes virtually everything.

Great!

> I found the quality of the softcover by CreateSpace pretty good in
> general but there was one copy that was trimmed unacceptable crooked.
> However, I've never seen one with a bad glue.

Have you seen this one:

http://www.amazon.com/gp/customer-reviews/R1WWT9EIV3UDI0/ref=cm_cr_arp_d_rvw_ttl?ie=UTF8=0692599436

> On the other hand, the hardcover edition that I have has a different
> kind of binding issue: The long rectangular spine piece is too narrow.

Hmm...that's strange as well...

> I presume the paper used by the printer has gotten thicker over time,
> presumably still within spec, but the template that they give to the
> cover designer is still for thinner paper. (?) The end result is a
> book that doesn't fit inside that narrow spine piece well. :-/

I was publishing hardcover books so I know what are you talking about.

Otoh, if I'd put paperback in hardcover at some local shop. it would
cost me additional $10  - almost the price difference, but I might think
about it since the end result might be better. (btw, I also put Andrei's
book in hardcover and the end result is superb.)

> I've gone all the trouble to also publish with IngramSpark and gave
> the book stores a very big discount just so that users could return
> their books. How about order your copy through your local book store
> and see how it looks and whether the return process is pleasant.

Well, I'm from Croatia and the D is too unpopular here, so there is no
way to find the book in the local store.

Anyway, thank you for additional info about book production and its
quality, so I can have proper decision what to buy.

(If not, I'll buy you dinner in Berlin at DConf. ;) )

Thank you for an invitation - I'm not sure I'll make it, but, at least,
I'm happy to be back to D and your book is one of the reasons. ;)


Sincerely,
Gour

-- 
>From wherever the mind wanders due to its flickering and unsteady
nature, one must certainly withdraw it and bring it back under
the control of the self.


Re: Is D a good choice for embedding python/octave/julia

2016-03-13 Thread Laeeth Isharc via Digitalmars-d-learn

On Sunday, 13 March 2016 at 18:42:59 UTC, Bastien wrote:
The sticking point is unless I commit the rest of my life to 
maintaining this software, I can't write it all in D. The 
algorithms change/are improved yearly; the output format from 
the instrument changes once in a while and therefore these need 
to be easily scripted/modified by other (non-programming) 
scientists and the community that only really know python and 
octave.


It's pretty easy to use D from python and python from D.  The 
documentation for PyD isn't so great, but once you have figured 
it out, it's easy.  Start with something very small (the examples 
and tests in the PyD repo are the best documentation) and work up 
from there.


You can even embed D in a Jupyter/iPython notebook, and write 
some cells in D and some in python and have them call each other. 
 See PydMagic by John Colvin.

https://github.com/DlangScience/PydMagic

D can talk to Julia via C linkage already.  Just extern(C) when 
you declare your D function, and I guess use C style arrays.


I started porting julia.h to D, but didn't get have time to 
finish.  Ilya Yaroshenko, who created the ndslice library in 
std.experimental, will be working on julia integration in coming 
months.


By the way, you can also embed R in D and call D from R - see 
work by bachmeier on bitbucket.  That's very important because of 
the huge numbers of R libraries.  Although R is slow, there 
apparently shouldn't be so much overhead in calling a C library 
written for R from D.
I guess my resilience to using D for the algorithms is because 
with python, I have access to numpy and matplotlib. There do 
seem to be some ongoing developments though:

http://forum.dlang.org/post/mailman.4923.1434903477.7663.digitalmar...@puremagic.com


You already have access to matplotlib from D - see here (and 
scroll down or search for matplotlib):

https://d.readthedocs.org/en/latest/examples.html


And you can call numpy from D, but there is some overhead, and I 
wouldn't want to do it inside a tight loop.


From PyD unit tests:

InterpContext context = new InterpContext();

context.py_stmts(outdent("
import numpy
a = numpy.eye(2, dtype='complex128')
"));

context.a.to_d!(Complex!double[][] )();





Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread anonymous via Digitalmars-d-learn

On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:

ref const(Array!Type) view(){}

Unless the result is explicitly cast later it can't me modified.


No, it can't be modified, period. Casting away const and then 
mutating is not allowed, it has undefined behavior.


Re: How to list all version identifiers?

2016-03-13 Thread Iakh via Digitalmars-d-learn

On Sunday, 13 March 2016 at 20:16:36 UTC, Basile B. wrote:

On Sunday, 13 March 2016 at 16:28:50 UTC, Iakh wrote:

On Sunday, 13 March 2016 at 15:50:47 UTC, Basile B. wrote:
trivial answer, let's say you have dcd-server running in the 
background:


dcd-client -c8 <<< "version("


Thanks. Will try.


But it was a joke actually. It works but this is not very 
straightforward. And it needs a bit of post processing since 
the output you'll get is normally made for the completion menu 
of D editors.


Maybe it is what I'm searching for if there is a way to specify
compiler/parser.


Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread ParticlePeter via Digitalmars-d-learn

On Sunday, 13 March 2016 at 20:28:33 UTC, JR wrote:

On Sunday, 13 March 2016 at 20:13:03 UTC, Basile B. wrote:

On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:

[...]


Basile beat me to it. Yes, ref const(Array!T) accessor.

http://dpaste.dzfl.pl/cb2bc5cf9917


Thank you very much, both of you. JR, that's excellent 
(additional) information :-) but my struct is not supposed to 
work as array, "wrapper" was a wrong expression.

ref const(Array!T) accessor() will still do :-)


Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread JR via Digitalmars-d-learn

On Sunday, 13 March 2016 at 20:13:03 UTC, Basile B. wrote:

On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:

[...]


Basile beat me to it. Yes, ref const(Array!T) accessor.

http://dpaste.dzfl.pl/cb2bc5cf9917



Re: How to list all version identifiers?

2016-03-13 Thread Basile B. via Digitalmars-d-learn

On Sunday, 13 March 2016 at 16:28:50 UTC, Iakh wrote:

On Sunday, 13 March 2016 at 15:50:47 UTC, Basile B. wrote:
trivial answer, let's say you have dcd-server running in the 
background:


dcd-client -c8 <<< "version("


Thanks. Will try.


But it was a joke actually. It works but this is not very 
straightforward. And it needs a bit of post processing since the 
output you'll get is normally made for the completion menu of D 
editors.


Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread Basile B. via Digitalmars-d-learn

On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:

Unless the result is explicitly cast later it can't me modified.


import std.stdio, std.container.array;

struct Foo
{
private Array!int arr;
ref const(Array!int) view()
{
return arr;
}
}

void main(string[] args)
{
Foo foo;
auto a = foo.view.dup;
}


...and any attempt will produce an error, like in my sample:

Error: mutable method std.container.array.Array!int.Array.dup is 
not callable using a const object


Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread Basile B. via Digitalmars-d-learn

On Sunday, 13 March 2016 at 19:37:42 UTC, ParticlePeter wrote:
I have a struct that privately warps an std.container.array. I 
would like to return a read-only reference of this array, it 
should not be duplicated. How can I do this?


Cheers, ParticlePeter


ref const(Array!Type) view(){}

Unless the result is explicitly cast later it can't me modified.


import std.stdio, std.container.array;

struct Foo
{
private Array!int arr;
ref const(Array!int) view()
{
return arr;
}
}

void main(string[] args)
{
Foo foo;
auto a = foo.view.dup;
}


Re: Where do I learn to use GtkD

2016-03-13 Thread karabuta via Digitalmars-d-learn

On Sunday, 13 March 2016 at 19:34:36 UTC, WebFreak001 wrote:

On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote:
Any help on where I can get better leaning materials(GtkD)? 
Repo, blogs post, etc please


there isn't much about GtkD specificly, but as a start there is 
this: https://sites.google.com/site/gtkdtutorial/


Funny thing is that I just found that and was about to post it :) 
Thanks




I think the closest are GTK# and the one for Vala.


I will do that right away :)


But gtkd is just a nice wrapper for gtk. I'm not really someone 
who can write tutorials but you or someone else could make some 
tutorials for it. Might attract more people.


Great idea. I thinks I will just keep my code and use it as a 
guide/tutorial in my repo just like the pygtk book.



and in the (not quite complete) documentation you can find 
widgets you might want to use. Its a great place for getting 
ideas on which widgets to use imo. 
http://api.gtkd.org/src/gtk/AboutDialog.html


That thing really need some work to make it consumable :)




How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread ParticlePeter via Digitalmars-d-learn
I have a struct that privately warps an std.container.array. I 
would like to return a read-only reference of this array, it 
should not be duplicated. How can I do this?


Cheers, ParticlePeter


Re: Where do I learn to use GtkD

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn

On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote:
Any help on where I can get better leaning materials(GtkD)? 
Repo, blogs post, etc please


there isn't much about GtkD specificly, but as a start there is 
this: https://sites.google.com/site/gtkdtutorial/


If you get the basics from that site how the D specific stuff 
works you can just follow some other tutorials like PyGTK, GTK#, 
gtkmm, etc.


I think the closest are GTK# and the one for Vala.

But gtkd is just a nice wrapper for gtk. I'm not really someone 
who can write tutorials but you or someone else could make some 
tutorials for it. Might attract more people.


If you want to find the D function name for some C gtk function 
you can just search for the function in their github repository: 
https://github.com/gtkd-developers/GtkD


and in the (not quite complete) documentation you can find 
widgets you might want to use. Its a great place for getting 
ideas on which widgets to use imo. 
http://api.gtkd.org/src/gtk/AboutDialog.html


Where do I learn to use GtkD

2016-03-13 Thread karabuta via Digitalmars-d-learn
Gtk3 from python3 has got I nice book with examples that are not 
so advanced but enough to get you doing real work(from a beginner 
point of view). GtkD seem to have changed the API structure 
compared to python3 Gtk3 and the demo examples just "show-off" 
IMO :). The documentation is really^ not good :)


Any help on where I can get better leaning materials(GtkD)? Repo, 
blogs post, etc please


Re: Is D a good choice for embedding python/octave/julia

2016-03-13 Thread Bastien via Digitalmars-d-learn

On Sunday, 13 March 2016 at 18:12:07 UTC, cym13 wrote:

On Sunday, 13 March 2016 at 13:02:16 UTC, Bastien wrote:
Hi, apologies for what may be a fairly obvious question to 
some.


## The background:
I have been tasked with building software to process data 
output by scientific instruments for non-experts - basically 
with GUI, menus, easy config files (JSON or similar) - and the 
ability to do some serious number crunching.


My background is python/octave and would be happy building it 
in python (or god forbid, even octave), but it would end up 
clunky and slow once ported to a standalone executable. Hence 
why I'm looking at other languages. D caught my eye.


## The problem:
The sticking point is unless I commit the rest of my life to 
maintaining this software, I can't write it all in D. The 
algorithms change/are improved yearly; the output format from 
the instrument changes once in a while and therefore these 
need to be easily scripted/modified by other (non-programming) 
scientists and the community that only really know python and 
octave.


Essentially I'd like a D front end, and a D back-end that does 
most of the memory and data management but calls and 
interprets .py, .m and/or .jl scripts (python, matlab, julia) 
to know how to treat the data. This leaves the py/m/jl scripts 
visible to be edited by the end user.


## The question:
Can it be done?
Does this entirely defeat the point of using D and I should 
just code it in python because of the added overheads?



Thanks for your help!
B



I don't have much experience in mixing python and D but here's 
my take on it:


D is a great language but it's not a great glue language. I 
know of no
binding to Julia but good bindings to python exist (pyd as said 
above).
However, if what you want to keep in python is the algorithms 
themselves then
I don't see the point. If I were to mix the two languages I'd 
use python to
do the user interface, some module interface in order to link 
the tool to
others maybe, but the algorithm would definitely be the one 
thing I would do

in D because that's what D is for.


Thanks for all the very useful replies!
Overall seems that D on its own may be better. May not be such a 
bad thing in the end if it moves the scientists away from 
commerical matlab and the great python 2/3 schism.


I guess my resilience to using D for the algorithms is because 
with python, I have access to numpy and matplotlib. There do seem 
to be some ongoing developments though:

http://forum.dlang.org/post/mailman.4923.1434903477.7663.digitalmar...@puremagic.com

So maybe that will all change. I've just ordered a couple books 
which will hopefully give me a bit more insight into the 
feasibility of this project. Otherwise, I'll fall back on 
python...


Re: Is D a good choice for embedding python/octave/julia

2016-03-13 Thread cym13 via Digitalmars-d-learn

On Sunday, 13 March 2016 at 13:02:16 UTC, Bastien wrote:

Hi, apologies for what may be a fairly obvious question to some.

## The background:
I have been tasked with building software to process data 
output by scientific instruments for non-experts - basically 
with GUI, menus, easy config files (JSON or similar) - and the 
ability to do some serious number crunching.


My background is python/octave and would be happy building it 
in python (or god forbid, even octave), but it would end up 
clunky and slow once ported to a standalone executable. Hence 
why I'm looking at other languages. D caught my eye.


## The problem:
The sticking point is unless I commit the rest of my life to 
maintaining this software, I can't write it all in D. The 
algorithms change/are improved yearly; the output format from 
the instrument changes once in a while and therefore these need 
to be easily scripted/modified by other (non-programming) 
scientists and the community that only really know python and 
octave.


Essentially I'd like a D front end, and a D back-end that does 
most of the memory and data management but calls and interprets 
.py, .m and/or .jl scripts (python, matlab, julia) to know how 
to treat the data. This leaves the py/m/jl scripts visible to 
be edited by the end user.


## The question:
Can it be done?
Does this entirely defeat the point of using D and I should 
just code it in python because of the added overheads?



Thanks for your help!
B



I don't have much experience in mixing python and D but here's my 
take on it:


D is a great language but it's not a great glue language. I know 
of no
binding to Julia but good bindings to python exist (pyd as said 
above).
However, if what you want to keep in python is the algorithms 
themselves then
I don't see the point. If I were to mix the two languages I'd use 
python to
do the user interface, some module interface in order to link the 
tool to
others maybe, but the algorithm would definitely be the one thing 
I would do

in D because that's what D is for.



Re: Get address of object in constructor.

2016-03-13 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 13 March 2016 at 16:16:55 UTC, MGW wrote:

void* thisAddr = cast(void*) 


This doesn't really make sense anyway, this is a local variable, 
you want to do cast(void*) this in a class if you need the 
address (which btw, you shouldn't actually, the reference itself 
ought to be enough)


Re: Programming in D vs The D Programming Language

2016-03-13 Thread Ali Çehreli via Digitalmars-d-learn

On 03/13/2016 09:27 AM, gour wrote:

> a) how much is Andrei's book still relevant?

You may find that D has changed since TDPL was printed but it's still a 
great read. In some places it explains tradeoffs in language design in 
general.


> b) whether PiD is recommended one to start with D *today* ?

PiD starts as a tutorial to novices but can also be used a D language 
(not Phobos) reference because it includes virtually everything. (There 
are exceptions e.g. __ctor and friends are not mentioned at all.)


Best thing for you to do is to check out PiD first before deciding to 
buy. The PDF file is exactly the same as the printed version:


  http://ddili.org/ders/d.en/

> plan to release PiD with hardcover

There is a hardcover edition:

  978-0-692-59943-3

> since several reviewers @Amazon reported that the glued used to
> bind the book is not the best*

I found the quality of the softcover by CreateSpace pretty good in 
general but there was one copy that was trimmed unacceptable crooked. 
However, I've never seen one with a bad glue. I think this is due to 
different regional printers: Perhaps the printers that shipped to my 
address (Bay Area, California) were better. (?)


On the other hand, the hardcover edition that I have has a different 
kind of binding issue: The long rectangular spine piece is too narrow. 
(I've heard this from a reader as well.) I presume the paper used by the 
printer has gotten thicker over time, presumably still within spec, but 
the template that they give to the cover designer is still for thinner 
paper. (?) The end result is a book that doesn't fit inside that narrow 
spine piece well. :-/


I've gone all the trouble to also publish with IngramSpark and gave the 
book stores a very big discount just so that users could return their 
books. How about order your copy through your local book store and see 
how it looks and whether the return process is pleasant. (If not, I'll 
buy you dinner in Berlin at DConf. ;) )


Ali



Re: Programming in D vs The D Programming Language

2016-03-13 Thread _d0s_ via Digitalmars-d-learn

On Sunday, 13 March 2016 at 16:27:07 UTC, gour wrote:

Hello,

after quite some time I'm returning to D being fed up with some 
other languages to become more ready for writing open-source 
multi-platform desktop app(s)...


I already own copy of Andrei's The D Programming Language book, 
but never went fully through it, but I see in the meantime 
Programming in D by Ali was released so I wonder:


a) how much is Andrei's book still relevant?

b) whether PiD is recommended one to start with D *today* ?

Btw, I prefer hardcopy books, if possible, and interested 
whether there is plan to release PiD with hardcover since 
several reviewers @Amazon reported that the glued used to bind 
the book is not the best*



Sincerely,
Gour


b) i prefer this one :)
http://ddili.org/ders/d.en/


Re: Is D a good choice for embedding python/octave/julia

2016-03-13 Thread Chris Wright via Digitalmars-d-learn
On Sun, 13 Mar 2016 13:02:16 +, Bastien wrote:
> The sticking point is unless I commit the rest of my life to maintaining
> this software, I can't write it all in D. The algorithms change/are
> improved yearly; the output format from the instrument changes once in a
> while and therefore these need to be easily scripted/modified by other
> (non-programming) scientists and the community that only really know
> python and octave.

http://code.dlang.org/packages/pyd has you covered.

The degree to which it has you covered is based on how much you can wrap 
expensive operations up opaquely. If it turns out next year that someone 
has a new algorithm they need for something you implemented in D, it's 
going to be more work overall.


Re: How to list all version identifiers?

2016-03-13 Thread Iakh via Digitalmars-d-learn

On Sunday, 13 March 2016 at 15:50:47 UTC, Basile B. wrote:
trivial answer, let's say you have dcd-server running in the 
background:


dcd-client -c8 <<< "version("


Thanks. Will try.


Programming in D vs The D Programming Language

2016-03-13 Thread gour via Digitalmars-d-learn

Hello,

after quite some time I'm returning to D being fed up with some 
other languages to become more ready for writing open-source 
multi-platform desktop app(s)...


I already own copy of Andrei's The D Programming Language book, 
but never went fully through it, but I see in the meantime 
Programming in D by Ali was released so I wonder:


a) how much is Andrei's book still relevant?

b) whether PiD is recommended one to start with D *today* ?

Btw, I prefer hardcopy books, if possible, and interested whether 
there is plan to release PiD with hardcover since several 
reviewers @Amazon reported that the glued used to bind the book 
is not the best*



Sincerely,
Gour


Re: Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn

On Sunday, 13 March 2016 at 16:02:07 UTC, WebFreak001 wrote:
However note that this is not the same as that function. 
cast(void*)this and  are 2 different things. So if you 
want to do the same as saveThis just do void* thisAddr = 
cast(void*)  instead


void* thisAddr = cast(void*) 

Error compile: Deprecation: this is not an lvalue




Re: Is D a good choice for embedding python/octave/julia

2016-03-13 Thread Lass Safin via Digitalmars-d-learn

On Sunday, 13 March 2016 at 13:02:16 UTC, Bastien wrote:

Hi, apologies for what may be a fairly obvious question to some.

## The background:
I have been tasked with building software to process data 
output by scientific instruments for non-experts - basically 
with GUI, menus, easy config files (JSON or similar) - and the 
ability to do some serious number crunching.


My background is python/octave and would be happy building it 
in python (or god forbid, even octave), but it would end up 
clunky and slow once ported to a standalone executable. Hence 
why I'm looking at other languages. D caught my eye.


## The problem:
The sticking point is unless I commit the rest of my life to 
maintaining this software, I can't write it all in D. The 
algorithms change/are improved yearly; the output format from 
the instrument changes once in a while and therefore these need 
to be easily scripted/modified by other (non-programming) 
scientists and the community that only really know python and 
octave.


Essentially I'd like a D front end, and a D back-end that does 
most of the memory and data management but calls and interprets 
.py, .m and/or .jl scripts (python, matlab, julia) to know how 
to treat the data. This leaves the py/m/jl scripts visible to 
be edited by the end user.


## The question:
Can it be done?
Does this entirely defeat the point of using D and I should 
just code it in python because of the added overheads?



Thanks for your help!
B


I REALLY don't think you should use _any_ scripted language, if 
what you're looking for is speed.

Now for your main question:
It can be done.
An incomplete list of libraries and bindings for D: 
http://wiki.dlang.org/List_of_Libraries_and_Frameworks.

It includes tools such as GTK.

And I'm very sure that it will be faster than writing it 
completely in python.


Another thing: I myself find D *much* easier to program in than 
python (having experience in both). The many meta-programming 
tools in D and the nice syntactic features of D really make-up 
for the increased complexity of the language compared to Python.



Somethings I'd like to recommend: OpenCL. For algorithms and 
such, using the GPU is much much faster than using the CPU.


Re: Get address of object in constructor.

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn

On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote:

Cfoo foo = new Cfoo(); foo.saveThis();


However note that this is not the same as that function. 
cast(void*)this and  are 2 different things. So if you want 
to do the same as saveThis just do void* thisAddr = cast(void*) 
 instead


Re: Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn

On Sunday, 13 March 2016 at 15:49:20 UTC, WebFreak001 wrote:

On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote:
I want to get address of object Cfoo in constructor. Whether 
it is possible?


class Cfoo {
void* adrThis;
this() {
adrThis = cast(void*) this;
}
}
...
Cfoo foo = new Cfoo();

"this" should work

(pun intended)


Super! Ok!


Re: How to list all version identifiers?

2016-03-13 Thread Basile B. via Digitalmars-d-learn

On Sunday, 13 March 2016 at 15:15:22 UTC, Iakh wrote:

There is trick for gcc:
gcc -dM -E - < /dev/null

It shows all default #defines

Is there way to show all version identifiers for D?
For all or any compiler you know


trivial answer, let's say you have dcd-server running in the 
background:


dcd-client -c8 <<< "version("


Re: Get address of object in constructor.

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn

On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote:
I want to get address of object Cfoo in constructor. Whether it 
is possible?


class Cfoo {
void* adrThis;
this() {
adrThis = cast(void*) this;
}
}
...
Cfoo foo = new Cfoo();

"this" should work

(pun intended)


Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
I want to get address of object Cfoo in constructor. Whether it 
is possible?


now:
-
class Cfoo {
void* adrThis;
void saveThis(void* adr) {  adrThis = adr; }
}
...
Cfoo foo = new Cfoo(); foo.saveThis();

shall be
--
class Cfoo {
void* adrThis;
this() {
adrThis = ?
}
}
...
Cfoo foo = new Cfoo();



Re: In D, lexically, which are the chars that can follow $, exactly ?

2016-03-13 Thread Basile B. via Digitalmars-d-learn

On Sunday, 13 March 2016 at 14:55:36 UTC, Marc Schütz wrote:

On Sunday, 13 March 2016 at 14:07:31 UTC, Basile B. wrote:
'$' is only valid in an indexExpression 
(https://dlang.org/spec/grammar.html#IndexExpression),

so it can only be followed by

- ' '
- ']'
-  operators , usually '-' but also '/', '+', '>>' etc

Is that right ?

I'd like to relax the lexical rule for C.E static macros which 
currently is


- "^\$\w*[a-zA-Z]$", so for example "$a1A" is valid and "$a1" 
is not.


But it looks like for example "$)" or "$}" wouldn't be 
ambiguous since it's not possible in D.


I don't know what C.E is, but `$` is an expansion of 
`PrimaryExpression`, which means it can (syntactically) appear 
anywhere a `PrimaryExpression` is allowed. For example, this 
compiles:


void main() {
int[] a;
a[0 .. ($)] = 0;
}


Then the C.E macros syntax can't be enhanced. At least the 
current is not ambiguous.


The thing is that a macro is substitued automatically/dynamically 
so the requirement is that nothing that's syntaxically valid in D 
must replacable.


How to list all version identifiers?

2016-03-13 Thread Iakh via Digitalmars-d-learn

There is trick for gcc:
gcc -dM -E - < /dev/null

It shows all default #defines

Is there way to show all version identifiers for D?
For all or any compiler you know


Re: In D, lexically, which are the chars that can follow $, exactly ?

2016-03-13 Thread Marc Schütz via Digitalmars-d-learn

On Sunday, 13 March 2016 at 14:07:31 UTC, Basile B. wrote:
'$' is only valid in an indexExpression 
(https://dlang.org/spec/grammar.html#IndexExpression),

so it can only be followed by

- ' '
- ']'
-  operators , usually '-' but also '/', '+', '>>' etc

Is that right ?

I'd like to relax the lexical rule for C.E static macros which 
currently is


- "^\$\w*[a-zA-Z]$", so for example "$a1A" is valid and "$a1" 
is not.


But it looks like for example "$)" or "$}" wouldn't be 
ambiguous since it's not possible in D.


I don't know what C.E is, but `$` is an expansion of 
`PrimaryExpression`, which means it can (syntactically) appear 
anywhere a `PrimaryExpression` is allowed. For example, this 
compiles:


void main() {
int[] a;
a[0 .. ($)] = 0;
}


Re: Clearing associative array.

2016-03-13 Thread ciechowoj via Digitalmars-d-learn

On Sunday, 13 March 2016 at 13:42:02 UTC, cym13 wrote:
The problem was brought up a few days ago (can't remember 
where) and it happens to be a documentation mistake: there is a 
clear() method planned but for a future release (the next one?).


That would be great : )


Re: Is there a sorted map?

2016-03-13 Thread cym13 via Digitalmars-d-learn

On Sunday, 13 March 2016 at 14:11:14 UTC, Anonymouse wrote:

On Sunday, 13 March 2016 at 13:44:35 UTC, cym13 wrote:
Note that implementing an (admitedly not perfect) ordered 
associative array yourself really isn't much work: 
https://github.com/cym13/miscD/blob/master/ordered_aa.d


Unsigned integer comparison with -1 in the remove function, by 
the way. :)


Nice catch, thanks ^^


Re: Is there a sorted map?

2016-03-13 Thread Anonymouse via Digitalmars-d-learn

On Sunday, 13 March 2016 at 13:44:35 UTC, cym13 wrote:
Note that implementing an (admitedly not perfect) ordered 
associative array yourself really isn't much work: 
https://github.com/cym13/miscD/blob/master/ordered_aa.d


Unsigned integer comparison with -1 in the remove function, by 
the way. :)




In D, lexically, which are the chars that can follow $, exactly ?

2016-03-13 Thread Basile B. via Digitalmars-d-learn
'$' is only valid in an indexExpression 
(https://dlang.org/spec/grammar.html#IndexExpression),

so it can only be followed by

- ' '
- ']'
-  operators , usually '-' but also '/', '+', '>>' etc

Is that right ?

I'd like to relax the lexical rule for C.E static macros which 
currently is


- "^\$\w*[a-zA-Z]$", so for example "$a1A" is valid and "$a1" is 
not.


But it looks like for example "$)" or "$}" wouldn't be ambiguous 
since it's not possible in D.




Re: Filling an array

2016-03-13 Thread user42 via Digitalmars-d-learn

On Saturday, 12 March 2016 at 18:33:16 UTC, Alex wrote:

On Saturday, 12 March 2016 at 16:37:25 UTC, user42 wrote:

On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote:

/snip


I thought this was supposed to halt with an error rather than 
compile and set all members to 1.
The syntax, to me anyways, doesn't really communicate the 
intention of: set all members to 1.

//arr[] = 1;


Whereas the following does

fill(arr, 1);


Well, this was not the question. As stated here:
https://dlang.org/spec/arrays.html
in the section "array setting", it is possible to set an array 
in such a manner. And my question was, why a specific array 
behaves not as expected.
So, either there is a problem with filling an array, or, there 
is a problem with implicit conversion of a Nullable!T to its 
underlying type.


Learned something new. I guess I missed that detail when I read 
that page.




Re: Is there a sorted map?

2016-03-13 Thread cym13 via Digitalmars-d-learn

On Sunday, 13 March 2016 at 10:06:24 UTC, stunaep wrote:
On Sunday, 13 March 2016 at 08:33:43 UTC, Jonathan M Davis 
wrote:
On Sunday, March 13, 2016 02:35:27 stunaep via 
Digitalmars-d-learn wrote:

[...]


The closest that we have in Phobos at the moment is 
RedBlackTree in std.container. Its API is geared towards sets, 
not maps, but you can get it to work as a map if you define 
the comparison functions appropriately. Red-black trees are 
typically used for both sets and maps, so using RedBlackTree 
in that manner is pretty normal from an implementation 
perspective, but there's no question that what we really need 
is a wrapper around it that provides a map API, since it's not 
terribly user-friendly to use the set API for a map, much as 
it works.


[...]


Wow, thanks!


Note that implementing an (admitedly not perfect) ordered 
associative array yourself really isn't much work: 
https://github.com/cym13/miscD/blob/master/ordered_aa.d


Re: Clearing associative array.

2016-03-13 Thread cym13 via Digitalmars-d-learn

On Saturday, 12 March 2016 at 12:59:02 UTC, ciechowoj wrote:

On Saturday, 12 March 2016 at 12:42:04 UTC, Adam D. Ruppe wrote:

On Saturday, 12 March 2016 at 12:34:16 UTC, ciechowoj wrote:
If above doesn't work how am I supposed to clear the array? 
`x = string[string].init;` is somewhat ugly.


Read the Tip of the Week section here:

http://arsdnet.net/this-week-in-d/dec-13.html

Short answer: use `= null` to clear the AA. [] doesn't work 
just because the compiler is a bit stupid about the type you 
intend it to be, but null works fine.


BTW you might want to glance through more of the issues for 
the tip section too and see if there's more that interest you.


Nice article :), thanks. But still, what about clear()? In the 
documentation https://dlang.org/spec/hash-map.html#properties 
there is written that associative arrays have clear property.


The problem was brought up a few days ago (can't remember where) 
and it happens to be a documentation mistake: there is a clear() 
method planned but for a future release (the next one?).


Gdmd compiling error

2016-03-13 Thread Orkhan via Digitalmars-d-learn

Hello. I need your help !

I am struggling to compile and install ca Xcom server files which 
is using gdmd .
It is in linux system , and when I type make command it returns 
error like:

/bin/sh: 1: gdmd: not found
Makefile:35: recipe for target 'protocol-daemon' failed
make: ***[protocol-daemon] Error 127

I am in linux Ubuntu. The Makefile file is like that :

DFLAGS_DEBUG=-debug=2 -g -Isrc
DFLAGS_DEBUG1=-debug=1 -g -Isrc
DFLAGS=-O -inline -Isrc

PROTOCOL_SRC=src/misc_util.d src/socket_base.d 
src/xcomm_sockets.d src/msgserver_core.d src/char_outbuffer.d 
src/logging.d src/xml_util.d src/plugins.d src/xcomm_protocol/*.d 
src/stork/*.d src/stork/*/*.d

PROTOCOL_LIBS=-fPIC -q,-rdynamic -L-ldl
PROTOCOL_OUTPUT=./xcomm
PROTOCOL_FLAGS=-c xcomm.conf

PLUGIN_LIBS=-fPIC -q,-rdynamic,-shared

defaulttarget: protocol-daemon plugins-opt
all: protocol-daemon plugins-opt
distclean: clean

protocol:
	gdmd $(DFLAGS_DEBUG) -op -of$(PROTOCOL_OUTPUT) $(PROTOCOL_SRC) 
$(PROTOCOL_LIBS)

find . -name "*.o" -print0 | xargs -0 rm -f

protocol-debug1:
	gdmd $(DFLAGS_DEBUG1) -op -of$(PROTOCOL_OUTPUT) $(PROTOCOL_SRC) 
$(PROTOCOL_LIBS)

find . -name "*.o" -print0 | xargs -0 rm -f

protocol-test: protocol plugins
$(PROTOCOL_OUTPUT) $(PROTOCOL_FLAGS)

protocol-opt:
	gdmd $(DFLAGS) -op -of$(PROTOCOL_OUTPUT) $(PROTOCOL_SRC) 
$(PROTOCOL_LIBS)

find . -name "*.o" -print0 | xargs -0 rm -f

protocol-opt-test: protocol-opt plugins-opt
$(PROTOCOL_OUTPUT) $(PROTOCOL_FLAGS)

protocol-daemon:
	gdmd $(DFLAGS) -version=daemon -op -of$(PROTOCOL_OUTPUT) 
$(PROTOCOL_SRC) $(PROTOCOL_LIBS)

find . -name "*.o" -print0 | xargs -0 rm -f

daemon-debug:
	gdmd $(DFLAGS_DEBUG) -version=daemon -op -of$(PROTOCOL_OUTPUT) 
$(PROTOCOL_SRC) $(PROTOCOL_LIBS)

find . -name "*.o" -print0 | xargs -0 rm -f

protocol-debug: protocol plugins
find . -name "*.o" -print0 | xargs -0 rm -f
gdb --args $(PROTOCOL_OUTPUT) $(PROTOCOL_FLAGS)

plugins:
	gdmd $(DFLAGS_DEBUG) -op -ofplugins/random.so 
src/plugins/random.d $(PLUGIN_LIBS)
	gdmd $(DFLAGS_DEBUG) -op -ofplugins/game_sets.so 
src/plugins/game_sets.d $(PLUGIN_LIBS)


plugins-opt:
	gdmd $(DFLAGS) -op -ofplugins/random.so src/plugins/random.d 
$(PLUGIN_LIBS)
	gdmd $(DFLAGS) -op -ofplugins/game_sets.so 
src/plugins/game_sets.d $(PLUGIN_LIBS)


clean:
find . -name "*.o" -print0 | xargs -0 rm -f
rm -f *.log
rm -f plugins/*.so
rm -f src/test_clients/old_n_crufty
rm -f src/test_clients/scripted
rm -f src/test_clients/spammer
rm -f src/test_clients/spammer2
rm -f $(PROTOCOL_OUTPUT)

backup: distclean
@if [ ! -e dist ]; then mkdir dist; fi
	tar c . --exclude=CVS --exclude=.svn --exclude=dist | bzip2 -9 > 
dist/xcomm-backup_`date +"%Y-%m-%d_%H%M"`.tar.bz2


# Create a release tarball.
dist: distclean
	@if [ "$(DISTVER)" = "" ]; then echo DISTVER not set - please 
set it to 1.0 or similar.; echo; exit 1; fi

@if [ ! -e dist ]; then mkdir dist; fi
	tar c . --exclude=CVS --exclude=.svn --exclude=dist 
--exclude=debug.conf | bzip2 -9 > dist/xcomm-$(DISTVER).tar.bz2


.PHONY: protocol protocol-test protocol-opt protocol-opt-test 
protocol-daemon protocol-debug plugins plugins-opt clean dist 
distclean backup all defaulttarget

.NOTPARALLEL:



Is D a good choice for embedding python/octave/julia

2016-03-13 Thread Bastien via Digitalmars-d-learn

Hi, apologies for what may be a fairly obvious question to some.

## The background:
I have been tasked with building software to process data output 
by scientific instruments for non-experts - basically with GUI, 
menus, easy config files (JSON or similar) - and the ability to 
do some serious number crunching.


My background is python/octave and would be happy building it in 
python (or god forbid, even octave), but it would end up clunky 
and slow once ported to a standalone executable. Hence why I'm 
looking at other languages. D caught my eye.


## The problem:
The sticking point is unless I commit the rest of my life to 
maintaining this software, I can't write it all in D. The 
algorithms change/are improved yearly; the output format from the 
instrument changes once in a while and therefore these need to be 
easily scripted/modified by other (non-programming) scientists 
and the community that only really know python and octave.


Essentially I'd like a D front end, and a D back-end that does 
most of the memory and data management but calls and interprets 
.py, .m and/or .jl scripts (python, matlab, julia) to know how to 
treat the data. This leaves the py/m/jl scripts visible to be 
edited by the end user.


## The question:
Can it be done?
Does this entirely defeat the point of using D and I should just 
code it in python because of the added overheads?



Thanks for your help!
B





Re: std.stdio.File.seek error

2016-03-13 Thread Nicholas Wilson via Digitalmars-d-learn

f.seek(173445340 , SEEK_SET);
f.seek(173445340 , SEEK_REL);

oops that should be 3173445340.


Re: std.stdio.File.seek error

2016-03-13 Thread Nicholas Wilson via Digitalmars-d-learn

On Sunday, 13 March 2016 at 10:32:41 UTC, stunaep wrote:
I have a very large file I need to read data from at certain 
positions, but I have run into this error
std.conv.ConvOverflowException@std\conv.d(1328): Conversion 
positive overflow
when seeking to 6346890680. Seeking to smaller values such as 
3580720 work with no problem. The file is well over 8GB, so it 
must be able to read data at positions that high.


are you on a 32 or 64 bit system?
You could try 2 or more consecutive relative seeks in place of an 
absolute seek.

i.e.
File f = ... ;
f.seek(173445340 , SEEK_SET);
f.seek(173445340 , SEEK_REL);
also what does
f.seek(0,SEEK_END);
writeln(f.tell());
print?





std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn
I have a very large file I need to read data from at certain 
positions, but I have run into this error
std.conv.ConvOverflowException@std\conv.d(1328): Conversion 
positive overflow
when seeking to 6346890680. Seeking to smaller values such as 
3580720 work with no problem. The file is well over 8GB, so it 
must be able to read data at positions that high.


Re: Is there a sorted map?

2016-03-13 Thread stunaep via Digitalmars-d-learn

On Sunday, 13 March 2016 at 08:33:43 UTC, Jonathan M Davis wrote:
On Sunday, March 13, 2016 02:35:27 stunaep via 
Digitalmars-d-learn wrote:

[...]


The closest that we have in Phobos at the moment is 
RedBlackTree in std.container. Its API is geared towards sets, 
not maps, but you can get it to work as a map if you define the 
comparison functions appropriately. Red-black trees are 
typically used for both sets and maps, so using RedBlackTree in 
that manner is pretty normal from an implementation 
perspective, but there's no question that what we really need 
is a wrapper around it that provides a map API, since it's not 
terribly user-friendly to use the set API for a map, much as it 
works.


[...]


Wow, thanks!


Re: Is there a sorted map?

2016-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 13, 2016 02:35:27 stunaep via Digitalmars-d-learn wrote:
> Is there any sorted map in D? I need a map and I need to be able
> to get the highest key in the map. In java I would use a TreeMap
> and use map.lastKey(), but since associative arrays are not
> sorted that would be O(n). I know about RedBlackTree, but that's
> a set and it must be a map.

The closest that we have in Phobos at the moment is RedBlackTree in
std.container. Its API is geared towards sets, not maps, but you can get it
to work as a map if you define the comparison functions appropriately.
Red-black trees are typically used for both sets and maps, so using
RedBlackTree in that manner is pretty normal from an implementation
perspective, but there's no question that what we really need is a wrapper
around it that provides a map API, since it's not terribly user-friendly to
use the set API for a map, much as it works.

But unfortunately, the container situation in Phobos has been stalled for a
while. It was decided that it would get a major overhaul once allocators
were added to the standard library, so they didn't get much love for quite a
while, and now that we finally have std.experimental.allocator, Andrei is
working on a major redesign of our container solution that's supposed to
replace what we have now, but in the interim, we're stuck with what we've
had for a while.

An alternative would be dcollections: 
https://github.com/schveiguy/dcollections

It does have a HashMap, but it doesn't look like it's been updated in a
while, so I don't know quite what its state is. It was solid, and as long as
it still compiles, it should be fine, but it looks like Steven hasn't made
any updates to it in a while (though it's my understanding that he intends
to).

Another alternative would be EMSI's containers:
http://code.dlang.org/packages/emsi_containers

They also appear to have a TreeMap, and that code should be up-to-date.  In
addition, since that library is up on code.dlang.org, it's easy to pull into
your project and use it if you're building your project with D.

- Jonathan M Davis