SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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 MenDelhi Call girls
 
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 RobisonAnna Loughnan Colquhoun
 
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 Servicegiselly40
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 slidevu2urc
 
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 Nanonetsnaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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 DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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 2024The Digital Insurer
 
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 2024Rafal Los
 
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 Scriptwesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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

Hinweis der Redaktion

  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)