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;
// ...
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
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() {
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
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.
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
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
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
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
What is missing?
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
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,
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
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
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
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);
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
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
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) {
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);
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
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
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
Old project link is http://www.dsource.org/projects/xmlp
The launchpad and dsource repositories are dead for two years
now. Anyone using it?
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
got it to work by using the thrift code from the fbthrift repo
(minus the tests).
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
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
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() {
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
On Friday, 28 November 2014 at 12:35:28 UTC, Kagamin wrote:
What is missing?
an ISO standard ?
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
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
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:
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'
'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
36 matches
Mail list logo