SlideShare une entreprise Scribd logo
1  sur  34
on Discovering Joy
    Francis Fish (@fjfish)
Fish?
NOT COMPUTER SCIENTIST
LIKE PROGRAMMING
LEARN NEW LANGUAGE LONG TIME
NOW
KNOW NOTHING, YOU MUCH CLEVERER
THAN ME
DISCOVERING JOY - NOT EXPERT!
Blame Braithwaite


Appendix
 Finding joy in
 combinators
Combinators
Combinator?

http://en.wikipedia.org/wiki/Combinator
A combinator is a higher-order function that uses
only function application and earlier defined
combinators to define a result from its arguments.
(no parameters, functions as arguments)
Joy Resources

http://en.wikipedia.org/wiki/Joy_(programmin
Invented by Manfred von Thun of La Trobe
University in Melbourne, Australia (retired)
Purely functional, combinatorial, stack based
Mirror
http://www.kevinalbrecht.com/code/joy-mirror
Interesting
Program is data (like Lisp)
Stack based - no parameters
Post-fix (goes with stack)
Does functional stuff well
Combinators - take what’s on the stack and do
stuff - including combining other combinators
Not Forth - no dictionary - functional
Stack Based?



Let’s go see
Example: Square

5 dup * .
- will print 25 and leave the stack empty
(as a function)
square == dup *
(== is the only infix operator - not runtime)
WAT?
Parameters, None

A stack of combinators
Code acts on the stack
dup *
Copy it and multiply the top 2 elements
together
Cube - you tell
me :)
5 dup dup * *.
5#5
dup # 5 5
dup # 5 5 5
* # 5 25
* # 125
125
Programs



Joy programs are built from smaller programs by
just two operations: concatenation and quotation.
Quoted Programs
[bob alice]
Is a list, but also a quoted program
You can plug it into things and then execute
Built in functions, anonymous Y combinator
etc.
Fill in the blanks
Types

character, file, float, integer, list, set, string,
truth
What else do you need?
(Except maybe hash)
And sets are weird
Combinators

ifte - if then else
The ifte combinator expects three quoted programs on the stack, an if-part, a then-part and an else-part,
in that order, with the else-part on top


dip
dip combinator expects a program on top of the stack and below that another value. It saves the value,
executes the program on the remainder of the stack and then restores the saved value.


i
identity - run the quoted program on the top of the stack
Combinators
concat
Join two aggregates together


cons - lisp
Add the top thing to the aggregate behind it on the stack


dup
Duplicate the stack top


swap
cause a flight of penguins
Combinators


Not talking about:
construct, dupd, map, popd, rolldown, rolldownd,
rollup, rollupd, rotate, succ, pred, swap, swapd,
swons, times, take, ternary, treegenrec, unswons,
x, first ...
Example:
Factorial
Factorial
Linear Recursion

5 [null] [succ] [dup pred] [*] linrec .
["null" false]
      linrec   : [P] [T] [R1] [R2] -> ....Executes P. If that yields true, executes T.Else execu

["dup pred" 4 5]
["null" false 5]
["null" false 3 4 5]
["*" 6 4 5]
...["*" 120]
["linrec" 120]
120
Primitive Recursion
5 [1] [*] primrec .
["R0" 1 1 2 3 4 5]
["*" 1 2 3 4 5]       primrec       : X [I] [C] -> R.Executes I to obtain
["*" 2 3 4 5]         an initial value R0.For integer X uses increasing
                      positive integers to X, combines by C for new
["*" 6 4 5]           R.For aggregate X uses successive members and
["*" 24 5]            combines by C for new R.

["*" 120]
120
(HINT: it’s not recursion)
Y-Combinator

5
[ [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte ]
[dup cons] swap concat dup cons i
Explanation


5    Cond        Else            Then
[ [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte ]
[dup cons] swap concat dup cons i
If the top of the stack is 0
 discard the copied program and the 0 left and
push 1
else
 duplicate the top of the stack and subtract 1 from
the top value
then dip and call the copy of yourself underneath
the stack top
on return apply *
 * the value below with the one you calculated
[dup cons] swap concat program and the integer on
(We already have the quoted dup cons i
the top of the stack)

(We push a quoted dup cons onto the stack)

run whats comes out of:

Take the stack top and cons to aggregate underneath

dup the aggregate

concat them together swap with whatever’s on the stack
top

We end up with the previous quoted program on the stack
top and run it
['1 false 4 5]

['3 2 3 4 5]             Just for laffs
['6 [[dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] dup cons [pop 0 =] [pop pop 1]
[[dup 1 -] dip i *] ifte] 2 3 4 5]

['1 false 3 4 5]

['3 1 2 3 4 5]

['6 [[dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] dup cons [pop 0 =] [pop pop 1]
[[dup 1 -] dip i *] ifte] 1 2 3 4 5]

['1 false 2 3 4 5]

['3 0 1 2 3 4 5]

['6 [[dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] dup cons [pop 0 =] [pop pop 1]
[[dup 1 -] dip i *] ifte] 0 1 2 3 4 5]

['1 true 1 2 3 4 5]

['2 1 1 2 3 4 5]

['5 1 1 2 3 4 5]
What Have I discovered?
Ruby Practice

How do we do recursion?
 We can see the stack, this reminds us of
 things we had forgotten
Recursion can always be recast as iteration
 Quick poll - how many people know this?
 How many had forgotten?
Can make difficult problems more tractable
Ruby Practice

Program is data?
 Method missing/symbols
 Dispatch tables etc.
 ERB - macro languages
THings to think about

Can we use stacks and combinators to solve
problems more easily?
Can we create DSL’s that do this?
Would we want to :)
Building a web app

    Who needs HAML when we could have:
[
    [
     [
        ["Hello" div]
      ] body
     ]
     [
      [
       [“My App” title]
       [“main.js” script]
      ] head]
    ] html
Next?
http://programjoy.eu - £1.40 :)
Will front a runtime and links to the mirror
Will run the tutorial
If you want to help - contact me
More fun to work on rather than <corporate-
bs>next big ecommerce social doo dah
site</corporate-bs>
Finis/Questions
   Francis Fish (@fjfish)
   www.francisfish.com
  www.leanpub.com/fjfish

Contenu connexe

Tendances

Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5karmuhtam
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operationSenthil Kumar
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTSoumen Santra
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.CIIT Atd.
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaDipayan Sarkar
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6ecomputernotes
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structurepcnmtutorials
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 

Tendances (20)

Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
Stacks
StacksStacks
Stacks
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
 
Stack project
Stack projectStack project
Stack project
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
stack presentation
stack presentationstack presentation
stack presentation
 

En vedette

The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

En vedette (8)

Lean isn't lean
Lean isn't leanLean isn't lean
Lean isn't lean
 
It's not your fault
It's not your faultIt's not your fault
It's not your fault
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Catalogo de tarjetas navideñas
Catalogo de tarjetas navideñasCatalogo de tarjetas navideñas
Catalogo de tarjetas navideñas
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similaire à Discovering joy

Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsRuth Marvin
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Bryan O'Sullivan
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfKabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfattalurilalitha
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
My-Selected-Project-Proposal
My-Selected-Project-ProposalMy-Selected-Project-Proposal
My-Selected-Project-ProposalBhautik Mavani
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelpmeinhomework
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdfpaijitk
 
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitBrogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitRon Reiter
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmerShawn Button
 

Similaire à Discovering joy (20)

ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Functional programming in C++
Functional programming in C++Functional programming in C++
Functional programming in C++
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
My-Selected-Project-Proposal
My-Selected-Project-ProposalMy-Selected-Project-Proposal
My-Selected-Project-Proposal
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
 
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitBrogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and Git
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmer
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 

Dernier

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Dernier (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

Discovering joy

  • 1. on Discovering Joy Francis Fish (@fjfish)
  • 2. Fish? NOT COMPUTER SCIENTIST LIKE PROGRAMMING LEARN NEW LANGUAGE LONG TIME NOW KNOW NOTHING, YOU MUCH CLEVERER THAN ME DISCOVERING JOY - NOT EXPERT!
  • 5. Combinator? http://en.wikipedia.org/wiki/Combinator A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments. (no parameters, functions as arguments)
  • 6. Joy Resources http://en.wikipedia.org/wiki/Joy_(programmin Invented by Manfred von Thun of La Trobe University in Melbourne, Australia (retired) Purely functional, combinatorial, stack based Mirror http://www.kevinalbrecht.com/code/joy-mirror
  • 7. Interesting Program is data (like Lisp) Stack based - no parameters Post-fix (goes with stack) Does functional stuff well Combinators - take what’s on the stack and do stuff - including combining other combinators Not Forth - no dictionary - functional
  • 9. Example: Square 5 dup * . - will print 25 and leave the stack empty (as a function) square == dup * (== is the only infix operator - not runtime)
  • 10. WAT?
  • 11. Parameters, None A stack of combinators Code acts on the stack dup * Copy it and multiply the top 2 elements together
  • 12. Cube - you tell me :)
  • 13. 5 dup dup * *. 5#5 dup # 5 5 dup # 5 5 5 * # 5 25 * # 125 125
  • 14. Programs Joy programs are built from smaller programs by just two operations: concatenation and quotation.
  • 15. Quoted Programs [bob alice] Is a list, but also a quoted program You can plug it into things and then execute Built in functions, anonymous Y combinator etc. Fill in the blanks
  • 16. Types character, file, float, integer, list, set, string, truth What else do you need? (Except maybe hash) And sets are weird
  • 17. Combinators ifte - if then else The ifte combinator expects three quoted programs on the stack, an if-part, a then-part and an else-part, in that order, with the else-part on top dip dip combinator expects a program on top of the stack and below that another value. It saves the value, executes the program on the remainder of the stack and then restores the saved value. i identity - run the quoted program on the top of the stack
  • 18. Combinators concat Join two aggregates together cons - lisp Add the top thing to the aggregate behind it on the stack dup Duplicate the stack top swap cause a flight of penguins
  • 19. Combinators Not talking about: construct, dupd, map, popd, rolldown, rolldownd, rollup, rollupd, rotate, succ, pred, swap, swapd, swons, times, take, ternary, treegenrec, unswons, x, first ...
  • 21. Linear Recursion 5 [null] [succ] [dup pred] [*] linrec . ["null" false] linrec : [P] [T] [R1] [R2] -> ....Executes P. If that yields true, executes T.Else execu ["dup pred" 4 5] ["null" false 5] ["null" false 3 4 5] ["*" 6 4 5] ...["*" 120] ["linrec" 120] 120
  • 22. Primitive Recursion 5 [1] [*] primrec . ["R0" 1 1 2 3 4 5] ["*" 1 2 3 4 5] primrec : X [I] [C] -> R.Executes I to obtain ["*" 2 3 4 5] an initial value R0.For integer X uses increasing positive integers to X, combines by C for new ["*" 6 4 5] R.For aggregate X uses successive members and ["*" 24 5] combines by C for new R. ["*" 120] 120 (HINT: it’s not recursion)
  • 23. Y-Combinator 5 [ [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte ] [dup cons] swap concat dup cons i
  • 24. Explanation 5 Cond Else Then [ [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte ] [dup cons] swap concat dup cons i
  • 25. If the top of the stack is 0 discard the copied program and the 0 left and push 1 else duplicate the top of the stack and subtract 1 from the top value then dip and call the copy of yourself underneath the stack top on return apply * * the value below with the one you calculated
  • 26. [dup cons] swap concat program and the integer on (We already have the quoted dup cons i the top of the stack) (We push a quoted dup cons onto the stack) run whats comes out of: Take the stack top and cons to aggregate underneath dup the aggregate concat them together swap with whatever’s on the stack top We end up with the previous quoted program on the stack top and run it
  • 27. ['1 false 4 5] ['3 2 3 4 5] Just for laffs ['6 [[dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] 2 3 4 5] ['1 false 3 4 5] ['3 1 2 3 4 5] ['6 [[dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] 1 2 3 4 5] ['1 false 2 3 4 5] ['3 0 1 2 3 4 5] ['6 [[dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] dup cons [pop 0 =] [pop pop 1] [[dup 1 -] dip i *] ifte] 0 1 2 3 4 5] ['1 true 1 2 3 4 5] ['2 1 1 2 3 4 5] ['5 1 1 2 3 4 5]
  • 28. What Have I discovered?
  • 29. Ruby Practice How do we do recursion? We can see the stack, this reminds us of things we had forgotten Recursion can always be recast as iteration Quick poll - how many people know this? How many had forgotten? Can make difficult problems more tractable
  • 30. Ruby Practice Program is data? Method missing/symbols Dispatch tables etc. ERB - macro languages
  • 31. THings to think about Can we use stacks and combinators to solve problems more easily? Can we create DSL’s that do this? Would we want to :)
  • 32. Building a web app Who needs HAML when we could have: [ [ [ ["Hello" div] ] body ] [ [ [“My App” title] [“main.js” script] ] head] ] html
  • 33. Next? http://programjoy.eu - £1.40 :) Will front a runtime and links to the mirror Will run the tutorial If you want to help - contact me More fun to work on rather than <corporate- bs>next big ecommerce social doo dah site</corporate-bs>
  • 34. Finis/Questions Francis Fish (@fjfish) www.francisfish.com www.leanpub.com/fjfish

Notes de l'éditeur

  1. Brief aside - combinator names come from the puzzle book. First order logic is the Mathematics professor version. Birds are a tribute to Haskell Curry’s being a twitcher.
  2. Forth small processors, lots of history, build language up from primitives and down from domain and meet in the middle - just like with Ruby DSL’s
  3. 5 dup dup * * .
  4. [P] [T] [R1] [R2] If P is true T else Call R1 with self R2
  5. If the data parameter is zero, then the first quotation has to produce the value to be returned. If the data parameter is positive then the second has to combine the data parameter with the result of applying the function to its predecessor.
  6. UNPICK ON NEXT SLIDE - don’t jump the gun
  7. HAML marvy - JS Frameworks etc. Quote lisp easier (maybe)