On Saturday, 1 September 2018 at 17:17:37 UTC, puffi wrote:
Hi,
Is it by design that when calling functions with either ubyte
or byte variables the char overload is called instead of the
int (or generic) one?
It seems this is by design.
"If two or more functions have the same match level, th
On Saturday, 1 September 2018 at 16:20:11 UTC, Dr.No wrote:
why move flush to outside the synchronized block?
flush should be thread safe. In general, yiu want as little code
as possible to run under the lock. Not that important though.
trying out this approach I found to be ok except in som
On Thursday, 30 August 2018 at 19:59:17 UTC, Dr.No wrote:
I would to process the current block in parallel but priting
need to be theread-safe so I'm using
foreach(x; parallel(arr)) {
auto a = f(x);
auto res = g(a);
synchronized {
stdout.writeln(res);
stdout.flush();
On Friday, 24 August 2018 at 13:04:47 UTC, Uknown wrote:
I was quite surprised by the fact that parallel ran so much
slower than recursive and loop implementations. Does anyone
know why?
n = 100 is too small to see parallelism gains.
Try n = 1
https://run.dlang.io/is/XDZTSd
Consider this code, which is used as an example only:
auto scaleAll(int[] xs, int m) {
return xs.map!(x => m * x);
}
As m is captured, the delegate for map will rightly allocate the
closure in the GC heap.
In C++, you would write the lambda to capture m by value, but
this is not a facility
On Saturday, 7 February 2015 at 21:33:51 UTC, Kenny wrote:
The above code snippet works correctly when I use LDC compiler
(it finds expected 'f' value and prints it to console). I'm
wondering is it a bug in DMD?
p.s. the final code used by both compilers:
import std.stdio;
import std.conv;
i
On Saturday, 7 February 2015 at 23:06:15 UTC, anonymous wrote:
On Saturday, 7 February 2015 at 22:46:56 UTC, Ali Çehreli wrote:
1.0 is famously not representable exactly.
1.0 is representable exactly, though.
I think he meant 0.1 :-)
On Thursday, 15 January 2015 at 17:05:32 UTC, Ola Fosheim Grøstad
wrote:
On Thursday, 15 January 2015 at 15:31:17 UTC, Peter Alexander
wrote:
On Thursday, 15 January 2015 at 15:24:55 UTC, Ola Fosheim
Grøstad wrote:
That would be nice, because then a precise garbage collector
could choose
On Thursday, 15 January 2015 at 15:24:55 UTC, Ola Fosheim Grøstad
wrote:
I am trying to understand the idea behind "shared" typing fully.
If I am only allowed to share objects with another thread if it
is typed "shared", doesn't that imply that it should be
allocated as shared too and only be
On Tuesday, 6 January 2015 at 23:32:25 UTC, Artur Skawina via
That shows a static struct, so I'm not sure it's the same
problem.
static structs with template alias parameters to local symbols
count as nested structs.
Your solution would likely work, but yes, I'm looking for
something less h
Consider:
auto foo(T)(T a) {
T b; // Error: cannot access frame pointer of main.X
b.data[] = 1;
return b;
}
void main() {
struct X {
this(int) {}
int[4096] data;
}
foo(X());
}
Note the error is because you c
On Friday, 2 January 2015 at 23:51:05 UTC, John Colvin wrote:
The rule (in C(++) at least) is that all data is assumed to be
visible and mutable from multiple other threads unless proved
otherwise. However, given that you do not write a race, the
compiler will provide full sequential consistenc
On Friday, 2 January 2015 at 00:08:02 UTC, anonymous wrote:
Apparently dmd thinks that the result of f must be a nested
struct. I.e. it needs a context pointer. And I guess hell would
break loose if you'd use a nested struct with a null context
pointer. At least when the context pointer is actu
Can someone please explain this behaviour? I find it totally
bizarre.
auto f(T)(T x) {
struct S {
T y;
this(int) { }
}
return S(0);
}
void main() {
f(f(0));
}
Error: constructor f376.f!(S).f.S.this field y must be
initialized in
On Thursday, 1 January 2015 at 13:13:10 UTC, Andrej Mitrovic via
Digitalmars-d-learn wrote:
On 1/1/15, Idan Arye via Digitalmars-d-learn
wrote:
If I have an associative array and I only modify it's values,
without changing the keys, can I assume that the order won't
change?
Associative arrays
You need to take a slice of the buffer:
char[] buf = Input[];
readln(buf);
// line now in buf
The reason for this is because you need to know where the string
ends. If you just passed in Input, how would you know how long
the line read was?
On Friday, 24 October 2014 at 21:56:20 UTC, Nordlöw wrote:
bool isPalindrome(R)(in R range) @safe pure
Aside: for templates, just let the compiler infer @safe and pure.
You don't know whether the range operations on R are pure or not.
As for the actual algorithm, there's no need for the rand
On Saturday, 9 August 2014 at 00:34:43 UTC, Puming wrote:
Yes, rust is a more infantile language compared to D, but
people are already using them to create complicate applications
like browser!
Rust was designed to build Servo. The people building Servo are
the people building Rust. With all
On Sunday, 3 August 2014 at 23:48:09 UTC, Martin wrote:
When I use the spawnProcess function in std.process, the
command line arguments that I provide to the function seem to
get "quoted".
I can't reproduce this on OS X with 2.066rc1 (args are unquoted).
Can someone else check Windows? Sounds
template Foo(T...) {}
template Bar(T...) {}
template isFoo(alias F)
{
enum isFoo = __traits(isSame, F, Foo);
}
pragma(msg, isFoo!Foo); // true
pragma(msg, isFoo!Bar); // false
Well, it doesn't work in 2.065, so must be 2.066 :-)
P.S. thanks for letting me know about this feature. I had no idea
it was going in!
On Wednesday, 19 February 2014 at 09:46:04 UTC, Gopan wrote:
On Wednesday, 19 February 2014 at 09:09:25 UTC, Tobias Pankrath
It's O(k) with k = vals.length, which is the number of
arguments given to the function, which is a compile time
constant and not dependent on any input of the final progr
On Saturday, 14 December 2013 at 16:00:06 UTC, seany wrote:
the std.algorithm.splitter returns a blank or null (eg a null
string "") between two consecuting delimeters.
for example, splitting "hello world" (two spaces between
words) will return ["hello" , "", "world"]
is there an improoved
On Sunday, 22 September 2013 at 18:13:39 UTC, Peter Alexander
wrote:
On Sunday, 22 September 2013 at 14:26:14 UTC, bearophile wrote:
auto r2 = [1, 2]
.map!(x => [1, 2].map!(y => '*'))
.join("_");
The problem is that you are trying to map
On Sunday, 22 September 2013 at 14:26:14 UTC, bearophile wrote:
auto r2 = [1, 2]
.map!(x => [1, 2].map!(y => '*'))
.join("_");
The problem is that you are trying to map a range of range of
chars with a range of dchars.
auto r2 = [1, 2]
.map!(x =>
On 19/01/12 9:55 PM, RenatoL wrote:
Just curious: why in D we are not obligated to use break in every
branch of a swicth structure? That is:
switch (i)
{
case 1:
writeln("You wrote 1");
case 2:
writeln("You wrote 2");
On 15/01/12 10:29 PM, Philippe Sigaud wrote:
On Sun, Jan 15, 2012 at 22:19, Timon Gehr wrote:
Nick:
Goddamnnit, what the fuck is wrong with me? Yes that works :)
I suspect a better error message would have prevented this.
DMD still has some potential of improvement in that area. =)
In that
On 15/01/12 2:19 AM, Andrej Mitrovic wrote:
I guess join() could be specialized for static arrays and then just do
a dup and a cast? Would that work ok?
There should be no need to allocate extra memory to do this.
On 13/01/12 10:48 PM, DNewbie wrote:
I can't understand it. Why would someone need template programming. What
problem does template solve?
Suppose you want to write a function to get the minimum of two integers.
It's easy:
int min(int a, int b)
{
return a < b ? a : b;
}
Suppose then yo
On 7/01/12 1:19 AM, Daniel wrote:
Hi, I've read on Bugzilla Issue 6398 that this is a bug:
static int value;
ref foo(){ printf("getter\n"); return value; }
ref foo(int x){ printf("setter\n"); value = x; return value; }
void main(){ foo = 1; } // Should print "setter", but print "getter" in 2.0
On 5/01/12 5:26 AM, Andrej Mitrovic wrote:
The first call doesn't do anything because the delegate is wrapped
inside of another delegate. I want this template to be versatile
enough to be used by both lazy expressions and delegate literals, but
I don't know how.
void test(T)(lazy T dg)
{
st
On 14/12/11 9:21 PM, Timon Gehr wrote:
On 12/14/2011 09:14 PM, Justin Whear wrote:
I've looked through std.algorithm and std.range, but haven't found
anything
to compute the Cartesian product of several ranges. I have the nagging
feeling that this can be accomplished by combining several of the
On 24/11/11 10:38 PM, Andrej Mitrovic wrote:
But I bet you would waste more memory at compile-time if you had to
type a long template instance name instead of using auto. We're
talkin' bytes here!
Actually, using `auto` should be faster because the compiler doesn't
need to do any name lookup.
Can anyone help me with this?
http://stackoverflow.com/questions/7375165/aligning-stack-variables-in-d
---
Is there a way to align data on the stack? In particular, I want to
create an 16-byte aligned array of floats to load into XMM registers
using movaps, which is significantly faster than
On 2/08/11 2:24 AM, Adam Ruppe wrote:
From what I can tell, it's Google's alternative to Flash; they want
to make crappy games on it.
Consider that the first thing they ported to it, again, just like
their javascript nonsense, was Quake. (I think Google loves
Javascript too much to let it go an
I've been having strange linker errors recently and I have no ideas why
they've started happening.
When compiling/linking:
import std.stdio;
void main() { writeln("Hello"); }
with DMD 2.053 I get linker error:
Undefined symbols:
"_D3std9exception7bailOutFAyaixAaZv", referenced from:
_
I'm trying to run the test suite for DMD, but I'm running into issues.
I've cloned dmd from github, and successfully built dmd, but when I run
'make' from the dmd/test dir, I get:
$ make
Creating output directory: test_results
Building d_do_test tool
object.d: Error: module object is i
On 1/05/11 2:53 PM, Dmitry Olshansky wrote:
Ehm.. Well, first things first: you shouldn't use classes for
lightweight & plain data things like vectors. There are structs for
that. In general, structs are value-like objects living on the stack
while classes are reference-like objects living on the
On 1/05/11 2:30 PM, CrypticMetaphor wrote:
Hi, I've been away from D for a while, but now I'm back and I'm stuck
with an compile time error.
I've got a Matrix33 class and a Vector3 class, but something is wrong
with the way I return my Vector3 in my matrix class:
If I do this I get an error:
M
On 11/04/11 9:35 PM, Andrej Mitrovic wrote:
I realize runtime checks would be out of the question...
debug doRuntimeCheck();
:-)
On 18/03/11 5:53 PM, Jonathan M Davis wrote:
On Friday, March 18, 2011 03:32:35 spir wrote:
On 03/18/2011 10:29 AM, Peter Alexander wrote:
On 13/03/11 12:05 AM, Jonathan M Davis wrote:
So, when you're using a range of char[] or wchar[], you're really using
a range of dchar. These
On 13/03/11 12:05 AM, Jonathan M Davis wrote:
So, when you're using a range of char[] or wchar[], you're really using a range
of dchar. These ranges are bi-directional. They can't be sliced, and they can't
be indexed (since doing so would likely be invalid). This generally works very
well. It's e
On 13/02/11 9:32 PM, Sean Eskapp wrote:
== Quote from bearophile (bearophileh...@lycos.com)'s article
Sean Eskapp:
Is there a nicer way to do this in D, or am I stuck with the same thing?
Andrei has recently said no one needs double dispatch (in D) :-) So Andrei will
be interested in your use
On 6/02/11 11:35 PM, Julius wrote:
Hi there,
i'm all new to D but not new to programming in general.
I'd like to try D but i didn't find a nice tutorial yet.
I don't want to read a whole book, I just want to get the basics so I can start.
Can you help me find something like that?
Best regards, J
How do you set the priority of a thread, or otherwise control how much
CPU time it gets?
It appears that std.thread had an answer for this, but it has been
removed from Phobos by the looks of things.
On a side note, why is std.thread still in the online documentation if
it was removed long a
On 4/02/11 11:44 PM, Sean Kelly wrote:
Peter Alexander Wrote:
How would you do it with message passing though? As I understand, all of
the std.concurrency message passing routines are blocking, and I need
this to be asynchronous.
What do you mean by blocking? The receive call will block
On 5/02/11 12:11 AM, Sean Kelly wrote:
Peter Alexander Wrote:
Things might be easier if the error messages associated with D's
concurrent features weren't especially unhelpful (for example, trying to
spawn a thread with reference type parameters just gives you a 'no match
for
On 4/02/11 8:42 PM, spir wrote:
On 02/04/2011 07:18 PM, Peter Alexander wrote:
I would like to be able to spawn a thread, which does a lot of work,
and then
returns (in some way) the result of its computations to the main
thread. I
would really like to avoid copying its results if possible
On 4/02/11 8:23 PM, Jesse Phillips wrote:
Peter Alexander Wrote:
Essentially, the work that doWork does needs to be returned to the main
thread asynchronously, and obviously in a thread-safe manner.
What's the best way to do this? The above won't work because ~= isn't
atomic,
I would like to be able to spawn a thread, which does a lot of work, and
then returns (in some way) the result of its computations to the main
thread. I would really like to avoid copying its results if possible.
Logically, what I would like is something like this:
class LotsOfData { ... }
v
On 17/01/11 8:16 AM, bioinfornatics wrote:
will be great if we have a planet. An example here :
http://planet.fedoraproject.org/
A planet it is a web page who feed several blog, user can use a cms for to
write a blog like Dotclear, wordpress ...
http://planet.dsource.org/
Problem is: it's no
Take a look at the website (either digitalmars, or d-programming-language).
There is absolutely no indication on those sites that the D language is
actually going anywhere. Other than version numbers on the downloads,
nothing changes. Outsiders have no idea what's going on.
Here's a suggestio
On 2/01/11 2:16 PM, bearophile wrote:
Is this good enough?
struct Vec {
double[2] e;
static enum Vec zero = Vec([0.0, 0.0]);
this(real x, real y) {
e[0] = x;
e[1] = y;
}
}
Well it works, so yes :-)
That's quite irritating. Why does the automatically gen
Ok, someone put me out of my misery, I can't figure out for the life of
me how to do this. Basically, I have a vector class and want enums for
the zero vectors:
struct Vec
{
this(real x, real y) { e[0] = x; e[1] = y; }
real[2] e;
enum Vec zero = Vec(0, 0);
}
What can I do?
The above doe
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic
> wrote:
> > What does char[1 + Range.empty] do? It looks rather cryptic..
> char[1+Range.empty] is a type. If Range.empty is a compile-time constant,
> then this type is valid
On 7/08/10 4:33 PM, simendsjo wrote:
Is the following equalent?
int[] a;
int[] b = a;
assert(a is b);
assert(a.ptr == b.ptr);
No.
(a is b) implies (a.ptr == b.ptr)
but
(a.ptr == b.ptr) does not imply (a is b)
For example:
int[] a = [1, 2, 3];
int[] b = a[0..1];
Here, a.ptr == b.ptr, but
On 7/08/10 3:44 PM, bearophile wrote:
Peter Alexander:
Bye,
bearophile
Thanks for your detailed reply.
However, I'm not particularly satisfied with any of those :(
I have already gone with the single parameter init constructor in my
code until I find something better, but really, I
Since default constructors for structs are not allowed, how do I go
about making all the elements of this Matrix struct default to zero?
(floats default to nan by default).
struct Matrix(int M, int N)
{
float[M][N] elements;
}
Matrix(3, 3) m;
assert(m[0][0] == 0);
?
Lars T. Kyllingstad Wrote:
> Disclaimer: You didn't say whether you use D1 or D2, but I use D2, so
> I'll give my answer in D2 code. It is highly likely it will also work in D1.
I'm using neither :) I'm just considering learning at the moment.
> First of all, I don't know how it is in C++, bu
Simen Kjaeraas Wrote:
>
> T foo( T, U )( U value ) {...}
>
> template fooPartial( T ) {
>alias foo!( T, int ) fooPartial;
> }
>
> This may or may not have been what you want.
Not quite sure what's going on there, but it doesn't look like what I want.
I want a general function:
T foo(T, U)
Hey all,
I'm considering learning D at the moment, and one thing that has bothered me in
C++ is the lack of partial template function specializations. For example, you
can create something like this:
template
const Field norm(const V& v);
and you can specialize it:
template <>
const double n
61 matches
Mail list logo