-
Notifications
You must be signed in to change notification settings - Fork 0
/
self_cheatsheet.tex
795 lines (518 loc) · 22.3 KB
/
self_cheatsheet.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
% Copyright (c) 2016 Bystroushaak
% Permission is hereby granted, free of charge, to any person
% obtaining a copy of this software and associated documentation
% files (the "Software"), to deal in the Software without
% restriction, including without limitation the rights to use,
% copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the
% Software is furnished to do so, subject to the following
% conditions:
% The above copyright notice and this permission notice shall be
% included in all copies or substantial portions of the Software.
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
% OTHER DEALINGS IN THE SOFTWARE.
% Inspired by http://tex.stackexchange.com/questions/99765/document-class-for-reference-cards
\documentclass[10pt]{article}
\usepackage{fixltx2e}
\usepackage[orthodox,l2tabu,abort]{nag}
\usepackage{textcomp}
\usepackage{hyperref}
\usepackage{dirtree}
\DTsetlength{0.2em}{0.5em}{0.3em}{0.4pt}{1.6pt}
% Page layout
\usepackage[a4paper,landscape,margin=1cm]{geometry}
\usepackage{multicol}
\setlength{\columnsep}{0.5cm}
% Title area
\usepackage{titling} % Allows for use of date, author, etc. after \maketitle
% Ref: http://tex.stackexchange.com/questions/3988/titlesec-versus-titling-mangling-thetitle
\let\oldtitle\title
\renewcommand{\title}[1]{\oldtitle{#1}\newcommand{\mythetitle}{#1}}
\renewcommand{\maketitle}{
{\begin{center}\Large \mythetitle\end{center}}
}
% Document divisions
\usepackage{titlesec}
\setcounter{secnumdepth}{0}
\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{3pt}{0pt}
\titlespacing{\subsubsection}{0pt}{0pt}{0pt}
\setlength{\parskip}{2pt}
\usepackage{nopageno} % To keep \section from resetting page style
\setlength{\parindent}{0pt} % disabling indentation by default
% Lists
\usepackage{enumitem} % for consistent formatting of lists
\newlist{ttdesc}{description}{1}
\setlist[ttdesc]{font=\ttfamily,noitemsep}
\usepackage{calc} % for \widthof
\usepackage{lipsum}
% Metadata definition
\title{Selflang cheat sheet}
\author{Bystroushaak}
\date{2016}
\pdfinfo {
/Author (\theauthor)
/Title (\thetitle)
/Subject (\thetitle)
/Keywords (Self, SelfLang, programming language, programming)
}
% Set listing
% https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings
\usepackage{listings}
\usepackage{pxfonts}
\lstset{
basicstyle=\ttfamily,
keywordstyle=\bfseries,
showstringspaces=false,
breaklines=false,
breakatwhitespace=false,
columns=fullflexible,
}
% Content %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{multicols*}{3}
\maketitle
\section{Object syntax}
An \textit{object} consists from (possibly empty) set of \textit{slots} and (optionally) \textit{code}.
Slots behave as key-value lookup table, translating messages to objects. \textit{Code} is a sequence of \textit{expressions} (\textit{message sends} and \textit{literals}) separated by dots, evaluated in order.
Syntax is straightforward:
\begin{lstlisting}
(| slot1. slot2 | 'code' printLine. 'str')
\end{lstlisting}
for object with \textit{slots} and \textit{code}, or
\begin{lstlisting}
(| | 'this is str') or ('this is str')
\end{lstlisting}
for object with \textit{code}, but no \textit{slots}, or
\begin{lstlisting}
(| slot1. slot2. slotN |)
\end{lstlisting}
for object with \textit{slots}, but no \textit{code}, or
\begin{lstlisting}
(| |) or ()
\end{lstlisting}
for empty object.
\subsection{Comments}
Comments use double quotes and are ignored by parser.
\begin{lstlisting}
("empty object same as () or (| |)")
\end{lstlisting}
\subsection{Slot assignments}
Slots can be assigned at the time of definition, either read only using \texttt{=} operator:
\texttt{(| slot = 1 |)}
Or rewritable using \texttt{<-} operator. This operator actually adds two slots - \texttt{slot} for the data and \texttt{slot:} with assignment method object.
\texttt{(| slot <- 1 |)}
\subsection{Messages}
\textit{Messages} are evaluated from left to right. Object is on the left, messages on the right. Messages can be without arguments:
\begin{lstlisting}
obj message
\end{lstlisting}
(to the \textit{obj} send a \textit{message}), or with arguments:
\begin{lstlisting}
obj message: argument
\end{lstlisting}
(to the \textit{obj} send a \textit{message} with \textit{argument} as value).
\columnbreak
{\small
\subsection{Special slots}
\subsubsection{\texttt{self} slot}
Every object has automatically created slot named \texttt{self}, pointing to object itself. Unlike other languages, \texttt{self} may be omitted, in \textit{message sends}, so
\begin{lstlisting}
self message
\end{lstlisting}
is same thing as
\begin{lstlisting}
message
\end{lstlisting}
\subsubsection{Annotation slot}
Additional informations may be provided in the \textit{annotation slot}:
\begin{lstlisting}
(| {} = 'Annotation string.' |)
\end{lstlisting}
or
\begin{lstlisting}
(| { 'Annotation string.' slot. another. } |)
\end{lstlisting}
\subsubsection{\texttt{parent} slots}
Every object may also contain one or more parent slots, which are slots whose names end in a star (\texttt{*}). Lookups unresolved in the receiving object are delegated to these parent slots. This is used to implement inheritance (often with a single parent slot named \texttt{parent*}) and also mixins, and namespaces.
}
\subsection{Method slots}
\textit{Method slots} is the storage for the code in objects.
\subsubsection{Unary slots}
Code \textit{slots} without arguments are called \textit{unary}.
\begin{lstlisting}
(| first = (printLine) |)
\end{lstlisting}
This \textit{method slot} can be invoked by sending \textit{unary} message:
\begin{lstlisting}
obj first
\end{lstlisting}
\subsubsection{Binary slots}
Slots with one argument is called \textit{binary}:
\begin{lstlisting}
(| first: = (| :arg | arg printLine) |)
\end{lstlisting}
Which has shorter equivalent:
\begin{lstlisting}
(| first: arg = (arg printLine) |)
\end{lstlisting}
Invocation is possible using the \textit{binary message}:
\begin{lstlisting}
obj first: 1
\end{lstlisting}
\textit{Binary slots} are also used as operators (one or more characters from \texttt{!@\#\$\%\^{}\&*-+=\textasciitilde/?\textless\textgreater,;|'\textbackslash{}} set).
\subsubsection{Keyword slots}
It is also possible to create \textit{keyword} slots with multiple arguments:
\begin{lstlisting}
(| first: x Second: y = (x + y printLine.) |)
\end{lstlisting}
Notice the upper-case \textit{S} in \texttt{Second}. Invocation is done via \textit{keyword message}:
\begin{lstlisting}
obj first: 3 Second: 5
\end{lstlisting}
\subsubsection{Priorities}
Constant definition \textgreater{} Unary \textgreater{} Binary \textgreater{} Keyword messages. Constant = self \textbar{} number \textbar{} string \textbar{} object.
\subsection{Block objects \textit{(closures)}}
\textit{Block objects} are Self closures, which means, that \texttt{self} slot is not present. Unresolved lookups are delegated via \texttt{parent*} to namespace surrounding the \textit{block object} at the time of creation. Syntax is same as with objects, but square brackets are used:
\begin{lstlisting}
[| slot1. slot2 | 'code']
\end{lstlisting}
Another difference is support of \textit{non-local return statement} using \texttt{\^} preceding the returned value. This returns the value not just from the \textit{closure}, but also from the enclosing namespace.
\begin{lstlisting}
(|
x = 6.
non_zero = (x > 5 ifTrue: [ ^ 'ok' ]
False: [ ^ 'nope' ])
|)
\end{lstlisting}
\^{} doesn't just return from the closure in \texttt{[]}, but also from the surrounding \textit{method object}. \texttt{non\_zero} message thus returns \texttt{'ok'}.
\subsubsection{Block messages}
\textit{Block objects} take by default message \texttt{value}, which evaluates the code and returns result of last statement.
If the \textit{block object} takes (multiple) parameters, they may be supplied using \texttt{value:\ With:} message pattern:
\begin{lstlisting}
block_obj value: x With: y .. With: z
\end{lstlisting}
Notice the upper-case first letters in \texttt{With:} message. This tells the Self, that it's still part of one message with multiple arguments. In case of blocks, \textbf{unrequested arguments are ignored}, so you may use unlimited number of \texttt{With:}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagebreak %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Namespaces}
\subsection{Traits}
Objects with shared behaviour, which is used by pointing \texttt{parent*} slots to them. This is analogical to \textit{sub-classing} in other languages.
\subsection{Mixins}
Mixins are small, parentless bundles of behavior designed to be \textit{mixed into} some other object. Approximate analogy to other languages would be \textit{interface with (partial) implementation}.
\subsection{Globals}
Prototype objects and \textit{oddballs} (unique singletons) like \texttt{true}, \texttt{false}, \texttt{nil}..
\section{Resends}
\textit{Resends} allows you to delegate the messages to the parent branches of OOP tree. \textit{Resend messages} are equivalent of \textit{super} calls in other languages.
Syntactically, \textit{resends} are implemented using \texttt{resend.} prefix for resent messages:
\begin{lstlisting}
resend.unary
resend.+ 1
resend.keyword: 1 Another: 2
\end{lstlisting}
You may also use \textit{directed resends}, targeting specific parent:
\begin{lstlisting}
intParent.+ 1
otherParent.keyword: 1 Another: 2
\end{lstlisting}
\section{Mirrors}
\textit{Mirrors} provide Self with introspection capabilities.
\textit{Mirror} can be created by sending \texttt{reflect:\ x} message to any \texttt{defaultBehavior} instance. The message will return \textit{dictionary-like} \textit{mirror} object.
\begin{lstlisting}
defaultBehavior reflect: 1
\end{lstlisting}
\textit{Mirror} presents you with sort of introspection layer usable for structural changes in \textit{reflectee} (original object \texttt{x}) by manipulating the \textit{dictionary-like mirror} object.
This may be used for examination, addition or removal of the \textit{slots} of the \textit{reflectee}.
\vfill
\columnbreak
\section{Collections}
Various containers for data are implemented as \textit{key:\ val} storages. Even lists use this convention (elements are used both as \textit{key} and \textit{value}).
Self offers a rich variations of \textit{Sets}, \textit{Dictionaries} and \textit{Trees}:
\vspace*{0.4cm}
% http://texblog.org/2012/08/07/semi-automatic-directory-tree-in-latex/
\dirtree{%
.1 traits \textbf{collection}.
.2 traits \textbf{abstractSetOrDictionary}.
.3 traits \textbf{abstractSet}.
.4 traits \textbf{universalSet}.
.5 \textbf{universalSet}.
.4 traits \textbf{hashTableSet}.
.5 \textbf{identitySet} parent.
.5 \textbf{customizableSet} parent.
.5 \textbf{reflectiveIdentitySet} parent.
.5 traits \textbf{set}.
.5 traits \textbf{sharedSet}.
.3 traits \textbf{abstractDictionary}.
.4 traits \textbf{orderedDictionary}.
.4 traits \textbf{universalDictionary}.
.5 \textbf{universalDictionary}.
.4 traits \textbf{hashTableDictionary}.
.5 \textbf{identityDictionary} parent.
.5 \textbf{customizableDictionary} parent.
.5 \textbf{reflectiveIdentityDictionary} parent.
.5 traits \textbf{dictionary}.
.5 traits \textbf{sharedDictionary}.
.2 traits \textbf{tree}.
.3 traits \textbf{emptyTrees} abstract.
.4 traits \textbf{emptyTrees bag}.
.4 traits \textbf{emptyTrees set}.
.3 traits \textbf{treeNodes} abstract.
.4 traits \textbf{treeNodes bag}.
.4 traits \textbf{treeNodes set}.
}
\vspace*{0.4cm}
\textit{Sets} behave like mathematical sets - unordered unique collection of values. \textit{Dictionaries} work as \textit{key: val} storages and are implemented using hashmaps.
\textit{Trees} are different implementations of \textit{dictionaries} using \textit{unbalanced binary trees}.
Note: If the elements are added in sorted order, \textit{trees} may degenerate into lists, which may result in really bad performance.
\columnbreak
There is also variety of \textit{Lists}, \textit{Vectors}, \textit{Strings} and \textit{Queues}:
\vspace*{0.4cm}
\dirtree{%
.1 traits \textbf{collection}.
.2 traits \textbf{path}.
.2 traits \textbf{sharedQueue}.
.2 traits \textbf{priorityQueue}.
.2 traits \textbf{list}.
.3 traits \textbf{orderedSet}.
.3 \textbf{sortedList} parent.
.4 \textbf{sortedListSet} parent.
.2 traits \textbf{indexable}.
.3 traits \textbf{mutableIndexable}.
.4 traits \textbf{sequence}.
.5 traits \textbf{sortedSequence}.
.4 traits \textbf{vector}.
.5 \textbf{vector}.
.4 traits \textbf{byteVector}.
.5 \textbf{byteVector}.
.5 traits \textbf{int32or64}.
.6 traits \textbf{int64}.
.6 traits \textbf{int32}.
.5 traits \textbf{string}.
.6 traits \textbf{immutableString}.
.7 traits \textbf{canonicalString}.
.6 traits \textbf{mutableString}.
}
\vspace*{0.4cm}
Collections have rich message protocol, allowing various operations. Most important are:
\vspace*{0.2cm}
\small{\begin{tabular}{ p{50pt} p{180pt} l l }
Message & Description
\\\hline\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{at:}
&
Get item at position / key.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{at: Put:}
&
Put item to position / key.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{add:}
&
Add item (to the end in ordered) collections.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{addAll:}
&
Add all items to (end of) collection.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{do:}
&
Iterate over collections.
\\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tabular}}
\subsection{Collector}
\textit{Collector} is special kind of object created using \texttt{\&} operator. \textit{Collector} is not a collection, but can be converted to one.
Main reason to use it is the \texttt{\&} operator, which may simplify the syntax required to create such collection.
\nointerlineskip\begin{lstlisting}
(1 & '+' & 2) asList
\end{lstlisting}\nointerlineskip
\subsection{Point}
Another kind of container often used with \textit{collections} is \texttt{point} and naturally the \texttt{rectangle} made of two points.
\vfill
\columnbreak
\section{Control sequences}
As usual in \textit{Smalltalk-like} languages, \textit{control sequences} are implemented using message sends combined with block.
\subsection{Conditionals}
\textit{If condition} works by using messages defined in \texttt{boolean} (or \texttt{boolean traits}) objects:
\vspace*{0.2cm}
\small{\begin{tabular}{ p{70pt} p{140pt} l l }
Message & Description
\\\hline\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{obj ifTrue: b}
&
Execute \texttt{b} if the \textit{obj} is \texttt{true}.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\texttt{obj\ ifFalse:\ b}
&
Execute \texttt{b} if the \textit{obj} is \texttt{false}.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\nointerlineskip
\begin{lstlisting}[aboveskip=0pt,belowskip=-0.8 \baselineskip]
obj ifTrue: b1
False: b2
\end{lstlisting}
&
\textit{b1} is executed, when \textit{obj} evaluates to \texttt{true}.
If not, (optional) \textit{b2} block is used.
\\\hline %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\nointerlineskip
\begin{lstlisting}[aboveskip=-8pt,belowskip=-0.8 \baselineskip]
obj ifFalse: b1
True: b2
\end{lstlisting}
&
Opposite of previous.
\\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tabular}}
\subsection{Loops}
Looping is implemented by sending various loop messages to \textit{block objects}:
\begin{lstlisting}
[ ... ] loop
\end{lstlisting}
Loop over the \textit{block} indefinitely.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
[ proceed ] whileTrue: [ ... ]
\end{lstlisting}
Loop while \texttt{proceed} is \texttt{true}.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
[ quit ] whileFalse: [ ... ]
\end{lstlisting}
Loop while \texttt{quit} is \texttt{false}.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
[ ... ] untilTrue: [ quit ]
\end{lstlisting}
Loop until \texttt{quit} is \texttt{true}. Loop at least once.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
[ ... ] untilFalse: [ proceed ]
\end{lstlisting}
Loop until \texttt{proceed} is \texttt{false}. Loop at least once.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
[| :exit | ... cond ifTrue: exit ... ] loopExit
\end{lstlisting}
Loop until the \texttt{exit} parameter is not evaluated.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
[
| :exit |
...
cond ifTrue: [ exit value: expr ]
] loopExitValue
\end{lstlisting}
Loop until the \texttt{exit} parameter is not evaluated. Allows to return the \texttt{value} with the exit from the loop.
\subsubsection{integerIteration loops}
There is also loops defined as message sends to integers:
\begin{lstlisting}
numObj do: block
\end{lstlisting}
Do the \texttt{block} \textit{numObj} times.
\vspace*{0.2cm}
\hrule
\begin{lstlisting}
numObj to: end Do: block
\end{lstlisting}
Do the \texttt{block} each time counting from \textit{numObj} to \texttt{end}. For example \texttt{5\ to:\ 8\ Do:\ [|\ :i\ |\ i\ print]} will print \texttt{5678}.
Following messages are all variations of this message:
\begin{lstlisting}
numObj to: By: Do:
numObj to: ByNegative: Do:
numObj to: ByPositive: Do:
numObj upTo: Do:
numObj upTo: By: Do:
numObj downTo: Do:
numObj downTo: By: Do:
\end{lstlisting}
\section{Useful bits}
\subsection{copy message}
Often, you will need to create new instance of some object. What is in other languages implemented by calling \texttt{new}, or other processes calling the object builders is in prototype languages usually done by copying the object into new instance.
In Self, you may do this simply by sending the \texttt{copy} message:
\begin{lstlisting}
obj copy
\end{lstlisting}
\subsection{Interpreter parameters}
When you run the Self interpreter on the \textit{commandline}, it expects that you specify the path to the \textit{World snapshot}. That may be supplied using \texttt{-s} parameter.
Self \textit{worlds} are images for the virtual machine. You may use the official, but there is nothing that prevents you to create your own, with or without Graphical User Interface.
\subsection{Self's REPL}
When you run your world, it is easy to forget, that Self's interpreter also provides you with Read Eval Print Loop in the terminal. This allows you to send messages like if you were in the Shell in GUI. For example, if no windows opens, or the \textit{desktop} crashes, you may open it by sending:
\begin{lstlisting}
desktop open
\end{lstlisting}
\texttt{CTRL+c} will bring the scheduler, where you may kill processes.
You may also \href{http://handbook.selflanguage.org/4.5/textdebug.html}{debug} processes using \texttt{debugger\ attach:\ N}.
\vfill
\columnbreak
\section{Additional informations}
\subsection{Download}
Newest Self may be downloaded from the official web:
\begin{itemize}[noitemsep]
\item \url{http://selflanguage.org}
\end{itemize}
Source code may be obtained from the GitHub:
\begin{itemize}[noitemsep]
\item \url{https://github.com/russellallen/self}
\end{itemize}
\subsection{Manual and tutorial}
There is good manual called Self handbook:
\begin{itemize}[noitemsep]
\item \href{http://handbook.selflanguage.org/4.5/}{Self Handbook} (online)
\item \href{https://dl.dropboxusercontent.com/u/11891854/tmp/ebooks/Self/SelfHandbook.pdf}{Self Handbook} (pdf)
\item \href{https://dl.dropboxusercontent.com/u/11891854/tmp/ebooks/Self/SelfHandbook.epub}{Self Handbook} (ePub)
\end{itemize}
This \textit{Cheat sheet} was created with high inspiration from this book.
If one of the links doesn't work, you may always build it for yourself from sources (\texttt{/docs/handbook}) using Sphinx (\texttt{make} \texttt{html} / \texttt{pdf} / \texttt{epub}).
There is also slightly outdated Self tutorial (\texttt{/docs/tutorial}) called \href{http://kitakitsune.org/bhole/self_tutorial/}{\footnotesize Prototype-Based Application Construction Using SELF 4.0}.
\subsection{Other writings}
There is blog:
\begin{itemize}[noitemsep]
\item \url{http://blog.selflanguage.org}
\end{itemize}
and also a lot of academic papers:
\begin{itemize}[noitemsep]
\item \url{http://bibliography.selflanguage.org}
\end{itemize}
\subsection{Community}
There is not-quite dead IRC channel \texttt{\#self-lang} at \texttt{irc://freenode.org:6667}.
There is also forum at:
\begin{itemize}[noitemsep]
\item \url{http://forum.selflanguage.org/}
\end{itemize}
If the forum doesn't work, don't worry, it is just frontend for mail conference \href{https://groups.yahoo.com/neo/groups/self-interest/info}{[email protected]}.
\subsection{Disclaimer}
I did this as my notes while learning Self. That means, that there will be typos and bugs. If you find any, please send pull request.
Self may seem dead, but it is not. There is not much active people, but that only means, that you can make difference.
% Footer
\vspace*{0.4cm}
\hrule
\smallskip
{\small
This file may be freely distributed under
the terms of the MIT license ---
Copyleft \textcopyleft\ \thedate{} \href{http://kitakitsune.org}{\theauthor}. Version 1.1 (07.03.2016).
\url{https://github.com/Bystroushaak/SelfCheatSheet}
}
\end{multicols*}
\end{document}