Pascal,
I've tried to redefine the ask method but no response obtain in Java...
About the paragraph that you say, is the opposite of how you're saying. What I want is that the response comes from Java not from lisp. The Yes, No, help key,... needs that comes from Java.
In Babylon, when I start the knowledge, before starts the questions, there are a question about if I want to continue with the process using this function:
(def$method (tty-dialog-mixin :confirm) (&rest comments) "writes comments to dialog-stream and waits for input.comments are printed without slashification.returns :yes if *end-key* is entered and nil otherwise."
(lexpr-$send self :notify comments) (format dialog-stream "~:[~;~%~] ~@? " (rest comments) (getentry type-end-to-confirm-str babylon-io-table) *end-key*) (format t "¤") (force-output dialog-stream) (let ((char (read-char *standard-input*))) (if (eql char #\e) :yes) ))
This code is calling the standard-input function, and If you type "e", then you continue. Because, I want that the e pass from Java to Lisp, I use this line (format t "¤") as a signal. When Java see ¤ then exit from a loop, sends some character (in this case e) and then waits the response from Lisp and it's works.
In the method ASK-USER I can't see any standard-input, so I don't know how to get the response from Java. In the babylon-read function, it appears dialog-stream that points standard-output, but output it's not the same that input.
I tried to change dialog-stream by *standard-input* and/or added the (format t "¤") between the let and the cond but Java don't respond. Java is awaiting response from Lisp
(def$method (tty-dialog-mixin :babylon-read) (&optional special-keys) "reads in a character or a lisp form from dialog-stream.only those characters occurring in the list special-keys are read."
(let ((char (read-char dialog-stream))) ;;(format t "¤") (cond ((member char special-keys :test 'char-equal) (clear-input dialog-stream) char) (t (prog2 (unread-char char dialog-stream) (read dialog-stream) (clear-input dialog-stream))))))
Java always stops in this line:
while((ByteE=entrada.read())!='\n'){
entrada it's waiting from the input, then from Lisp, but any response appears from Lisp
entrada = new BufferedReader(new InputStreamReader(socket.getInputStream()));
So, what I'm trying to do is to change the ask:user function to resembles the :confirm function, so I can get the response from Java and pass to Lisp, and the response from Lisp, return to Java (all the dialog appears in Java so I can add some windows, buttons, menus...)
Thanks
----Mensaje original----De: pjb@...: 03/08/2012 11:44Para: <scarbonell@...: <clisp-list@...: Re: [clisp-list] trying to understand a lisp code"scarbonell@..." <scarbonell@...> writes:> Pascal, thanks for your help,>> This code was made in 80's and there aren't any documentation about> how was coded.>> About the nomalize-answer function this is the code:>> (defun normalize-answer (answer)> (or (cdr (assoc answer (getentry possible-answers babylon-io-table)))> answer))>> and the possible-answer: >> (defbabylon-entry possible-answers babylon-io-table english> '((yes . yes)> (y . yes)> (no . no)> (n . no)> (unknown . unknown)> (u . unknown)> (? . help)> (h . help)> (prompt . prompt)> (p . prompt)> ))>> about the choose-from-menu function, it's appearing a menu with all> options if the user don't put any valid response.>> so, the code it's passing the answer to the normalize-answer function,> so the answer was obtained before. That's why I thought in the> babylon-read function, but you are right in that the babylon-read> function are only using the *help-key* and no the others keys: yes,> no.. and this is why I didn't know what was doing this function.Well, no. It is not using the value bound to the variable *HELP-KEY*.The symbol *HELP-KEY* appears in a quoted list, so it is used as a meresymbol, not as a variable.The method :ASK-USER should be redefined as: (def$method (basic-free-text-processor :ask-user) (fact &optional (negation-flag nil)) (let ((item-list `(,(if negation-flag (getentry expected-answer-no-str free-text-io-table) (getentry expected-answer-yes-str free-text-io-table)) ("" :no-select t) ,@(getentry ask-item-list free-text-io-table))) (label (getentry choose-one-of-str free-text-io-table))) ($send meta-processor :babylon-format "~%~A" (format-translate-true-or-false fact)) (do ((answer (normalize-answer ($send meta-processor :babylon-read (list *help-key*))) ($send meta-processor :choose-from-menu item-list label)) (echo nil t)) ((or (eql answer *help-key*) ; use *help-key* (member answer '(yes no unknown help))) ; as a variable (if echo ; no << ! ($send meta-processor :babylon-format "~(~S~)" (translate-answer answer))) (cond ((eq answer 'yes) ($send self :add fact 'true) 'true) ((eq answer 'no) ($send self :add fact 'false) 'false) ((eq answer 'unknown) ($send self :add fact 'false) 'unknown) ((eq answer 'help) 'help) ((eql answer *help-key*) ($send meta-processor :babylon-format "?") 'help))))))> About the echo function I see this:It's not a function it's a local lexical variable defined by the DOmacro.> I don't see how Java true or false are relevant here. The program is> asking and reading an answer from the user, and is processing it however> it wants. Notably, the method :ask-user returns a lisp symbol of type> (member true false unknown help). There's no Java value here.You've not reacted to this paragraph. Do you realize that :ASK-USERjust reads user input and return one of the lisp symbols YES, NO,UNKNOWN, HELP, or the value of the variable *HELP-KEY*? If you need toreturn that symbol to java you will have to convert it to some Javavalue.-- __Pascal Bourguignon__ http://www.informatimago.com/A bad day in () is better than a good day in {}.
|