CLIM mail archive

[Prev][Next][Index][Thread]

Re: CLIM 1.1 (OR NULL (SEQUENCE ...)) in ACCEPTING-VALUES



I had a LONG discussion about a similar problem in MCL2.0/CLIM1.1 and
Lucid4.0/CLIM.1... selected exerpts follow, hope it's relevant to what
you're doing. (this is long).

----------
Date: Mon, 8 Nov 93 17:32:40 PST
From: winarske@lucid.com (Amy Winarske)
To: Daniel D Suthers <suthers+@pitt.edu>
Subject: Re: use of AND and Or in presentation specs


Hello -

   Also, could someone tell me whether '(and p1 p2) and '(or p1 p2) is
   supposed to be legal wherever presentation types are expected? That's
   all I was asking originally, so I wouldn't waste a lot of time trying to
   make conjuncts and disjuncts work where they aren't supposed to.

Your examples and questions all look valid to us.  There was a bug in the
generic CLIM code which we've patched.  We've reported it to Scott
McKay but he is out of town.

----------
Date: Wed, 17 Nov 1993 15:14:15 -0500 (EST)
From: Daniel D Suthers <suthers+@pitt.edu>
To: clim-support@lucid.com, doughty@hq.ileaf.com, york@lucid.com,
    SWM@STONY-BROOK.SCRC.Symbolics.COM
Subject: Re: use of AND and Or in presentation specs
CC: Massimo Paolucci <paolucci+@pitt.edu>

Folks,

In CLIM1.1, I'm trying to write commands that accept conjunctive
presentation types, so I don't have to take the cross-product of two
independent presentation type hierarchies. Disjunctives would also be
useful for other reasons. I've been corresponding with Amy Winarske
about this...

Amy: The 7241 patch appears not to do what I expected (see enclosed).

MCL2.0 CLIM1.1 folks: I have the same problem in your environment. Any
refers to this as a "generic bug" -- do you have a patch for it? 

Thanks much! 

#|-------------------------------------------------------------------------

Using "and" and "or" presentation types in commands.  Output as

   (with-output-as-presentation (... :type '(and a b))...)

works with commands defined on a single presentation type, but we
get an error with commands defined on a composite presentation type:

  (define-test-window-command (...)
      ((presentation '(and a b)...)
       ...)

NOTE that we get a similar error in both LUCID and MCL2.0 CLIM1.1. This is why
my original query was whether I understand the legal use of and/or syntax or
not -- I wasn't sure if this was a bug or something CLIM wasn't supposed to
do. Amy calls this a "generic" bug so I assume I need to get a separate patch
for MCL.

-------------------------------------------------------------------------|#

(in-package :CLIM-USER)

#+:MCL (setq CLIM::*COMMANDS-IN-MENUBAR* nil)

(defvar *root-window* (clim:open-root-window #+:CLX :clx
					     #+:MCL :mcl
					     ))

(define-application-frame TEST-WINDOW ()
  ;;
  ()
  (:panes (
	   (output-pane
            :application
            :scroll-bars :vertical)
	   (test-display :application
                         :display-after-commands nil
                         :display-function 'display-test
                         :scroll-bars :both)
           (documentation :pointer-documentation)
           (menu :command-menu)))
  (:layout ((default
		(:column :rest
			 (test-display  17/20)
			 (output-pane   1/20)
			 (documentation 1/20)
			 (menu         :rest))))))

(clim:define-presentation-type A ())
(clim:define-presentation-type B ())

;;; This is what we want to AVOID having to do, since there
;;; would be too many combinations of predefined syntactic
;;; presentations with application-dependent semantic
;;; presentations.
;;;
;;; (clim:define-presentation-type AB () :inherit-from '(a b))

(defun RUN-TEST ()
  ;;
  (let ((frame (clim:make-application-frame
	        'test-window
	        :parent *root-window*
	        :width 600
                :height 600)))
    (clim:run-frame-top-level frame)))

(define-test-window-command (BEEP-ON-A-PRESENTATIONS :menu "Find A's")
    ((presentation 'A :gesture :select))
  (declare (ignore presentation))
  (clim:beep)
  (format *standard-output* "~%You found an A."))

(define-test-window-command (BEEP-ON-B-PRESENTATIONS :menu "Find B's")
    ((presentation 'B :gesture :select))
  (declare (ignore presentation))
  (clim:beep)
  (format *standard-output* "~%You found a B."))

(define-test-window-command (BEEP-ON-A-AND-B-PRESENTATIONS :menu "Find
AandB's")
    ((presentation '(and a b) ; <------------- what we want to do
		   :gesture :select))
  (declare (ignore presentation))
  (clim:beep)
  (format *standard-output* "~%You found an AandB."))

(define-test-window-command (BEEP-ON-A-OR-B-PRESENTATIONS :menu "Find AorB's")
    ((presentation '(or a b) ; <------------- what we want to do
		   :gesture :select))
  (declare (ignore presentation))
  (clim:beep)
  (format *standard-output* "~%You found an AorB."))

(define-test-window-command (DONE :menu "Done") ()
  (clim:frame-exit clim:*application-frame*)
  )

(defmethod DISPLAY-TEST ((application test-window) stream)
  (window-clear stream)
  ;;
  ;; Draw some A's
  ;;
  (with-output-as-presentation
      (:stream stream :object 'a :type 'A)
    (surrounding-output-with-border
     (stream :shape ':rectangle)
     (draw-text* stream "A" 50 50)))
  (with-output-as-presentation
      (:stream stream :object 'a :type 'A)
    (surrounding-output-with-border
     (stream :shape ':rectangle)
     (draw-text* stream "A" 300 200)))
  ;;
  ;; Draw some B's
  ;;
  (with-output-as-presentation
      (:stream stream :object 'b :type 'B)
    (surrounding-output-with-border
     (stream :shape ':rectangle)
     (draw-text* stream "B" 450 350)))
  (with-output-as-presentation
      (:stream stream :object 'b :type 'B)
    (surrounding-output-with-border
     (stream :shape ':rectangle)
     (draw-text* stream "B" 200 300)))
  ;;
  ;; Draw some AandB's.
  ;;
  ;; >>>>> THIS IS WHERE WE NEED "AND" THE MOST, especially with <<<<<
  ;; >>>>> the presentation types being determined at run time.   <<<<<
  ;;
  (with-output-as-presentation
      (:stream stream :object 'ab :type '(and a b))
    (surrounding-output-with-border
     (stream :shape ':rectangle)
     (draw-text* stream "AandB" 110 90)))
  (with-output-as-presentation
      (:stream stream :object 'ab :type '(and a b))
    (surrounding-output-with-border
     (stream :shape ':rectangle)
     (draw-text* stream "AandB" 280 180)))
  ;;
  #+:MCL (clim::redisplay-decorations stream))

#|-----------------------------------------------------------------------------
-
Here is what I get when I click on the "Find AandB's" command in Lucid:

> (clim-user::run-test)
>>Error: No applicable method exists for the generic-function
CLIM::PRESENTATION-TYPEP-METHOD when called with these arguments:
(#<{Instance?} #X119FF06E> NIL ("Find AandB's" NIL (:COMMAND #))
CLIM-USER::A)

(:GENERIC-FUNCTION NO-APPLICABLE-METHOD :|dispatch code|):
   Required arg 0 (GENERIC-FUNCTION): #<Presentation-Generic-Function
CLIM::PRESENTATION-TYPEP-METHOD (21)>
   Rest arg 1 (ARGS): (#<{Instance?} #X119FF06E> NIL ("Find AandB's" NIL
(:COMMAND #)) CLIM-USER::A)
:C  0: Try this call again
:A  1: Return to Test Window command level
    2: Test Window top level
    3: Exit Test Window
    4: Abort to Lisp Top Level


NOTE: In MCL2.0 CLIM1.1, I get a similar error, and it can occur even after
using another command.

------------------------------------------------------------------------------|
#

----------
Date: Thu, 18 Nov 1993 10:29 -0500
From: Scott McKay <SWM@STONY-BROOK.SCRC.Symbolics.COM>
Subject: Re: use of AND and Or in presentation specs
To: suthers+@pitt.edu, clim-support@lucid.com, doughty@hq.ileaf.com,
        york@lucid.com, SWM@STONY-BROOK.SCRC.Symbolics.COM
Cc: paolucci+@pitt.edu

    Date: Wed, 17 Nov 1993 15:14 EST
    From: Daniel D Suthers <suthers+@pitt.edu>

I am quite sure I already replied to this bug report once.  You need to
define PRESENTATION-TYPEP methods for your types A and B, otherwise CLIM
cannot determine class membership.  In later versions of CLIM, there is
a default method for PRESENTATION-TYPEP that issues an error message
telling you that you should define a PRESENTATION-TYPEP method.

----------

Date: Thu, 18 Nov 1993 17:16 -0500
From: Scott McKay <SWM@STONY-BROOK.SCRC.Symbolics.COM>
Subject: Re: use of AND and Or in presentation specs
To: suthers+@pitt.edu, clim-support@lucid.com, doughty@hq.ileaf.com,
        york@lucid.com, SWM@STONY-BROOK.SCRC.Symbolics.COM,
        SWM@STONY-BROOK.SCRC.Symbolics.COM
Cc: paolucci+@pitt.edu

    Date: Thu, 18 Nov 1993 12:28 EST
    From: Daniel D Suthers <suthers+@pitt.edu>

     > Date: Thu, 18 Nov 1993 10:29 -0500
     > From: Scott McKay <SWM@STONY-BROOK.SCRC.Symbolics.COM>
     > I am quite sure I already replied to this bug report once.  You need to
     > define PRESENTATION-TYPEP methods for your types A and B, otherwise CLIM
     > cannot determine class membership.  In later versions of CLIM, there is
     > a default method for PRESENTATION-TYPEP that issues an error message
     > telling you that you should define a PRESENTATION-TYPEP method.

    I found your previous message -- perhaps I missed your comments which
    followed a long quote of my own message. Thanks.

    I now understand why I need to define a presentation (it got by with
    EQ until I started using AND/OR) but now have several more questions.

    ----------
     1. I get an error when defining the method. Should I take option 0 or 1?

    (defmethod clim:presentation-typep (object (type 'a))
      nil)
    >>Error: PRESENTATION-TYPEP already names an ordinary function or a macro

Use DEFINE-PRESENTATION-METHOD, not DEFMETHOD.

    ----------
     2. I did a trace on presentation-typep during my application and was
    surprized to see that it is called with the objects being displayed,
    not the presentations.

A presentation is simply a visual representation of an object of a
certain presentation type.  PRESENTATION-TYPEP answers the question "is
the object X of the presentation type PT?".  In fact, you can use
WITH-OUTPUT-AS-PRESENTATION to create a presentation of the object 999
with type STRING, but that "is an error" (as we say in dpANS).

      1 Enter PRESENTATION-TYPEP A (COMMAND-NAME :COMMAND-TABLE
    #<COMMAND-TABLE TEST-WINDOW 11960E66>)
      1 Exit PRESENTATION-TYPEP NIL
      1 Enter PRESENTATION-TYPEP AB (COMMAND-NAME :COMMAND-TABLE
    #<COMMAND-TABLE TEST-WINDOW 11960E66>)
      1 Exit PRESENTATION-TYPEP NIL

    Isn't this supposed to be a predicate on presentations? I want to know
    if I've selected a presentation of type '(and a b), which requires
    testing the presentation, not the object displayed. 
							
No, it requires testing the displayed object.  You don't need to write a
PRESENTATION-TYPEP for (AND A B), since CLIM already has a method for
the AND type.

							How would you
    distinguish multiple displays of the same object in different
    presentations of different types? (For example, in our application an
    object gets displayed in different presentations depending on the role
    it is playing, so I need to test the presentation, not the object.)

You are a little confused here, but I'm not sure how to deconfuse you.
If you are distinguishing the behavior of an object based on *how* it is
presented (as opposed to *what* it is presented as), then you are
confusing type with appearance.  For instance, a textual representation
of a pathname and a little iconic file folder are both valid
representations of pathnames, and should be treated identically in terms
of the semantics of your application.  Conversely, the number 2962649665
could be both the current universal time (and hence a time object) or
the number of male humans on Earth (and hence an integer); the fact that
the same intrinsic data object is used to represent two completely
different semantic types is only an implementation detail.

    On the other hand, if it were called on presentations, I wouldn't know
    how to write the code to test its type.  Would I access a CLOS slot in
    the presentation?

    ----------
     3.  Scott's message stated that this was a bug in 1.0, but Amy
    implies that this is new a bug ...

      > Date: Thu, 4 Nov 93 16:02:56 PST
      > From: winarske@lucid.com (Amy Winarske)
      > Thank you for your test cases.
      > The test case for this problem has enabled us to identify a new
      > Lucid bug, #7241. 
      > With meta types, PRESENTATION-TYPEP of the object usually fails.
      > Development is working on the problem and we will let you know when
      > a patch becomes available.

    in fact a generic one ...

      > Date: Mon, 8 Nov 93 17:32:40 PST
      > From: winarske@lucid.com (Amy Winarske)
      > Your examples and questions all look valid to us.  There was a
bug in the
      > generic CLIM code which we've patched.  We've reported it to Scott
      > McKay but he is out of town.

    Is it a bug or am I doing something wrong (or both)?

I think that Amy is alluding to is not in fact buggy.  I think that the
bug really is in your (Dan's) code.
----------
Date: Fri, 19 Nov 1993 11:55 -0500
From: Scott McKay <SWM@STONY-BROOK.SCRC.Symbolics.COM>
Subject: Re: use of AND and Or in presentation specs
To: suthers+@pitt.edu, clim-support@lucid.com, doughty@hq.ileaf.com,
        york@lucid.com, SWM@STONY-BROOK.SCRC.Symbolics.COM,
        SWM@STONY-BROOK.SCRC.Symbolics.COM, SWM@STONY-BROOK.SCRC.Symbolics.COM
Cc: paolucci+@pitt.edu

    Date: Fri, 19 Nov 1993 10:44 EST
    From: Daniel D Suthers <suthers+@pitt.edu>

    Scott's responses clarify everything, thanks.  Though for our
    application it's unfortunate that presentation types are properties of
    the object, not the presentation:

     > A presentation is simply a visual representation of an object of a
     > certain presentation type.  PRESENTATION-TYPEP answers the question "is
     > the object X of the presentation type PT?".

    because that means I can't have different functionality on an object
    according to *how it is used* on the screen (e.g., a fact in an argument
    can be the same fact but used in different ways) -- I have to make
    copies of the object and classify it differently in my application in
    order to get it to have different presentations with different
    functionalities on the screen.

I guess I was a little scatter-brained yesterday.  Why not simply add a
presentation type parameter that describes how the object is to be used?
Then you don't need to subclass the object at all.

For example, if you have a PATHNAME presentation type, you could add a
:DIRECTORYP parameter to the type.  :Delete File might apply to all
pathnames, but :Show File would apply only when :DIRECTORYP is NIL.

----------


Date: Fri, 19 Nov 1993 15:20 -0500
From: Scott McKay <SWM@STONY-BROOK.SCRC.Symbolics.COM>
Subject: use of AND and Or in presentation specs
To: york@parc.xerox.com, suthers+@pitt.edu
Cc: clim-support@lucid.com, doughty@hq.ileaf.com,
        SWM@STONY-BROOK.SCRC.Symbolics.COM, SWM@STONY-BROOK.SCRC.Symbolics.COM,
        paolucci+@pitt.edu

    Date: Fri, 19 Nov 1993 14:13 EST
    From:	"William M. York" <york@parc.xerox.com>

       Date:	Thu, 18 Nov 1993 09:28:59 -0800
       From:	Daniel D Suthers <suthers+@pitt.edu>

	> Date: Thu, 18 Nov 1993 10:29 -0500
	> From: Scott McKay <SWM@STONY-BROOK.SCRC.Symbolics.COM>
	> I am quite sure I already replied to this bug report once.  You need to
	> define PRESENTATION-TYPEP methods for your types A and B, otherwise CLIM
	> cannot determine class membership.

       I found your previous message -- perhaps I missed your comments which
       followed a long quote of my own message. Thanks.

       I now understand why I need to define a presentation (it got by with
       EQ until I started using AND/OR) but now have several more questions.

    I have not been following this very closely, but pardon me if this has
    been covered.

	2. I did a trace on presentation-typep during my application and was
       surprized to see that it is called with the objects being displayed,
       not the presentations.

	 1 Enter PRESENTATION-TYPEP A (COMMAND-NAME :COMMAND-TABLE
       #<COMMAND-TABLE TEST-WINDOW 11960E66>)
	 1 Exit PRESENTATION-TYPEP NIL
	 1 Enter PRESENTATION-TYPEP AB (COMMAND-NAME :COMMAND-TABLE
       #<COMMAND-TABLE TEST-WINDOW 11960E66>)
	 1 Exit PRESENTATION-TYPEP NIL

       Isn't this supposed to be a predicate on presentations? I want to know
       if I've selected a presentation of type '(and a b), which requires
       testing the presentation, not the object displayed. How would you
       distinguish multiple displays of the same object in different
       presentations of different types? (For example, in our application an
       object gets displayed in different presentations depending on the role
       it is playing, so I need to test the presentation, not the object.)

       On the other hand, if it were called on presentations, I wouldn't know
       how to write the code to test its type.  Would I access a CLOS slot in
       the presentation?

    There are two issues, handled by two different CLIM predicates.
    Sometimes you need to know if an object is "presentation-typep" of a
    certain presentation type, and sometimes you need to know if one
    presentation type is "presentation-subtypep" of another.

    I guess that I have forgotton exactly what your original problem is,
    but if you are presenting objects as specific presentation types (even
    if the underlying data objects are of the same Lisp type) then in
    general ACCEPT can rely on the presentation-subtypep test, comparing
    the stated type of the presentation with the type of the input
    context.

    However, when you have type arguments things get more compicated.  Say
    you (ACCEPT '(INTEGER 0 10)).  Well, it is unlikely that anyone
    presented any integers with an explicit '(INTEGER 0 10) type.  And
    (PRESENTATION-SUBTYPEP 'INTEGER '(INTEGER 0 10)) is NIL.  So when you
    wave the mouse over integers, CLIM needs to call PRESENTATION-TYPEP on
    the integer and the type to see if the integer is a member of the
    type.  (I think that CLIM first checks to see if the stated type of
    the presentation is subtypep of the "stripped" context type (i.e.
    without the data args) so that it isn't calling PRESENTATION-TYPEP on
    strings and the like.)

Yes, this is a pretty accurate description.

    For presentation types that are linked to Lisp/CLOS types,
    PRESENTATION-TYPEP just becomes TYPEP.

This is pretty much the case, although if you add p-type parameters to
something that is already a Lisp/CLOS type, CLIM has to do a little bit
more work.

    The AND presentation type has similar problems.  I assume that there
    aren't any presentations in your history whose presentation type field
    is '(AND A B).  Instead you have some A's and some B's and some of the
    A's also could be B's.  So, we call PRESENTATION-TYPEP (maybe only on
    objects that have stated type A?) to see if they qualify.

    Sorry if this is all obvious to you by now, or if I have missed the
    point, or if I have gotten the mechanism wrong (it has been a while).


----------
From: "William M. York" <york@parc.xerox.com>
To: suthers+@pitt.edu
Cc: clim-support@lucid.com, doughty@hq.ileaf.com,
        SWM@stony-brook.scrc.symbolics.com, paolucci+@pitt.edu
Subject: use of AND and Or in presentation specs
Date: 	Fri, 19 Nov 1993 17:05:53 PST

   Date:	Fri, 19 Nov 1993 13:39:20 -0800
   From:	Daniel D Suthers <suthers+@pitt.edu>

   Actually, we DO want to have presentations with '(and a b) ... 

   This part works, because my COMMANDS only care about a single type

   The part I had trouble with was writing commands that look for compound
   (conjunctive or disjunctive) types. (The most immediate need was for
   disjunctive.) This crashed, Amy thought it was a bug, Steve said it
   isn't, I just haven't written some methods ... 

   BTW, we got involved in commands on disjunctive types because command
   definitions don't act like defmethod (which is what we thought it
   would). That is, we thought we could write things like

Well, the command defining/processing mechanism has some pretty
specific requirements that drive this decision.  Primarily, when you
invoke the command processor to read a command from the keyboard the
CP has to know which argument parser to run in advance of reading the
arguments.  So, there can only be one "active" command registered
under a given name.

I take it that you don't use the CP for keyboard input of commands
much, but just click on presentations in order to invoke
single-argument commands on the selected presentation data object,
right?

You might consider just "trampolining" to the actual CLOS dispatch
mechanism if that's what you want.  That is, just have one
presentation translator that invokes a CLOS generic function on the
item clicked upon.  Then define methods for your various classes.

Here is some Lisp/CLIM pseudo-code that illustrates the idea (that is,
this code won't run, but you can build from it):

(define-belvedere-frame-command (com-inspect-something)
	((thing 'expression))  ;; maybe use type T and :gesture :inspect?
	(inspect-a-thing thing))

(define-presentation-to-command-translator inspect-thing
    (t com-inspect-something belvedere-frame
     :gesture :inspect)
    (object)
  (list object))

(defmethod inspect-a-thing ((thing president))
 ...)

(defmethod inspect-a-thing ((thing month))
 ...)


This assumes that you have different Lisp/CLOS types for all your
objects.  If you only have different presentation types it is a bit
clunkier, but maybe not too bad:

(define-belvedere-frame-command (com-inspect-something)
	((type 'symbol)
	 (thing 'expression))  ;; maybe use type T and :gesture :inspect?
	(inspect-a-thing type thing))

(define-presentation-to-command-translator inspect-thing
    (t com-inspect-something belvedere-frame
     :gesture :inspect)
    (object presentation)
  (list (presentation-type presentation) object))

(defmethod inspect-a-thing ((type (eql president)) thing)
  ...)

These are just rough ideas.  You could even punt the command processor
for this particular thing.  Define a presentation action that takes
the data object and/or presentation object and trampolines to a CLOS
method as above.
--------------------------------------------------
 Dan Suthers           | LRDC, room 505A
 suthers+@pitt.edu     | 3939 O'Hara Street
 (412) 624-7036 office | University of Pittsburgh
 (412) 624-9149 fax    | Pittsburgh, PA 15260
--------------------------------------------------

References:

Main Index | Thread Index