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

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 do

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: 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 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 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 things are

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: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

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: 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 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

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 did

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

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

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

Defining a static array with values in a range

2015-01-21 Thread tcak via Digitalmars-d-learn
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 something like EBNF definitions. So, I do not want to use loops, or define every

Re: Defining a static array with values in a range

2015-01-21 Thread Vlad Levenfeld via Digitalmars-d-learn
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 way to do this? I am trying to do something like EBNF

Re: Defining a static array with values in a range

2015-01-21 Thread anony via Digitalmars-d-learn
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 way to do this? I am trying to do something like EBNF