Post by Andrei N.SobchuckWhen pragmas where introduced?
Well, I think of pragmas being introduced back in Smalltalk 80 (or
possibly earlier). The first pragma was
<primitive: N>
In ObjectWorks 2.5 this was extended with
<primitive: N errorCode: errorCodeTempVar>
In VisualWorks 1.0 (or possibly ObjectWorks 4.x) another pragma was
introduced:
<resource: #symbol>
used for marking methods defining "resources" such as GUI and Menu specs.
CPOK, the C programmer's Object Kit, which was introduced somewhere
around the same time (before my time at ParcPlace) introduced another:
<C: c typedef or define>
Then in the run-up to VisualWorks 2.5 I joined ParcPlace and was
offended by the mechanism by which the unwind-protect methods
valueNowOrOnUnwindDo: and valueOnUnwindDo: [thankfully now renamed ;) ]
were marked for unwind. The class side of BlockClosure implemented
#validateMethod:forSelector:, which was a hook sent on installing a
method into a method dictionary, provided for just this purpose. The
method checked for the selector being either valueNowOrOnUnwindDo: or
valueOnUnwindDo: and marked the methods appropriately. I found it an
egregious hack. After all one could have redefined the method selectors
to be anything and the system would still have attempted to mark them as
unwinds. The semantics had been moved to something related to the
selectors, not the methods themselves.
So I decided the methods should use a pragma:
<exception: #unwind>
and Steve Dahl generalized the scheme such that all the above could be
considered pragmas, i.e. messages with literal arguments that could be
associated with methods and queried. We used them for unwinds and
exception handlers.
Then in the run-up to VW 3.0 I hit on the idea of menu pragmas, where
menus could be composed from methods that included menu pragmas, and
hence adding a method with a pragma could immediately extend a menu
without having to rebuild it. But the real motivation was to avoid menu
definition conflicts when different parcels needed to extend the same
menu with different methods. Menu pragmas allowed one to avoid writing
a menu spec for the extended menu, and hence avoided having to resolve
the conflicts between different extended specs.
Whatever you want. They're useful in attaching meta data to a method
such as "this method is an action method on a particular menu" or "this
method has exotic execution semantics". One of my favourite uses is in
marking COM server methods, invented by Tami Lee. One adds the COM
signature of a method one wants to export to the method as a pragma and
then runs a wizard which generates all the COM type machinery to
actually export the interface to COM. Another is Vassili's part-whole
framework for dialog composition in vw7.2.
But my favourite one is Steve Dahl's invention for resolving conflicts
between different systems that need to add pragmas. Our first idea with
pragmas in 3.0 was that anyone should be able to add their own pragmas,
and the first person other than Steve and I was Tami with her COM
interface scheme. We needed a way of specifying which pragmas a class
would compile because we thought it was safer being able to specify a
particular set than compiling any old pragma. Otherwise how would one
spot speeling errors like
<primtive: N>
?
In the first general implementation we required classes to define a
pragmaKeywords method to answer an array of pragma selectors. The
problem was exactly analogous to menu spec conflicts. If two different
parcels tried to extend the same class with different sets of pragma
keywords they'd conflict. So Steve invented the pragma pragma. If you
want to add pragmas you define a class side method with whatever
selector you want which answers a literal array of pragma methods and uses
<pragmas: #instance>
and/or
<pragmas: #class>
to specify whether the pragmas are legal in class and/or instance side
methods.
Look at senders of #pragmas:.
The best thing about pragmas is their implementation as Message
instances. So one can do senders and implementors on them, and process
them by performing them. For example, menus get built by sending the
actual menu pragma message to a MenuAutomaticGenerator.
Post by Andrei N.SobchuckDo pragmas exist in other Smalltalk dialects?
As Vassili said, he did an implementation for Squeak. David Simmons has
done similar stuff in AOS and S#, but VW's pragmas are "just" messages
with literal arguments, whereas his are I think more general XML
annotations.
--
_______________,,,^..^,,,____________________________
Eliot Miranda Smalltalk - Scene not herd