structural simplification makes it easier to understand the languagebut also
As the variety of constructs decreases, so does the variety of linguistic cues to a system's structure.Is the syntax in Self too uniform? What about LISP? Java? Python with tables instead of classes? Is experience with the language a factor?
Many languages, including Self and Python, parse code into compact instructions for a virtual machine. In some sense this is compiling, in another sense interpreting. Is the distinction relevant anymore?
| p = (| x = 5. f = (x) |) |From an environment where x is bound to 4, a call to f could either:
(p _AddSlots: (| g = (| x = 4 | f) |)) g
(| x = 4. parent* = p |) f
(| x = 3. parent* = p. g = (| x = 4 | f) |) g
loopmessage, which evaluates a block endlessly, requires low-level support. For example, this is the definition of
untilTrue:, Self's version of Pascal's
repeat ... untilstatement:
untilTrue: cond = ([ self value. cond value ifTrue: [ ^nil ]] loop)In English:
untilTrue:. Caret is the return operator in Self.
Your task is to implement C's
for loop in Self. This
construct has four parts:
while:Do:Then:which takes these arguments in order. The implementation should look similar to
untilTrue:. Use this to test:
| i | [ i: 0 ] while: [ i < 10 ] Do: [ i printLine ] Then: [ i: i + 1 ]In C, this corresponds to:
int i; for( i = 0 ; i < 10 ; i++ ) printf("%d\n", i);If you can't work out the syntax, explain in English.
| f = (| x = 3 | (self + x) * x) | 4 f "prints 21"Suppose we're debugging, and we'd like to know about the run-time behavior of f, e.g. how many times x is used during execution. In this simple case, we know it is used twice; but f could be more complicated. Furthermore, we want to treat f as a black box; no modification of code.
Describe, in English, how we might write a function monitor: which modifies a black-box function so that all accesses to a particular variable cause a message to be printed. The monitored function should otherwise behave normally. For example:
((lobby _Mirror at: 'f') contents) monitor: 'x' 4 f "prints 'reading x','reading x', and 21"
Barometer question: What are the features of Self that allow us to do this?