Re: attribute length missing in std.array: Appender

2014-11-28 Thread Ali Çehreli via Digitalmars-d-learn
On 11/27/2014 08:08 AM, Andre wrote: import std.array: appender; const HEADER_LENGTH = 8; auto app = appender!(ubyte[])(); app.put(cast(ubyte)40); app.put(cast(ubyte)5); app.put(cast(ubyte)234); // ... add 5 times 0 A fancy way: :) import std.range; // ...

Re: Passing reference data to class and incapsulation

2014-11-28 Thread bearophile via Digitalmars-d-learn
Uranuz: Same situation happens when I assign reference data to properties. Someone has suggested to solve this problem with an attribute, like owned, that forbids to return mutable reference data owned by a class/struct instance. Bye, bearophuile

Re: attribute length missing in std.array: Appender

2014-11-28 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: auto app = appender!(ubyte[])(); app.put(cast(ubyte)40); app.put(cast(ubyte)5); app.put(cast(ubyte)234); // ... add 5 times 0 A fancy way: :) import std.range; // ... app.put(repeat(cast(ubyte)0).take(5)); Now we have a better syntax for implicit casts: void main() {

Re: Passing reference data to class and incapsulation

2014-11-28 Thread mark_mcs via Digitalmars-d-learn
Same situation happens when I assign reference data to properties. I can check or do something with data at the moment of assignment, but I can't control that someone will modify using initial reference from outside. So do you copy reference data in constructors or properties? Should it be? Or

Re: Passing reference data to class and incapsulation

2014-11-28 Thread Daniel Kozák via Digitalmars-d-learn
V Fri, 28 Nov 2014 06:19:37 + Uranuz via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: In D we a several data types which are passed by reference: dynamic arrays, associative arrays. And sometimes we need to pass these reference data to class instance to store it inside.

Dynamic array head const in library code?

2014-11-28 Thread bearophile via Digitalmars-d-learn
In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later don't have to change length nor to be reassigned, but I have to

Re: [dub] Size of executable

2014-11-28 Thread Chris via Digitalmars-d-learn
On Thursday, 27 November 2014 at 17:08:00 UTC, CraigDillabaugh wrote: On Thursday, 27 November 2014 at 14:14:50 UTC, Chris wrote: On Thursday, 27 November 2014 at 13:59:23 UTC, CraigDillabaugh wrote: On Thursday, 27 November 2014 at 13:56:19 UTC, Chris wrote: On Thursday, 27 November 2014 at

Re: [dub] Size of executable

2014-11-28 Thread Kapps via Digitalmars-d-learn
On Thursday, 27 November 2014 at 09:33:49 UTC, Chris wrote: [Maybe this has been asked before.] I usually use dub to create and build projects. I built one of the projects with dub and then by hand with dmd[1] passing all the files etc. Turned out that the executable built with dub was 1.4

Re: Dynamic array head const in library code?

2014-11-28 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Friday, 28 November 2014 at 10:55:27 UTC, bearophile wrote: In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later

Re: Still not D standard yet ?

2014-11-28 Thread Kagamin via Digitalmars-d-learn
What is missing?

jsnode crypto createHmac createHash

2014-11-28 Thread andre via Digitalmars-d-learn
Hi, I translate some functionality written in jsnode, which contains a crypto library. Although there is some sha256 support in phobos I think, they do not provide all functionality I need to translate following two functions. (Input and output is ubyte[]) Is there a library which supports the

Re: Dynamic array head const in library code?

2014-11-28 Thread bearophile via Digitalmars-d-learn
Dominikus Dittes Scherkl: Why you don't use static arrays for such a purpose? I thought this is exactly what they are made for, aren't they? Currently you can't create a static array with a length known only at run-time. And passing around a fixed-size arrays has some costs. Bye,

Re: jsnode crypto createHmac createHash

2014-11-28 Thread Daniel Kozák via Digitalmars-d-learn
V Fri, 28 Nov 2014 12:46:25 + andre via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: Hi, I translate some functionality written in jsnode, which contains a crypto library. Although there is some sha256 support in phobos I think, they do not provide all functionality

Re: Dynamic array head const in library code?

2014-11-28 Thread John Colvin via Digitalmars-d-learn
On Friday, 28 November 2014 at 10:55:27 UTC, bearophile wrote: In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later

Re: jsnode crypto createHmac createHash

2014-11-28 Thread andre via Digitalmars-d-learn
fantastic, thanks a lot. Kind regards André On Friday, 28 November 2014 at 13:09:34 UTC, Daniel Kozák via Digitalmars-d-learn wrote: V Fri, 28 Nov 2014 12:46:25 + andre via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: Hi, I translate some functionality written in

Re: jsnode crypto createHmac createHash

2014-11-28 Thread Etienne Cimon via Digitalmars-d-learn
Keep an eye on this one: Botan in D, https://github.com/etcimon/botan Should be finished in a couple weeks. e.g. from the TLS module: auto hmac = get_mac(HMAC(SHA-256)); hmac.set_key(secret_key); hmac.update_be(client_hello_bits.length); hmac.update(client_hello_bits);

Re: Passing reference data to class and incapsulation

2014-11-28 Thread Uranuz via Digitalmars-d-learn
On Friday, 28 November 2014 at 08:31:26 UTC, bearophile wrote: Uranuz: Same situation happens when I assign reference data to properties. Someone has suggested to solve this problem with an attribute, like owned, that forbids to return mutable reference data owned by a class/struct

Re: Passing reference data to class and incapsulation

2014-11-28 Thread mark_mcs via Digitalmars-d-learn
Yes. Problem is even if you have property that controls correct assignment. If you have getter that returns mutable reference type and you try to access some fields of it or apply index operator (for arrays or AA) *host* cannot control corectness of these assignments or cannot react to these

Can't understand templates

2014-11-28 Thread Sly via Digitalmars-d-learn
Here is an example from the tutorial: struct Point(T) { T x; T y; } T getResponse(T)(string question) { writef(%s (%s): , question, T.stringof); T response; readf( %s, response); return response; } Point!T getResponse(T: Point!T)(string question) {

Re: Can't understand templates

2014-11-28 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 28, 2014 at 07:32:38PM +, Sly via Digitalmars-d-learn wrote: Here is an example from the tutorial: [...] Point!T getResponse(T: Point!T)(string question) { writefln(%s (Point!%s), question, T.stringof); auto x = getResponse!T( x); auto y = getResponse!T( y);

Why the DMD Backend?

2014-11-28 Thread Xinok via Digitalmars-d-learn
Given that we have GDC with the GCC backend and LDC with the LLVM backend, what are the benefits of keeping the DMD compiler backend? It seems to me that GCC and LLVM are far more developed and better supported by their respective communities. They have superior optimizers and are better

Re: Why the DMD Backend?

2014-11-28 Thread ketmar via Digitalmars-d-learn
On Fri, 28 Nov 2014 19:59:39 + Xinok via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Given that we have GDC with the GCC backend and LDC with the LLVM backend, what are the benefits of keeping the DMD compiler backend? build time for the whole DMD compiler with standard

Re: Why the DMD Backend?

2014-11-28 Thread LeakingAntonovPlane via Digitalmars-d-learn
On Friday, 28 November 2014 at 19:59:40 UTC, Xinok wrote: Given that we have GDC with the GCC backend and LDC with the LLVM backend, what are the benefits of keeping the DMD compiler backend? It seems to me that GCC and LLVM are far more developed and better supported by their respective

Is someone still using or maintaining std.xml2 aka xmlp?

2014-11-28 Thread Tobias Pankrath via Digitalmars-d-learn
Old project link is http://www.dsource.org/projects/xmlp The launchpad and dsource repositories are dead for two years now. Anyone using it?

Re: Can't understand templates

2014-11-28 Thread Sly via Digitalmars-d-learn
On Friday, 28 November 2014 at 19:45:48 UTC, H. S. Teoh via Digitalmars-d-learn wrote: This syntax is a little confusing, but basically the : there is saying this type, when instantiated with the following pattern, produces a valid type. Essentially it's equivalent to: Point!T

Re: thrift and dub

2014-11-28 Thread yawniek via Digitalmars-d-learn
got it to work by using the thrift code from the fbthrift repo (minus the tests).

Re: Casting in Safe D

2014-11-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 26, 2014 16:27:53 David Held via Digitalmars-d-learn wrote: On 11/23/2014 3:12 PM, anonymous wrote: [...] And even pointer dereferencing is @safe. Invalid ones will fail with a segfault at run time: void foo(int* a) @safe {*a = 13;} Hmm...throwing an exception is

Re: Can't understand templates

2014-11-28 Thread Ali Çehreli via Digitalmars-d-learn
On 11/28/2014 12:36 PM, Sly wrote: Let's take a simpler example from earlier in the tutorial, where Point is a non-template struct: // The general definition of the function template (same as before) T getResponse(T)(string question) { [...] } That definition would work with any type

Re: attribute length missing in std.array: Appender

2014-11-28 Thread Ali Çehreli via Digitalmars-d-learn
On 11/28/2014 12:44 AM, bearophile wrote: Now we have a better syntax for implicit casts: [...] app.put(ubyte(0).repeat.take(5)); Much better! :) But I have a question too. What's the best way to append several lazy items to a dynamic array? This doesn't work: void main() {

Re: attribute length missing in std.array: Appender

2014-11-28 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: void expandWith(A, R)(ref A arr, R range) { foreach (e; range) { arr ~= e; } } I'd like a function like that in Phobos (with a little improvement: when the length of the given range is available inside expandWith, it should first extend the capacity to increase

Re: Still not D standard yet ?

2014-11-28 Thread Ledd via Digitalmars-d-learn
On Friday, 28 November 2014 at 12:35:28 UTC, Kagamin wrote: What is missing? an ISO standard ?

Re: Still not D standard yet ?

2014-11-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 29, 2014 01:30:55 Ledd via Digitalmars-d-learn wrote: On Friday, 28 November 2014 at 12:35:28 UTC, Kagamin wrote: What is missing? an ISO standard ? Someday, maybe, but most languages don't have an ISO standard, and I really on't see what it would buy us. What we're

Re: Is someone still using or maintaining std.xml2 aka xmlp?

2014-11-28 Thread Etienne Cimon via Digitalmars-d-learn
On 2014-11-28 15:15, Tobias Pankrath wrote: Old project link is http://www.dsource.org/projects/xmlp The launchpad and dsource repositories are dead for two years now. Anyone using it? Nope. I found kXML while searching for the same, it has everything I've needed up to spec. I'm maintaining

Re: Can't understand templates

2014-11-28 Thread Sly via Digitalmars-d-learn
OK, so we *can* have overlapping templates in one fits better than another, just like in C++. I still don't understand how to read this signature: Point!T getResponse(T: Point!T)(string question) On Friday, 28 November 2014 at 23:59:07 UTC, Ali Çehreli wrote: On 11/28/2014 12:36 PM, Sly wrote:

Why does hello world not compile in safe?

2014-11-28 Thread Freddy via Digitalmars-d-learn
import std.stdio; @safe: void main() { writeln(Edit source/app.d to start your project.); } source/app.d(5): Error: safe function 'D main' cannot call system function 'std.stdio.writeln!(string).writeln'

Re: Why does hello world not compile in safe?

2014-11-28 Thread ketmar via Digitalmars-d-learn
'cause `writeln`() is not @safe, as you can read in the following compiler message: source/app.d(5): Error: safe function 'D main' cannot call system function 'std.stdio.writeln!(string).writeln' signature.asc Description: PGP signature