Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #49228 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2016-07-19 11:29 +0000 |
| Last post | 2016-07-23 03:19 -0400 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.forth
Let's play golf "WJ" <w_a_x_man@yahoo.com> - 2016-07-19 11:29 +0000
Re: Let's play golf hughaguilar96@gmail.com - 2016-07-19 14:07 -0700
Re: Let's play golf "HAA" <someone@microsoft.com> - 2016-07-21 18:31 +1000
Re: Let's play golf Doug Hoffman <glidedog@gmail.com> - 2016-07-22 08:59 -0400
Re: Let's play golf hughaguilar96@gmail.com - 2016-07-22 14:04 -0700
Re: Let's play golf Doug Hoffman <glidedog@gmail.com> - 2016-07-23 03:19 -0400
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2016-07-19 11:29 +0000 |
| Subject | Let's play golf |
| Message-ID | <nml2tv$bfm$1@dont-email.me> |
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?
--
If confirmed, Garland would be the fourth Jewish justice on the nation's
highest court, which is comprised entirely of Jews and Catholics. The three
current Jewish members of the Supreme Court are Ruth Bader Ginsburg, Elana
Kagan, and Stephen Breyer.
www.jta.org/2016/03/16/news-opinion/united-states/obama-to-name-jewish-federal-judge-to-supreme-court
[toc] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-07-19 14:07 -0700 |
| Message-ID | <0e31ced8-c2db-4aca-80aa-9d3b01da28f1@googlegroups.com> |
| In reply to | #49228 |
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.
> If confirmed, Garland would be the fourth Jewish justice on the nation's
> highest court, which is comprised entirely of Jews and Catholics. The three
> current Jewish members of the Supreme Court are Ruth Bader Ginsburg, Elana
> Kagan, and Stephen Breyer.
> www.jta.org/2016/03/16/news-opinion/united-states/obama-to-name-jewish-federal-judge-to-supreme-court
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.
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-07-21 18:31 +1000 |
| Message-ID | <nmq14j$1knh$1@gioia.aioe.org> |
| In reply to | #49232 |
hughaguilar96@gmail.com wrote: > ... > 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. He could just as easily argue portable code libraries was the reason behind ANS-Forth. If Forthers haven't written the libraries he uses - preferring instead to endlessly chatter and fight over what should be in the *next* standard - it is a problem he doesn't have.
[toc] | [prev] | [next] | [standalone]
| From | Doug Hoffman <glidedog@gmail.com> |
|---|---|
| Date | 2016-07-22 08:59 -0400 |
| Message-ID | <579218d4$0$292$14726298@news.sunsite.dk> |
| In reply to | #49232 |
On 7/19/16 5:07 PM, hughaguilar96@gmail.com wrote:
> 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
With an objects extension and library:
${ Cat ate mouse } ok \ 1
dup reverse: ok \ 1
dup last: lower: ok \ 1
dup first: capitalize: ok \ 1
dup p: ${ Mouse ate cat } ok \ 1
But there was a period to deal with:
${ Cat ate mouse. } ok \ 1
dup reverse: ok \ 1
dup last: dup lower: '.' swap +: ok \ 1
dup first: dup trim: capitalize: ok \ 1
dup p: ${ Mouse ate cat. } ok \ 1
The nice thing about using objects here (for handling a list of strings)
is the code was easily derived by inheriting from existing
dynamically sizeable list and string classes. In a similar manner it was
easy to have lists of integers, floats, and any objects. All derived
(inherited) from the same base class. Easy re-use of existing code.
The other nice thing about objects is the ability to re-use words
(messages) for different data types. reverse: last: +: first: and p: are
all messages common to many different object types and do what one would
expect for each.
Naturally there are lots of different ways to approach this kind of
problem. I had already written the library code quite awhile ago so I
used that.
-Doug
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-07-22 14:04 -0700 |
| Message-ID | <b78e9dc4-db9c-4b59-b29d-1ab51be9504f@googlegroups.com> |
| In reply to | #49323 |
On Friday, July 22, 2016 at 6:00:06 AM UTC-7, Doug Hoffman wrote:
> On 7/19/16 5:07 PM, hughaguilar96@gmail.com wrote:
>
> > 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
>
> With an objects extension and library:
>
> ${ Cat ate mouse } ok \ 1
> dup reverse: ok \ 1
> dup last: lower: ok \ 1
> dup first: capitalize: ok \ 1
> dup p: ${ Mouse ate cat } ok \ 1
>
>
> But there was a period to deal with:
>
> ${ Cat ate mouse. } ok \ 1
> dup reverse: ok \ 1
> dup last: dup lower: '.' swap +: ok \ 1
> dup first: dup trim: capitalize: ok \ 1
> dup p: ${ Mouse ate cat. } ok \ 1
>
>
> The nice thing about using objects here (for handling a list of strings)
> is the code was easily derived by inheriting from existing
> dynamically sizeable list and string classes. In a similar manner it was
> easy to have lists of integers, floats, and any objects. All derived
> (inherited) from the same base class. Easy re-use of existing code.
I agree that inheritance is fundamental to any general-purpose data-structure.
> The other nice thing about objects is the ability to re-use words
> (messages) for different data types. reverse: last: +: first: and p: are
> all messages common to many different object types and do what one would
> expect for each.
I disagree that polymorphism is necessary --- this kills the speed --- it is just a convenience, so I don't think it is worth the cost.
There are sometimes name clashes though. I noticed when writing this that I have REVERSE in string-stack.4th (reverses the chars in a string) and also have REVERSE in list.4th (reverses the elements in a list), so I had to change the string-stack.4th one to REVERSE-STR instead --- I had never used the two packages together before and hadn't noticed the clash.
> Naturally there are lots of different ways to approach this kind of
> problem. I had already written the library code quite awhile ago so I
> used that.
What library is this?
My method certainly gets the prize for being the simplest Forth OOP package --- it is not really a "package" but rather it is just a style of programming --- other than FIELD and ALLOCATION (used for cloning data-structures) there isn't anything to it.
[toc] | [prev] | [next] | [standalone]
| From | Doug Hoffman <glidedog@gmail.com> |
|---|---|
| Date | 2016-07-23 03:19 -0400 |
| Message-ID | <57931a76$0$302$14726298@news.sunsite.dk> |
| In reply to | #49344 |
On 7/22/16 5:04 PM, hughaguilar96@gmail.com wrote: > What library is this? My personal library. > My method certainly gets the prize for being the simplest Forth OOP > package --- it is not really a "package" but rather it is just a style > of programming --- other than FIELD and ALLOCATION (used for cloning > data-structures) there isn't anything to it. Sounds good. You should stick with that. -Doug
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web