SlideShare a Scribd company logo
Functional Smalltalk
Dave Mason
Toronto Metropolitan University
©2022 Dave Mason
Value
I’m going to start with a quote from Kent Beck
Value
Software creates value 2 ways:
What it does today
What new things we can make it do tomorrow
Value
Software creates value 2 ways:
What it does today
What new things we can make it do tomorrow
Value
Software creates value 2 ways:
What it does today
What new things we can make it do tomorrow
Value
Smalltalk creates value 2 ways:
What it does today
What new things we can make it do tomorrow
Functional Smalltalk
Smalltalk already has many functional features
extensions by syntax
extensions by class
Functional Smalltalk
Smalltalk already has many functional features
extensions by syntax
extensions by class
Syntax: Functional Programming
Smalltalk has always had blocks - needed full closures
CompileWithCompose in Pharo-Functional repo
leverages class-bounded alternative compiler
just syntactic sugar - more succinct
all are upward compatible as they are currently syntax errors
Syntax: Functional Programming
Smalltalk has always had blocks - needed full closures
CompileWithCompose in Pharo-Functional repo
leverages class-bounded alternative compiler
just syntactic sugar - more succinct
all are upward compatible as they are currently syntax errors
Syntax: Functional Programming
Smalltalk has always had blocks - needed full closures
CompileWithCompose in Pharo-Functional repo
leverages class-bounded alternative compiler
just syntactic sugar - more succinct
all are upward compatible as they are currently syntax errors
Syntax: Functional Programming
Smalltalk has always had blocks - needed full closures
CompileWithCompose in Pharo-Functional repo
leverages class-bounded alternative compiler
just syntactic sugar - more succinct
all are upward compatible as they are currently syntax errors
Syntax: Functional Programming
Smalltalk has always had blocks - needed full closures
CompileWithCompose in Pharo-Functional repo
leverages class-bounded alternative compiler
just syntactic sugar - more succinct
all are upward compatible as they are currently syntax errors
Compose/pipe/parrot operator
very convenient to pass result of one expression to another
without parentheses
particularly convenient in PharoJS for e.g. D3
Compose/pipe/parrot operator
very convenient to pass result of one expression to another
without parentheses
particularly convenient in PharoJS for e.g. D3
1 foo
2 " s e l f new foo >>> 42 "
3 ↑ 17 negated
4 :> min: -53
5 :> abs
6 :> < 100
7 :> and: [ 4 > 2 ]
8 :> and: [ 5 < 10 ]
9 :> ifTrue: [ 42 ] ifFalse: [ 99 ]
Compose/pipe/parrot operator
very convenient to pass result of one expression to another
without parentheses
particularly convenient in PharoJS for e.g. D3
1 foo
2 " s e l f new foo >>> 42 "
3 ↑ 17 negated
4 :> min: -53
5 :> abs
6 :> < 100
7 :> and: [ 4 > 2 ]
8 :> and: [ 5 < 10 ]
9 :> ifTrue: [ 42 ] ifFalse: [ 99 ]
... Compose/pipe/parrot operator
The precedence is the same as cascade, so you can intermix them
and could say something like:
1 x := OrderedCollection new
2 add: 42;
3 add: 17;
4 yourself
5 :> collect: #negated
6 :> add: 35;
7 add: 99;
8 yourself
9 :> with: #(1 2 3 4) collect: [:l :r| l+r ]
10 :> max
... Compose/pipe/parrot operator
If you don’t want to use the alternate compiler (and get the :> syntax)
PharoFunctional also provides a chain method on Object that
supports chaining using cascades (unfortunately quite a bit slower
because it requires a DNU and perform for each chained message):
1 foo
2 " s e l f new foo >>> 42 "
3 ↑ 17 chain
4 negated
5 ; min: -53
6 ; abs
7 ; < 100
8 ; and: [ 4 > 2 ]
9 ; and: [ 5 < 10 ]
10 ; ifTrue: [ 42 ] ifFalse: [ 99 ]
Point-free programming style
popular style of functional programming
composing functions to build up operations with implicit
parameters
various ā€œcombinatorsā€ that recognize patterns in these
compositions
in Smalltalk this is composing symbols and blocks
e.g.
1 isPalindrome := #reverse <| > #= .
2 isPalindrome value: ’madam’
Point-free programming style
popular style of functional programming
composing functions to build up operations with implicit
parameters
various ā€œcombinatorsā€ that recognize patterns in these
compositions
in Smalltalk this is composing symbols and blocks
e.g.
1 isPalindrome := #reverse <| > #= .
2 isPalindrome value: ’madam’
Point-free programming style
popular style of functional programming
composing functions to build up operations with implicit
parameters
various ā€œcombinatorsā€ that recognize patterns in these
compositions
in Smalltalk this is composing symbols and blocks
e.g.
1 isPalindrome := #reverse <| > #= .
2 isPalindrome value: ’madam’
Point-free programming style
popular style of functional programming
composing functions to build up operations with implicit
parameters
various ā€œcombinatorsā€ that recognize patterns in these
compositions
in Smalltalk this is composing symbols and blocks
e.g.
1 isPalindrome := #reverse <| > #= .
2 isPalindrome value: ’madam’
Point-free programming style
popular style of functional programming
composing functions to build up operations with implicit
parameters
various ā€œcombinatorsā€ that recognize patterns in these
compositions
in Smalltalk this is composing symbols and blocks
e.g.
1 isPalindrome := #reverse <| > #= .
2 isPalindrome value: ’madam’
Expressions as unary or binary messages
To use point-free style, it is very convenient to have a more succinct
syntax for applying them
1 x (...)
2 x (...) + y
3 x (...): y
4 x (#sort <| > #=)
Converts to.
1 ([...] value: x)
2 ([...] value: x) + y
3 ([...] value: x value: y)
4 ((#sort <| > #=) value: x)
Blocks as unary or binary messages
You can do the same with unary or binary blocks. Because we know
the arity of blocks the trailing : isn’t used for block operators
1 x [:w| ...]
2 x [:w:z| ...] y
becomes
1 ([:w| ...] value: x)
2 ([:w:z| ...] value: x value: y)
Initializing local variables at point of declaration
Even in functional languages where mutation is possible, it is rarely
used. Instead programming is by a sequence of definitions, which
always have a value. I personally very much miss this in Smalltalk.
1 | w x := 42. y = x+5. z a |
is legal, but
1 | x := 42. y = x+5. z = 17 |
isn’t.
Collection literals
Arrays have a literal syntax {1 . 2 . 3}, but other collections don’t.
This extension recognizes :className immediately after the { and
translates, e.g.
1 {:Set 3 . 4 . 5 . 3}
2 {:Dictionary #a->1 . #b->2}
3 {:Set 1 . 2 . 3 . 4 . 5 . 6 . 7}
to
1 Set with: 3 with: 4 with: 5 with: 3
2 Dictionary with: #a->1 with: #b->2
3 Set withAll: {1 . 2 . 3 . 4 . 5 . 6 . 7}
Destructuring collections
There isn’t a convenient way to return multiple values from a method,
or even to extract multiple values from a collection. For example:
1 :| a b c | := some-collection
destructures the 3 elements of a SequenceableCollection or would
extract the value of keys #a #b etc. if it was a Dictionary, with anything
else being a runtime error. This is conveniently done by converting that
to:
1 ([:temp|
2 a := temp firstNamed: #a.
3 b := temp secondNamed: #b.
4 c := temp thirdNamed: #c.
5 temp] value: some-collection)
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Classes: Functional Programming
PharoFunctional adds several new classes and a variety of extension
methods to facilitate functional programming.
curry: and @@
value:, value:value: and cull, etc. for Symbol
map:, map:map: for BlockClosure and Symbol
<*> and other combinators for BlockClosure and Symbol
nilOr:, emptyOrNilOr:
Slice, Pair and Tuple, ZippedCollection
zip:, >===<
iota
many algorithms on collections: rotate:, slide:, product,
allEqual, unique, isUnique, groupByRunsEqual:,
groupByRunsTrue:
Demo
Using CompileWithCompose
1 Metacello new
2 baseline: ’PharoFunctional’;
3 repository: ’github://dvmason/Pharo-Functional:ma
4 load: #compiler
Then for any class heirarchy, add a trait:
1 RBScannerTest subclass: #ComposeExampleTest
2 uses: ComposeSyntax
3 instanceVariableNames: ’’
4 classVariableNames: ’’
5 package: ’CompileWithCompose-Tests’
Or, on the class-side define the following method:
1 compilerClass
2 " Answer a compiler c l a s s a p p r o p r i a t e f o r source
3 ↑ ComposeCompiler
You can use this second approach if you want to add it to the entire
image (including in playgrounds), by defining this in Object class.
Conclusions
Smalltalk already has the fundamentals for functional
programming
some simple syntactic suger can make it a lot more pleasant
I would love it if some of these became mainstream (with no
backward compatibility issues)
in the meantime, anyone can add this to their Pharo
the compiler tweaks are not hard for other Smalltalks to implement
Conclusions
Smalltalk already has the fundamentals for functional
programming
some simple syntactic suger can make it a lot more pleasant
I would love it if some of these became mainstream (with no
backward compatibility issues)
in the meantime, anyone can add this to their Pharo
the compiler tweaks are not hard for other Smalltalks to implement
Conclusions
Smalltalk already has the fundamentals for functional
programming
some simple syntactic suger can make it a lot more pleasant
I would love it if some of these became mainstream (with no
backward compatibility issues)
in the meantime, anyone can add this to their Pharo
the compiler tweaks are not hard for other Smalltalks to implement
Conclusions
Smalltalk already has the fundamentals for functional
programming
some simple syntactic suger can make it a lot more pleasant
I would love it if some of these became mainstream (with no
backward compatibility issues)
in the meantime, anyone can add this to their Pharo
the compiler tweaks are not hard for other Smalltalks to implement
Conclusions
Smalltalk already has the fundamentals for functional
programming
some simple syntactic suger can make it a lot more pleasant
I would love it if some of these became mainstream (with no
backward compatibility issues)
in the meantime, anyone can add this to their Pharo
the compiler tweaks are not hard for other Smalltalks to implement
Questions?
@DrDaveMason dmason@ryerson.ca
https://github.com/dvmason/Pharo-Functional

More Related Content

What's hot (20)

PDF
How Fast is AI in Pharo? Benchmarking Linear Regression
ESUG
Ā 
PDF
Music With Pharo
ESUG
Ā 
PDF
Porting VisualWorks code to Pharo
ESUG
Ā 
PDF
Introducing GitLab (June 2018)
Noa Harel
Ā 
PDF
Guide tests fonctionnels
cvcby
Ā 
PDF
Introduction to Git and Github
Houari ZEGAI
Ā 
PDF
Introducing GitLab (September 2018)
Noa Harel
Ā 
PDF
Asynchronous JavaScript Programming
Haim Michael
Ā 
PPTX
Dart presentation
Lucas Leal
Ā 
PPTX
GitLab.pptx
LeoulZewelde1
Ā 
PDF
Git Workflow With Gitflow
Josh Dvir
Ā 
PPTX
What's new in Java 11
Michel Schudel
Ā 
PPT
Test plan
Sanjai San
Ā 
PPTX
Git
Shinu Suresh
Ā 
PPTX
Github basics
Radoslav Georgiev
Ā 
PPTX
Git & GitLab
Gaurav Wable
Ā 
PPTX
Uft Basics
Archana Krushnan
Ā 
PPTX
Git Lab Introduction
Krunal Doshi
Ā 
KEY
Introduction To Git
Arnaud Seilles
Ā 
PPTX
Hybrid automation framework
doai tran
Ā 
How Fast is AI in Pharo? Benchmarking Linear Regression
ESUG
Ā 
Music With Pharo
ESUG
Ā 
Porting VisualWorks code to Pharo
ESUG
Ā 
Introducing GitLab (June 2018)
Noa Harel
Ā 
Guide tests fonctionnels
cvcby
Ā 
Introduction to Git and Github
Houari ZEGAI
Ā 
Introducing GitLab (September 2018)
Noa Harel
Ā 
Asynchronous JavaScript Programming
Haim Michael
Ā 
Dart presentation
Lucas Leal
Ā 
GitLab.pptx
LeoulZewelde1
Ā 
Git Workflow With Gitflow
Josh Dvir
Ā 
What's new in Java 11
Michel Schudel
Ā 
Test plan
Sanjai San
Ā 
Github basics
Radoslav Georgiev
Ā 
Git & GitLab
Gaurav Wable
Ā 
Uft Basics
Archana Krushnan
Ā 
Git Lab Introduction
Krunal Doshi
Ā 
Introduction To Git
Arnaud Seilles
Ā 
Hybrid automation framework
doai tran
Ā 

Similar to Functional Smalltalk (20)

ODP
Aspect-oriented programming in Perl
megakott
Ā 
PDF
Swift, swiftly
Jack Nutting
Ā 
PDF
A Recovering Java Developer Learns to Go
Matt Stine
Ā 
PDF
The use of the code analysis library OpenC++: modifications, improvements, er...
PVS-Studio
Ā 
PDF
Google Interview Questions By Scholarhat
Scholarhat
Ā 
PDF
New features in Ruby 2.5
Ireneusz Skrobiś
Ā 
DOC
1183 c-interview-questions-and-answers
Akash Gawali
Ā 
PPTX
Matlab for diploma students(1)
Retheesh Raj
Ā 
PDF
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
Ā 
KEY
What's New In Python 2.4
Richard Jones
Ā 
PDF
EKON 12 Closures Coding
Max Kleiner
Ā 
PDF
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Puppet
Ā 
PDF
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
bobmcwhirter
Ā 
PPT
Andy On Closures
melbournepatterns
Ā 
PDF
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
Ā 
PPTX
Php
Rajkiran Mummadi
Ā 
ODP
Best practices tekx
Lorna Mitchell
Ā 
PDF
Sinatra and friends
Jiang Wu
Ā 
PPTX
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
Ā 
PPTX
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
Ā 
Aspect-oriented programming in Perl
megakott
Ā 
Swift, swiftly
Jack Nutting
Ā 
A Recovering Java Developer Learns to Go
Matt Stine
Ā 
The use of the code analysis library OpenC++: modifications, improvements, er...
PVS-Studio
Ā 
Google Interview Questions By Scholarhat
Scholarhat
Ā 
New features in Ruby 2.5
Ireneusz Skrobiś
Ā 
1183 c-interview-questions-and-answers
Akash Gawali
Ā 
Matlab for diploma students(1)
Retheesh Raj
Ā 
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
Ā 
What's New In Python 2.4
Richard Jones
Ā 
EKON 12 Closures Coding
Max Kleiner
Ā 
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Puppet
Ā 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
bobmcwhirter
Ā 
Andy On Closures
melbournepatterns
Ā 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
Ā 
Best practices tekx
Lorna Mitchell
Ā 
Sinatra and friends
Jiang Wu
Ā 
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
Ā 
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
Ā 
Ad

More from ESUG (20)

PDF
Selective Pretenuring and about allocation sites
ESUG
Ā 
PDF
ESUG 2025: Pharo 13 and Beyond (Stephane Ducasse)
ESUG
Ā 
PDF
ESUG 2025: Welcome to ESUG 2025 in Gdansk!
ESUG
Ā 
PDF
Words words words... Automatic detection of word repetition
ESUG
Ā 
PDF
ShowUs: Compiling with inlining Druid + Opal = DrOpal
ESUG
Ā 
PDF
Show us your Prokject #esug2024: "Gregg Shorthand"
ESUG
Ā 
PDF
Slides from ShowUs #esug2024: "QuickTalk: Multicultural Microwiki"
ESUG
Ā 
PDF
Pharo GitLab Example: This is a simple Pharo Smalltalk pipeline example
ESUG
Ā 
PDF
Show us your Project @ ESUG2024: Security cards
ESUG
Ā 
PDF
Phausto: fast and accessible DSP programming for sound and music creation in ...
ESUG
Ā 
PDF
Modest-Pharo: Unit Test Generation Based on Traces and Metamodels
ESUG
Ā 
PDF
GLOSS - A GLSP1 Model Server on the Smalltalk Platform
ESUG
Ā 
PDF
Smalltalk JIT Compilation: LLVM Experimentation
ESUG
Ā 
PDF
Towards resilience against highly dynamic challenges for Wireless Sensor Netw...
ESUG
Ā 
PDF
SoSAF: A Pharo-Based Framework for Enhancing System-Of-Systems Dependencies A...
ESUG
Ā 
PDF
Pyramidion : a framework for Domain-Specific Editor
ESUG
Ā 
PDF
Intentional Benchmarking of Dynamic Languages
ESUG
Ā 
PDF
MethodProxies: A Safe and Fast Message-Passing Control Library
ESUG
Ā 
PDF
Runtime Type Collection and its usage in Code Transpiling
ESUG
Ā 
PDF
Inlined Code Generation for Smalltalk. From IWST2024
ESUG
Ā 
Selective Pretenuring and about allocation sites
ESUG
Ā 
ESUG 2025: Pharo 13 and Beyond (Stephane Ducasse)
ESUG
Ā 
ESUG 2025: Welcome to ESUG 2025 in Gdansk!
ESUG
Ā 
Words words words... Automatic detection of word repetition
ESUG
Ā 
ShowUs: Compiling with inlining Druid + Opal = DrOpal
ESUG
Ā 
Show us your Prokject #esug2024: "Gregg Shorthand"
ESUG
Ā 
Slides from ShowUs #esug2024: "QuickTalk: Multicultural Microwiki"
ESUG
Ā 
Pharo GitLab Example: This is a simple Pharo Smalltalk pipeline example
ESUG
Ā 
Show us your Project @ ESUG2024: Security cards
ESUG
Ā 
Phausto: fast and accessible DSP programming for sound and music creation in ...
ESUG
Ā 
Modest-Pharo: Unit Test Generation Based on Traces and Metamodels
ESUG
Ā 
GLOSS - A GLSP1 Model Server on the Smalltalk Platform
ESUG
Ā 
Smalltalk JIT Compilation: LLVM Experimentation
ESUG
Ā 
Towards resilience against highly dynamic challenges for Wireless Sensor Netw...
ESUG
Ā 
SoSAF: A Pharo-Based Framework for Enhancing System-Of-Systems Dependencies A...
ESUG
Ā 
Pyramidion : a framework for Domain-Specific Editor
ESUG
Ā 
Intentional Benchmarking of Dynamic Languages
ESUG
Ā 
MethodProxies: A Safe and Fast Message-Passing Control Library
ESUG
Ā 
Runtime Type Collection and its usage in Code Transpiling
ESUG
Ā 
Inlined Code Generation for Smalltalk. From IWST2024
ESUG
Ā 
Ad

Recently uploaded (20)

PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
Ā 
PDF
Adobe Premiere Pro Crack / Full Version / Free Download
hashhshs786
Ā 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
Ā 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
Ā 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
Ā 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
Ā 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
Ā 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
Ā 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
Ā 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
Ā 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
Ā 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
Ā 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
Ā 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
Ā 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
Ā 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
Ā 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
Ā 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
Ā 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
Ā 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
Ā 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
Ā 
Adobe Premiere Pro Crack / Full Version / Free Download
hashhshs786
Ā 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
Ā 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
Ā 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
Ā 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
Ā 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
Ā 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
Ā 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
Ā 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
Ā 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
Ā 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
Ā 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
Ā 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
Ā 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
Ā 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
Ā 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
Ā 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
Ā 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
Ā 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
Ā 

Functional Smalltalk

  • 1. Functional Smalltalk Dave Mason Toronto Metropolitan University Ā©2022 Dave Mason
  • 2. Value I’m going to start with a quote from Kent Beck
  • 3. Value Software creates value 2 ways: What it does today What new things we can make it do tomorrow
  • 4. Value Software creates value 2 ways: What it does today What new things we can make it do tomorrow
  • 5. Value Software creates value 2 ways: What it does today What new things we can make it do tomorrow
  • 6. Value Smalltalk creates value 2 ways: What it does today What new things we can make it do tomorrow
  • 7. Functional Smalltalk Smalltalk already has many functional features extensions by syntax extensions by class
  • 8. Functional Smalltalk Smalltalk already has many functional features extensions by syntax extensions by class
  • 9. Syntax: Functional Programming Smalltalk has always had blocks - needed full closures CompileWithCompose in Pharo-Functional repo leverages class-bounded alternative compiler just syntactic sugar - more succinct all are upward compatible as they are currently syntax errors
  • 10. Syntax: Functional Programming Smalltalk has always had blocks - needed full closures CompileWithCompose in Pharo-Functional repo leverages class-bounded alternative compiler just syntactic sugar - more succinct all are upward compatible as they are currently syntax errors
  • 11. Syntax: Functional Programming Smalltalk has always had blocks - needed full closures CompileWithCompose in Pharo-Functional repo leverages class-bounded alternative compiler just syntactic sugar - more succinct all are upward compatible as they are currently syntax errors
  • 12. Syntax: Functional Programming Smalltalk has always had blocks - needed full closures CompileWithCompose in Pharo-Functional repo leverages class-bounded alternative compiler just syntactic sugar - more succinct all are upward compatible as they are currently syntax errors
  • 13. Syntax: Functional Programming Smalltalk has always had blocks - needed full closures CompileWithCompose in Pharo-Functional repo leverages class-bounded alternative compiler just syntactic sugar - more succinct all are upward compatible as they are currently syntax errors
  • 14. Compose/pipe/parrot operator very convenient to pass result of one expression to another without parentheses particularly convenient in PharoJS for e.g. D3
  • 15. Compose/pipe/parrot operator very convenient to pass result of one expression to another without parentheses particularly convenient in PharoJS for e.g. D3 1 foo 2 " s e l f new foo >>> 42 " 3 ↑ 17 negated 4 :> min: -53 5 :> abs 6 :> < 100 7 :> and: [ 4 > 2 ] 8 :> and: [ 5 < 10 ] 9 :> ifTrue: [ 42 ] ifFalse: [ 99 ]
  • 16. Compose/pipe/parrot operator very convenient to pass result of one expression to another without parentheses particularly convenient in PharoJS for e.g. D3 1 foo 2 " s e l f new foo >>> 42 " 3 ↑ 17 negated 4 :> min: -53 5 :> abs 6 :> < 100 7 :> and: [ 4 > 2 ] 8 :> and: [ 5 < 10 ] 9 :> ifTrue: [ 42 ] ifFalse: [ 99 ]
  • 17. ... Compose/pipe/parrot operator The precedence is the same as cascade, so you can intermix them and could say something like: 1 x := OrderedCollection new 2 add: 42; 3 add: 17; 4 yourself 5 :> collect: #negated 6 :> add: 35; 7 add: 99; 8 yourself 9 :> with: #(1 2 3 4) collect: [:l :r| l+r ] 10 :> max
  • 18. ... Compose/pipe/parrot operator If you don’t want to use the alternate compiler (and get the :> syntax) PharoFunctional also provides a chain method on Object that supports chaining using cascades (unfortunately quite a bit slower because it requires a DNU and perform for each chained message): 1 foo 2 " s e l f new foo >>> 42 " 3 ↑ 17 chain 4 negated 5 ; min: -53 6 ; abs 7 ; < 100 8 ; and: [ 4 > 2 ] 9 ; and: [ 5 < 10 ] 10 ; ifTrue: [ 42 ] ifFalse: [ 99 ]
  • 19. Point-free programming style popular style of functional programming composing functions to build up operations with implicit parameters various ā€œcombinatorsā€ that recognize patterns in these compositions in Smalltalk this is composing symbols and blocks e.g. 1 isPalindrome := #reverse <| > #= . 2 isPalindrome value: ’madam’
  • 20. Point-free programming style popular style of functional programming composing functions to build up operations with implicit parameters various ā€œcombinatorsā€ that recognize patterns in these compositions in Smalltalk this is composing symbols and blocks e.g. 1 isPalindrome := #reverse <| > #= . 2 isPalindrome value: ’madam’
  • 21. Point-free programming style popular style of functional programming composing functions to build up operations with implicit parameters various ā€œcombinatorsā€ that recognize patterns in these compositions in Smalltalk this is composing symbols and blocks e.g. 1 isPalindrome := #reverse <| > #= . 2 isPalindrome value: ’madam’
  • 22. Point-free programming style popular style of functional programming composing functions to build up operations with implicit parameters various ā€œcombinatorsā€ that recognize patterns in these compositions in Smalltalk this is composing symbols and blocks e.g. 1 isPalindrome := #reverse <| > #= . 2 isPalindrome value: ’madam’
  • 23. Point-free programming style popular style of functional programming composing functions to build up operations with implicit parameters various ā€œcombinatorsā€ that recognize patterns in these compositions in Smalltalk this is composing symbols and blocks e.g. 1 isPalindrome := #reverse <| > #= . 2 isPalindrome value: ’madam’
  • 24. Expressions as unary or binary messages To use point-free style, it is very convenient to have a more succinct syntax for applying them 1 x (...) 2 x (...) + y 3 x (...): y 4 x (#sort <| > #=) Converts to. 1 ([...] value: x) 2 ([...] value: x) + y 3 ([...] value: x value: y) 4 ((#sort <| > #=) value: x)
  • 25. Blocks as unary or binary messages You can do the same with unary or binary blocks. Because we know the arity of blocks the trailing : isn’t used for block operators 1 x [:w| ...] 2 x [:w:z| ...] y becomes 1 ([:w| ...] value: x) 2 ([:w:z| ...] value: x value: y)
  • 26. Initializing local variables at point of declaration Even in functional languages where mutation is possible, it is rarely used. Instead programming is by a sequence of definitions, which always have a value. I personally very much miss this in Smalltalk. 1 | w x := 42. y = x+5. z a | is legal, but 1 | x := 42. y = x+5. z = 17 | isn’t.
  • 27. Collection literals Arrays have a literal syntax {1 . 2 . 3}, but other collections don’t. This extension recognizes :className immediately after the { and translates, e.g. 1 {:Set 3 . 4 . 5 . 3} 2 {:Dictionary #a->1 . #b->2} 3 {:Set 1 . 2 . 3 . 4 . 5 . 6 . 7} to 1 Set with: 3 with: 4 with: 5 with: 3 2 Dictionary with: #a->1 with: #b->2 3 Set withAll: {1 . 2 . 3 . 4 . 5 . 6 . 7}
  • 28. Destructuring collections There isn’t a convenient way to return multiple values from a method, or even to extract multiple values from a collection. For example: 1 :| a b c | := some-collection destructures the 3 elements of a SequenceableCollection or would extract the value of keys #a #b etc. if it was a Dictionary, with anything else being a runtime error. This is conveniently done by converting that to: 1 ([:temp| 2 a := temp firstNamed: #a. 3 b := temp secondNamed: #b. 4 c := temp thirdNamed: #c. 5 temp] value: some-collection)
  • 29. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 30. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 31. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 32. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 33. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 34. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 35. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 36. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 37. Classes: Functional Programming PharoFunctional adds several new classes and a variety of extension methods to facilitate functional programming. curry: and @@ value:, value:value: and cull, etc. for Symbol map:, map:map: for BlockClosure and Symbol <*> and other combinators for BlockClosure and Symbol nilOr:, emptyOrNilOr: Slice, Pair and Tuple, ZippedCollection zip:, >===< iota many algorithms on collections: rotate:, slide:, product, allEqual, unique, isUnique, groupByRunsEqual:, groupByRunsTrue:
  • 38. Demo
  • 39. Using CompileWithCompose 1 Metacello new 2 baseline: ’PharoFunctional’; 3 repository: ’github://dvmason/Pharo-Functional:ma 4 load: #compiler Then for any class heirarchy, add a trait: 1 RBScannerTest subclass: #ComposeExampleTest 2 uses: ComposeSyntax 3 instanceVariableNames: ’’ 4 classVariableNames: ’’ 5 package: ’CompileWithCompose-Tests’ Or, on the class-side define the following method: 1 compilerClass 2 " Answer a compiler c l a s s a p p r o p r i a t e f o r source 3 ↑ ComposeCompiler You can use this second approach if you want to add it to the entire image (including in playgrounds), by defining this in Object class.
  • 40. Conclusions Smalltalk already has the fundamentals for functional programming some simple syntactic suger can make it a lot more pleasant I would love it if some of these became mainstream (with no backward compatibility issues) in the meantime, anyone can add this to their Pharo the compiler tweaks are not hard for other Smalltalks to implement
  • 41. Conclusions Smalltalk already has the fundamentals for functional programming some simple syntactic suger can make it a lot more pleasant I would love it if some of these became mainstream (with no backward compatibility issues) in the meantime, anyone can add this to their Pharo the compiler tweaks are not hard for other Smalltalks to implement
  • 42. Conclusions Smalltalk already has the fundamentals for functional programming some simple syntactic suger can make it a lot more pleasant I would love it if some of these became mainstream (with no backward compatibility issues) in the meantime, anyone can add this to their Pharo the compiler tweaks are not hard for other Smalltalks to implement
  • 43. Conclusions Smalltalk already has the fundamentals for functional programming some simple syntactic suger can make it a lot more pleasant I would love it if some of these became mainstream (with no backward compatibility issues) in the meantime, anyone can add this to their Pharo the compiler tweaks are not hard for other Smalltalks to implement
  • 44. Conclusions Smalltalk already has the fundamentals for functional programming some simple syntactic suger can make it a lot more pleasant I would love it if some of these became mainstream (with no backward compatibility issues) in the meantime, anyone can add this to their Pharo the compiler tweaks are not hard for other Smalltalks to implement