SlideShare a Scribd company logo
Writing iPhone apps in Scheme
              λ
What is Scheme?
• Scheme is a dialect of Lisp, around since the
  70s
• Functional, although not “pure”
• Extremely minimal, concise, and expressive
 • Fully defined in R5RS   [1]


 • Build bigger parts from smaller parts
                                                  λ
Implementations
• Scheme by itself is the language specification
• There are many implementations of
  Scheme, each with different strengths:
  • Gambit-C: speed, portability
  • PLT: ease-of-use, libraries
  • Scheme48: modules, formal semantics
  • etc.
                                                  λ
Syntax
• Uses S-expressions and prefix notation
• (function arg1 arg2 ...)
• (+ 5 5)
 • 10
• (- (foo 3 2) 1)
 •?
• (+ 1 2 3 4 5)
 • 15                                     λ
Syntax




         λ
Functions
• `define` declares functions
 • (define (multiply x y)
      (other-function x)
      (* x y))
• The last value is returned, so unless
  `other-function` has a side effect, that call
  is essentially ignored
• `define` also create variables
 • (define foo 5)
                                                  λ
Functions
• `lambda` creates an anonymous function
• (lambda () (+ 1 2))
• (lambda (x y) (* x y))
• lambdas are ubiquitous in Scheme, too
  powerful to fully explain here, but it’s
  another dimension of Scheme’s
  expressiveness
• Our “multiply” function could be defined as:
 • (define multiply (lambda (x y) (* x y)))      λ
Functions
• Functions are full closures with tail-
  recursion where possible
• (define (foo x y)
     (define z (get-z-axis))
     (lambda () (+ x y z)))
• (define (bar)
     (read-network-blocking-and-act)
     (bar))

                                           λ
Identifiers
• The name of an identifier is very flexible; can
  contain almost any character
• Very expressive
 • (define the-number 5)
 • (define !@#$%^&* 10)
 • (define (is-alive?) ...)
                                                  λ
Lists
• The list is Scheme’s fundamental data
  structure
• Special syntax for lists:
 • ‘(1 2 3 “foo”)
 • ‘(1 2 3 (4 5 6))
 • `(1 2 3 ,data) (define data “foo”)
 • `(1 2 3 ,@data) (define data ‘(4 5 6))
                                           λ
Lists
• Lists are made up of “cons cells” or pairs
• Fundamental list functions:
 • car
   • (car ‘(1 2 3)) => 1
 • cdr
   • (cdr ‘(1 2 3)) => (2 3)
 • cons
   • (cons 1 ‘(2 3)) => (1 2 3)                λ
Lists

• Question: is a function not simply a list of
  elements?
  • ‘(define (foo x y) (* x y))
• Yes, it is.
• In fact, any code in Scheme is data — simply
  a list of elements.


                                                 λ
Macros
• Macros are Scheme functions that take
  arguments and expand into different code
• Macros usually parse code, which is easy in
  Scheme because code is data!
• (define-macro (my-define func . body)
    (let ((name (car func))
          (args (cdr func)))
      `(define ,name (lambda ,args ,@body))))
• (my-define (foo x y) (* x y)) expands into
 • (define foo (lambda (x y) (* x y)))           λ
Macros
• Macros are lazy
• Macros allow an extremely powerful tool for
  extending the language for your needs
• Any new construct can be integrated
• You could redefine `if`
• Other macro systems exist which integrate
  pattern matching and other features

                                                λ
Say again?
• Because of consistency and conciseness, it’s
  easy to write reusable, small bits of code in
  Scheme, which is good
• Other libraries implement tons of stuff, such
  as object systems, vectors, etc.
  • SRFI’s
• Not covered: continuations, eval, and more
• Questions or comments?
                                                  λ
Practical Examples
• It turns out that it’s easy to implement
  functional programming in an imperative
  language like C [3]
• Gambit-C is a Scheme system which takes
  Scheme and compiles it to C [2]
  • Extremely fast and portable
  • Easy to interface to C/C++/Obj-C
    libraries

                                             λ
Taking Scheme to the iPhone


• Cross-compiled Gambit’s run-time library
  for the ARM architecture (for the iPhone)
• Compiled my Scheme code to C
• Linked everything together, and it ran fine!
• Wasn’t that easy? [4]




                                                λ
Example
Benefits

• Write iPhone apps in Scheme, of course
• Garbage collector
• Faster, real-time development
 • Load in Scheme files at run-time
 • Much more sane debugging

                                           λ
Loading in Scheme at run-time

• Scheme has a `load` procedure which takes
  a filename, loads in the code and evaluates it
• In Gambit, this function loads code at run-
  time (`include` does the same thing at
  compile-time)
• Compile an app with a `load` statement,
  install it once, and develop with interpreted
  code forever.

                                                  λ
Example
Sane Debugging
• What is a REPL?
 • Read-Eval-Print-Loop
• A debugger is a REPL with special
  commands
• Gambit comes with a nice command-line
  debugger, so we want this to work for our
  iPhone apps.

                                              λ
Sane Debugging
• Since code is simply S-expressions, it’s really
  easy to parse, pass around the network, etc.
• We’ve created a “remote debugger” which
  implements the functionality of a networked
  REPL
• Instead of reading from the console, the
  REPL reads and writes from/to a network
  port
• A “debugging server” gives you access to
  REPLs running inside the application              λ
Example
Optimizing
• Compiling to C makes it easy to fine tune
  hotspots in your application
 • (define fast-sqrt
       (c-lambda (float) float “fast_sqrt”))
• Once you’ve written and debugged your app
  sanely, profile and optimize specific parts of
  your app
 • Re-write small pieces of code in C
 • Use `declare` in Gambit                       λ
Paredit
• Another benefit of concise syntax is more
  advanced text editing
• Instead of thinking in terms of lines, think in
  terms of S-expressions
• Paredit implements key-bindings in Emacs to
  manipulate S-expressions
  • Really powerful way of writing code
                                                    λ
Example
[1] R5RS: http://schemers.org/Documents/Standards/R5RS/

[2] Gambit Scheme: http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page

[3] 90 Minute Scheme-to-C compiler http://lambda-the-ultimate.org/node/349

[4] Writing iPhone apps in Scheme: http://jlongster.com/blog/2009/06/17/write-apps-iphone-scheme/




           For more info, check out my blog:
               http://jlongster.com/blog

                                                                          @jlongster

More Related Content

What's hot

Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
Akhil Kaushik
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Avelin Huo
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
Mahesh Kumar Chelimilla
 
Lecture5 syntax analysis_1
Lecture5 syntax analysis_1Lecture5 syntax analysis_1
Lecture5 syntax analysis_1
Mahesh Kumar Chelimilla
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
DataminingTools Inc
 
Basic lisp
Basic lispBasic lisp
Basic lisp
Arvind sahu
 
Lisp
LispLisp
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
Ravi Rao
 
Lisp
LispLisp
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
Kiran Acharya
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
wahab khan
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
Yaser Jaradeh
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Lecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxLecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptx
Iffat Anjum
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
DataminingTools Inc
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
Devnology
 

What's hot (20)

Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
 
Lecture5 syntax analysis_1
Lecture5 syntax analysis_1Lecture5 syntax analysis_1
Lecture5 syntax analysis_1
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
Basic lisp
Basic lispBasic lisp
Basic lisp
 
Lisp
LispLisp
Lisp
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
 
Lisp
LispLisp
Lisp
 
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Lecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxLecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptx
 
Lisp
LispLisp
Lisp
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
Ch6
Ch6Ch6
Ch6
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 

Viewers also liked

Step adivasi chetna 20 1-15
Step adivasi chetna 20 1-15Step adivasi chetna 20 1-15
Step adivasi chetna 20 1-15Jauhar Jauhar
 
Analysis of Embedded Linux Literature Review Report
Analysis of Embedded Linux Literature Review ReportAnalysis of Embedded Linux Literature Review Report
Analysis of Embedded Linux Literature Review ReportSitakanta Mishra
 
Suse Linux Enterprise Server 9 - A Review by Larkin Cunningham
Suse Linux Enterprise Server 9 - A Review by Larkin CunninghamSuse Linux Enterprise Server 9 - A Review by Larkin Cunningham
Suse Linux Enterprise Server 9 - A Review by Larkin Cunningham
Larkin Cunningham
 
Javascript as a Platform
Javascript as a PlatformJavascript as a Platform
Javascript as a Platform
Vlad Mysla
 
Mensa
MensaMensa
Mensa
DainSanye
 
An introduction to Windows 10
An introduction to Windows 10 An introduction to Windows 10
An introduction to Windows 10
Cynoteck Technology Solutions Private Limited
 
Windows 10
Windows 10Windows 10
Windows 10
KrishnaTeja Siva
 
Windows 10 in 10 Minutes
Windows 10 in 10 MinutesWindows 10 in 10 Minutes
Windows 10 in 10 Minutes
Hemant Prasad
 
Windows 10 Forensics: OS Evidentiary Artefacts
Windows 10 Forensics: OS Evidentiary ArtefactsWindows 10 Forensics: OS Evidentiary Artefacts
Windows 10 Forensics: OS Evidentiary Artefacts
Brent Muir
 

Viewers also liked (9)

Step adivasi chetna 20 1-15
Step adivasi chetna 20 1-15Step adivasi chetna 20 1-15
Step adivasi chetna 20 1-15
 
Analysis of Embedded Linux Literature Review Report
Analysis of Embedded Linux Literature Review ReportAnalysis of Embedded Linux Literature Review Report
Analysis of Embedded Linux Literature Review Report
 
Suse Linux Enterprise Server 9 - A Review by Larkin Cunningham
Suse Linux Enterprise Server 9 - A Review by Larkin CunninghamSuse Linux Enterprise Server 9 - A Review by Larkin Cunningham
Suse Linux Enterprise Server 9 - A Review by Larkin Cunningham
 
Javascript as a Platform
Javascript as a PlatformJavascript as a Platform
Javascript as a Platform
 
Mensa
MensaMensa
Mensa
 
An introduction to Windows 10
An introduction to Windows 10 An introduction to Windows 10
An introduction to Windows 10
 
Windows 10
Windows 10Windows 10
Windows 10
 
Windows 10 in 10 Minutes
Windows 10 in 10 MinutesWindows 10 in 10 Minutes
Windows 10 in 10 Minutes
 
Windows 10 Forensics: OS Evidentiary Artefacts
Windows 10 Forensics: OS Evidentiary ArtefactsWindows 10 Forensics: OS Evidentiary Artefacts
Windows 10 Forensics: OS Evidentiary Artefacts
 

Similar to The Scheme Language -- Using it on the iPhone

Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
Eugene Lazutkin
 
Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga
DTU - Technical University of Denmark
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
Mohsen Zainalpour
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rutvik Pensionwar
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
Adriano Bonat
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
Azilen Technologies Pvt. Ltd.
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptxCLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
JEEVANANTHAMG6
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
Shimi Bandiel
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
KarthickT28
 
Core JavaScript
Core JavaScriptCore JavaScript
Core JavaScript
Lilia Sfaxi
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
Diego Freniche Brito
 
Unit ii
Unit   iiUnit   ii
Unit ii
sathisaran
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscriptBill Buchan
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Ahmed Raza
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
chouguleamruta24
 
Functions
FunctionsFunctions

Similar to The Scheme Language -- Using it on the iPhone (20)

Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 
Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptxCLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
Core JavaScript
Core JavaScriptCore JavaScript
Core JavaScript
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscript
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
 
Functions
FunctionsFunctions
Functions
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

The Scheme Language -- Using it on the iPhone

  • 1. Writing iPhone apps in Scheme λ
  • 2. What is Scheme? • Scheme is a dialect of Lisp, around since the 70s • Functional, although not “pure” • Extremely minimal, concise, and expressive • Fully defined in R5RS [1] • Build bigger parts from smaller parts λ
  • 3. Implementations • Scheme by itself is the language specification • There are many implementations of Scheme, each with different strengths: • Gambit-C: speed, portability • PLT: ease-of-use, libraries • Scheme48: modules, formal semantics • etc. λ
  • 4. Syntax • Uses S-expressions and prefix notation • (function arg1 arg2 ...) • (+ 5 5) • 10 • (- (foo 3 2) 1) •? • (+ 1 2 3 4 5) • 15 λ
  • 5. Syntax λ
  • 6. Functions • `define` declares functions • (define (multiply x y) (other-function x) (* x y)) • The last value is returned, so unless `other-function` has a side effect, that call is essentially ignored • `define` also create variables • (define foo 5) λ
  • 7. Functions • `lambda` creates an anonymous function • (lambda () (+ 1 2)) • (lambda (x y) (* x y)) • lambdas are ubiquitous in Scheme, too powerful to fully explain here, but it’s another dimension of Scheme’s expressiveness • Our “multiply” function could be defined as: • (define multiply (lambda (x y) (* x y))) λ
  • 8. Functions • Functions are full closures with tail- recursion where possible • (define (foo x y) (define z (get-z-axis)) (lambda () (+ x y z))) • (define (bar) (read-network-blocking-and-act) (bar)) λ
  • 9. Identifiers • The name of an identifier is very flexible; can contain almost any character • Very expressive • (define the-number 5) • (define !@#$%^&* 10) • (define (is-alive?) ...) λ
  • 10. Lists • The list is Scheme’s fundamental data structure • Special syntax for lists: • ‘(1 2 3 “foo”) • ‘(1 2 3 (4 5 6)) • `(1 2 3 ,data) (define data “foo”) • `(1 2 3 ,@data) (define data ‘(4 5 6)) λ
  • 11. Lists • Lists are made up of “cons cells” or pairs • Fundamental list functions: • car • (car ‘(1 2 3)) => 1 • cdr • (cdr ‘(1 2 3)) => (2 3) • cons • (cons 1 ‘(2 3)) => (1 2 3) λ
  • 12. Lists • Question: is a function not simply a list of elements? • ‘(define (foo x y) (* x y)) • Yes, it is. • In fact, any code in Scheme is data — simply a list of elements. λ
  • 13. Macros • Macros are Scheme functions that take arguments and expand into different code • Macros usually parse code, which is easy in Scheme because code is data! • (define-macro (my-define func . body) (let ((name (car func)) (args (cdr func))) `(define ,name (lambda ,args ,@body)))) • (my-define (foo x y) (* x y)) expands into • (define foo (lambda (x y) (* x y))) λ
  • 14. Macros • Macros are lazy • Macros allow an extremely powerful tool for extending the language for your needs • Any new construct can be integrated • You could redefine `if` • Other macro systems exist which integrate pattern matching and other features λ
  • 15. Say again? • Because of consistency and conciseness, it’s easy to write reusable, small bits of code in Scheme, which is good • Other libraries implement tons of stuff, such as object systems, vectors, etc. • SRFI’s • Not covered: continuations, eval, and more • Questions or comments? λ
  • 16. Practical Examples • It turns out that it’s easy to implement functional programming in an imperative language like C [3] • Gambit-C is a Scheme system which takes Scheme and compiles it to C [2] • Extremely fast and portable • Easy to interface to C/C++/Obj-C libraries λ
  • 17. Taking Scheme to the iPhone • Cross-compiled Gambit’s run-time library for the ARM architecture (for the iPhone) • Compiled my Scheme code to C • Linked everything together, and it ran fine! • Wasn’t that easy? [4] λ
  • 19. Benefits • Write iPhone apps in Scheme, of course • Garbage collector • Faster, real-time development • Load in Scheme files at run-time • Much more sane debugging λ
  • 20. Loading in Scheme at run-time • Scheme has a `load` procedure which takes a filename, loads in the code and evaluates it • In Gambit, this function loads code at run- time (`include` does the same thing at compile-time) • Compile an app with a `load` statement, install it once, and develop with interpreted code forever. λ
  • 22. Sane Debugging • What is a REPL? • Read-Eval-Print-Loop • A debugger is a REPL with special commands • Gambit comes with a nice command-line debugger, so we want this to work for our iPhone apps. λ
  • 23. Sane Debugging • Since code is simply S-expressions, it’s really easy to parse, pass around the network, etc. • We’ve created a “remote debugger” which implements the functionality of a networked REPL • Instead of reading from the console, the REPL reads and writes from/to a network port • A “debugging server” gives you access to REPLs running inside the application λ
  • 25. Optimizing • Compiling to C makes it easy to fine tune hotspots in your application • (define fast-sqrt (c-lambda (float) float “fast_sqrt”)) • Once you’ve written and debugged your app sanely, profile and optimize specific parts of your app • Re-write small pieces of code in C • Use `declare` in Gambit λ
  • 26. Paredit • Another benefit of concise syntax is more advanced text editing • Instead of thinking in terms of lines, think in terms of S-expressions • Paredit implements key-bindings in Emacs to manipulate S-expressions • Really powerful way of writing code λ
  • 28. [1] R5RS: http://schemers.org/Documents/Standards/R5RS/ [2] Gambit Scheme: http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page [3] 90 Minute Scheme-to-C compiler http://lambda-the-ultimate.org/node/349 [4] Writing iPhone apps in Scheme: http://jlongster.com/blog/2009/06/17/write-apps-iphone-scheme/ For more info, check out my blog: http://jlongster.com/blog @jlongster