Thread overview
[phobos] Splitting words with delimiter
Aug 29, 2011
unDEFER
Sep 01, 2011
unDEFER
August 29, 2011
Hello!
So as I understand that D tries to make really practical tasks more easy I
want to ask about one often meeting task.
If I want to print words with delimiter I can do it with 3 ways:

1)
<print first word>
foreach <other word>
	print ", " ~ <word>
end for

2)
foreach <all words>
	if (not first)
		print ", "
	print <word>
end for

3)
foreach <all words>
	print <word> ~ ", "
end for
if <list of words not empty>
	<delete last character>

But sometimes there is other similar tasks which makes any from this
approach very ugly.
The simple example: putting array of strings to cells of tables on the
pages. Each page is table with 5 rows and 2 columns. And print at the end
of each page the "next" or "first" (for last page) button.
I really don't remember details but in my anyfs-tools.sf.net I had many
examples of this task and it was not connected with just printing.

If there is any good methods to do any complex case of this task more
beautiful with D?
Thank you.

-- 
Nikolay Krivchenkov aka unDEFER
I want to believe... in unDE.su
registered Linux user #360474
Don't worry, I can read OpenOffice.org/Libre Office/Lotus Symphony
documents
August 29, 2011
joiner

Andrei

On 8/29/11 1:45 PM, unDEFER wrote:
> Hello!
> So as I understand that D tries to make really practical tasks more easy
> I want to ask about one often meeting task.
> If I want to print words with delimiter I can do it with 3 ways:
>
> 1)
> <print first word>
> foreach <other word>
> print ", " ~ <word>
> end for
>
> 2)
> foreach <all words>
> if (not first)
> print ", "
> print <word>
> end for
>
> 3)
> foreach <all words>
> print <word> ~ ", "
> end for
> if <list of words not empty>
> <delete last character>
>
> But sometimes there is other similar tasks which makes any from this
> approach very ugly.
> The simple example: putting array of strings to cells of tables on the
> pages. Each page is table with 5 rows and 2 columns. And print at the
> end of each page the "next" or "first" (for last page) button.
> I really don't remember details but in my anyfs-tools.sf.net I had many
> examples of this task and it was not connected with just printing.
>
> If there is any good methods to do any complex case of this task more
> beautiful with D?
> Thank you.
>
September 01, 2011
OK. I understand, my question is too fuzzy. I try to make the concrete
suggestion.
Really often I want to have the next statement in a language:

for(...)
{
	if first iteration
	{
		...
	}
	else
	{
		...
	}

	...

	if last iteration
	{
		...
	}
	else
	{
		...
	}
}

Of course "if first iteration" easy implemented with the "first" flag
variable. But also as "for" makes code more clear than it's implementation
with "while", I think this statement may help to make it more clear.
"if last iteration" maybe implementable on the compiler level only with
constraints, but this feature maybe even more cool.

On 8/29/11 1:45 PM, unDEFER wrote:
> Hello!
> So as I understand that D tries to make really practical tasks more easy
> I want to ask about one often meeting task.
> If I want to print words with delimiter I can do it with 3 ways:
>
> ...
> But sometimes there is other similar tasks which makes any from this
> approach very ugly.
> The simple example: putting array of strings to cells of tables on the
> pages. Each page is table with 5 rows and 2 columns. And print at the
> end of each page the "next" or "first" (for last page) button.
> I really don't remember details but in my anyfs-tools.sf.net I had many
> examples of this task and it was not connected with just printing.
>
> If there is any good methods to do any complex case of this task more
> beautiful with D?
> Thank you.

-- 
Nikolay Krivchenkov aka unDEFER
I want to believe... in unDE.su
registered Linux user #360474
Don't worry, I can read OpenOffice.org/Libre Office/Lotus Symphony
documents