SlideShare a Scribd company logo
Pharo: Syntax in a
Nutshell
S. Ducasse
http://www.pharo.org
No constructors
No types declaration
No interfaces
No packages/private/protected
No parametrized types
No boxing/unboxing
And really powerful
Less is More
Pharo Hands-On: 02 syntax
A Pure OO World
Only objects!
mouse, booleans, arrays, numbers, strings, windows, scrollbars, canvas, files, trees, compilers, sound, url, socket, fonts, text,
collections, stack, shortcut, streams, …
3 kinds of messages
Unary messages
Binary messages
Keywords messages
5 factorial!
Transcript cr
3 + 4
2 between: 0 and: 5!
!
Transcript show: 'hello world'
postman.send(mail,recipient);
postman.send(mail,recipient);
postman send mail recipient
postman send mail to recipient
postman send: mail to: recipient
() > Unary > Binary >
Keywords
!
1 class maxVal + 1
(1 class maxVal + 1) class
1 class maxVal raised: 3+ 2
Typical Expression
ZnEasy client
	 url: 'http://bugs.pharo.org/issues/name/', text asString;
	 get;
	 response.
Some basic objects
String: 'a string'
Symbole (unique String): #aSymbol
Character: $A
Array: #(1 2 3) { 1 . 2 . 3}
OrderedCollection: OrderedCollection new add: 35;
add: 45; yourself
Set: Set new add: 1; add: 2; yourself
yourself?
	 Set new add: 1; add: 2; yourself
is equivalent to
	 | s |
	 s := Set new.
	 s add: 1; add: 2.
	 s
Block: Lambda Expressions
[ :x | x + 2 ] value: 5
	 -> 7
!
anonymous method
[ ]
:x is the block arguments
Blocks can be stored
| b |
b := [ :x | x + 2 ].
b value: 5
	 -> 7
b value: 33
	 -> 35
Conditionals: ifTrue:ifFalse:
Booleans are objects
Conditional are messages sent to booleans or block
!
!
	 	 initialAnswer := fullName isEmptyOrNil
	 	 	 ifTrue: ['FirstnameLastname' translated]
	 	 	 ifFalse: [fullName].
ifTrue:
forceItalicOrOblique
	 	 self slantValue = 0 ifTrue: [ slantValue := 1 ]
ifFalse:ifTrue:
	 index = 0
	 	 ifFalse: [values at: index]
	 	 ifTrue: [self privateAt: key put: aBlock value]
ifEmpty:
(myProtocol
	 ifEmpty: ['As yet unclassified’]
!
self listItems
	 	 ifNotEmpty: [ :aList | aList at: currentIndex ]
Use [ ] when you do not know how many time it is
executed.
( x isNil) ifTrue: [ .... ]
( ...) vs. [ ]
Some loops
	4 timesRepeat: [ self doSomething ]
	0 to: 100 [ :i | ... ]
	0 to: 100 by: 3 [ :i | ... ]
	aCol do: [:each | ... ]
Some loops: to:by:do:
| sum |
0 to: 100 by: 3 [ :i | sum= sum + i ]
#(15 10 19 68) do:
[:i | Transcript show: i ; cr ]
#(15 10 19 68) do:
[:i | Transcript show: i ; cr ]
#(2 -3 4 -35 4) collect: [ :each| each abs]
#(2 -3 4 -35 4) collect: [ :each| each abs]
> #(2 3 4 35 4)
Defining a method
(2@3) <= (5@6)
!
<= aPoint
	 "Answer whether the receiver is neither below nor to
the right of aPoint."
	 ^ x <= aPoint x and: [y <= aPoint y]
Class definition
Object subclass: #Point
	 instanceVariableNames: 'x y'
	 classVariableNames: ''
	 category: 'Graphics-Primitives'
Conclusion
Messages (unary, binary, keywords)
Blocks
Methods are named blocks

More Related Content

PDF
Pharo Hands-on: 05 object model
Pharo
 
PDF
Calypso browser
Denis Kudryashov
 
PDF
Introduction To Scala
Peter Maas
 
PPTX
scala-101
Joe Conley
 
PPTX
Ios development
elnaqah
 
PDF
StringTokenizer in java
Muthukumaran Subramanian
 
PDF
Ponies and Unicorns With Scala
Tomer Gabel
 
PDF
From android/java to swift (3)
allanh0526
 
Pharo Hands-on: 05 object model
Pharo
 
Calypso browser
Denis Kudryashov
 
Introduction To Scala
Peter Maas
 
scala-101
Joe Conley
 
Ios development
elnaqah
 
StringTokenizer in java
Muthukumaran Subramanian
 
Ponies and Unicorns With Scala
Tomer Gabel
 
From android/java to swift (3)
allanh0526
 

What's hot (18)

PPTX
introduction to c #
Sireesh K
 
PDF
Metaprogramming in Ruby
Nicolò Calcavecchia
 
KEY
Metaprogramming Primer (Part 1)
Christopher Haupt
 
PPTX
Secure code 3rd_party_libs
FKM Naimul Huda, PMP
 
PDF
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
Pôle Systematic Paris-Region
 
PPT
Java
Manav Prasad
 
PPT
JVM and OOPS Introduction
SATYAM SHRIVASTAV
 
PPT
10 - OOP - Inheritance (a)
The World of Smalltalk
 
PPT
string tokenization
JayabalanRajalakshmi
 
PPTX
30csharp
Sireesh K
 
PDF
Swift 3 Programming for iOS : extension
Kwang Woo NAM
 
PDF
Introduction to Swift 2
Joris Timmerman
 
PDF
Scala Types of Types @ Lambda Days
Konrad Malawski
 
PDF
Head First Java Chapter 1
Tom Henricksen
 
PPT
Lesson3
Arpan91
 
PDF
Python in 90 minutes
Bardia Heydari
 
PPTX
32sql server
Sireesh K
 
PPT
Reversing JavaScript
Roberto Suggi Liverani
 
introduction to c #
Sireesh K
 
Metaprogramming in Ruby
Nicolò Calcavecchia
 
Metaprogramming Primer (Part 1)
Christopher Haupt
 
Secure code 3rd_party_libs
FKM Naimul Huda, PMP
 
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
Pôle Systematic Paris-Region
 
JVM and OOPS Introduction
SATYAM SHRIVASTAV
 
10 - OOP - Inheritance (a)
The World of Smalltalk
 
string tokenization
JayabalanRajalakshmi
 
30csharp
Sireesh K
 
Swift 3 Programming for iOS : extension
Kwang Woo NAM
 
Introduction to Swift 2
Joris Timmerman
 
Scala Types of Types @ Lambda Days
Konrad Malawski
 
Head First Java Chapter 1
Tom Henricksen
 
Lesson3
Arpan91
 
Python in 90 minutes
Bardia Heydari
 
32sql server
Sireesh K
 
Reversing JavaScript
Roberto Suggi Liverani
 
Ad

Viewers also liked (11)

PDF
Pharo devnology20150401
Stephan Eggermont
 
PDF
The Pharo Programming Language
bergel
 
PDF
Pharo: Objects at your Fingertips
Marcus Denker
 
PDF
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 
PDF
2008 Sccc Smalltalk
bergel
 
PPTX
Squeak & Pharo @ NYC Smalltalk
SeanDeNigris
 
PDF
Pharo tutorial at ECOOP 2013
Pharo
 
PDF
Pharo Roadmap
ESUG
 
PDF
You Can’t Do That With Smalltalk!
ESUG
 
PDF
Haskell vs. F# vs. Scala
pt114
 
PPT
Stoop 432-singleton
The World of Smalltalk
 
Pharo devnology20150401
Stephan Eggermont
 
The Pharo Programming Language
bergel
 
Pharo: Objects at your Fingertips
Marcus Denker
 
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 
2008 Sccc Smalltalk
bergel
 
Squeak & Pharo @ NYC Smalltalk
SeanDeNigris
 
Pharo tutorial at ECOOP 2013
Pharo
 
Pharo Roadmap
ESUG
 
You Can’t Do That With Smalltalk!
ESUG
 
Haskell vs. F# vs. Scala
pt114
 
Stoop 432-singleton
The World of Smalltalk
 
Ad

Similar to Pharo Hands-On: 02 syntax (20)

PDF
2013 lecture-02-syntax shortnewcut
Pharo
 
PDF
Pharo: Syntax in a Nutshell
Marcus Denker
 
PDF
Trafaret: monads and python
Mikhail Krivushin
 
PPSX
Java Tutorial
Akash Pandey
 
PDF
Introduction to clojure
Abbas Raza
 
KEY
Pharo, an innovative and open-source Smalltalk
Serge Stinckwich
 
PPTX
Type script - advanced usage and practices
Iwan van der Kleijn
 
PPTX
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
PDF
XAML/C# to HTML/JS
Michael Haberman
 
PDF
Presentation pythonpppppppppppppppppppppppppppppppppyyyyyyyyyyyyyyyyyyytttttt...
manikbuma
 
PDF
Elm dev front-end
Helder Pinto
 
PPTX
“Insulin” for Scala’s Syntactic Diabetes
Tzach Zohar
 
PDF
So I am writing a CS code for a project and I keep getting cannot .pdf
ezonesolutions
 
PDF
Scala Paradigms
Tom Flaherty
 
KEY
Cassandra Client Tutorial
Joe McTee
 
PDF
Quick swift tour
Kazunobu Tasaka
 
PDF
Introduction to Python for Plone developers
Jim Roepcke
 
PDF
Ruby Language - A quick tour
aztack
 
PDF
Ur Domain Haz Monoids DDDx NYC 2014
Cyrille Martraire
 
PPT
Java Tutorial
Vijay A Raj
 
2013 lecture-02-syntax shortnewcut
Pharo
 
Pharo: Syntax in a Nutshell
Marcus Denker
 
Trafaret: monads and python
Mikhail Krivushin
 
Java Tutorial
Akash Pandey
 
Introduction to clojure
Abbas Raza
 
Pharo, an innovative and open-source Smalltalk
Serge Stinckwich
 
Type script - advanced usage and practices
Iwan van der Kleijn
 
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
XAML/C# to HTML/JS
Michael Haberman
 
Presentation pythonpppppppppppppppppppppppppppppppppyyyyyyyyyyyyyyyyyyytttttt...
manikbuma
 
Elm dev front-end
Helder Pinto
 
“Insulin” for Scala’s Syntactic Diabetes
Tzach Zohar
 
So I am writing a CS code for a project and I keep getting cannot .pdf
ezonesolutions
 
Scala Paradigms
Tom Flaherty
 
Cassandra Client Tutorial
Joe McTee
 
Quick swift tour
Kazunobu Tasaka
 
Introduction to Python for Plone developers
Jim Roepcke
 
Ruby Language - A quick tour
aztack
 
Ur Domain Haz Monoids DDDx NYC 2014
Cyrille Martraire
 
Java Tutorial
Vijay A Raj
 

More from Pharo (20)

PDF
Yesplan: 10 Years later
Pharo
 
PDF
Object-Centric Debugging: a preview
Pharo
 
PDF
The future of testing in Pharo
Pharo
 
PDF
Spec 2.0: The next step on desktop UI
Pharo
 
PDF
UI Testing with Spec
Pharo
 
PDF
Pharo 7.0 and 8.0 alpha
Pharo
 
PDF
PHARO IoT: Installation Improvements and Continuous Integration
Pharo
 
PDF
Easy REST with OpenAPI
Pharo
 
PDF
Comment soup with a pinch of types, served in a leaky bowl
Pharo
 
PDF
apart Framework: Porting from VisualWorks
Pharo
 
PDF
XmppTalk
Pharo
 
PDF
A living programming environment for blockchain
Pharo
 
PDF
Raspberry and Pharo
Pharo
 
PDF
Welcome: PharoDays 2017
Pharo
 
PDF
Pharo 6
Pharo
 
PDF
Robotic Exploration and Mapping with Pharo
Pharo
 
PDF
Pharo 64bits
Pharo
 
PDF
Smack: Behind the Refactorings
Pharo
 
PDF
Pharo VM Performance
Pharo
 
PDF
Git with Style
Pharo
 
Yesplan: 10 Years later
Pharo
 
Object-Centric Debugging: a preview
Pharo
 
The future of testing in Pharo
Pharo
 
Spec 2.0: The next step on desktop UI
Pharo
 
UI Testing with Spec
Pharo
 
Pharo 7.0 and 8.0 alpha
Pharo
 
PHARO IoT: Installation Improvements and Continuous Integration
Pharo
 
Easy REST with OpenAPI
Pharo
 
Comment soup with a pinch of types, served in a leaky bowl
Pharo
 
apart Framework: Porting from VisualWorks
Pharo
 
XmppTalk
Pharo
 
A living programming environment for blockchain
Pharo
 
Raspberry and Pharo
Pharo
 
Welcome: PharoDays 2017
Pharo
 
Pharo 6
Pharo
 
Robotic Exploration and Mapping with Pharo
Pharo
 
Pharo 64bits
Pharo
 
Smack: Behind the Refactorings
Pharo
 
Pharo VM Performance
Pharo
 
Git with Style
Pharo
 

Recently uploaded (20)

PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
The Future of Artificial Intelligence (AI)
Mukul
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 

Pharo Hands-On: 02 syntax