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