Nп/п : 71 из 100
 От   : Marcel Hendrix                      2:5075/128        29 сен 23 13:27:30
 К    : Marcel Hendrix                                        29 сен 23 23:31:02
 Тема : Re: Simple Forth programs
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
<062d8265-df2b-48e0-935c-e3dd8b319a82n@googlegroups.com> 2f76731b
@REPLY:
<ac9b82d1-53fe-4bcc-b1a2-165b0a31b7b4n@googlegroups.com> 59df17df
@REPLYADDR Marcel Hendrix <mhx@iae.nl>
@REPLYTO 2:5075/128 Marcel Hendrix
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<55f30e3c-a6fe-428c-a95f-02bacf08c1een@googlegroups.com> <dbfca034-8ca9-4a9b-b563-3fa9da176386n@googlegroups.com>
<51074ba9-ac74-49aa-8f12-28668d28171fn@googlegroups.com> <8f99b90f-7f00-4544-8fa6-d258ee6f4ef2n@googlegroups.com>
<84586256-f364-4dcd-9b34-ef354fcd834dn@googlegroups.com> <790b5095-79fe-4012-8fee-e2d1cb33f7a3n@googlegroups.com>
<ac9b82d1-53fe-4bcc-b1a2-165b0a31b7b4n@googlegroups.com>
@RFC-Message-ID:
<062d8265-df2b-48e0-935c-e3dd8b319a82n@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
(*
 * LANGUAGE    : ANS Forth
 * PROJECT     : Forth Environments
 * DESCRIPTION : Eliza is a psychiatrist of the Carl Roger school.
 * CATEGORY    : AI Game, text based, by Weizenbaum.
 * AUTHOR      : Marcel Hendrix, November 11, 1986
 * LAST CHANGE : July 24, 1993, Marcel Hendrix, case problem my$ My$
 * LAST CHANGE : March 20, 1992, Marcel Hendrix, new TO strings
 * LAST CHANGE : March 15, 1992, Marcel Hendrix
 *)


NEEDS -miscutil
NEEDS -terminal
NEEDS -strings

REVISION -eliza "--- The Psychiater      Version 1.21 ---"

PRIVATES


        3 =: #RespPRIVATE
      #17 =: #ConjupairsPRIVATE
0 VALUE last-cPRIVATE
0 VALUE char#PRIVATE
0 VALUE phrase vocPRIVATE

DEFER ECHOPRIVATE


: RmarginC/L #10 - ;PRIVATE


WARNING @  WARNING OFF

: CRCR  CLEAR char# ; PRIVATE

: SPACEchar# IF  SPACE  1 +TO char#
   ENDIF ; PRIVATE

WARNING !

: EMIT`char# 1+ Rmargin > OVER BL = AND\\  --- <>
    IFCR DROP
  ELSE  DUP TO last-c  EMIT  1 +TO char#
 ENDIF ; PRIVATE

: PRINT-?last-c `?` <>  last-c `!` <>  AND\\ <> --- <>
IF `.` EMIT` ENDIF ; PRIVATE

: `TYPE`ABS #255 MIN\\   --- <>
0 ?DO
C@+
        DUP `*` <> IF EMIT`\\ This is all..
         ELSE DROP -1 +TO char#
      ECHO\\ More (forward)
        ENDIF
 LOOP DROP ; PRIVATE


-- print a CR or BL, then the string

: .STRING DUP char# + Rmargin >\\   --- <>
   IF  CR
 ELSE  SPACE
ENDIF `TYPE` ; PRIVATE


 S" Please do not repeat yourself."$CONSTANT Notrepeat$PRIVATE
 S" Goodbye"$CONSTANT Goodbye$PRIVATE
 S" Ok, hope to see you again." $CONSTANT Farewell$PRIVATE
 S" Hello..."$CONSTANT Hello$PRIVATE
 S" The doctor is in..please stand by."$CONSTANT Doctorin$PRIVATE
 S" Welcome in my shrinker`s office."   $CONSTANT Session$PRIVATE

 S" are you"$CONSTANT Areyou$PRIVATE
 S" are you"$CONSTANT Are you$PRIVATE
 S" you are"$CONSTANT Youare$  PRIVATE
 S" you are"$CONSTANT You are$PRIVATE
 S" am I"$CONSTANT AmI$PRIVATE
 S" am I"$CONSTANT Am I$PRIVATE
 S" I am"$CONSTANT Iam$  PRIVATE
 S" I am"$CONSTANT I am$PRIVATE
 S" YOU"$CONSTANT YOU$PRIVATE
 S" my"$CONSTANT myl$PRIVATE
 S" My"$CONSTANT Myu$PRIVATE


-- Read ahead in text file. This doesn`t work with a terminal.
-- A nice feature: the read text is interpreted, so { 1 2 + } works!

: READ-INFILEREFILL 0= ABORT" REFILL: Sorry"
TIB #TIB @ EVALUATE ; PRIVATE


-- Now read n strings ( 1 per line) from THIS file into a string array.

: READ-$ARRAYLOCAL arr\\  <$mid> --- <>
0 ?DO
      READ-INFILE  TO I (( arr )) DO$ARRAY
 LOOP
REFILL 0= ABORT" REFILL: Sorry" ; PRIVATE


-- Read n strings ( 2 per line) from THIS file into a string array.

: 2READ-$ARRAYLOCAL arr\\  <$mid> --- <>
  0 ?DO
        READ-INFILE \\ <> ---    
        TO I 1+ (( arr )) DO$ARRAY
        TO I    (( arr )) DO$ARRAY
2 +LOOP
REFILL 0= ABORT" REFILL: Sorry" ; PRIVATE


8 $ARRAY random replies PRIVATE   #40 NEW$ARRAY random replies

8  $MID random replies  READ-$ARRAY
S" What does that suggest to you?"
S" Please elaborate on that"
S" I`m not sure I understand that fully"
S" Why?"
S" That`s very interesting"
S" Well....please continue....."
S" And then?"
S" I see..Please tell me more about that"


STRING temp    PRIVATE#255 NEW temp
STRING temp2   PRIVATE#255 NEW temp2
STRING temp3   PRIVATE#255 NEW temp3
STRING old     PRIVATE#255 NEW old
STRING keep    PRIVATE#255 NEW keep
STRING work    PRIVATE#255 NEW work


 #99 =: PUSH!PRIVATE
 #66 =: PICK!PRIVATE
 #33 =: EMPTY?PRIVATE
 #24 =: /linesPRIVATE
#256 =: /charsPRIVATE


: STACKCREATEHERE >S  0 , ( addr)  0 , ( sp)\\   --- <>
* DUP ALLOCATE ?ALLOCATE
DUP S> !
SWAP ERASE
FORGET>@ FREE ?ALLOCATE
DOES>DUP @ LOCAL $stack
CELL+ LOCAL $sp
CASE
  PUSH! OF  $stack  $sp @ /chars *  +\\   --- <>
    PACK DROP
    $sp @ 1+  /lines MOD  $sp !
     ENDOF
  PICK! OF  $stack  $sp @ CHOOSE\\ <> ---  
    /chars * +  COUNT
     ENDOF
 EMPTY? OF  $sp @ 1 U<\\ <> --- 
     ENDOF
ENDCASE ; PRIVATE

/lines /chars STACK CMDS  PRIVATE

: OPENING-MESSAGE
CLS
#20 #10 AT-XY Doctorin$.STRING
#1000 MS CLS
#20 #10 AT-XY Session$.STRING
#00 #13 AT-XY Hello$.STRING ; PRIVATE


: INPUTBEGIN
   CR C/L 2- 0 DO   `?` EMIT LOOP
   CR ." $ "  $ID temp #255 $INPUT
   SIZEOF temp 0= IF QUIT ENDIF\\ Empty string
   temp keep $= \\ the same as before!
WHILE
   CR Notrepeat$ .STRING
REPEAT
temp TO keep
`.` RTRIM temp  `?` RTRIM temp  temp TO old
Goodbye$ INDEX temp  -1 <> IF CR Farewell$ .STRING
      CR QUIT
                ENDIF ; PRIVATE


#Conjupairs 2* $ARRAY conjugations PRIVATE   8 NEW$ARRAY conjugations

#Conjupairs 2*  $MID conjugations  2READ-$ARRAY
S" are"S" am"
 S" am"S" are"
S" you"    S" me"
S" my"    S" your"
S" your"  S" my"
S" was"    S" were"
S" mine"S" yours"
S" you"    S" I"
S" I"  S" you"
S" I`ve"S" you`ve"
S" you`ve"S" I`ve"
S" you are"S" I am"
S" are you"S" am I"
S" I am"S" you are"
S" am I"S" are you"
S" myself" S" yourself"
S" yourself" S" myself"


7 $ARRAY  earlier remarks  PRIVATE#60 NEW$ARRAY earlier remarks

7  $MID earlier remarks  READ-$ARRAY
S" Please tell me more about your*"
S" Is there a link here with your*?"
S" Does that have anything to do with your*?"
S" Why don`t we go back and discuss your* a little more?"
S" Does any connection between that and your* suggest itself?"
S" Would you prefer to talk about your*"
S" I think perhaps worries about your* are bothering you"


: USE-EARLY-REMARKS
CR EMPTY? CMDS IF 8 CHOOSE random replies .STRING
  EXIT
    ENDIF
7 CHOOSE earlier remarks
0 ?DOC@+ DUP `*`
<> IF EMIT`
 ELSE DROP PICK! CMDS .STRING
ENDIF
 LOOP DROP ; PRIVATE


-- Take first blank-delimited word of userinput, the rest if no delimiter
-- found.

: NEXT-WORDBL SPLIT old  \\ <> ---  
   IF DROP 2SWAP TO temp  TO old
      temp
 ELSE old  0 0 TO old
ENDIF ; PRIVATE

: CONJUGATED#Conjupairs 2*\\  -- 
  0 ?DO
2DUP I conjugations  COMPARE
0= IF   2DROP
I 1+ conjugations
LEAVE
ENDIF
2 +LOOP ; PRIVATE

: .CONJUGATEDCONJUGATED .STRING ; PRIVATE\\   --- <>


-- alternative trigger: ``my`` or ``My``

: "MY"-INPUT?myl$ INDEX old
DUP -1 <> IF  3 + #255  MID old  PUSH! CMDS EXIT ENDIF  DROP
Myu$ INDEX old
DUP -1 <> IF  3 + #255  MID old  PUSH! CMDS EXIT ENDIF  DROP ;
PRIVATE

: echo.itAreyou$ Are you$ REPLACE old\\ <> --- <>
Youare$ You are$ REPLACE old
AmI$    Am I$    REPLACE old
Iam$    I am$    REPLACE old
BEGIN
   NEXT-WORD DUP
WHILE
   .CONJUGATED
REPEAT 2DROP ; PRIVATE

` echo.it IS ECHO


-- LOOKUP searches in PHRASE only.

: LOOKUP \\   ---   | 
phrase voc SEARCH-WORDLIST ; PRIVATE


: get$>S   \\  ---  
NEXT-WORD TO temp2\\ could be 0 string
S> 0  ?DO
  S"  " +TO temp2
  NEXT-WORD +TO temp2
     LOOP
temp2 ; PRIVATE


: ?PHRASEFALSE  \\ <> --- 
   1 3 DO
  old TO work
  I get$
  LOOKUP IF  EXECUTE 0= LEAVE
       ELSE  work TO old
      ENDIF
 -1 +LOOP ; PRIVATE


: ?WORDFALSE >S  old TO work\\ <> --- 
BEGIN
   NEXT-WORD
   DUP  S 0=  AND
WHILE
   LOOKUP IF  EXECUTE S> INVERT >S
       ENDIF
REPEAT 2DROP
S> DUP FALSE = IF  work TO old
    ENDIF ; PRIVATE


4 $ARRAY w`s  PRIVATE5 NEW$ARRAY w`s

S" Why"   TO 0 w`s
S" When"   TO 1 w`s
S" Where"  TO 2 w`s
S" Who"   TO 3 w`s


--  Why do I stink ... ==> (why don`t YOU tell me)  why you do stink.

: "W"-INPUT?4 0 DO
I w`s INDEX old
0= IF
NEXT-WORD   TO temp2  1 BL RPASTE temp2
S"  " TO temp3
NEXT-WORD  +TO temp3  1 BL RPASTE temp3
 NEXT-WORD  TO+ temp3
temp3 +TO temp2
temp2 TO+ old
LEAVE
ENDIF
  LOOP ; PRIVATE


-- The main word.

: DOCTOROPENING-MESSAGE
BEGIN
  INPUT
  "MY"-INPUT?
  ?PHRASE  0= IF "W"-INPUT?
 ?WORD 0= IF USE-EARLY-REMARKS ENDIF
   ENDIF
  PRINT-?
AGAIN ;


:ABOUTCR ." ***********************************************************"
CR ." Start with:  DOCTOR    "
CR ." Stop  with:  Goodbye.  (Case-sensitive, notice the `.`)"
CR ." ***********************************************************" ;


-- Compare oldinput$ against the trigger phrase vocabulary

#300 =: capacity

capacity $ARRAY phrases PRIVATE

0 VALUE #phrase        PRIVATE


: TPHRASECREATE#phrase ,\\   ...   --- <>
#Resp 0 DO
   DUP NEW (( #phrase )) phrases
        TO (( #phrase )) phrases
   1 +TO #phrase
      LOOP
DOES>@  #Resp CHOOSE +  phrases CR .STRING ; PRIVATE


.HELP CR



-- Type randomly one of three possible response strings.
-- Add your trigger phrases (about 200 free yet) and amaze your friends...


VOCABULARY PHRASEALSO PHRASE DEFINITIONS  CURRENT @ TO phrase voc

S" Why do you need*"
S" Would it really be helpful if you got*"
S" Are you sure you need*"TPHRASE  I need

S" Do you really think I don`t*"
S" Perhaps I eventually will*"
S" Do you really want me to*"TPHRASE Why don`t you

S" Do you think you should be able to*"
S" Why can`t you*"
S" Perhaps you didn`t try"TPHRASE Why can`t I

S" Why are you interested whether I am or not*"
S" Would you prefer it if I were not*"
S" Perhaps you sometimes dream I am*"TPHRASE Are you

S" How do you know you can`t*"
S" Have you tried?"
S" Perhaps, now, you can*"TPHRASE I can`t

S" Did you come to me because you are*"
S" Do you think it is absolutely normal to be*"
S" How long have you been*"TPHRASE I am

S" Do you enjoy being*"
S" Why tell me you`re*"
S" Why are you*"TPHRASE I`m

S" What would it mean to you if you got*"
S" Why do you want*"
S" What would it add to your life if you got*"
TPHRASE I want

S" Why do you ask?"
S" How would an answer to that help you?"
S" What do you think?"TPHRASE what

S" How would you solve that?"
S" It would be best to answer that for yourself"
S" What is it you`re really asking?"TPHRASE how

S" Do you often think about such questions?"
S" What answer would put your mind at rest?"
S" Who do you think*"TPHRASE Who

S" That`s a pretty silly question"
S" Do you really need to know where*"
S" What would it mean to you if I told you where*"
TPHRASE Where

S" Things have a habit of happening more or less at the right time"
S" The time should not be discussed here"
S" How should I know when*"TPHRASE When

S" Please repeat the information needed to tell you why*"
S" Why don`t y o u tell me the reason why*"
S" Do you really need to know why*"     TPHRASE Why

S" Is that the real reason?"
S" What else does that explain?"
S" What other reasons come to mind?"    TPHRASE Because

S" In what other circumstances do you apologize?"
S" There are many times when no apology is needed"
S" What feelings do you have when you apologize?"
TPHRASE sorry

S" How are you.. I`m looking forward to another chat with you"
S" Hello to you.. I`m glad you could drop by today"
S" Hello.. it`s good to see you"TPHRASE Hello

S" Hi there.. I`m glad to see you here today"
S" Hi. I`m glad you`ve dropped by......we`ve got lots of time to chat"
S" Hi to you..relax now, and let`s talk about your situation"
TPHRASE Hi

S" You seem a little hesitant"
S" That`s pretty indecisive"
S" In what other situations do you show such a tentative approach?"
TPHRASE maybe

S" That`s pretty forceful. What does it suggest to you?"
S" Are you saying that just to be negative"
S" Why are you being so negative about it?" TPHRASE No

S" Please give me a specific example"
S" When?"
S" Isn`t `ALWAYS` a little strong?"TPHRASE always

S" Do you doubt*"
S" Do you really think so?"
S" But you are not sure*"TPHRASE I think

S" Why do you bring up the subject of friends?"
S" Please tell me more about your friendship.."
S" What is your best memory of a friend?"TPHRASE friend

S" In what way do your friends` reactions bother you?"
S" What made you start to talk about friends just now?"
S" In what way do your friends impose on you?"TPHRASE friends

S" What feelings do you get, sitting there talking to me like this?"
S" Are you thinking about me in particular"
S" What aspect of computers interests you the most?"
TPHRASE computer

S" How do you dare bring up such obscene subject matter!"
S" Oh no, we are NOT going to describe our sex life are we!"
S" Why not discuss something more down to earth, like your stamp collection?"
TPHRASE tForth

S" Work... I can look at it for ages"
S" I know what it is when your boss hates you"
S" It is a universal problem, but that`s no solace"
TPHRASE work

S" How sick can you get."
S" Read about that thing in Reader`s Digest. You mean FORTRAN eeh?"
S" Does your wife know that you still have the habit?"
TPHRASE Forth

S" That`s my man! I like seeing too, especially pretty women"
S" Read about that thing in Fortune Magazine. Are you a millionaire yet?"
S" Any other perversities? You still beat your wife and kids?"
TPHRASE C

S" Do you think it is*"
S" In what circumstances would it*"
S" It could well be that*"TPHRASE Is it

S" What degree of certainty would you place on it being*"
S" Are you certain that it`s*"
S" What emotions would you feel if I told you that it probably isn`t*"
TPHRASE It is

S" What makes you think I can`t*"
S" Don`t you think that I can*"
S" Perhaps you would like to be able to*"TPHRASE Can you

S" Perhaps you don`t want to*"
S" Do you want to be able to*"
S" I doubt it"TPHRASE Can I

S" Why do you think I am*"
S" Perhaps you would like to be*"
S" Does it please you to believe I am*"TPHRASE You are

S" Why do you think I am*"
S" Why do you say I`m*"
S" Does it please you to believe I am*"TPHRASE You`re

S" Don`t you really*"
S" Why don`t you*"
S" Do you want to be able to*"TPHRASE I don`t

S" Tell me more about such feelings"
S" Do you often feel*"
S" Do you enjoy feeling*"TPHRASE I feel

S" Let`s explore that statement a bit"
S" What emotions do such feelings stir up in you?"
S" Do you often feel like that?"TPHRASE feel

S" Why tell me that you`ve*"
S" How can I help you with*"
S" It`s obvious to me that you have*"TPHRASE I have

S" Could you explain why you would*"
S" How sure are you that you would*"
S" Who else have you told you would*"TPHRASE I would

S" Of course there is*"
S" It`s likely that there is*"
S" Would you like there to be*"TPHRASE Is there

S" What does it mean to you, that your*"
S" That`s interesting! You really said your*, didn`t you?"
S" I see, your*"TPHRASE My

S" This session is to help you...not to discuss me"
S" What prompted you to say that about me?"
S" Remember, I`m taking notes on all this to solve your situation"
TPHRASE You


 ONLY FORTH DEFINITIONS

CR #phrase DEC. .( strings used, out of ) capacity DEC. CR

DEPRIVE

      (* End of Source *)

-marcel
--- G2/1.0
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх