On Saturday, 5 April 2014 at 01:57:59 UTC, Meta wrote:
When I put a println inside both functions, they both print out
[2, 1, 0]. Shouldn't the first print [0, 1, 2] while the second
prints [2, 1, 0]?
No, sorry, I was mistaken about what was going on.
On Saturday, 5 April 2014 at 01:28:06 UTC, bearophile wrote:
Can you spot the difference between foo1 and foo2?
import std.algorithm: map;
import std.range: iota;
void foo1(in int[] a, in int[] b) pure {
int[] r;
foreach (immutable i; 0 .. a.length)
r ~= (i % 2) ? a[i] : b[i];
By using the interface,
it also
forces the user to include all of the attributes of each pin
such as
direction, max load, DC current, etc. Since class type enums
are references,
they are light, - and they should be immutable - so they are
thread safe aslo.
I'm not sure how you're using your
Can you spot the difference between foo1 and foo2?
import std.algorithm: map;
import std.range: iota;
void foo1(in int[] a, in int[] b) pure {
int[] r;
foreach (immutable i; 0 .. a.length)
r ~= (i % 2) ? a[i] : b[i];
}
void foo2(in int[] a, in int[] b) pure {
int[] r;
f
On Thursday, 3 April 2014 at 23:16:14 UTC, Eric wrote:
Okay - I'm new to D, and I'm comming from a java background.
Suppose
you are designing an API, and you want the user to supply
arguments
as an enum. But the user needs to define the enum, so how can
the API
know in advance what enum to re
i stumbled upon something strange while wondering around meta/codegen-lands. it
took me almost a week to reduce it to the following test case. i have no clue
what is going on, whether i have entered bug territory or just encountered my
own limitations
mind you, i have 2 issues with the cod
Sorry Steven,
I hadn't seen your answer.
Thanks for the extra information.
O.
On Friday, 4 April 2014 at 20:42:32 UTC, Steven Schveighoffer
wrote:
On Fri, 04 Apr 2014 16:35:57 -0400, Olivier Grant
wrote:
That is one responsive D community :) Thank you to all three
of you for these quick
On 04/05/14 00:54, Joseph Rushton Wakeling wrote:
> Hello all,
>
> If we change the length of a dynamic array using the normal GC-based methods,
> e.g. by setting the array's .length property, we find that the array's
> capacity typically does not simply equal the length, but some greater value;
Joseph Rushton Wakeling:
Question: is there a comparable phenomenon for memory that is
manually allocated using malloc?
Manually allocated memory can over-allocate, but not
geometrically as arrays do.
Take a look at the difference between core.memory.extend and
core.memory.realloc.
Bye,
Hello all,
If we change the length of a dynamic array using the normal GC-based methods,
e.g. by setting the array's .length property, we find that the array's capacity
typically does not simply equal the length, but some greater value; there is
excess allocation.
Question: is there a compar
(This was in C and probably a common mistake that I haven't experienced
until today.)
tldr; The following two expressions are not equivalent:
a)length - 1 - length / 2
b)length / 2 - 1
I was trying to write a recursive function similar to binary search:
- Process the middle elemen
Yes, that definitely seems like a good start. To be honest, I not
familiar enough yet with how you are suppose to organise your
source code in D.
Is there any agreed-on naming convention when it comes to member
variables to avoid that kind of name clash ?
Thanks,
O.
On Friday, 4 April 2014
Olivier Grant:
Is there any way to hide Splicer.array to the outside world?
If your splice is inside another module, and you tag the array
field with private, you will receive an error:
auto splice( size_t N, R )( R range )
if(isInputRange!R)
{
struct Splicer
{
private R arr
On Fri, 04 Apr 2014 16:35:57 -0400, Olivier Grant
wrote:
That is one responsive D community :) Thank you to all three of you for
these quick answers.
I was really scratching my head on that one. This shows that UFCS can be
quite dangerous. Is there any way to hide Splicer.array to the ou
That is one responsive D community :) Thank you to all three of
you for these quick answers.
I was really scratching my head on that one. This shows that UFCS
can be quite dangerous. Is there any way to hide Splicer.array to
the outside world? It just seems that it would be very easy to
break
On Friday, 4 April 2014 at 20:19:53 UTC, Olivier Grant wrote:
Hi,
I've started using D as a scripting language at work and for
personal projects as a means to learn the language and I've
bumped into a case where I would like to iterate a slice by a
certain number of elements at a time such th
On Friday, 4 April 2014 at 20:19:53 UTC, Olivier Grant wrote:
import std.stdio;
import std.range;
import std.array;
auto splice( size_t N, R )( R range )
if(isInputRange!R)
{
struct Splicer
{
R array;
@property bool empty( ) const
{ return 0 == array.length; }
On Friday, 4 April 2014 at 20:19:53 UTC, Olivier Grant wrote:
iterate a slice by a certain number of elements at a time such
that :
foreach(s; [1,2,3,4].splice!(2))
{
writeln(s);
}
would print :
[1,2]
[3,4]
First of all, is there such a function in D's standard library
as I didn't seem
Hi,
I've started using D as a scripting language at work and for
personal projects as a means to learn the language and I've
bumped into a case where I would like to iterate a slice by a
certain number of elements at a time such that :
foreach(s; [1,2,3,4].splice!(2))
{
writeln(s);
}
wou
On Friday, 4 April 2014 at 15:13:25 UTC, Bienlein wrote:
What I was actually looking for was how to get this to work:
immutable int b = if(1 == 1) { return 123; } else { return 456;
};
But I'm happy enough with the solution through a delegate.
What bearophile said, or:
immutable int b = {i
Once every few years spamhaus 'cleans up' their white lists with no notifications. I've already
initiated the re-removal. Sigh. I hate spamhaus, they're a pain in every mail sender's backside.
On 4/4/14, 10:25 AM, Hugo Florentino wrote:
Hi,
IP 173.45.241.208 (slice-1.puremagic.com) seems to
On 04/04/2014 08:42 AM, ketmar wrote:
You can hack around that limitation if it's acceptable to use a
temporary variable:
sure, and i can rewrite the whole call, passing destination variable as
template argument. but this looks ugly.
A regular function would work too:
void func0 () { }
int f
Hi,
IP 173.45.241.208 (slice-1.puremagic.com) seems to be blacklisted in
zen.spamhaus.org
Please check for a possible misuse of the server, or in case of a false
positive report to spamhaus.org
Regards, Hugo
H. S. Teoh:
This means that the hash of MyKey is computed based on its
binary
representation, disregarding the contents of any array (and
other
reference) fields. This will certainly break AA's.
I'm almost certain this has already been reported as a bug, but
I
vaguely remember someone mentio
On Fri, Apr 04, 2014 at 04:48:52PM +, dnspies wrote:
> On Thursday, 3 April 2014 at 23:01:27 UTC, Steven Schveighoffer wrote:
> >On Thu, 03 Apr 2014 17:42:16 -0400, bearophile
> >wrote:
> >
> >
> >>I have filed this big problem four years ago or more.
> >
> >Bug report?
> >
> >-Steve
>
> This
On Thursday, 3 April 2014 at 23:01:27 UTC, Steven Schveighoffer
wrote:
On Thu, 03 Apr 2014 17:42:16 -0400, bearophile
wrote:
I have filed this big problem four years ago or more.
Bug report?
-Steve
This is the closest I could find:
https://d.puremagic.com/issues/show_bug.cgi?id=11025
On Friday, 4 April 2014 at 13:23:48 UTC, Bienlein wrote:
Hello,
I took some code snippet from some sample D code and modified
it a bit:
template TCopy(T, V) {
private int i = 2;
void copy(out T to, out V to2, T from) {
to = from;
to2 = from;
writeln("i: ", i);
}
}
You can hack around that limitation if it's acceptable to use a
temporary variable:
sure, and i can rewrite the whole call, passing destination
variable as template argument. but this looks ugly.
thanx for the answer anyway (and bearophile too).
Unfortunately, you cannot use template mixins fo
On Friday, 4 April 2014 at 13:22:39 UTC, ketmar wrote:
i have some C code like this:
void func0 (void) { … }
int func1 (void) { … return smth+42; }
#define MYMACRO() ({ func0(); func1(); })
int v;
…
v = MYMACRO()-16;
v = mixin(MYMACRO())-16;
and have the same effect as in C code: all MYMA
Bienlein:
What I was actually looking for was how to get this to work:
immutable int b = if(1 == 1) { return 123; } else { return 456;
};
immutable b = (1 == 1) ? 123 : 456;
Bye,
bearophile
On Friday, 4 April 2014 at 13:53:33 UTC, bearophile wrote:
If your D function has one argument, you have to give it one
argument, even if it doesn't have a visible name and it's
unused.
Ah! Admittedly, I though it's the return type .. So this works
now:
immutable int b = () {
if(1 ==
On Fri, 04 Apr 2014 09:35:57 -0400, Bienlein wrote:
"auto" is used to declare an instance, or an object.
"alias" is used to declare a name.
What you are currently doing is saying "the function TCopy!(int, int)
can now be refered to as myCopy". You aren't actually creating any data.
All r
Bienlein:
Whereas this does not compile:
immutable int b = (int) {
if(1 == 1) {
return 123;
} else {
return 456;
}
}(); // line x
However, this does compile and displays correctly 123:
immutable int b = (int) {
if(1 == 1) {
On Friday, 4 April 2014 at 13:23:48 UTC, Bienlein wrote:
template TCopy(T, V) {
[...]
}
On Friday, 4 April 2014 at 13:35:58 UTC, Bienlein wrote:
auto myCopy = new TCopy!(int, int);
alias myCopy = new TCopy!(int, int);
Neither nor compiles now. How can? Seems to me a template is
no
Thanks so far. I have another one, though. Not trying to tease
people, I really don't know ;-).
This compiles and runs:
immutable int a = (int val) {
if(1 == 1) {
return val;
} else {
return 456;
}
}(123);
writeln(a);
Whereas th
On Fri, 04 Apr 2014 09:25:49 -0400, Marc Schütz wrote:
On Wednesday, 2 April 2014 at 16:51:57 UTC, Benjamin Thaut wrote:
Am 02.04.2014 17:57, schrieb Andrea Fontana:
I mean: if it is an exported function (of a shared library) what
happens? There's no reference kept anywhere (in D). So if I'm
"auto" is used to declare an instance, or an object.
"alias" is used to declare a name.
What you are currently doing is saying "the function
TCopy!(int, int) can now be refered to as myCopy". You aren't
actually creating any data.
All right, thanks. Then I create an instance:
auto myCopy =
ketmar:
and have the same effect as in C code: all MYMACRO content
(this can be almost anything) *always* inlined.
Define a function. And in D there is no way to require a sure
inline.
Some people have asked for a __forceinline but Andrei&Walter
don't seem sufficiently interested.
Bye,
bea
On Friday, 4 April 2014 at 13:23:48 UTC, Bienlein wrote:
Hello,
I took some code snippet from some sample D code and modified
it a bit:
template TCopy(T, V) {
private int i = 2;
void copy(out T to, out V to2, T from) {
to = from;
to2 = from;
writeln("i: ", i);
}
}
On Wednesday, 2 April 2014 at 16:51:57 UTC, Benjamin Thaut wrote:
Am 02.04.2014 17:57, schrieb Andrea Fontana:
I mean: if it is an exported function (of a shared library)
what
happens? There's no reference kept anywhere (in D). So if I'm
right it
could be freed immediatly by GC. Right?
If y
On Friday, 4 April 2014 at 07:23:51 UTC, Andrej Mitrovic wrote:
On 4/4/14, Meta wrote:
alias TemplateArgs(T: Foo!U, U) = U;
It's also in std.traits, TemplateArgsOf, which is more complete.
I thought I remembered that being in std.traits, but I couldn't
find it after quickly skimming. I mus
Hello,
I took some code snippet from some sample D code and modified it
a bit:
template TCopy(T, V) {
private int i = 2;
void copy(out T to, out V to2, T from) {
to = from;
to2 = from;
writeln("i: ", i);
}
}
void main(string[] args)
{
int x = 2;
int
i have some C code like this:
void func0 (void) { … }
int func1 (void) { … return smth+42; }
#define MYMACRO() ({ func0(); func1(); })
int v;
…
v = MYMACRO()-16;
what it does? it uses GCC extension "statement expression" which
allows to place almost arbitrary C operator block inside any
ex
On Friday, 4 April 2014 at 08:52:09 UTC, Daniel Murphy wrote:
On Friday, 4 April 2014 at 04:10:51 UTC, Saurabh Das wrote:
Hello,
Say I compile a program with:
dmd -unittest -debug -cov test.d
Then, when I run ./test, a file 'test.lst' is generated in the
current working directory. Is there a
On Friday, 4 April 2014 at 04:10:51 UTC, Saurabh Das wrote:
Hello,
Say I compile a program with:
dmd -unittest -debug -cov test.d
Then, when I run ./test, a file 'test.lst' is generated in the
current working directory. Is there a way in which I can
instruct the file to be created in a separ
On 4/4/14, Meta wrote:
> alias TemplateArgs(T: Foo!U, U) = U;
It's also in std.traits, TemplateArgsOf, which is more complete.
46 matches
Mail list logo