home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / PROGRAMS / DIFF.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  15.2 KB  |  568 lines

  1. /*
  2.   Copyright (c) 1986, 90 by Prolog Development Center
  3. */
  4. /* SYMBOLIC DIFFERENTIATION EXAMPLE */
  5. DOMAINS
  6. /*
  7.   The input string is converted to a list of
  8.   tokens
  9. */
  10. TOKL = STRING*
  11.  
  12. /*
  13.   Expressions are modeled via EXP
  14. */
  15. EXP=var(STRING);
  16.     int(INTEGER);
  17.     plus(EXP,EXP);
  18.     minus(EXP,EXP);
  19.     mult(EXP,EXP);
  20.     div(EXP,EXP);
  21.     ln(EXP);
  22.     cos(EXP); 
  23.     sin(EXP); 
  24.     tan(EXP); 
  25.     sec(EXP); 
  26.     potens(EXP,EXP)
  27.  
  28. PREDICATES
  29.     run
  30.     diff
  31.     d(EXP,STRING,EXP);
  32.     readexp(EXP);
  33.     readexp(EXP,string,integer)
  34.     check(EXP,TOKL,EXP);
  35.  
  36.     writeexp(EXP);
  37.     strexp(EXP,string);
  38.     strPOTENS(EXP,string);
  39.     strMULT(EXP,string);
  40.     strMINUS(EXP,string);
  41.     strDIV(EXP,string);
  42.     strPAR(EXP,string);
  43.  
  44.     tokl(STRING,TOKL);      /* Scanner */
  45.     front(STRING,TOKL,TOKL);
  46.  
  47.     s_exp(TOKL,TOKL,EXP);   /* Parser */
  48.     potensexp(TOKL,TOKL,EXP);
  49.     potensexp1(TOKL,TOKL,EXP,EXP);
  50.     multexp(TOKL,TOKL,EXP);
  51.     multexp1(TOKL,TOKL,EXP,EXP);
  52.     plusexp(TOKL,TOKL,EXP);
  53.     plusexp1(TOKL,TOKL,EXP,EXP);
  54.     elmexp(TOKL,TOKL,EXP);
  55.  
  56.     reduce(EXP,EXP);        /* Reducer */
  57.     plusr(EXP,EXP,EXP);
  58.     minusr(EXP,EXP,EXP);
  59.     multr(EXP,EXP,EXP);
  60.     divr(EXP,EXP,EXP);
  61.     lnr(EXP,EXP)
  62.  
  63.     /* String Editor */
  64.     editstr(string,string,integer,integer,integer).
  65.     editstr(char,string,string,integer,integer,integer).
  66.     editstr(symbol,char,string,string,integer,integer,integer).
  67.  
  68.     lstcat(TOKL,string)
  69.     
  70.     repeat
  71.  
  72. GOAL
  73.     run.
  74.  
  75. CLAUSES
  76.   run:- 
  77.       makewindow(1,71,7,"",0,0,25,80),
  78.       makewindow(1,71,7,"",1,14,9,52),
  79.       write("   S Y M B O L I C  D I F F E R E N T A T I O N"),nl,
  80.       write("   ********************************************"),nl,
  81.       field_attr(0,3,44,112),
  82.       write("           An expression may include: "),nl,
  83.       write(" addition, subtraction, multiplication, division \n"),
  84.       write(" exponents, natual logarithms, cos, sin and tan.\n\n"),
  85.       write(" e.g. x+x  or  x*(2+y)^2  or  ln(1+1/(1-x))"),
  86.       makewindow(3,7,7,"",10,3,14,73),
  87.       clearwindow,diff.
  88.  
  89.   diff :- 
  90.       readexp(EXP),
  91.       d(EXP,"x",EXP1),
  92.       write("\n  Differentiated expression:\n  "),
  93.       writeexp(EXP1),
  94.       write("\n\n  Reduced expression:\n  "),
  95.       reduce(EXP1,EXP2), writeexp(EXP2),
  96.       write("\n\n  Hit any key to continue..."),readchar(_),
  97.       fail. 
  98.  
  99. diff :- diff.  
  100.  
  101.   repeat.
  102.   repeat:- repeat.
  103.  
  104. /*
  105.   CLAUSES FOR DIFFERENTIATION
  106. */
  107.  
  108.  
  109.   d(int(_),_,int(0)).
  110.   d(var(X),X,int(1)):-!.
  111.   d(var(_),_,int(0)).
  112.   d(plus(U,V),X,plus(U1,V1)):-
  113.       d(U,X,U1),
  114.       d(V,X,V1).
  115.   d(minus(U,V),X,minus(U1,V1)):-
  116.       d(U,X,U1),
  117.       d(V,X,V1).
  118.   d(mult(U,V),X,plus(mult(U1,V),mult(U,V1))):-
  119.       d(U,X,U1),
  120.       d(V,X,V1).
  121.   d(div(U,V),X,div(minus(mult(U1,V),mult(U,V1)),mult(V,V))):-
  122.       d(U,X,U1),
  123.       d(V,X,V1).
  124.   d(ln(U),X,mult(div(int(1),U),U1)):-d(U,X,U1).
  125.   d(potens(E1,int(I)),X,mult(mult(int(I),potens(E1,int(I1))),EXP)):- 
  126.       I1=I-1, 
  127.       d(E1,X,EXP). 
  128.   d(sin(U),X,mult(cos(U),U1)) :- d(U,X,U1). 
  129.   d(cos(U),X,minus(int(0),mult(sin(U),U1))) :- d(U,X,U1).
  130.   d(tan(U),X,mult(potens(sec(U),int(2)),U1)) :- d(U,X,U1).
  131.   
  132. /*
  133.   CLAUSES FOR READING OF AN EXPRESSION
  134. */
  135.   readexp(EXP) :-
  136.       clearwindow,
  137.       cursor(11,1),
  138.       write("<?> for help     <ESC> to quit"),
  139.       cursor(1,1),
  140.       write("Write an expression: "),!,
  141.       readexp(EXP,"",0).
  142.   readexp(int(0)):-exit(0).
  143.  
  144.   readexp(EXP1,STR,Pos) :-
  145.       cursor(Ypos,Xpos),
  146.       editstr(STR,STR1,Xpos,Ypos,Pos),
  147.       cursor(2,0), write("                                            "),
  148.       cursor(2,22),
  149.       tokl(STR1,TOKL),
  150.       s_exp(TOKL,OL,EXP),
  151.       !,
  152.       check(EXP,OL,EXP1).
  153.  
  154.   check(EXP,[],EXP):-
  155.       cursor(2,22),
  156.       write("                                             \n"), 
  157.       write("                                             \n"),
  158.       write("                                             \n"),
  159.       write("                                             \n"),
  160.       write("                                             \n"),
  161.       cursor(2,0),!.
  162.   check(EXP,Rest,NewExp):- 
  163.       strexp(EXP,Str1),
  164.       lstcat(Rest,Str2),
  165.       str_len(Str1,LenStr1),
  166.       ErrPos = 22 + LenStr1,
  167.       cursor(2,ErrPos),
  168.       write("^ syntax error"),
  169.       cursor(1,22),
  170.       concat(Str1,Str2,Str3),
  171.       !,
  172.       readexp(NewExp,Str3,LenStr1).
  173.       
  174.  
  175.   tokl(STR,[TOK|TOKL]):-
  176.       fronttoken(STR,TOK,STR1),!,
  177.       tokl(STR1,TOKL).
  178.   tokl(_,[]).
  179.  
  180.  
  181. /*
  182.   CLAUSES FOR PARSING OF AN EXPRESSION
  183. */
  184.  
  185.   s_exp(IL,OL,EXP):-plusexp(IL,OL,EXP).
  186.  
  187.   plusexp(IL,OL,EXP2):-
  188.       multexp(IL,OL1,EXP1),
  189.       plusexp1(OL1,OL,EXP1,EXP2).
  190.  
  191.   plusexp1(["+"|IL],OL,EXP1,EXP3):-!,
  192.       multexp(IL,OL1,EXP2),
  193.       plusexp1(OL1,OL,plus(EXP1,EXP2),EXP3).
  194.   plusexp1(["-"|IL],OL,EXP1,EXP3):-!,
  195.       multexp(IL,OL1,EXP2),
  196.       plusexp1(OL1,OL,minus(EXP1,EXP2),EXP3).
  197.   plusexp1(IL,IL,EXP,EXP).
  198.  
  199.   multexp(IL,OL,EXP2):-
  200.       potensexp(IL,OL1,EXP1),
  201.       multexp1(OL1,OL,EXP1,EXP2).
  202.  
  203.   multexp1(["*"|IL],OL,EXP1,EXP3):-!,
  204.       potensexp(IL,OL1,EXP2),
  205.       multexp1(OL1,OL,mult(EXP1,EXP2),EXP3).
  206.   multexp1(["/"|IL],OL,EXP1,EXP3):-!,
  207.       potensexp(IL,OL1,EXP2),
  208.       multexp1(OL1,OL,div(EXP1,EXP2),EXP3).
  209.   multexp1(IL,IL,EXP,EXP).
  210.  
  211.   potensexp(IL,OL,EXP2):-
  212.       elmexp(IL,OL1,EXP1),
  213.       potensexp1(OL1,OL,EXP1,EXP2).
  214.   potensexp1(["^"|IL],OL,EXP1,EXP3):-!,
  215.       elmexp(IL,OL1,EXP2),
  216.       potensexp1(OL1,OL,potens(EXP1,EXP2),EXP3).
  217.   potensexp1(IL,IL,EXP,EXP).
  218.  
  219.   elmexp(["("|IL],OL,EXP):-
  220.       s_exp(IL,OL1,EXP),
  221.       front(")",OL1,OL),!.
  222.   elmexp(["ln","("|IL],OL,ln(EXP)):-
  223.       s_exp(IL,OL1,EXP),
  224.       front(")",OL1,OL),!.
  225.   elmexp(["sin","("|IL],OL,sin(EXP)):-
  226.       s_exp(IL,OL1,EXP),
  227.       front(")",OL1,OL),!.
  228.   elmexp(["cos","("|IL],OL,cos(EXP)):-
  229.       s_exp(IL,OL1,EXP),
  230.       front(")",OL1,OL),!.
  231.   elmexp(["tan","("|IL],OL,tan(EXP)):-
  232.       s_exp(IL,OL1,EXP),
  233.       front(")",OL1,OL),!.
  234.   elmexp(["-",TALSTR|IL],IL,int(INT)):-
  235.       str_int(TALSTR,INTp),
  236.       INT = -INTp.
  237.   elmexp([TALSTR|IL],IL,int(INT)):-str_int(TALSTR,INT),!.
  238.   elmexp([NAME|IL],IL,var(NAME)).
  239.  
  240.   front(TOK,[TOK|L],L).
  241.  
  242. /*
  243.   CLAUSE FOR WRITING OF AN EXPRESSION
  244. */
  245.   writeexp(EXP) :-
  246.     strexp(EXP,STR),
  247.     write(STR).
  248.  
  249. /*
  250.   CLAUSES FOR REDUCTION OF AN EXPRESSION
  251. */
  252.  
  253.   reduce(plus(X,Y),R):- !,
  254.       reduce(X,X1),
  255.       reduce(Y,Y1),
  256.       plusr(X1,Y1,R).
  257.   reduce(minus(X,Y),R):-!,
  258.       reduce(X,X1),
  259.       reduce(Y,Y1),
  260.       minusr(X1,Y1,R).
  261.   reduce(mult(X,Y),R):-!,
  262.       reduce(X,X1),
  263.       reduce(Y,Y1),
  264.       multr(X1,Y1,R).
  265.   reduce(div(X,Y),R):-!,
  266.       reduce(X,X1),
  267.       reduce(Y,Y1),
  268.       divr(X1,Y1,R).
  269.   reduce(ln(X),R):-!,
  270.       reduce(X,X1),
  271.       lnr(X1,R).
  272.   reduce(potens(E,int(1)),E):-!.
  273.   reduce(R,R).
  274.  
  275. /*
  276.   CLAUSES FOR REDUCTION OF AN ADDITION EXPRESSION
  277. */
  278.  
  279.   plusr(int(0),X,X):-!.
  280.   plusr(X,int(0),X):-!.
  281.   plusr(int(X),int(Y),int(Z)):-!,
  282.       X+Y=Z.
  283.   plusr(X,X,mult(int(2),X)):-!.
  284.   plusr(int(X),Y,Z) :- 
  285.       X < 0,
  286.       T = -X, !,
  287.       minusr(int(T),Y,Z).
  288.   plusr(Y,int(X),Z) :-  
  289.       X < 0,
  290.       T = -X, !,
  291.       minusr(int(T),Y,Z).
  292.   plusr(mult(int(I),X),X,mult(int(I1),X)):-!,
  293.       I+1=I1.
  294.   plusr(X,mult(int(I),X),mult(int(I1),X)):-!,
  295.       I+1=I1.
  296.   plusr(mult(int(I1),X),mult(int(I2),X),mult(int(I3),X)):-!,
  297.       I1+I2=I3.
  298.   plusr(int(I),X,plus(X,int(I))):-!.
  299.   plusr(plus(X,int(I1)),int(I2),plus(X,int(I3))):-!,
  300.       I1+I2=I3.
  301.   plusr(plus(X,int(I1)),plus(Y,int(I2)),plus(R,int(I3))):-!,
  302.       I1+I2=I3,
  303.       plusr(X,Y,R).
  304.   plusr(plus(X,int(I)),Y,plus(R,int(I))):-!,
  305.       plusr(X,Y,R).
  306.   plusr(X,Y,plus(X,Y)).
  307.  
  308. /*
  309.   CLAUSES FOR REDUCTION OF A MINUS EXPRESSION
  310. */
  311.  
  312.   minusr(int(X),int(Y),int(Z)):-!,
  313.       Z=X-Y.
  314.   minusr(X,int(0),X):-!.
  315.   minusr(X,X,int(0)):-!.
  316.   minusr(X,int(I),plus(int(I1),X)):- !,
  317.       I1=-I.
  318.   minusr(X,Y,minus(X,Y)).
  319.  
  320. /*
  321.   CLAUSES FOR REDUCTION OF A MULTIPLICATION EXPRESSION
  322. */
  323.  
  324.   multr(int(X),int(Y),int(Z)):-!,
  325.       X*Y=Z.
  326.   multr(int(0),_,int(0)):-!.
  327.   multr(_,int(0),int(0)):-!.
  328.   multr(int(1),X,X):-!.
  329.   multr(X,int(1),X):-!.
  330.   multr(M,plus(X,Y),plus(X1,Y1)):-!,   
  331.       multr(M,X,X1),multr(M,Y,Y1). 
  332.   multr(M,minus(X,Y),minus(X1,Y1)):-!, 
  333.       multr(M,X,X1),multr(M,Y,Y1). 
  334.   multr(plus(X,Y),M,plus(X1,Y1)):-!, 
  335.       multr(M,X,X1),multr(M,Y,Y1). 
  336.   multr(minus(X,Y),M,minus(X1,Y1)):-!,
  337.       multr(M,X,X1),multr(M,Y,Y1). 
  338.   multr(mult(int(I1),X),int(I2),M1):-!,
  339.       I1*I2=I3,
  340.       multr(int(I3),X,M1).
  341.   multr(int(I1),mult(int(I2),X),M1):-!,
  342.       I1*I2=I3,
  343.       multr(int(I3),X,M1).
  344.   multr(mult(int(I1),X),mult(int(I2),Y),mult(int(I3),R)):-!,
  345.       I1*I2=I3, 
  346.       multr(X,Y,R).
  347.   multr(mult(int(I),X),Y,mult(int(I),R)):-!,
  348.       multr(X,Y,R).
  349.   multr(X,int(I),mult(int(I),X)):-!.
  350.   multr(potens(X,int(I1)),potens(X,int(I2)),potens(X,int(I3))):-!,
  351.       I3=I1+I2.
  352.   multr(X,potens(X,int(I)),potens(X,int(I1))):-!,
  353.       I1=I+1.
  354.   multr(potens(X,int(I)),X,potens(X,int(I1))):-!,
  355.       I1=I+1.
  356.   multr(X,X,potens(X,int(2))):-!.
  357.   multr(X,Y,mult(X,Y)).
  358.  
  359. /*
  360.   CLAUSES FOR REDUCTION OF A DIVISION EXPRESION
  361. */
  362.  
  363.   divr(int(0),_,int(0)):-!.
  364.   divr(_,int(0),var("'endless'")):-!,
  365.       write("division by zero"),nl.
  366.   divr(X,int(1),X):-!.
  367.   divr(X,Y,div(X,Y)).
  368.  
  369. /*
  370.   CLAUSES FOR REDUCTION OF A LOGARITHM EXPRESSION
  371. */
  372.  
  373.   lnr(int(0),var("endless")):-!,
  374.       write("logarithm error"),nl.
  375.   lnr(int(1),int(0)):-!.
  376.   lnr(X,ln(X)).
  377.  
  378.  
  379. /*
  380.   CLAUSES FOR CONVERTING AN EXPRESSION TO A STRING
  381. */
  382. % Taken from the old writeexp clauses
  383.  
  384.   strexp(var(NAME),NAME).
  385.   strexp(int(INT),INTSTR) :-
  386.       str_int(INTSTR,INT).
  387.   strexp(ln(EXP),STR)  :-
  388.       strPAR(EXP,STRp),
  389.       concat("ln",STRp,STR).
  390.   strexp(sin(EXP),STR) :- 
  391.       strPAR(EXP,STRp),
  392.       concat("sin",STRp,STR).
  393.   strexp(cos(EXP),STR) :- 
  394.       strPAR(EXP,STRp),
  395.       concat("cos",STRp,STR).
  396.   strexp(tan(EXP),STR) :- 
  397.       strPAR(EXP,STRp),
  398.       concat("tan",STRp,STR).
  399.   strexp(sec(EXP),STR) :- 
  400.       strPAR(EXP,STRp),
  401.       concat("sec",STRp,STR).
  402.   strexp(plus(EXP1,EXP2),STR):-
  403.       strexp(EXP1,STR1),
  404.       concat(STR1,"+",STR3),
  405.       strexp(EXP2,STR2),
  406.       concat(STR3,STR2,STR).
  407.   strexp(minus(EXP1,EXP2),STR):-
  408.       strexp(EXP1,STR1),
  409.       concat(STR1,"-",STR3),
  410.       strMINUS(EXP2,STR2),
  411.       concat(STR3,STR2,STR).
  412.   strexp(mult(EXP1,EXP2),STR):-
  413.       strMINUS(EXP1,STR1),
  414.       concat(STR1,"*",STR3),
  415.       strMULT(EXP2,STR2),
  416.       concat(STR3,STR2,STR).
  417.   strexp(div(EXP1,EXP2),STR):-
  418.       strMULT(EXP1,STR1),
  419.       concat(STR1,"/",STR3),
  420.       strDIV(EXP2,STR2),
  421.       concat(STR3,STR2,STR).
  422.   strexp(potens(EXP1,EXP2),STR):-
  423.       strDIV(EXP1,STR1), 
  424.       concat(STR1,"^",STR3),
  425.       strPOTENS(EXP2,STR2),
  426.       concat(STR3,STR2,STR).
  427.  
  428.   strPOTENS(div(X,Y),STR):-!,strPAR(div(X,Y),STR).
  429.   strPOTENS(X,STR):-strDIV(X,STR).
  430.  
  431.   strDIV(mult(X,Y),STR):-!,strPAR(mult(X,Y),STR).
  432.   strDIV(X,STR):-strMULT(X,STR).
  433.  
  434.   strMULT(minus(X,Y),STR):- !,strPAR(minus(X,Y),STR).
  435.   strMULT(X,STR):-strMINUS(X,STR).
  436.  
  437.   strMINUS(plus(X,Y),STR):-!,strPAR(plus(X,Y),STR).
  438.   strMINUS(X,STR):-strexp(X,STR).
  439.  
  440.   strPAR(EXP,STR):-
  441.       strexp(EXP,STR1),
  442.       concat("(",STR1,STR2),
  443.       concat(STR2,")",STR).
  444.  
  445. /*
  446.   CLAUSES TO EDIT A STRING
  447. */
  448.  
  449.   editstr(InString, OutString, Xpos, Ypos, Cpos) :-
  450.     cursor(Ypos,Xpos),
  451.     write(InString," "),
  452.     NXPos = Xpos+Cpos,
  453.     cursor(Ypos,NXpos),
  454.     readchar(Ch),
  455.     !,
  456.     editstr(Ch, InString, OutString, Xpos, Ypos, Cpos).
  457.  
  458.   % Return -- Accept the current string.
  459.   editstr('\13',InString,InString,Xpos,Ypos,_) :-
  460.     cursor(Ypos,Xpos),
  461.     write(InString), nl.
  462.     
  463.   % ESC -- Terminate the program.
  464.   editstr('\27',_,"",_,_,_) :- exit.
  465.   
  466.   % HELP -- Display the help message
  467.   % taken from checkhelp.
  468.   editstr('?',InString,OutString,Xpos,Ypos,Cpos) :- 
  469.     makewindow(4,23,7,"",10,3,14,73),
  470.     file_str("diff.hlp",I),
  471.     display(I),
  472.     removewindow,
  473.     !,
  474.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  475.   
  476.   % ^S -- Move Cursor left
  477.   editstr('\19',InString,OutString,Xpos,Ypos,Cpos) :-
  478.     Cpos > 0,
  479.     NewCpos = Cpos - 1,
  480.     !,
  481.     editstr(InString,OutString,Xpos,Ypos,NewCpos).
  482.   editstr('\19',InString,OutString,Xpos,Ypos,Cpos) :- !,
  483.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  484.      
  485.   % ^D -- Move Cursor left
  486.   editstr('\4',InString,OutString,Xpos,Ypos,Cpos) :-
  487.     str_len(InString,InStrLen),
  488.     Cpos < InStrLen,
  489.     NewCpos = Cpos + 1, !,
  490.     editstr(InString,OutString,Xpos,Ypos,NewCpos).
  491.   editstr('\4',InString,OutString,Xpos,Ypos,Cpos) :- !,
  492.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  493.     
  494.   % ^H -- Backspace, Delete the previous character.
  495.   editstr('\8',InString,OutString,Xpos,Ypos,1) :-
  496.     frontchar(InString,_,NewString),
  497.     !,
  498.     editstr(NewString,OutString,Xpos,Ypos,0).
  499.   editstr('\8',InString,OutString,Xpos,Ypos,Cpos) :-
  500.     Cpos > 1,
  501.     NewCpos = Cpos - 1,
  502.     !,
  503.     editstr('\21',InString,OutString,Xpos,Ypos,NewCpos). % Delete Char.
  504.   editstr('\8',InString,OutString,Xpos,Ypos,Cpos) :- !,
  505.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  506.   
  507.   % ^U -- Delete the current character.
  508.   editstr('\21',InString,OutString,Xpos,Ypos,Cpos) :-
  509.     frontstr(Cpos,InString,HeadString,TailStringP),
  510.     frontchar(TailStringP,_,TailString),
  511.     concat(HeadString,TailString,NewString),
  512.     !,
  513.     editstr(NewString,OutString,Xpos,Ypos,Cpos).
  514.   editstr('\21',InString,OutString,Xpos,Ypos,Cpos) :- !,
  515.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  516.  
  517.   % Insert a Character.
  518.   editstr(Ch,InString,OutString,Xpos,Ypos,Cpos) :-
  519.     makewindow(_,_,_,_,_,_,_,Width),
  520.     str_len(InString,InStrLen),
  521.     InStrLen < Width - 3 - Xpos,
  522.     Ch >= ' ', Ch <= '~',
  523.     frontstr(Cpos,InString,HeadString,TailStringP),
  524.     frontchar(TailString,Ch,TailStringP),
  525.     concat(HeadString,TailString,NewString),
  526.     NewCpos = Cpos + 1,
  527.     !,
  528.     editstr(NewString,OutString,Xpos,Ypos,NewCpos).
  529.     
  530.   % Extended Key Hit.
  531.   editstr('\0',InString,OutString,Xpos,Ypos,Cpos) :-
  532.     readchar(Key), !,
  533.     editstr(extended,Key,InString,OutString,Xpos,Ypos,Cpos).
  534.     
  535.    % Ignore All other keys pressed.
  536.   editstr(_,InString,OutString,Xpos,Ypos,Cpos) :-
  537.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  538.  
  539.   % Process extended keys.
  540.   % Del Key, map to the ^U key.
  541.   editstr(extended,'\83',InString,OutString,Xpos,Ypos,Cpos) :- !,
  542.     editstr('\21',InString,OutString,Xpos,Ypos,Cpos).
  543.   % Left Arrow, map to the ^S key.
  544.   editstr(extended,'\75',InString,OutString,Xpos,Ypos,Cpos) :- !,
  545.     editstr('\19',InString,OutString,Xpos,Ypos,Cpos).
  546.   % Right Arrow, map to the ^D key.
  547.   editstr(extended,'\77',InString,OutString,Xpos,Ypos,Cpos) :- !,
  548.     editstr('\4',InString,OutString,Xpos,Ypos,Cpos).
  549.   % End.
  550.   editstr(extended,'\79',InString,OutString,Xpos,Ypos,_) :- 
  551.     str_len(InString,InStrLen),
  552.     !,
  553.     editstr(InString,OutString,Xpos,Ypos,InStrLen).
  554.   % Home.
  555.   editstr(extended,'\71',InString,OutString,Xpos,Ypos,_) :- !,
  556.     editstr(InString,OutString,Xpos,Ypos,0).
  557.   % Ignore the rest.
  558.   editstr(extended,_,InString,OutString,Xpos,Ypos,Cpos) :- !,
  559.     editstr(InString,OutString,Xpos,Ypos,Cpos).
  560.  
  561. /* 
  562.   UTILITY TO TRANSFORM A TOKANIZED LIST TO A LIST
  563. */
  564.   lstcat([],"").
  565.   lstcat([X|Xs],STR) :- 
  566.     lstcat(Xs,STR1),
  567.     concat(X,STR1,STR).
  568.