Re: iota and BigInt

2015-01-22 Thread Russel Winder via Digitalmars-d-learn
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 s

why spawn crash?

2015-01-22 Thread mzfhhhh via Digitalmars-d-learn
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 ca

Re: histogram [last thread contd]

2015-01-22 Thread bearophile via Digitalmars-d-learn
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 =

histogram [last thread contd]

2015-01-22 Thread ddos via Digitalmars-d-learn
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!(_ => uniform(0.0,1.

Re: generate an array of 100 uniform distributed numbers

2015-01-22 Thread bearophile via Digitalmars-d-learn
ddos: iota(0,100).map!(v => uniform(0.0,1.0)).writeln; You can also write: 100.iota.map!(_ => uniform01).writeln; Bye, bearophile

Re: generate an array of 100 uniform distributed numbers

2015-01-22 Thread ddos via Digitalmars-d-learn
thx, alot :) works as intended iota(0,100).map!(v => uniform(0.0,1.0)).writeln;

Re: generate an array of 100 uniform distributed numbers

2015-01-22 Thread Justin Whear via Digitalmars-d-learn
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).wri

Re: generate an array of 100 uniform distributed numbers

2015-01-22 Thread Ali Çehreli via Digitalmars-d-learn
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 dis

Re: generate an array of 100 uniform distributed numbers

2015-01-22 Thread Vladimir Panteleev via Digitalmars-d-learn
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, 1.0).wri

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
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

generate an array of 100 uniform distributed numbers

2015-01-22 Thread ddos via Digitalmars-d-learn
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 si

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
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 CTFE

Re: Defining a static array with values in a range

2015-01-22 Thread zeljkog via Digitalmars-d-learn
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

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
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

Re: Defining a static array with values in a range

2015-01-22 Thread zeljkog via Digitalmars-d-learn
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!...

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread ketmar via Digitalmars-d-learn
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

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
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 easi

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
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

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
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;

Re: Defining a static array with values in a range

2015-01-22 Thread Meta via Digitalmars-d-learn
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 automatically

Re: iota and BigInt

2015-01-22 Thread H. S. Teoh via Digitalmars-d-learn
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(on

Re: Changing by ref a class passed in function

2015-01-22 Thread Zaher Dirkey via Digitalmars-d-learn
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 M

Re: Defining a static array with values in a range

2015-01-22 Thread bearophile via Digitalmars-d-learn
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 you

Re: Defining a static array with values in a range

2015-01-22 Thread tcak via Digitalmars-d-learn
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 do

Re: On Variable References

2015-01-22 Thread Meta via Digitalmars-d-learn
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: I,

Re: Defining a static array with values in a range

2015-01-22 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: for ranges

2015-01-22 Thread Steven Schveighoffer via Digitalmars-d-learn
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 standar

iota and BigInt

2015-01-22 Thread Russel Winder via Digitalmars-d-learn
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 immut

Re: for ranges

2015-01-22 Thread Russel Winder via Digitalmars-d-learn
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 W

Re: for ranges

2015-01-22 Thread bearophile via Digitalmars-d-learn
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; forea

Re: for ranges

2015-01-22 Thread bearophile via Digitalmars-d-learn
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

for ranges

2015-01-22 Thread Russel Winder via Digitalmars-d-learn
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

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
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 jquer

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
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 list

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread ketmar via Digitalmars-d-learn
On Thu, 22 Jan 2015 11:40:52 + Gary Willoughby via Digitalmars-d-learn 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]`) > > > > ? > > Select all

Re: Initialization of structure field w/o default ctor

2015-01-22 Thread Kenji Hara via Digitalmars-d-learn
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_;

Re: Defining a static array with values in a range

2015-01-22 Thread bearophile via Digitalmars-d-learn
Jonathan M Davis: but that's easy fixed with some +1's. But the +1 changes the char to an int. Bye, bearophile

Re: Defining a static array with values in a range

2015-01-22 Thread Jonathan M Davis via Digitalmars-d-learn
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 thin

Re: On Variable References

2015-01-22 Thread via Digitalmars-d-learn
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 is

Re: Changing by ref a class passed in function

2015-01-22 Thread anonymous via Digitalmars-d-learn
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);

Re: Changing by ref a class passed in function

2015-01-22 Thread anonymous via Digitalmars-d-learn
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 nullIt(ref

Re: What to do with InvalidMemoryOperationError

2015-01-22 Thread Nordlöw
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 al

Changing by ref a class passed in function

2015-01-22 Thread Zaher Dirkey via Digitalmars-d-learn
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 = ne

Re: Initialization of structure field w/o default ctor

2015-01-22 Thread drug via Digitalmars-d-learn
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; Foo

Re: Initialization of structure field w/o default ctor

2015-01-22 Thread bearophile via Digitalmars-d-learn
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

Initialization of structure field w/o default ctor

2015-01-22 Thread drug via Digitalmars-d-learn
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?

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Gary Willoughby via Digitalmars-d-learn
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 te

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Nordlöw
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]`) ?

Re: Defining a static array with values in a range

2015-01-22 Thread bearophile via Digitalmars-d-learn
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:

Re: Defining a static array with values in a range

2015-01-22 Thread Kagamin via Digitalmars-d-learn
On Thursday, 22 January 2015 at 09:26:21 UTC, tcak wrote: There are convenient constants defined in std.ascii. import std.ascii; string arr = lowercase ~ uppercase ~ digits; // also 'std.ascii.letters' gives ('A' .. 'Z' ~ 'a' .. 'z') Well, that's just disguising what we can't do. D has alot

Re: Defining a static array with values in a range

2015-01-22 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread Suliman via Digitalmars-d-learn
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.

Re: Defining a static array with values in a range

2015-01-22 Thread bearophile via Digitalmars-d-learn
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 t

Re: Defining a static array with values in a range

2015-01-22 Thread tcak via Digitalmars-d-learn
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

Re: Extracting Structure from HTML using Adam's dom.d

2015-01-22 Thread via Digitalmars-d-learn
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 paragraph that is preceeded by a heading with a specific id (say "H2_A") or conten