SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Prototypes in Pharo
Pavel Krivanek, Inria Nord Europe, RMoD
Prototype­based programming
● prototype: a typical member
used to represent a family or
a category of objects
● shared behavior using
delegation
● JavaScript, Lua, REBOL, Ioke…
● Self (first)
● 1986 Xerox PARC (David Ungar, Randall Smith)
● Standford University, Sun Microsystems (1990)
● slow progress since 1995, latest release May 2017
http://www.selflanguage.org/
How can we improve Smalltalk?
Let’s make it even simpler!
● prototype-based Smalltalk
● no classes, no metaclasses
● more focused on objects
● more Smalltalkish than Smalltalk
● only one keyword
● no symbols
● uniform messages and variables
● multiple dynamic inheritance
● namespaces
● modules
● full closures
● total object encapsulation
● was faster (2x)
Objects: composition of slots
● named references
– data slots (read-only / read-write)
– methods
– argument slots
– parent slots (read-only /read-write)
– auxiliary (unnamed slots, unnamed parent slots…)
Delegation
DEMO
Prototypes and traits
Prototypes and traits
Interesting syntax changes
● self-sends without self
● ifTrue:False:
● binary messages
1+2*3 must be (1+2)*3 or 1+(2*3)
● no symbols (canonical/mutable strings)
● implicit return value of methods
● literals for objects
● temporary variables, arguments
● 0-based indexes, C-like strings escaping
Method activation
Method activation
Method activation
Method activation
Delegation
mul: arg
parent*
a 3
x 2
:self*
:arg
(arg * a) pushSelf
send arg
pushSelf
send a
send *
returnTop
Delegation
mul: arg
parent*
a 3
x 2
:self*
:arg
(arg * a) pushSelf
send arg
pushSelf
send a
send *
returnTop
:self*
:arg
(arg * a) pushSelf
send arg
pushSelf
send a
send *
returnTop
(clone)
mul: x
Blocks
parent*
(lexicalParent)
value
(parent*)
(a + b) pushSelf
send a
pushSelf
send b
send +
returnTop
traits block
enclosing method's
activation object
block
block method
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
:self*
literal1
([y+y] value) pushSelf
send literal1
send value
returnTop
(clone) doSomething
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
:self*
literal1
([y+y] value) pushSelf
send literal1
send value
returnTop
(clone) doSomething
parent*
(lexicalParent)
value
(clone) block expression
evaluated
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
:self*
literal1
([y+y] value) pushSelf
send literal1
send value
returnTop
(clone) doSomething
parent*
(lexicalParent)
value
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
(clone)
value
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
4
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
4
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
4
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
value:
4
Prototypes in Smalltalk
● Several attempts (System-Prototypes, Prototypes)
● possible issues:
– memory inefficiency (dictionaries, associations)
– slow (DNU processing)
– limited delegation
– self sends
– tools support
Russel Allen’s dark magic (2005)
● create instance of Behavior (parent)
● set its superclass to Behavior
● create prototype as instance of the
parent
● clone instance variables of the
parent into the prototype
(superclass, method dict, format)
● parent gets identity of the prototype
● extend methods dictionary from
Prototype (addSlot:…)
Russel Allen’s dark magic (2005)
● create instance of Behavior (parent)
● set its superclass to Behavior
● create prototype as instance of the
parent
● clone instance variables of the
parent into the prototype
(superclass, method dict, format)
● parent gets identity of the prototype
● extend methods dictionary from
Prototype (addSlot:…)
→ the object is its own instance
Marvin
● objects as arrays
● no associations
● nil as separators
– parent slots
– methods
– data slots
– indexed content
Marvin
● Delegation implemented in VM
– Depth First Search (unlike Self)
– easy in that time
● Follow the Smalltalk infrastructure
– Smalltalk blocks
– Symbols
Marvin
● own syntax (SmaCC)
● mix of Self and Smalltalk
| p1 |
p1: (|
parent* = (|
parent* = (|
a = ( ^a ).
b = ‘symbol’ |).
a = ( resend.a ) |).
a = (|
a = 3.
b = 4 |).
method = ( resend.a a ) |).
p1 method
Self:
| p1 |
p1: (|
parent* = (|
parent* = (|
a = { ^a }.
b = #symbol |).
a = { ^resend a } |).
a = (|
a = 3.
b = 4 |).
method = { ^resend a a } |).
p1 method
Marvin:
current Marvin
● Delegation based on DNU
● Easier combination with regular objects
● Indexed content at the beginning
– Indexed access to inst. variables in CM
● Smalltalk objects injection
https://github.com/pavel-krivanek/Marvin
Objects injection
objectToExtend := Date today.
Objects injection
objectToExtend := Date today.
parent := MarvinPrototype new.
parent _AddMethod: 'suffix ^ self suffixString asUppercase'.
parent _AddReadSlot: #suffixString value: '_suffix'.
Objects injection
objectToExtend := Date today.
parent := MarvinPrototype new.
parent _AddMethod: 'suffix ^ self suffixString asUppercase'.
parent _AddReadSlot: #suffixString value: '_suffix'.
object := MarvinPrototype new.
object _AddParentSlot: #parent value: parent.
object _AddMethod: 'dayOfWeekName
^ super dayOfWeekName, self suffix'.
suffixString '_suffix’
suffix ^ self suffixString asUppercase
parent*
dayOfWeekName ^ super dayOfWeekName, self suffix
Objects injection
suffixString '_suffix’
suffix ^ self suffixString asUppercase
Date
parent*
class*
dayOfWeekName ^ super dayOfWeekName, self suffix
Date today
(instance variables)
objectToExtend := Date today.
parent := MarvinPrototype new.
parent _AddMethod: 'suffix ^ self suffixString asUppercase'.
parent _AddReadSlot: #suffixString value: '_suffix'.
object := MarvinPrototype new.
object _AddParentSlot: #parent value: parent.
object _AddMethod: 'dayOfWeekName
^ super dayOfWeekName, self suffix'.
object _Inject: objectToExtend.
object dayOfWeekName >>> 'Thursday_SUFFIX'
Why Self
is not more widely known and used?
What about Smalltalkers?
Self disadvantages
● lost commercial support (Sun)
● complicated VM
● platforms (no Windows VM, late Linux,
32-bits only)
● Morphic, UI, tools (outliners)
● Documentation
● Community
788x50844
Self disadvantages
Does it remove from Smalltalk things that 
make people productive?
Easy to loose control?
power of simplicity
under the hood
Prototypes in Pharo

Weitere ähnliche Inhalte

Was ist angesagt?

2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day One
retronym
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
Yardena Meymann
 

Was ist angesagt? (19)

The Arrow Library in Kotlin
The Arrow Library in KotlinThe Arrow Library in Kotlin
The Arrow Library in Kotlin
 
2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day One
 
Proposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyondProposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyond
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
All about scala
All about scalaAll about scala
All about scala
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Cats in Scala
Cats in ScalaCats in Scala
Cats in Scala
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Introductory Clojure Presentation
Introductory Clojure PresentationIntroductory Clojure Presentation
Introductory Clojure Presentation
 
Scala
ScalaScala
Scala
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
01. haskell introduction
01. haskell introduction01. haskell introduction
01. haskell introduction
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
 
Generics
GenericsGenerics
Generics
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 

Ähnlich wie Prototypes in Pharo

Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 

Ähnlich wie Prototypes in Pharo (20)

Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Python to scala
Python to scalaPython to scala
Python to scala
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in Groovy
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Introductiontoprogramminginscala
IntroductiontoprogramminginscalaIntroductiontoprogramminginscala
Introductiontoprogramminginscala
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Scala: A brief tutorial
Scala: A brief tutorialScala: A brief tutorial
Scala: A brief tutorial
 

Mehr von ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
ESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
ESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
ESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
ESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
ESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
ESUG
 

Mehr von ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Prototypes in Pharo

  • 2. Prototype­based programming ● prototype: a typical member used to represent a family or a category of objects ● shared behavior using delegation ● JavaScript, Lua, REBOL, Ioke… ● Self (first)
  • 3. ● 1986 Xerox PARC (David Ungar, Randall Smith) ● Standford University, Sun Microsystems (1990) ● slow progress since 1995, latest release May 2017 http://www.selflanguage.org/
  • 4.
  • 5.
  • 7. ● prototype-based Smalltalk ● no classes, no metaclasses ● more focused on objects ● more Smalltalkish than Smalltalk ● only one keyword ● no symbols ● uniform messages and variables
  • 8. ● multiple dynamic inheritance ● namespaces ● modules ● full closures ● total object encapsulation ● was faster (2x)
  • 9. Objects: composition of slots ● named references – data slots (read-only / read-write) – methods – argument slots – parent slots (read-only /read-write) – auxiliary (unnamed slots, unnamed parent slots…)
  • 13. Interesting syntax changes ● self-sends without self ● ifTrue:False: ● binary messages 1+2*3 must be (1+2)*3 or 1+(2*3) ● no symbols (canonical/mutable strings) ● implicit return value of methods ● literals for objects ● temporary variables, arguments ● 0-based indexes, C-like strings escaping
  • 18. Delegation mul: arg parent* a 3 x 2 :self* :arg (arg * a) pushSelf send arg pushSelf send a send * returnTop
  • 19. Delegation mul: arg parent* a 3 x 2 :self* :arg (arg * a) pushSelf send arg pushSelf send a send * returnTop :self* :arg (arg * a) pushSelf send arg pushSelf send a send * returnTop (clone) mul: x
  • 20. Blocks parent* (lexicalParent) value (parent*) (a + b) pushSelf send a pushSelf send b send + returnTop traits block enclosing method's activation object block block method
  • 21. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value
  • 22. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value :self* literal1 ([y+y] value) pushSelf send literal1 send value returnTop (clone) doSomething
  • 23. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value :self* literal1 ([y+y] value) pushSelf send literal1 send value returnTop (clone) doSomething parent* (lexicalParent) value (clone) block expression evaluated
  • 24. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value :self* literal1 ([y+y] value) pushSelf send literal1 send value returnTop (clone) doSomething parent* (lexicalParent) value (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop (clone) value
  • 25. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop 4
  • 26. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop 4
  • 27. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop 4
  • 28. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value parent* (lexicalParent) value: parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop value: 4
  • 29. Prototypes in Smalltalk ● Several attempts (System-Prototypes, Prototypes) ● possible issues: – memory inefficiency (dictionaries, associations) – slow (DNU processing) – limited delegation – self sends – tools support
  • 30. Russel Allen’s dark magic (2005) ● create instance of Behavior (parent) ● set its superclass to Behavior ● create prototype as instance of the parent ● clone instance variables of the parent into the prototype (superclass, method dict, format) ● parent gets identity of the prototype ● extend methods dictionary from Prototype (addSlot:…)
  • 31. Russel Allen’s dark magic (2005) ● create instance of Behavior (parent) ● set its superclass to Behavior ● create prototype as instance of the parent ● clone instance variables of the parent into the prototype (superclass, method dict, format) ● parent gets identity of the prototype ● extend methods dictionary from Prototype (addSlot:…) → the object is its own instance
  • 32. Marvin ● objects as arrays ● no associations ● nil as separators – parent slots – methods – data slots – indexed content
  • 33. Marvin ● Delegation implemented in VM – Depth First Search (unlike Self) – easy in that time ● Follow the Smalltalk infrastructure – Smalltalk blocks – Symbols
  • 34. Marvin ● own syntax (SmaCC) ● mix of Self and Smalltalk | p1 | p1: (| parent* = (| parent* = (| a = ( ^a ). b = ‘symbol’ |). a = ( resend.a ) |). a = (| a = 3. b = 4 |). method = ( resend.a a ) |). p1 method Self: | p1 | p1: (| parent* = (| parent* = (| a = { ^a }. b = #symbol |). a = { ^resend a } |). a = (| a = 3. b = 4 |). method = { ^resend a a } |). p1 method Marvin:
  • 35. current Marvin ● Delegation based on DNU ● Easier combination with regular objects ● Indexed content at the beginning – Indexed access to inst. variables in CM ● Smalltalk objects injection https://github.com/pavel-krivanek/Marvin
  • 37. Objects injection objectToExtend := Date today. parent := MarvinPrototype new. parent _AddMethod: 'suffix ^ self suffixString asUppercase'. parent _AddReadSlot: #suffixString value: '_suffix'.
  • 38. Objects injection objectToExtend := Date today. parent := MarvinPrototype new. parent _AddMethod: 'suffix ^ self suffixString asUppercase'. parent _AddReadSlot: #suffixString value: '_suffix'. object := MarvinPrototype new. object _AddParentSlot: #parent value: parent. object _AddMethod: 'dayOfWeekName ^ super dayOfWeekName, self suffix'. suffixString '_suffix’ suffix ^ self suffixString asUppercase parent* dayOfWeekName ^ super dayOfWeekName, self suffix
  • 39. Objects injection suffixString '_suffix’ suffix ^ self suffixString asUppercase Date parent* class* dayOfWeekName ^ super dayOfWeekName, self suffix Date today (instance variables) objectToExtend := Date today. parent := MarvinPrototype new. parent _AddMethod: 'suffix ^ self suffixString asUppercase'. parent _AddReadSlot: #suffixString value: '_suffix'. object := MarvinPrototype new. object _AddParentSlot: #parent value: parent. object _AddMethod: 'dayOfWeekName ^ super dayOfWeekName, self suffix'. object _Inject: objectToExtend. object dayOfWeekName >>> 'Thursday_SUFFIX'
  • 41. Self disadvantages ● lost commercial support (Sun) ● complicated VM ● platforms (no Windows VM, late Linux, 32-bits only) ● Morphic, UI, tools (outliners) ● Documentation ● Community 788x50844