Article View: a.testing.group
Article #45[newbie] My first Forth Program
From: KezL
Date: Thu, 17 Jun 2010 19:43
Date: Thu, 17 Jun 2010 19:43
75 lines
3744 bytes
3744 bytes
Hi Everyone,
I am teaching myself FORTH.
I have written a progam which I hope can be the beginings of a "CHATTERBOT"
It is inspired by Mealy machines
Tell me what you think.
Thank you,
KezL
****** PROGRAM BEGINS ******
0 CONSTANT HAPPY
1 CONSTANT SAD
2 CONSTANT BORED
3 CONSTANT ANGRY
0 CONSTANT INSULT
1 CONSTANT FLATTER
2 CONSTANT ANNOY
3 CONSTANT AMUSE
\ RESPONSES: STATE TRANSITION TABLE 4 X 4 X 1 CELLS
\ Current Mood: HAPPY SAD BORED ANGRY
\ INPUT:
CREATE RESPONSES ANGRY , SAD , SAD , ANGRY , \ INSULT ME
HAPPY , HAPPY , SAD , BORED ,
\ FLATTER ME
BORED , SAD , BORED , ANGRY ,
\ ANNOY ME
HAPPY , HAPPY , ANGRY , BORED , \
AMUSE ME
\ COMMENTS: OUTPUT TABLE 4 X 4 X 10 CELLS
CREATE COMMENTS ," I DON'T LIKE YOU ANY MORE! "
," KICK ME WHEN I'M DOWN THEN YOU FIEND! "
," LEAVE ME ALONE! "
," GO TO HECK! "
," THANK YOU "
," I FEEL BETTER NOW "
," I KNOW YOU DON'T MEAN IT "
," YEAH RIGHT WHATEVER "
," YAWN "
," SIGH "
," I'M SO BORED "
," GET LOST! "
," HE HE "
," THANKS FOR CHEERING ME UP "
," I'M NOT IN THE MOOD FOR JOKES "
," YOU'RE SO FUNNY - NOT! "
VARIABLE MOOD
HAPPY MOOD !
: REPORT ( -- ) \ REPORTS MOOD. USAGE: REPORT
CR
MOOD @ HAPPY = IF ." I AM HAPPY" THEN
MOOD @ SAD = IF ." I AM SAD" THEN
MOOD @ BORED = IF ." I AM BORED" THEN
MOOD @ ANGRY = IF ." I AM ANGRY" THEN
CR
;
: ME ( n -- ) \ INTERACT. USAGE: INSULT|FLATTER|ANNOY|AMUSE ME
CR DUP
40 CELLS * MOOD @ 10 CELLS * + COMMENTS + COUNT TYPE
4 CELLS * MOOD @ CELLS + RESPONSES + @ MOOD ! REPORT ;
Technical Details
Message-ID:
<iM6dnQ8BlY5L54fRnZ2dnUVZ7qKdnZ2d@bt.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10610a,3d66e3c7ae653f0d,start X-Google-NewGroupId: yes X-Google-Attributes: gid1190ecade0,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 17 Jun 2010 14:43:18 -0500 From: "KezL" <growl4me@googlemail.com> Newsgroups: a.testing.group Subject: [newbie] My first Forth Program Date: Thu, 17 Jun 2010 20:43:08 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6002.18197 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6002.18197 Message-ID: <iM6dnQ8BlY5L54fRnZ2dnUVZ7qKdnZ2d@bt.com> Lines: 76 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-sTGj2tJVCF9W/WZp2ZQJPi7zGUKWy2pFgxlPRLXeeOYAwlWXqGmUvlxa99RJQ07UNwI++hpbLLv95xZ!d0gE6t9HVgVFSuxnb528sGrZAjN7RbeZBsGnqpGx21WhhTM3cJo91v0mdu00JA3OOwOfBXYl+g== X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40