Notes From Prabhakar Ragde - Small, Elegant, Practical: The Benefits of a Minimal Approach
Prabhakar Ragde - Small, Elegant, Practical: The Benefits of a Minimal Approach
What is a reasonable minimal set of features in a Programming Language? -Not Minimum, but reasonable
Lambda - Church's Invention Church & Turing Church - influenced Software Turing - influenced Hardware
Lamda - First-Class Functions. Can be created at Runtime
Racket is a LISP Language
Define statement
Conditional Evaluation: (define (abs x) (cond [> x 0 x] [else (- x)]))
Cond was in the first implementation of LISP John McCarthy - ALGOL committee
Recursion instead of Iteration Tail Call Optimization - makes it as efficient as Iteration [Is this Generators in Python???]
(define (fact n) (cond [(zero? n) 1] [else (* n (fact (sub1 n)))]))
Need a concise, simple & high-level model of computation
A Racket program is a sequence of definitions and expression.
The expressions are reduced to values by substitution.
Data Structures Lists empty (cons 3 empty) (cons 'blue (cons 3 empty))
Substitution Rules work for Lists (First (cons v1 v2)) -> v1 (Rest (cons v1 v2)) -> v2
Minimal Required Features in a Programming Language: lambda, predefined functions, function application define, cond lists
Nice Additions: Lightweight Testing Racket: (check-expect (sqr 4 ) 16) List abbreviations [This is List Comprehensions in Python???] (list 'blue 3) '(blue 3) ~(blue ,(garment-name x) 3)
Higher Order Functions
Trees Represented as Nested Lists (list root child1 ... childn) S-Expression [Symbolic Expression] These get used with JSON, XML, HTML, etc
Records with Named Fields Improves on lists... [Didn't entirely get this]
Implement Let with Macros Rewrite let to be a Lambda (Define-syntax-rule (let ([x e] ...) body) ((lambda (x ...) body) e ...))
Core Language SYntactic Sugar "Desugaring"
Temptations: Homoiconicity (eval '(+ (* 2 3) (* 4 5))) eval is basically recursion If you had variables (especially runtime variables) in this statement, it gets bad...
Dynamic Scope should be avoided.
Lexical scope is the way to go. [Think Namespaces] eval should be used Very Sparingly Better: Small interpreters for domain-specific languages
Build a Domain Scoped Language & run it on top...
Lambda defers computations [Lambda seems to just basically be a "pointer" to a function/object??] [So we don't need to know what it is at the start]
What about Assignment?? Called "Mutation" in the Functional Programming World
Should be used sparingly: Destroys equational reasoning Complicates the Substitution Model Mutation Destroys Information
Use Sparingly Hide Under Pure Interfaces (under the hood) Contain It (Objects, Monads, etc)
Other Useful Features: Pattern Matching Arrays/vectors finite maps modules I/O exceptions continuations static typing laziness...
Message: Focus on small elegant core With a clear semantic model & make that the focus of your thinking
Essentially, be Conscious about what you do
Q&A
Question: Have you tried applying this approach to Non-LISP Languages
Answer: I haven't tried w/ JS or Python Python treats Functional Programming as 2nd Class, so this wouldn't work so well JS the Good Parts is mostly Functional Programming
Question: What does the phrase "Object-Oriented Computation Should be called Message-Oriented" mean??
Answer: Alan K invented Small Talk Lambda can implement objects In Message View: Object Receives Messages & then Acts on those Messages
Question: Do you just get Error Handling for Conditionals? Or is that a part of the Core?
Answer: At a very basic level, if an error happens, everything stops. Instead, you can have Exceptions. This is essentially a Conditional/Substitution around a Handler processing a computation & its subsequent Error
Question: Does a language need Side Effects to be useful
Answer: Mutation is a Side Effect. I/O ... Output can't be modified afterwards. These are essentially similar to Monads. You can extend the Substitution Model to do this, but then it gets Loaded.
Question: Static Typing vs. Dynamic Typing:
Answer: You can catch errors at Compile Time & then you can erase all the types & at run time, you have less overhead. When you start piling on Features, it becomes more convoluted (Haskell does this well)
Question: What's a Viable Alternative to Type Classes is you want to have something like Paremtricity/Polymoprhic Paremtricity
Answer: Type Classes are a pretty nice idea. When they were first put in, it wasn't understood how useful they would be. More languages are adopting the idea of Type Classes. There's more advanced notions of Type Theory type things - Higher Order Polymorphism - that will eventually replace Type Classing ... but they're not ready yet.
Question: What are Type Classes
Answer: They're a Principle Way of Doing Overloading Plus & Times can apply to Numbers or Matrices
Type Classes say in order to create an instance of the class, you just have to specify a set of operations you will support.
Matrices would be an instance Vectors, Quaternians, Complex Numbers are instances
Philip Wadmore paper introducing Type Classes
Question: Can you recommend a Beginners Guide to thinking of Programs as Programs, instead of in the context of its interactions with Hardware ... if that's what Functional Programming is good for.
Answer: Racket was created by a scholar who got infuriated at what his kid was learning. He pulled together some Grad Students to focus on education for a few years. Racket takes this idea of a Core Language ... You learn programming in a progressive way (Think different levels). Read the book "How To Design Programs" ... it's not a book about Racket, it's a book about desiging programs that are Modular or Testable, etc
Question: Type Classes in ___ How are they similar vs. different










