Pharo: Syntax in aNutshellS. Ducasse and M. Denkerhttp://www.pharo-project.org
Less is better No constructors No types declaration No interfaces No packages/private/protected No parametrized types No b...
Objects are instances of Classes
Objects are instances of Classes(10@200)
Objects are instances of Classes(10@200) class
Objects are instances of Classes(10@200) classPoint
Classes are objects too
Classes are objects tooPoint selectors
Classes are objects tooPoint selectors> an IdentitySet(#eightNeighbors #+ #isZero#sortsBefore: #degrees #printOn: #sideOf:...
Classes are objects tooPoint instVarNames
Classes are objects tooPoint instVarNames>#(x y)
Methods are public
Instance variables are protected
Single Inheritance
Single InheritanceObject subclass: #Point	   instanceVariableNames: x y	   classVariableNames: 	   category: Graphics-Prim...
Complete Syntax on a PostCardexampleWithNumber: x“A method that has unary, binary, and key word messages, declares argumen...
Language Constructs	^	    return “    comments#	     symbol or array ‘    string[ ]	   block or byte array.	     separator...
Syntaxcomment:      “a comment”character:	    $c $h $a $r $a $c $t $e $r $s $# $@string:       ‘a nice string’ ‘lulu’ ‘l’’...
3 kinds of messages                  5 factorialUnary messages    Transcript crBinary messages     3 + 4Keywords messages ...
A typical method in PointMethod name   Argument          Comment   <= aPoint   ! "Answer whether the receiver is neither  ...
Blocks• Anonymous method• Passed as method argument or stored• Functions  	 	     fct(x)= x*x+3, fct(2).  	 	     fct :=[:...
Block usage  Integer>>factorial     | tmp |     tmp := 1.     2 to: self do: [:i| tmp := tmp * i]  #(1 2 3) do: [:each | e...
Statements and cascades    Temporary variables                           Statement        | p pen |        p := 100@100.  ...
Control structuresEvery control structure is realized by message sends      4 timesRepeat: [Beeper beep]        max: aNumb...
Simple and elegant
Upcoming SlideShare
Loading in …5
×

Pharo: Syntax in a Nutshell

2,066 views

Published on

Talk at fOSSa 2012: Pharo Syntax in a Nutshell

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,066
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
22
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Pharo: Syntax in a Nutshell

  1. 1. Pharo: Syntax in aNutshellS. Ducasse and M. Denkerhttp://www.pharo-project.org
  2. 2. Less is better No constructors No types declaration No interfaces No packages/private/protected No parametrized types No boxing/unboxing And really powerful
  3. 3. Objects are instances of Classes
  4. 4. Objects are instances of Classes(10@200)
  5. 5. Objects are instances of Classes(10@200) class
  6. 6. Objects are instances of Classes(10@200) classPoint
  7. 7. Classes are objects too
  8. 8. Classes are objects tooPoint selectors
  9. 9. Classes are objects tooPoint selectors> an IdentitySet(#eightNeighbors #+ #isZero#sortsBefore: #degrees #printOn: #sideOf:#fourNeighbors #hash #roundUpTo: #min: #min:max:#max #adaptToCollection:andSend: #quadrantOf:
  10. 10. Classes are objects tooPoint instVarNames
  11. 11. Classes are objects tooPoint instVarNames>#(x y)
  12. 12. Methods are public
  13. 13. Instance variables are protected
  14. 14. Single Inheritance
  15. 15. Single InheritanceObject subclass: #Point instanceVariableNames: x y classVariableNames: category: Graphics-Primitives
  16. 16. Complete Syntax on a PostCardexampleWithNumber: x“A method that has unary, binary, and key word messages, declares arguments andtemporaries (but not block temporaries), accesses a global variable (but not andinstance variable), uses literals (array, character, symbol, string, integer, float), uses thepseudo variable true false, nil, self, and super, and has sequence, assignment, returnand cascade. It has both zero argument and one argument blocks.” |y| true & false not & (nil isNil) ifFalse: [self halt]. y := self size + super size. #($a #a ‘a’ 1 1.0) do: [:each | Transcript show: (each class name); show: (each printString); show: ‘ ‘]. ^x<y
  17. 17. Language Constructs ^ return “ comments# symbol or array ‘ string[ ] block or byte array. separator and not terminator (or namespace access in VW); cascade (sending several messages to the same instance)| local or block variable
  18. 18. Syntaxcomment: “a comment”character: $c $h $a $r $a $c $t $e $r $s $# $@string: ‘a nice string’ ‘lulu’ ‘l’’idiot’symbol: #mac #+array: #(1 2 3 (1 3) $a 4)byte array: #[1 2 3]integer: 1, 2r101real: 1.5, 6.03e-34,4, 2.4e7float: 1/33boolean: true, falsepoint: 10@120
  19. 19. 3 kinds of messages 5 factorialUnary messages Transcript crBinary messages 3 + 4Keywords messages 3 raisedTo: 10 modulo: 5 Transcript show: hello world
  20. 20. A typical method in PointMethod name Argument Comment <= aPoint ! "Answer whether the receiver is neither ! below nor to the right of aPoint." ! ^ x <= aPoint x and: [y <= aPoint y] Return Binary message Block Instance variable Keyword message (2@3) <= (5@6) true
  21. 21. Blocks• Anonymous method• Passed as method argument or stored• Functions fct(x)= x*x+3, fct(2). fct :=[:x| x * x + 3]. fct value: 2
  22. 22. Block usage Integer>>factorial | tmp | tmp := 1. 2 to: self do: [:i| tmp := tmp * i] #(1 2 3) do: [:each | each crLog]
  23. 23. Statements and cascades Temporary variables Statement | p pen | p := 100@100. pen := Pen new. pen up. pen goto: p; down; goto: p+p Cascade
  24. 24. Control structuresEvery control structure is realized by message sends 4 timesRepeat: [Beeper beep] max: aNumber ! ^ self < aNumber ! ! ifTrue: [aNumber] ! ! ifFalse: [self]
  25. 25. Simple and elegant

×