Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Self (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Basic syntax === The syntax for accessing slots is similar to that of Smalltalk. Three kinds of messages are available: ;unary : <code>''receiver'' slot_name</code> ;binary : <code>''receiver'' + ''argument''</code> ;keyword : <code>''receiver'' keyword: ''arg1'' With: ''arg2''</code> All messages return results, so the receiver (if present) and arguments can be themselves the result of other messages. Following a message by a period means Self will discard the returned value. For example: <syntaxhighlight lang="smalltalk">'Hello, World!' print.</syntaxhighlight> This is the Self version of the [["Hello, World!" program]]. The <code>'</code> syntax indicates a literal string object. Other literals include numbers, blocks and general objects. Grouping can be forced by using parentheses. In the absence of explicit grouping, the unary messages are considered to have the highest precedence followed by binary (grouping left to right) and the keywords having the lowest. The use of keywords for assignment would lead to some extra parenthesis where expressions also had keyword messages, so to avoid that Self requires that the first part of a keyword message selector start with a lowercase letter, and subsequent parts start with an uppercase letter. <syntaxhighlight lang="smalltalk">valid: base bottom between: ligature bottom + height And: base top / scale factor.</syntaxhighlight> can be parsed unambiguously, and means the same as: <syntaxhighlight lang="smalltalk">valid: ((base bottom) between: ((ligature bottom) + height) And: ((base top) / (scale factor))).</syntaxhighlight> In Smalltalk-80, the same expression would be written as: <syntaxhighlight lang="smalltalk">valid := self base bottom between: self ligature bottom + self height and: self base top / self scale factor.</syntaxhighlight> assuming <code>base</code>, <code>ligature</code>, <code>height</code> and <code>scale</code> were not [[instance variable]]s of <code>self</code> but were, in fact, methods.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)