On Tuesday, July 19, 2016 at 4:29:07 AM UTC-7, WJ wrote:
> Task:
>
> Convert "Cat ate mouse." to "Mouse ate cat.", using
> chop, split, reverse, join, capitalize, and
> string-concatenation.
>
> "Cat ate mouse.".chop
> ==>"Cat ate mouse"
> "Cat ate mouse.".chop.split
> ==>["Cat", "ate", "mouse"]
> "Cat ate mouse.".chop.split.reverse
> ==>["mouse", "ate", "Cat"]
> "Cat ate mouse.".chop.split.reverse.join(" ")
> ==>"mouse ate Cat"
> "Cat ate mouse.".chop.split.reverse.join(" ").capitalize
> ==>"Mouse ate cat"
> "Cat ate mouse.".chop.split.reverse.join(" ").capitalize + "."
> ==>"Mouse ate cat."
>
> Can it be shorter in ANS Forth?
Here it is using my LIST.4TH and STRING-STACK.4TH packages:
s" Cat ate mouse" ok-2
2dup uncapitalize ok-2
bl char " char " <split> ok-1
reverse ok-1
bl combine ok-1
count ok-2
2dup capitalize ok-2
2dup type Mouse ate cat ok-2
Note that I had to write CAPITALIZE because I didn't have that one, but it was trivial. It is in STRING-STACK.4TH now.
Note also that my SPLIT is much more sophisticated that the split function that WJ is using. I can do things like this:
s" <Aguilar, Hugh>, Pelc, " char , char < char > <split> ok-1
show-seq
Aguilar, Hugh
Pelc
ok
Note also that WJ is not a programmer. He is just a script-kiddie. He finds code-libraries and he learns how to use them, but he is not capable of writing code-libraries himself. By comparison, I wrote these code-libraries myself that I am using.
WJ is a jackass --- I recommend that nobody ever respond to any of his posts --- I only responded to this one because it was trivial, but as a matter of principle I generally ignore him.