CLIM mail archive


Re: Accept with '(or...) types that have accept methods

  Date: Tue, 1 Sep 1992 21:31-0500
  From: "Donald H. Mitchell" <>
  Subject: Accept with '(or...) types that have accept methods
  To: clim@BBN.COM
  CLIM 1.1 Genera 8.1
  I noticed something odd and was wondering whether anyone has a fix.  I define two
  presentation types and give each an accept method (using completing-from-suggestions),
  and then do an accept on '(or one-type the-other).  If I type sufficient to uniquely
  identify an object from the first type (one-type) and hit <tab>, it completes.  If I try
  for an object from the second type (the-other), the first time I hit <tab> nothing
  happens; if I immediately hit it again, then it completes.  After hitting it twice, it
  keeps working for either type (within the same accept call).
  (I can send a simple example code to anyone who wants it.)
  Don Mitchell
  Amoco Production Company	(918) 660-4270
  Tulsa Research Center
  P.O. Box 3385, Tulsa, OK 74102

This sure sounds familiar.  I was just working on exactly this problem.

I suggest that the "fix" is to change your approach.  OR simply does:
  (accept 'one-type)
  if that generates a parse-error, then reset and
  (accept 'the-other)
  if that generates a parse-error, then generate a parse-error

So you see that the first TAB gets consumed by the ONE-TYPE parser, and
the second TAB gets consumed by THE-OTHER parser.

The easiest thing would be a presentation-type like ONE-TYPE-OR-THE-OTHER
that completes over the union of the completions of ONE-TYPE and THE-OTHER.
If there is only one or two cases where this problem occurs, then this
is probably the easiest thing.

My own problem in this area is that there are many possible pairings
(groupings) of presentation-types.  A combinatorial explosion results.
I have written my own version of completing-from-suggestions to do the
job; its surprisingly easy to do using READ-TOKEN and REPLACE-INPUT.
In my case the completion character is a SPACE, and the completion
parser does not consume it unless there is a valid completion.
Given this approach, (accept '(or one-type the-other)) works fine.

jeff morrill

P.S.  Here is some example code from a recent debugging session of mine.
It is a little too simple because it should complain when there is
more than one completion, but you get the idea.

(in-package :clim-user)

(defun simple-completion-parser (stream presentation-type completions)
  (with-blip-characters ('(#\space))
    (let* ((loc (clim::input-position stream))
	   (token (read-token stream))
           (answer (choose-one token completions)))
      (cond (answer
	     (replace-input stream (string answer) :buffer-start loc)
	     (values answer presentation-type))
              (input-not-of-required-type token presentation-type))))))

(defun choose-one (hint choices)
  (let ((l (length hint)))
    (dolist (choice choices)
      (when (string-equal hint (string choice) :end1 l :end2 l)
	(return-from choose-one choice)))


Main Index | Thread Index