Jump to page: 1 2 3
Thread overview
foreach over split string
Jul 17, 2013
JS
Jul 17, 2013
JS
Jul 17, 2013
JS
Jul 17, 2013
John Colvin
Jul 17, 2013
JS
Jul 17, 2013
Ary Borenszweig
Jul 17, 2013
JS
Jul 17, 2013
John Colvin
Jul 17, 2013
Maxim Fomin
Jul 17, 2013
John Colvin
Jul 17, 2013
anonymous
Jul 17, 2013
Artur Skawina
Jul 17, 2013
Jonathan M Davis
Jul 17, 2013
JS
Jul 17, 2013
H. S. Teoh
Jul 18, 2013
JS
Jul 18, 2013
H. S. Teoh
Jul 18, 2013
JS
Jul 18, 2013
JS
Jul 18, 2013
JS
Jul 18, 2013
H. S. Teoh
Jul 18, 2013
JS
July 17, 2013
foreach(n; std.string.split(s, ","))
{
    // n can't be read at compile time
}

using in a ctfe.

How to loop over a string array in a ctfe?
July 17, 2013
On Wednesday, 17 July 2013 at 14:02:01 UTC, JS wrote:
>
> foreach(n; std.string.split(s, ","))
> {
>     // n can't be read at compile time
> }
>
> using in a ctfe.
>
> How to loop over a string array in a ctfe?


Strange...

The code actually works, but when I use my wrapper template it doesn't...

template splitstr(string n, string d = " ") { enum splitstr = std.string.split(n, d); }


I guess it has something to do with using an enum as the return type?
July 17, 2013
Ok, spoke too soon again,

my string requires compound splitting:

foreach(ss; split(s, ","))
{
    split(ss, "|"); // ss can't be read at compile time although I can use ss directly
    string a = ss; // works fine.
}
July 17, 2013
On Wednesday, 17 July 2013 at 14:09:28 UTC, JS wrote:
> Ok, spoke too soon again,
>
> my string requires compound splitting:
>
> foreach(ss; split(s, ","))
> {
>     split(ss, "|"); // ss can't be read at compile time although I can use ss directly
>     string a = ss; // works fine.
> }

Is there any possibility you could provide a compilable example (or not compilable, if that's the point :p )? It's an awful lot easier to quickly give the right answer to a question if you take the time to ask it clearly and precisely, in one go, with a minimised example.
Also, by virtue of you having made an example and checked it, it prevents accidentally talking about problems in code that is actually fine.
July 17, 2013
On Wednesday, 17 July 2013 at 14:18:25 UTC, John Colvin wrote:
> On Wednesday, 17 July 2013 at 14:09:28 UTC, JS wrote:
>> Ok, spoke too soon again,
>>
>> my string requires compound splitting:
>>
>> foreach(ss; split(s, ","))
>> {
>>    split(ss, "|"); // ss can't be read at compile time although I can use ss directly
>>    string a = ss; // works fine.
>> }
>
> Is there any possibility you could provide a compilable example (or not compilable, if that's the point :p )? It's an awful lot easier to quickly give the right answer to a question if you take the time to ask it clearly and precisely, in one go, with a minimised example.
> Also, by virtue of you having made an example and checked it, it prevents accidentally talking about problems in code that is actually fine.

Yes, but if ctfe's wern't so shitty it wouldn't be a problem in the first place. The error messages are crap, the type system is disjoint(passing strings to templates must be distinguished in many cases from types).

All I did was create a wrapper to std.string.split. when I use it, the code breaks... I don't get any obvious error about my template but just that I can't use a non-compile time variable.

What you don't understand it is is a lot of work to simplify my code to something that will make sense so you can "give your quick answer"(which is not what I'm looking for. This isn't stack overflow and you don't get a golden ticket for answering correctly).

There is also a lot of support code that I use which I have to remove... it's a lot more work than you want to make it out to be. What I'm learning is that error messages in CTFE's are about useless... but they still throw me for a loop.


If it will make you feel better to see some code, which does work,


template tSplitStr(string n, string d = " ") { enum tSplitStr = std.string.split(n, d); }


/// Implements each (name, type) pair in T
template tPImplS(T...)
{
	string eval()
	{
		string s;
		foreach(nt; tSplitStr!(tPDeclH!(T), "&"))
		{
			string name = (std.string.split(nt, ","))[0];
			string tname = (std.string.split(nt, ","))[1];
			s ~= "private "~tname~" _"~name~";\n";
			s ~= "@property "~tname~" "~name~"() { return _"~name~"}\n"~"@property "~tname~" "~name~"("~tname~" value) { return _"~name~" = value; }\n";
		}

		return s;
	}
	enum tPImplS = eval();
}

but note when I try to use the tSplitStr, I get errors. This makes no sense to me because tSplitStr simply wraps split, and I should be able to use it where I use split. I do realize one is a template and the other is ctfe... and realize that tSplitStr does work, in some cases, just not all(which is what makes it a bitch to figure out with errors like "nt can't be read at compile time").

My guess is the compiler is not smart enough to realize that tSplitStr does use any compile time features and really is just a wrapper to split.


It seems that if the compiler see's ! used it throws the generic error "cannot be read at compile time"... which I'm so sick of seeing it's driving me insane.



July 17, 2013
On 7/17/13 11:38 AM, JS wrote:
> On Wednesday, 17 July 2013 at 14:18:25 UTC, John Colvin wrote:
>> On Wednesday, 17 July 2013 at 14:09:28 UTC, JS wrote:
>>> Ok, spoke too soon again,
>>>
>>> my string requires compound splitting:
>>>
>>> foreach(ss; split(s, ","))
>>> {
>>>    split(ss, "|"); // ss can't be read at compile time although I can
>>> use ss directly
>>>    string a = ss; // works fine.
>>> }
>>
>> Is there any possibility you could provide a compilable example (or
>> not compilable, if that's the point :p )? It's an awful lot easier to
>> quickly give the right answer to a question if you take the time to
>> ask it clearly and precisely, in one go, with a minimised example.
>> Also, by virtue of you having made an example and checked it, it
>> prevents accidentally talking about problems in code that is actually
>> fine.
>
> Yes, but if ctfe's wern't so shitty it wouldn't be a problem in the
> first place.

If you think the language is shitty why are you using it?

You didn't pay for D, you are receiving it as a free tool. I don't think many people will help you if you continue with that attitude -.-

July 17, 2013
On Wednesday, 17 July 2013 at 14:55:12 UTC, Ary Borenszweig wrote:
> On 7/17/13 11:38 AM, JS wrote:
>> On Wednesday, 17 July 2013 at 14:18:25 UTC, John Colvin wrote:
>>> On Wednesday, 17 July 2013 at 14:09:28 UTC, JS wrote:
>>>> Ok, spoke too soon again,
>>>>
>>>> my string requires compound splitting:
>>>>
>>>> foreach(ss; split(s, ","))
>>>> {
>>>>   split(ss, "|"); // ss can't be read at compile time although I can
>>>> use ss directly
>>>>   string a = ss; // works fine.
>>>> }
>>>
>>> Is there any possibility you could provide a compilable example (or
>>> not compilable, if that's the point :p )? It's an awful lot easier to
>>> quickly give the right answer to a question if you take the time to
>>> ask it clearly and precisely, in one go, with a minimised example.
>>> Also, by virtue of you having made an example and checked it, it
>>> prevents accidentally talking about problems in code that is actually
>>> fine.
>>
>> Yes, but if ctfe's wern't so shitty it wouldn't be a problem in the
>> first place.
>
> If you think the language is shitty why are you using it?
>
> You didn't pay for D, you are receiving it as a free tool. I don't think many people will help you if you continue with that attitude -.-

Go fuck yourself you righteous asshole. First, I never said I paid for it, second, I never said D was shitty, I said ctfe was.  Also, I never asked for your damn help, if you don't like my attitude, don't respond, simple as that. If your ego gets hurt too fucking bad, grow up. Stop making assumptions to suit your own needs.



July 17, 2013
On Wednesday, 17 July 2013 at 15:18:03 UTC, JS wrote:
> On Wednesday, 17 July 2013 at 14:55:12 UTC, Ary Borenszweig wrote:
>> On 7/17/13 11:38 AM, JS wrote:
>>> On Wednesday, 17 July 2013 at 14:18:25 UTC, John Colvin wrote:
>>>> On Wednesday, 17 July 2013 at 14:09:28 UTC, JS wrote:
>>>>> Ok, spoke too soon again,
>>>>>
>>>>> my string requires compound splitting:
>>>>>
>>>>> foreach(ss; split(s, ","))
>>>>> {
>>>>>  split(ss, "|"); // ss can't be read at compile time although I can
>>>>> use ss directly
>>>>>  string a = ss; // works fine.
>>>>> }
>>>>
>>>> Is there any possibility you could provide a compilable example (or
>>>> not compilable, if that's the point :p )? It's an awful lot easier to
>>>> quickly give the right answer to a question if you take the time to
>>>> ask it clearly and precisely, in one go, with a minimised example.
>>>> Also, by virtue of you having made an example and checked it, it
>>>> prevents accidentally talking about problems in code that is actually
>>>> fine.
>>>
>>> Yes, but if ctfe's wern't so shitty it wouldn't be a problem in the
>>> first place.
>>
>> If you think the language is shitty why are you using it?
>>
>> You didn't pay for D, you are receiving it as a free tool. I don't think many people will help you if you continue with that attitude -.-
>
> Go fuck yourself you righteous asshole. First, I never said I paid for it, second, I never said D was shitty, I said ctfe was.  Also, I never asked for your damn help, if you don't like my attitude, don't respond, simple as that. If your ego gets hurt too fucking bad, grow up. Stop making assumptions to suit your own needs.

This is completely out of order.

I think I can speak quite safely for the majority of the community when I say that you are only welcome here if you can keep your aggressive and disrespectful comments to yourself.
July 17, 2013
On Wednesday, 17 July 2013 at 15:18:03 UTC, JS wrote:
> On Wednesday, 17 July 2013 at 14:55:12 UTC, Ary Borenszweig wrote:
[...]
>> If you think the language is shitty why are you using it?
>>
>> You didn't pay for D, you are receiving it as a free tool. I don't think many people will help you if you continue with that attitude -.-
>
> Go fuck yourself you righteous asshole. First, I never said I paid for it, second, I never said D was shitty, I said ctfe was.  Also, I never asked for your damn help, if you don't like my attitude, don't respond, simple as that. If your ego gets hurt too fucking bad, grow up. Stop making assumptions to suit your own needs.

G o o s f r a b a
July 17, 2013
On 07/17/13 16:38, JS wrote:
> it is is a lot of work to simplify my code to something that will make sense

Indeed.


> If it will make you feel better to see some code, which does work,

[...snipped incomplete example which doesn't...]


> template tSplitStr(string n, string d = " ") { enum tSplitStr = std.string.split(n, d); }

Use a function and forget about '!':

   auto tSplitStr(string n, string d = " ") { return std.string.split(n, d); }
   //...
   foreach(nt; tSplitStr(tPDeclH!(T), "&"))



> you don't get a golden ticket for answering correctly

I was going to explain /why/ your code can't work. But without a ticket? Hmm. Nah.


artur
« First   ‹ Prev
1 2 3