SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
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 linked list
Stack linked listStack linked list
Stack linked list
bhargav0077
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
ecomputernotes
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
pcnmtutorials
 

Mais procurados (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
 

Destaque

Destaque (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
 

Semelhante a Discovering joy

Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
Bryan 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.pdf
KabilaArun
 
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
attalurilalitha
 
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
vrickens
 
My-Selected-Project-Proposal
My-Selected-Project-ProposalMy-Selected-Project-Proposal
My-Selected-Project-Proposal
Bhautik Mavani
 

Semelhante a 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
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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

Notas do Editor

  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)