Browsing Cocoa with F-Script
Pages: 1, 2
Adding an Entry to the Workspace
You can assign the currently-selected object to a name in your workspace by clicking on the "Name" button, and typing the chosen name in the sheet. This operation is equivalent to the assignment instruction := in the F-Script language.

Fig. 3. A sheet asks for the name of the object.
Note: if you hit the button by mistake, pressing the Return key on your keyboard without typing anything will dismiss the sheet.
Browsing All Classes
You can browse the classes linked to the executable from which you are using the F-Script object browser (since F-Script is offered as an embeddable framework, you may want to use it from different applications). To start browsing the classes, just click on the "Classes" button.

Fig. 4. Browsing classes.
You can manipulate classes through the browser in the same way as other objects. This is because Cocoa classes are themselves regular objects. Indeed, each class is itself an instance of another class (called a meta-class) automatically created by the object system, and meta-classes are themselves objects. Since F-Script makes it so easy to browse these different levels, it can be useful to have a clear view of the topology of the Cocoa class system. We illustrate it below, using the Cocoa NSBox class as example.

Fig. 5. Topology of the Cocoa class system.
A few remarks:
- In this schema, the class of a class is denoted by adding
(meta)to the class name. For instance, the class of theNSBoxclass is denoted byNSBox (meta). - Each object (including classes) in the system is associated with another object (its class) by the "is instance of" relationship. Note that this relationship is not transitive. Within F-Script, you send the
classOrMetaclassmessage to an object in order to get its class. - The "inherits from" relationship applies at the class level. For most practical purposes, this relationship can be seen as transitive. You can traverse it by sending an object the
superclassmessage. NSObject, the root of the class hierarchy, does not inherit from another class. Sending it thesuperclassmessage returns nil.- With Cocoa, the class methods of a class
Aare the instances methods ofA (meta). - The fact that meta-classes are organized in a hierarchy that is similar to the corresponding classes' hierarchy explains why class methods are inherited.
- The fact that
NSObject (meta)inherits fromNSObjectexplains why instance methods defined for the root class are also class methods. NSObject (meta)is the class of all the meta-classes in this hierarchy: it is the meta-meta-class.
There are a few classes that you can't use with F-Script, and therefore can't browse. This includes classes not conforming to the NSObject protocol (like those inheriting from the "old" Object class), and some special system classes like NSFault and _NSZombie.
Sending the self Message
All Cocoa objects support the self message. This simply returns the receiver of the message. As with all other messages, it can be sent using the object browser in the way we described. But sending this message is (surprisingly) so useful in the context of the object browser that there is a shortcut, in the form of the "self" button. By clicking on it, you send the self message to the selected object.
Sending this message is useful for browsing nested collection, and for getting an up-to-date description of an object.
Inspecting the Selected Object
The "inspect" button opens an inspector for the selected object. A generic inspector is provided and some object offer more specific inspectors (by implementing the inspect method). For instance, inspecting a block will open a code editor for the block.
Browsing Collections
The object browser provides a handy way to browse collections of objects like NSArray, NSSet, or NSDictionary.
When browsing a collection, the browser not only presents the collection as a whole, but also displays and makes selectable each of the elements in the collection. Thus, you can select the collection itself, or directly select one of its elements.

Fig. 6. Browsing an NSArray of strings.
When browsing nested collections, sending the self message to an element lets you conveniently delve into nested sub-levels.
The Status Bar
As you move the mouse pointer, the status bar at the base of the browser shows you a more complete description of objects and methods than the one in the columns, which is sometimes limited by the column size.
![]()
Fig. 7. The status bar is handy!
Update Policy
Objects displayed in the column of the browser or by the generic inspector can be modified at any time in a number of ways: events, callbacks, sending a message with side effect from the object browser or from the F-Script shell, etc.
It is important to note that the browser doesn't automatically update its display when such modification occurs. However, selecting an object and sending it the self message or opening the generic inspector on it will let you see an updated description of the object.
Philippe Mougin specializes in object-oriented technologies and enterprise systems. He is the creator of F-Script, an open-source object-oriented scripting language for Cocoa.
Return to the Mac DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 3 of 3.
-
remarks on topology
2001-12-21 21:46:21 psheldon [Reply | View]
This is an atta boy.
I have an odd way of learning things. I like to be frustrated. Your remarks on topology seemed to be conceptualization of an axiomatic approach to the next step framework language. It frustrated me because I almost got it but not quite. Frustration is good. It motivates me to read the examples. Examples are good because I invariably get burned making mistakes and then I appreciate and learn the axioms better.
So I am not complaining because I was frustrated. I can easily frustrate myself, but I am not always sure this will lead to knowledge and it is apparent that you know more than I here and I trust you more than myself to frustrate me.
It is merciful to an author not to displace all my frustration onto him by asking why why why too soon because my confusion and frustration has to settle in for me to appreciate and be able to absorb an answer to all the why's. There is no royal road to mathematics.
These remarks might be a gracious attempt to try to pare down some sort of EBNF grammar defining next step object system, if there is any EBNF grammer so defining it or it might be the first step to daring to try to write down such a grammar.
I'm not ready, the author is not ready for why why why, but perhaps it is kind for me to say which is the most difficult axiom for me to allow myself to be frustrated with right now :
"The fact that NSObject (meta) inherits from NSObject explains why instance methods defined for the root class are also class methods."
-
Some more remarks
2001-12-26 05:50:53 pmougin [Reply | View]
A key point is that the structure described is actually present, in memory, for each Objective-C program during run-time. The "is instance of" and "inherits from" relationship are represented by mere pointers. This structure is created and managed automatically by the Objective-C run-time.
The main purpose of the in-memory representation of each class is to host a correlation table, which associates method names (in the form of selectors) with pointers to the actual compiled code of the methods. This is the basic information the messaging system needs in order to work.
This table is of course based on the information that was given to the compiler in the source code. In particular, instance methods (which are syntactically marked by "-" at the beginning of their declarations in Objective-C source code) are referenced in the correlation table of the corresponding class. Class methods (which are marked with "+") are referenced in the correlation table of the corresponding meta-class.
When a message is sent to an object, the run-time system exploit this structure in order to find the actual implementation of the method (the compiled code to execute). The first step is to traverse, just once, the "is instance of" relationship, from the receiver to its class. This allows the messaging system to get to the class of the object. Then, the messaging system looks into the correlation table hosted inside the class object in order to find the method that was invoked. If the method is not present in the table, the system follow the "inherits from" relationship, and try to find the method in the table of the super class. It goes upper in the hierarchy like this until it find the method or reach the root class.
Since classes are themselves objects, one can send them messages. The process presented below is applied exactly in the same way. Since NSObject is the root class for not only the class hierarchy but also for the meta-class hierarchy, instances methods defined in NSObject can also be invoked on classes.
Phil






I don't know that I am asking for definitions of callback right now, I think what I am trying to say is that I am intrigued by your formal knowledge and first attempts to "make a story about it" and, with the term meta, it bespeaks a familiarity with the formal pregenitors of next step in more general object oriented language theory.
Wild stuff.