[comp.windows.news] Surprising NeWS - feature

knut-skog%rglab.uit.uninett@NORUNIX.BITNET (Knut Skog) (05/20/89)

Have a look at this reprint of a small session with NeWS.


     " NeWS> /y 5 def
       NeWS> createevent begin /y 2 store end y =
       2                                      % OK
       NeWS> /z 5 def
       NeWS> createevent begin  z =
       5                                % OK
       NeWS> /z 2 def end
       NeWS> createevent begin /z 2 store end z =
       5                                 % ????????
       NeWS>  "

Can anybody tell me why the createevent operator is effected
by my careless def-ing of z into the eventdict.  I expected
to get a 'dictfull' message.  However, it looks as if
the defing effects the uninitiated eventdict so that all
later eventdicts  created now has the this  z-field. This will
last until the server is reinitiated (I think).
It is easy to make a def where you mean store. If this happens
when the current dict is an event dictionary the side-effect is
rather surprising.
I'm grateful if some of you would comment on this feature.
I myselfe tend to believe that it is a bug.

Krg,

Knut

ads@cs.qmc.ac.uk (Adam Billyard) (05/30/89)

In article <117*knut-skog@rglab.uit.uninett> knut-skog%rglab.uit.uninett@NORUNIX.BITNET (Knut Skog) writes:
>  ...
>Can anybody tell me why the createevent operator is effected
>by my careless def-ing of z into the eventdict.  I expected
>to get a 'dictfull' message.  However, it looks as if
>the defing effects the uninitiated eventdict so that all
>later eventdicts  created now has the this  z-field. This will
>last until the server is reinitiated (I think).
>It is easy to make a def where you mean store. If this happens
>when the current dict is an event dictionary the side-effect is
>rather surprising.
>I'm grateful if some of you would comment on this feature.
>I myselfe tend to believe that it is a bug.

I suspect this behaviour is due to event dictionaries being
magical, and not just regular dictionaries. I had a horrible
time trying to write a event preprocessor to be inserted into
"forkeventmgr" so that I got Clicked and Pressed events rather
than the simple Up/DownTransitions.

The problem I had was that a 'store' into the Action field
of an event simply doesn't work. I had to write my own 'store'
(imaginatively named mystore) to make this work.

The moral of the story is dont mess with Magic Events.

        Adam.


% define mystore to be used instead of store
systemdict /mystore % key val => -
{
  exch dup where {3 1 roll exch put}{exch def} ifelse
} put

%
% Econv converts events from Up/DownTransition to Clicked/Pressed
%
% Written 30/11/88 AMB
%
% fast way to do conditional ORs, lookup Key known = key1|..|keyN
/lookup 3 dict dup begin
  /LeftMouseButton null def
  /MiddleMouseButton null def
  /RightMouseButton null def
end def

/Cspeed 0.18 60 div def % click time in seconds

/Econv                  % event => event
{
  begin
    lookup Name known
    {
      Action DownTransition eq
      {
        3 dict begin
          /term1ev createevent def
           term1ev /Name Name put term1ev /Action UpTransition put
          /term2ev createevent def
           term2ev /Name /CTimer put
          /timer createevent def
           timer /Name /CTimer put timer /TimeStamp currenttime Cspeed add put
          timer sendevent term1ev expressinterest term2ev expressinterest
          awaitevent begin
            Name
            {
              /CTimer
              {
                /Pressed                % new Action field is..
              }
% case should really check to see if Key evaluates to a Literal so
we could use MenuButton etc. Sigh.
              /LeftMouseButton
              /MiddleMouseButton
              /RightMouseButton
              {
                timer recallevent       % cancel timer
                /Clicked                % new Action field is..
              }
            } case
          end
          term2ev revokeinterest
          term1ev revokeinterest
        end
        /Action exch mystore                % replace Action field
      } if
    } if
  currentdict end
} def

%
% To make forkeventmgr do conversion of event before CallBack
%
% /EventMgrFore where pop /EventMgrFore {Econv} put

-- 

JANET:  ads@cs.qmc.ac.uk
ARPA:   ads%cs.qmc.ac.uk@nss.cs.ucl.ac.uk
BITNET: ads%uk.ac.qmc.cs@ukacrl.bitnet