can someone explain to me what pragmas are in smal...
# thinking-together
g
can someone explain to me what pragmas are in smalltalk in very concrete terms? I’m trying out gtoolkit
also, @Tudor Girba i’d be stoked if you could add control of the slideshow with left and right arrows instead of just mouse. if you wanted, I’d even love to walk through implementing it in a recording for gtoolkit intro materials
t
@Garth Goldwater pragmas are called annotations in other languages. In Pharo, pragmas can be attached to methods. This paper describes the mechanism in a little more details: https://hal.inria.fr/hal-01353592/document.
g
I waas trying to understand that paper—are they intended purely for smalltalky reflection, eg “list all the methods in the image with the <3d-viewable> pragma”? or does it do other stuff? Do they get evaluated? I understand that they involve message sends, but I’m having trouble wrapping my head around how/why they’re dynamic
t
they do not get evaluated. yes, they are intended for discovery.
g
eg “it may be queried for senders, executed, etc”—does that mean objects who use the pragmas to query objects in the image, or the objects with the pragmas themselves?
Copy code
LargeInteger >> // anInteger

"Primitive. Divide the receiver by the argument and return the result. Round the result down towards negative infinity to make it a whole integer. Fail if the argument is 0. Fail if either the argument or the result is not a SmallInteger or a LargePositiveInteger less than 2-to-the-30th (1073741824)."

<primitive: 32>
^ super // anInteger
so… i get that you’re sending
32
to the object
primitive
… when does that message send get executed? on instance creation? or just during queries?
t
no.
primitive:
is a message.
32
is an argument.
g
hooo boy i’m very turned around
ok im going to read more stuff thanks for your help
t
if you look for the senders of
primitive:
you will get the locations in code that are using this message as pragma.
<primitive: 32>
would be equivalent to
@primitive(32)
in Java.
if you are playing with Glamorous Toolkit, you can also query for it explicitly. For example, inspect
#primitive: gtPragmas
in a Playground
g
so in that example, you’re sending the symbol
primitive
the argument
gtPragmas
and getting a list of all the methods that use primitives?
sorry, I need to break stuff down a whole lot in order to make sure i’m not using the wrong schema when i’m trying to learn something at first
t
yes. this is a fluent API. In this case, it’s implemented like this:
You can learn about this querying API through the slideshow from the home tab entitled
Querying Code