SlideShare a Scribd company logo
Pharo: Syntax in a
Nutshell
S. Ducasse and M. Denker
http://www.pharo-project.org
Less is better

 No constructors
 No types declaration
 No interfaces
 No packages/private/protected
 No parametrized types
 No boxing/unboxing
 And really powerful
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) class

Point
Classes are objects too
Classes are objects too



Point selectors
Classes are objects too



Point selectors


> an IdentitySet(#eightNeighbors #+ #isZero
#sortsBefore: #degrees #printOn: #sideOf:
#fourNeighbors #hash #roundUpTo: #min: #min:max:
#max #adaptToCollection:andSend: #quadrantOf:
Classes are objects too



Point instVarNames
Classes are objects too



Point instVarNames

>#('x' 'y')
Methods are public
Instance variables are protected
Single Inheritance
Single Inheritance
Object subclass: #Point

	   instanceVariableNames: 'x y'

	   classVariableNames: ''

	   category: 'Graphics-Primitives'
Complete Syntax on a PostCard
exampleWithNumber: x

“A method that has unary, binary, and key word messages, declares arguments and
temporaries (but not block temporaries), accesses a global variable (but not and
instance variable), uses literals (array, character, symbol, string, integer, float), uses the
pseudo variable true false, nil, self, and super, and has sequence, assignment, return
and 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
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
Syntax
comment:
      “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, 2r101
real:	         1.5, 6.03e-34,4, 2.4e7
float:          1/33
boolean:       true, false
point:	        10@120
3 kinds of messages
                  5 factorial
Unary messages    Transcript cr


Binary messages     3 + 4


Keywords messages
             3 raisedTo: 10 modulo: 5

             Transcript show: 'hello world'
A typical method in Point
Method 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
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
Block usage

  Integer>>factorial
     | tmp |
     tmp := 1.
     2 to: self do: [:i| tmp := tmp * i]


  #(1 2 3) do: [:each | each crLog]
Statements and cascades

    Temporary variables
                           Statement
        | p pen |
        p := 100@100.
        pen := Pen new.
        pen up.
        pen goto: p; down; goto: p+p


                          Cascade
Control structures
Every control structure is realized by message sends
      4 timesRepeat: [Beeper beep]




        max: aNumber
        ! ^ self < aNumber
        ! !   ifTrue: [aNumber]
        ! !   ifFalse: [self]
Simple and elegant

More Related Content

PDF
Pharo: Objects at your Fingertips
PDF
2013 lecture-02-syntax shortnewcut
PPT
Introduction To C#
PPTX
PDF
Python basic
PPT
Lecture 1
PPTX
Introduction to Python Programming
PPTX
F# Eye 4 the C# Guy - DDD Cambridge Nights 2014
Pharo: Objects at your Fingertips
2013 lecture-02-syntax shortnewcut
Introduction To C#
Python basic
Lecture 1
Introduction to Python Programming
F# Eye 4 the C# Guy - DDD Cambridge Nights 2014

What's hot (20)

PPT
C# basics
PPTX
Meta Object Protocols
PPTX
002. Introducere in type script
PPTX
F# for C# devs - Copenhagen .Net 2015
PPTX
Python Basics
PDF
2nd puc computer science chapter 8 function overloading
PPTX
Hack programming language
ODP
Domain Specific Languages In Scala Duse3
DOCX
PYTHON NOTES
 
PPT
Ruby For Java Programmers
PDF
Basic Concepts in Python
PPTX
Python basics
PPSX
Programming with Python
PPTX
Python Session - 4
PPTX
Loops in Python
PPSX
Esoft Metro Campus - Certificate in java basics
PDF
Compiler Construction | Lecture 7 | Type Checking
PPTX
Python advance
PDF
Let’s Learn Python An introduction to Python
C# basics
Meta Object Protocols
002. Introducere in type script
F# for C# devs - Copenhagen .Net 2015
Python Basics
2nd puc computer science chapter 8 function overloading
Hack programming language
Domain Specific Languages In Scala Duse3
PYTHON NOTES
 
Ruby For Java Programmers
Basic Concepts in Python
Python basics
Programming with Python
Python Session - 4
Loops in Python
Esoft Metro Campus - Certificate in java basics
Compiler Construction | Lecture 7 | Type Checking
Python advance
Let’s Learn Python An introduction to Python
Ad

Similar to Pharo: Syntax in a Nutshell (20)

PDF
The Pharo Programming Language
PPT
5 - OOP - Smalltalk in a Nutshell (c)
PDF
Smalltalk Bar Camp Hanoi 2009
PPT
8 - OOP - Syntax & Messages
PDF
Pharo: Objects at your Fingertips
PDF
7li7w devcon5
KEY
Pharo, an innovative and open-source Smalltalk
PDF
Pharo Hands-On: 02 syntax
PPT
5 - OOP - Smalltalk in a Nutshell (b)
PDF
Intro to io
PDF
Pharo tutorial at ECOOP 2013
PDF
Pharo tutorial at ECOOP 2013
PPT
5 - OOP - Smalltalk in a Nutshell (a)
PDF
Clojure for Rubyists
PPTX
Ruby introduction part1
PDF
Smalltalk, the dynamic language
PPT
Reliable and Concurrent Software - Erlang
PDF
Continuation Passing Style and Macros in Clojure - Jan 2012
PDF
Introduction to Ruby Programming Language
PDF
Introduction to clojure
The Pharo Programming Language
5 - OOP - Smalltalk in a Nutshell (c)
Smalltalk Bar Camp Hanoi 2009
8 - OOP - Syntax & Messages
Pharo: Objects at your Fingertips
7li7w devcon5
Pharo, an innovative and open-source Smalltalk
Pharo Hands-On: 02 syntax
5 - OOP - Smalltalk in a Nutshell (b)
Intro to io
Pharo tutorial at ECOOP 2013
Pharo tutorial at ECOOP 2013
5 - OOP - Smalltalk in a Nutshell (a)
Clojure for Rubyists
Ruby introduction part1
Smalltalk, the dynamic language
Reliable and Concurrent Software - Erlang
Continuation Passing Style and Macros in Clojure - Jan 2012
Introduction to Ruby Programming Language
Introduction to clojure
Ad

More from Marcus Denker (20)

PDF
Soil And Pharo
PDF
ConstantBlocks in Pharo11
PDF
Demo: Improved DoIt
PDF
First Class Variables as AST Annotations
PDF
Supporting Pharo / Getting Pharo Support
PDF
Lecture: "Advanced Reflection: MetaLinks"
PDF
thisContext in the Debugger
PDF
Variables in Pharo
PDF
Lecture. Advanced Reflection: MetaLinks
PDF
Improving code completion for Pharo
PDF
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
PDF
Slot Composition
PDF
Lecture: Advanced Reflection. MetaLinks
PDF
PHARO IOT
PDF
Open-Source: An Infinite Game
PDF
Lecture: MetaLinks
PDF
PharoTechTalk: Contributing to Pharo
PDF
Feedback Loops in Practice
PDF
Pharo6 - ESUG17
PDF
Soil And Pharo
ConstantBlocks in Pharo11
Demo: Improved DoIt
First Class Variables as AST Annotations
Supporting Pharo / Getting Pharo Support
Lecture: "Advanced Reflection: MetaLinks"
thisContext in the Debugger
Variables in Pharo
Lecture. Advanced Reflection: MetaLinks
Improving code completion for Pharo
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
Slot Composition
Lecture: Advanced Reflection. MetaLinks
PHARO IOT
Open-Source: An Infinite Game
Lecture: MetaLinks
PharoTechTalk: Contributing to Pharo
Feedback Loops in Practice
Pharo6 - ESUG17

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction
MIND Revenue Release Quarter 2 2025 Press Release
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The AUB Centre for AI in Media Proposal.docx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf

Pharo: Syntax in a Nutshell

  • 1. Pharo: Syntax in a Nutshell S. Ducasse and M. Denker http://www.pharo-project.org
  • 2. Less is better No constructors No types declaration No interfaces No packages/private/protected No parametrized types No boxing/unboxing And really powerful
  • 4. Objects are instances of Classes (10@200)
  • 5. Objects are instances of Classes (10@200) class
  • 6. Objects are instances of Classes (10@200) class Point
  • 8. Classes are objects too Point selectors
  • 9. Classes are objects too Point selectors > an IdentitySet(#eightNeighbors #+ #isZero #sortsBefore: #degrees #printOn: #sideOf: #fourNeighbors #hash #roundUpTo: #min: #min:max: #max #adaptToCollection:andSend: #quadrantOf:
  • 10. Classes are objects too Point instVarNames
  • 11. Classes are objects too Point instVarNames >#('x' 'y')
  • 15. Single Inheritance Object subclass: #Point instanceVariableNames: 'x y' classVariableNames: '' category: 'Graphics-Primitives'
  • 16. Complete Syntax on a PostCard exampleWithNumber: x “A method that has unary, binary, and key word messages, declares arguments and temporaries (but not block temporaries), accesses a global variable (but not and instance variable), uses literals (array, character, symbol, string, integer, float), uses the pseudo variable true false, nil, self, and super, and has sequence, assignment, return and 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. 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. Syntax comment: “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, 2r101 real: 1.5, 6.03e-34,4, 2.4e7 float: 1/33 boolean: true, false point: 10@120
  • 19. 3 kinds of messages 5 factorial Unary messages Transcript cr Binary messages 3 + 4 Keywords messages 3 raisedTo: 10 modulo: 5 Transcript show: 'hello world'
  • 20. A typical method in Point Method 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. 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. Block usage Integer>>factorial | tmp | tmp := 1. 2 to: self do: [:i| tmp := tmp * i] #(1 2 3) do: [:each | each crLog]
  • 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. Control structures Every control structure is realized by message sends 4 timesRepeat: [Beeper beep] max: aNumber ! ^ self < aNumber ! ! ifTrue: [aNumber] ! ! ifFalse: [self]