home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_37.arc / LASTPG37.FIG < prev    next >
Text File  |  1987-08-05  |  2KB  |  67 lines

  1.  
  2. /* listing 1   ``Lucid Lucy''      */
  3.  
  4. DOMAINS
  5.     integerlist = integer*
  6.     stringlist  = string*
  7. DATABASE
  8.     input(stringlist,integer)
  9.     output(integer,string)
  10. PREDICATES
  11.     start
  12.     main
  13.     check_table(stringlist,stringlist)
  14.     compare(string,string)
  15.     process(string)
  16.     string_to_list(string, stringlist)
  17. CLAUSES
  18.  
  19. start:-                          /* Set up continuation */
  20.     main.                    /* By using 2 predicates, */
  21. start:-                          /* start and main, & fail */
  22.     start.                   /* we can clear the stack, */
  23.                  /* and conserve memory. */
  24. main:-
  25.         readln(Sent),            /* Read input string. */
  26.     string_to_list(Sent,S2), /* Convert string to list. */
  27.         input(L,ActNo),          /* Get an input record. */
  28.         check_table(S2,L),       /* Compare input list */
  29.                      /* with input record. */
  30.         output(ActNo,Action),    /* If match, get output. */
  31.         process(Action),         /* Act. */
  32.         !,fail.                  /* Continue by forcing
  33.                      /* backtracking with fail. */
  34. main.
  35.  
  36. check_table([H|T],[H2|T2]):-     /* Recursively compare heads. */
  37.     compare(H,H2),
  38.     check_table(T,T2).
  39. check_table([],[]).
  40.  
  41. compare(H,H2):-                  /* Do the actual comparison */
  42.     H = H2.                  /* here. */
  43. compare(H,H2):-                  /* If the record allows */
  44.     H2 = "_".                /* wildcards, succeed. */
  45.  
  46. process("greeting"):-            /* Execute an instruction. */
  47.     write("Hello there."),   /* Expand Lucy by adding */
  48.     nl.                      /* predicates here. */
  49. process("greeting2"):-
  50.     write("Hello, how are you?."),
  51.     nl.
  52. process("exit"):-
  53.     write("Goodbye."),
  54.     exit.
  55. process(_).
  56.     
  57. string_to_list(S,[H|T]):-        /* Convert an input string */
  58.     fronttoken(S,H,S1),!,    /* to a string list. */
  59.     string_to_list(S1,T).
  60. string_to_list(_,[]).
  61.  
  62. GOAL
  63.     consult("input.dba"),    /* Load knowledge bases */
  64.     consult("output.dba"),
  65.     start.                   /* and begin. */
  66.     
  67.