What's the best way to initialize structure field that has no default ctor?
http://dpaste.dzfl.pl/64cd0a3879fa
Also can I avoid dummy non-default ctor for Bar?
On 22.01.2015 15:30, bearophile wrote:
drug:
Also can I avoid dummy non-default ctor for Bar?
One solution:
struct Foo {
int foo;
@disable this();
this(int foo_) pure nothrow @safe @nogc {
this.foo = foo_;
}
}
struct Bar {
enum arraySize = 3;
On Thursday, 22 January 2015 at 11:23:49 UTC, Nordlöw wrote:
What is the meaning of selectors such as
`a[href]`
used in
doc.querySelectorAll(`a[href]`)
?
Select all `a` tags that have a `href` attribute.
You can also select using the attribute value too. For example
get all the
On Thursday, 22 January 2015 at 13:06:42 UTC, Zaher Dirkey wrote:
See example bellow, i want to pass object to function nullIt
and want this function to null it.
import std.stdio;
static if (!is(typeof(writeln)))
alias writefln writeln;
class MyClass{
}
void
On Thursday, 22 January 2015 at 02:06:16 UTC, Adam D. Ruppe wrote:
You can do that with a CSS selector like:
document.querySelector(#H2_A + p);
What is the meaning of selectors such as
`a[href]`
used in
doc.querySelectorAll(`a[href]`)
?
On Wednesday, 21 January 2015 at 20:50:30 UTC, anonymous wrote:
Or maybe dustmite can help here?
If the file contains sensitive information, and you cannot
reduce it to a reasonable size, you may be able to
programmatically replace classes of characters with one
character. E.g. replace all
drug:
Also can I avoid dummy non-default ctor for Bar?
One solution:
struct Foo {
int foo;
@disable this();
this(int foo_) pure nothrow @safe @nogc {
this.foo = foo_;
}
}
struct Bar {
enum arraySize = 3;
Foo[arraySize] foo = Foo(1);
}
void main() @safe {
tcak:
Well, that's just disguising what we can't do.
When the a..b syntax was added to foreach() someone criticized
that syntax saing it's a one trick pony, and indeed I don't
know why Walter didn't make it a little more first-class.
But note that in D the a..b ranges are always open on
Adam, please add more simple docs about your parser on site.
Also it would be perfect to create dub, for easier including
parser to project.
On Thursday, January 22, 2015 05:56:39 tcak via Digitalmars-d-learn wrote:
I want to define alphanumeric characters in an easy way.
Something like that:
char[] arr = ['a'..'z', 'A'..'Z', '0'..'9'];
Though above example doesn't work. Is there any easy way to do
this?
I am trying to do
On Thursday, 22 January 2015 at 07:29:05 UTC, anony wrote:
On Thursday, 22 January 2015 at 05:56:40 UTC, tcak wrote:
I want to define alphanumeric characters in an easy way.
Something like that:
char[] arr = ['a'..'z', 'A'..'Z', '0'..'9'];
Though above example doesn't work. Is there any easy
On Thursday, 22 January 2015 at 02:06:16 UTC, Adam D. Ruppe wrote:
On Wednesday, 21 January 2015 at 23:31:26 UTC, Nordlöw wrote:
This means that I need some kind of interface to extract all
the contents of each p paragraph that is preceeded by a h2
heading with a specific id (say H2_A) or
Jonathan M Davis:
auto r = chain(uiota('a', 'z'), uiota('A', 'Z'), uiota('0',
'9'));
Those ranges are probably open on the right.
In Bugzilla I have asked for the syntax iota![](a, b) to
change how the extrema are handled, modelled on
std.random.uniform syntax.
---
Kagamin:
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote:
Whoops, I forgot to make it a template to force CTFE.
import std.stdio;
template charRange(string spec)
{
static processInput(string spec)
{
import std.algorithm;
import std.ascii;
import std.conv;
On Thursday, 22 January 2015 at 16:22:14 UTC, ketmar via
Digitalmars-d-learn wrote:
i miss it in Phobos.
I'm sure it'd fail the phobos review process though. But since it
is an independent file (or it + characterencodings.d for full
functionality), it is easy to just download and add to your
On Thursday, 22 January 2015 at 10:14:58 UTC, Suliman wrote:
Adam, please add more simple docs about your parser on site.
I'll post some ddoc in the next dmd release, now that dmd finally
supports some way to automatically escape xml examples.
Also it would be perfect to create dub, for
On Thu, 22 Jan 2015 18:39:25 +, Adam D. Ruppe wrote:
On Thursday, 22 January 2015 at 16:22:14 UTC, ketmar via
Digitalmars-d-learn wrote:
i miss it in Phobos.
I'm sure it'd fail the phobos review process though. But since it is an
independent file (or it + characterencodings.d for full
See example bellow, i want to pass object to function nullIt and
want this function to null it.
import std.stdio;
static if (!is(typeof(writeln)))
alias writefln writeln;
class MyClass{
}
void nullIt(ref Object o)
{
o = null;
}
void main()
{
auto o =
On Thursday, 22 January 2015 at 12:45:53 UTC, drug wrote:
On 22.01.2015 15:30, bearophile wrote:
drug:
Also can I avoid dummy non-default ctor for Bar?
One solution:
struct Foo {
int foo;
@disable this();
this(int foo_) pure nothrow @safe @nogc {
this.foo = foo_;
Jonathan M Davis:
but that's easy fixed with some +1's.
But the +1 changes the char to an int.
Bye,
bearophile
On Thu, 22 Jan 2015 11:40:52 +
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:
On Thursday, 22 January 2015 at 11:23:49 UTC, Nordlöw wrote:
What is the meaning of selectors such as
`a[href]`
used in
doc.querySelectorAll(`a[href]`)
?
On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw
wrote:
On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw
wrote:
int x;
auto ref xr;
Correction: I, of course mean,
int x = 42;
auto ref xr = x;
Walter
On Thursday, 22 January 2015 at 14:29:59 UTC, anonymous wrote:
o needs to be typed as Object:
Object o = new MyClass();
nullIt(o);
Alternatively, templatize nullIt:
void nullIt(O)(ref O o) {o = null;}
auto o = new MyClass();
nullIt(o);
On Thursday, January 22, 2015 10:42:59 bearophile via Digitalmars-d-learn wrote:
Jonathan M Davis:
auto r = chain(uiota('a', 'z'), uiota('A', 'Z'), uiota('0',
'9'));
Those ranges are probably open on the right.
They probably are actually, since open on the right is usually how things
are
i wrote a test code:
void worker(int firstNumber)
{
Thread.sleep(1.msecs);
}
void main()
{
foreach (i; 1 .. 1000) {
spawn(worker, i );
writeln(i);
}
thread_joinAll();
writeln(ok);
}
sometimes it's ok,sometimes it's crashed ! why ?
here is one of times
On 22.01.15 20:05, Meta wrote:
On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote:
On 22.01.15 19:26, Meta wrote:
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote:
Whoops, I forgot to make it a template to force CTFE.
You can force CTFE assigning to manifest constant.
enum
On Thursday, 22 January 2015 at 19:12:32 UTC, zeljkog wrote:
On 22.01.15 20:05, Meta wrote:
On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote:
On 22.01.15 19:26, Meta wrote:
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote:
Whoops, I forgot to make it a template to force
On 01/22/2015 11:26 AM, ddos wrote:
i want to create 100 uniform distributed numbers and print them
my first attempt, just written by intuition:
[0 .. 100].map!(v = uniform(0.0, 1.0).writeln);
i found out i can't write [0 .. 100] to define a simple number range,
As currently being
On Thu, 22 Jan 2015 19:26:44 +, ddos wrote:
hi guys, firstly this has no direct application, i'm just playing around
and learning
i want to create 100 uniform distributed numbers and print them my first
attempt, just written by intuition:
[0 .. 100].map!(v = uniform(0.0, 1.0).writeln);
thx, alot :) works as intended
iota(0,100).map!(v = uniform(0.0,1.0)).writeln;
hi guys, firstly this has no direct application, i'm just playing
around and learning
i want to create 100 uniform distributed numbers and print them
my first attempt, just written by intuition:
[0 .. 100].map!(v = uniform(0.0, 1.0).writeln);
i found out i can't write [0 .. 100] to define a
ddos:
iota(0,100).map!(v = uniform(0.0,1.0)).writeln;
You can also write:
100.iota.map!(_ = uniform01).writeln;
Bye,
bearophile
On 22.01.15 19:26, Meta wrote:
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote:
Whoops, I forgot to make it a template to force CTFE.
You can force CTFE assigning to manifest constant.
enum t = charRange!...
On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote:
On 22.01.15 19:26, Meta wrote:
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote:
Whoops, I forgot to make it a template to force CTFE.
You can force CTFE assigning to manifest constant.
enum t = charRange!...
By wrapping
On Thursday, 22 January 2015 at 19:13:46 UTC, Meta wrote:
On Thursday, 22 January 2015 at 19:12:32 UTC, zeljkog wrote:
On 22.01.15 20:05, Meta wrote:
On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote:
On 22.01.15 19:26, Meta wrote:
On Thursday, 22 January 2015 at 18:23:00 UTC, Meta
On Thursday, 22 January 2015 at 19:26:46 UTC, ddos wrote:
hi guys, firstly this has no direct application, i'm just
playing around and learning
i want to create 100 uniform distributed numbers and print them
my first attempt, just written by intuition:
[0 .. 100].map!(v = uniform(0.0,
Using reduce for factorial, seems to require iota, not a bad things per
se, with ulongs:
reduce!a*b(1, iota(1, n + 1))
works fine. Now switch to BigInt:
reduce!a*b(one, iota(one, n + one))
fails to compile, one and n + one are of different types. Problem is
that one is
It works for me:
Sorry, you are right, it loops:
void main() {
import std.stdio, std.bigint;
immutable BigInt one = 1;
immutable BigInt two = 2;
uint n = 0;
foreach (immutable i; two .. n + one)
i.writeln;
}
Bye,
bearophile
On Thursday, January 22, 2015 15:16:07 bearophile via Digitalmars-d-learn wrote:
Jonathan M Davis:
but that's easy fixed with some +1's.
But the +1 changes the char to an int.
True, though iota doesn't seem to like to operate on char anyway, so from
the little playing around with it I did
On Thursday, 22 January 2015 at 09:27:17 UTC, Per Nordlöw wrote:
BTW: Would you be interested in receiving a PR for dom.d where
I replace array allocations with calls to lazy ranges?
Maybe. It was on my todo list to do that for getElementsByTagName
at least, which is supposed to be a live
Playing with factorial implementations, as you do. I had a D
implementation using ulong. Not sensible obviously since overflow is a
bit of a problem. But the code worked, as did the tests. Now converting
to BigInt and…
The standard explicit iteration form uses a loop:
for(i; 2..n+1)
for
On Thu, 2015-01-22 at 16:48 +, bearophile via Digitalmars-d-learn
wrote:
It works for me:
Sorry, you are right, it loops:
So it is a bug, and I now have to find out how to report it!
--
Russel.
=
Dr Russel
On 1/22/15 11:41 AM, Russel Winder via Digitalmars-d-learn wrote:
Playing with factorial implementations, as you do. I had a D
implementation using ulong. Not sensible obviously since overflow is a
bit of a problem. But the code worked, as did the tests. Now converting
to BigInt and…
The
On Thursday, 22 January 2015 at 11:40:53 UTC, Gary Willoughby
wrote:
doc.querySelectorAll(`form[name=myform] input[type=text]`)
dom.d is awesome!
Something to remember btw is this also works in browser
JavaScript AND css itself, since IE8 and Firefox 3.5. (no need
for slow, bloated jquery)
Russel Winder:
However for BigInt:
for(i; two..n + one)
the loop starts at 0 and just keeps on going. This is clearly
not good.
It works for me:
void main() {
import std.stdio, std.bigint;
immutable BigInt one = 1;
immutable BigInt two = 2;
uint n = 100;
On Thursday, 22 January 2015 at 14:39:45 UTC, anonymous wrote:
On Thursday, 22 January 2015 at 14:29:59 UTC, anonymous wrote:
o needs to be typed as Object:
Object o = new MyClass();
nullIt(o);
Alternatively, templatize nullIt:
void nullIt(O)(ref O o) {o = null;}
auto o = new
On Thursday, 22 January 2015 at 17:45:59 UTC, tcak wrote:
So, at the end of the day (I left working on my Matcher class
in the morning waiting an answer for this question), there is
nothing to convert ['a'..'d', '0'..'3'] to ['a', 'b', 'c', 'd',
'0', '1', '2', '3'] at compile time
On Thu, Jan 22, 2015 at 05:12:17PM +, Russel Winder via Digitalmars-d-learn
wrote:
Using reduce for factorial, seems to require iota, not a bad things
per se, with ulongs:
reduce!a*b(1, iota(1, n + 1))
works fine. Now switch to BigInt:
reduce!a*b(one, iota(one, n +
On Thursday, 22 January 2015 at 14:52:26 UTC, Marc Schütz wrote:
On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote:
On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw
wrote:
On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw
wrote:
int x;
auto ref xr;
Correction:
On Thursday, 22 January 2015 at 17:15:34 UTC, Jonathan M Davis
via Digitalmars-d-learn wrote:
On Thursday, January 22, 2015 15:16:07 bearophile via
Digitalmars-d-learn wrote:
Jonathan M Davis:
but that's easy fixed with some +1's.
But the +1 changes the char to an int.
True, though iota
tcak:
So, at the end of the day (I left working on my Matcher class
in the morning waiting an answer for this question), there is
nothing to convert ['a'..'d', '0'..'3'] to ['a', 'b', 'c', 'd',
'0', '1', '2', '3'] at compile time automatically.
Right. The 'a'..'d' is not first class, and
i wrote a histogram algorithm
i tried to write it the shortest and most D way possible ...
please tell me if you see any simpler way of doing it
is there a simpler way of getting the minimum of a range? (by
intuition i tried range.min)
auto numbers = iota(0,1).map!(_ =
ddos:
auto numbers = iota(0,1).map!(_ = uniform(0.0,1.0)).array;
Better:
const numbers = 10_000.iota.map!(_ = uniform01).array;
auto nmin = numbers.reduce!((a,b) = min(a,b));
Better:
immutable nMin = numbers.reduce!min;
You can also combine both (untested):
immutable nMinMax =
On Thu, 2015-01-22 at 10:21 -0800, H. S. Teoh via Digitalmars-d-learn
wrote:
[…]
https://github.com/D-Programming-Language/phobos/pull/2895
This is just the tip of the iceberg. The full enhancement is described
in:
https://issues.dlang.org/show_bug.cgi?id=10762
Sadly, I suspect
54 matches
Mail list logo