• Save
lisp (vs ruby) metaprogramming
Upcoming SlideShare
Loading in...5
×
 

lisp (vs ruby) metaprogramming

on

  • 8,984 views

a very basic introduction to lisp macros in comparison to ruby meta-programming

a very basic introduction to lisp macros in comparison to ruby meta-programming

Statistics

Views

Total Views
8,984
Views on SlideShare
8,929
Embed Views
55

Actions

Likes
18
Downloads
0
Comments
3

5 Embeds 55

http://www.slideshare.net 45
http://paper.li 5
https://twimg0-a.akamaihd.net 2
https://twitter.com 2
https://si0.twimg.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • here's the one

    (define Z
    (lambda (f)
    ((lambda (x) (f (lambda (y) ((x x) y))))
    (lambda (x) (f (lambda (y) ((x x) y)))))))

    even more freaky
    Are you sure you want to
    Your message goes here
    Processing…
  • the Y combinator on slide 11, won't work in lisp, this is for call by name languages
    See http://en.wikipedia.org/wiki/Fixed_point_combinator
    Are you sure you want to
    Your message goes here
    Processing…
  • Thanks Antonio! Wanted to take a closer look at lisp for a long time.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

lisp (vs ruby) metaprogramming lisp (vs ruby) metaprogramming Presentation Transcript

  • Lisp Metaprogramming The programmable programming language Friday, February 19, 2010
  • I’d rather play COD Friday, February 19, 2010
  • “So, Ruby was a Lisp originally, in theory. Let's call it MatzLisp from now on. ;-)” -Matz Friday, February 19, 2010 View slide
  • "Lisp isn't a language, it's a building material." "the greatest single programming language ever designed" “OOP to me means only messaging, local retention and protection and hiding of state- process, and extreme late-binding of all things. It can be done in Smalltalk and in Lisp. There are possibly other systems in which this is possible, but I'm not aware of them.” -Alan Kay Friday, February 19, 2010 View slide
  • Friday, February 19, 2010
  • As seen in Lisp since 1958 late binding garbage collection dynamic typing if-then-else construct function type recursion symbol type Interactive development Lisp Machines ... Friday, February 19, 2010
  • As seen in Lisp since 1958 late binding garbage collection dynamic typing Scheme if-then-else construct Common Lisp function type Clojure recursion Arc symbol type NewLISP Interactive development (JavaScript) Lisp Machines ... Friday, February 19, 2010
  • Lisp in 6 slides Friday, February 19, 2010
  • Data structure: Linked lists Friday, February 19, 2010
  • Data structure: Linked lists ((1 2) (3 4) (5 6)) Friday, February 19, 2010
  • Syntax: Linked lists (again) (define y-combinator (lambda (f) ((lambda (x) (f (x x))) (lambda (x) (f (x x)))))) (homoiconicity) Friday, February 19, 2010
  • Semantics: λ - Calculus λxy.x Friday, February 19, 2010
  • Semantics: λ - Calculus λxy.x (lambda (x y) x) Friday, February 19, 2010
  • Semantics: λ - Calculus λxy.x (lambda (x y) x) (λxy.x 2 4) -β> 2 Friday, February 19, 2010
  • Semantics: λ - Calculus λxy.x (lambda (x y) x) (λxy.x 2 4) -β> 2 ((lambda (x y) x) 2 4) -> 2 Friday, February 19, 2010
  • Semantics: evaluation rule Read-Eval-Print-Loop (+ 3 (- 2 1)) (+ 3 1) 4 Friday, February 19, 2010
  • Semantics: special forms backquote/unquote (backquote (+ 2 3)) -> (+ 2 3) `(+ 2 3) -> (+ 2 3) Friday, February 19, 2010
  • Semantics: special forms backquote/unquote (backquote (+ 2 3)) -> (+ 2 3) `(+ 2 3) -> (+ 2 3) `(unquote (+ 2 3)) -> 5 `,(+ 2 3) -> 5 Friday, February 19, 2010
  • (Common) Lisp Macros Friday, February 19, 2010
  • Why macros? “Pascal is for building pyramids -- imposing, breathtaking, static structures built by armies pushing heavy blocks into place. Lisp is for building organisms -- imposing, breathtaking, dynamic structures built by squads fitting fluctuating myriads of simpler organisms into place. [...] Invent and fit; have fits and reinvent!” -from SICP foreword Friday, February 19, 2010
  • Russian dolls Lisp user forms special forms kernel language Friday, February 19, 2010
  • Russian dolls language extensions Lisp user forms special forms kernel language Friday, February 19, 2010
  • Functions vs Macros Function S-Expressions (f x) Values Macro S-Expressions (f x) S-Expressions Friday, February 19, 2010
  • Functions vs Macros S-Expressions Macro expansion (f x) time S-Expressions’ Compile / execution (f’ x) time Values Friday, February 19, 2010
  • The my-unless function (defun my-unless (c ef et) (if c et ef)) Friday, February 19, 2010
  • The my-unless function (defun my-unless (c ef et) (if c et ef)) (my-unless t 1 2) -> 2 (my-unless nil 1 2) -> 1 Friday, February 19, 2010
  • The my-unless function (defun my-unless (c ef et) (if c et ef)) (my-unless t 1 2) -> 2 (my-unless nil 1 2) -> 1 (my-unless t (print “test”) 1) ->”test” 1 Friday, February 19, 2010
  • The my-unless macro (defmacro my-unless (c ef et) (if c et ef)) Friday, February 19, 2010
  • The my-unless macro (defmacro my-unless (c ef et) (if c et ef)) (my-unless t (print “test”) 1) ->1 Friday, February 19, 2010
  • The my-unless macro (defmacro my-unless (c ef et) (if c et ef)) (my-unless t (print “test”) 1) ->1 (define *c* t) (my-unless *c* (print “test”) 1) Friday, February 19, 2010
  • The my-unless macro (defmacro my-unless (c ef et) `(if ,c ,et ,ef)) (define *c* t) (my-unless *c* (print “test”) 1) Friday, February 19, 2010
  • The my-unless macro (defmacro my-unless (c ef et) `(if ,c ,et ,ef)) (define *c* t) (my-unless *c* (print “test”) 1) (define *c* t) (if *c* 1 (print “test”)) Friday, February 19, 2010
  • The my-unless macro (defmacro my-unless (c ef et) `(if ,c ,et ,ef)) (define *c* t) (my-unless *c* (print “test”) 1) (define *c* t) 1 (if *c* 1 (print “test”)) Friday, February 19, 2010
  • Macros taxonomy flow modification “with” macros -> abstracting pattens (with-file) (with- gearman-request) Object Oriented Lisp (CLOS) and Meta Object Protocol Compilers, pasers, etc. Functional lisp: monads, comonads, Tarski arrows, currying, lazy evaluation Friday, February 19, 2010
  • The Macro Club The first rule of the Macro Club is Don’t Write Macros The second rule of Macro Club is Write Macros If That Is The Only Way to Encapsulate a Pattern -from Programming Clojure Friday, February 19, 2010
  • Ruby metaprogramming? Friday, February 19, 2010
  • Ruby metaprogramming is broken and cannot be fixed (imho) Friday, February 19, 2010
  • (Lisp) [Ruby] Simple regular sintax Complex sintax Complex undefined Simple defined semantics semantics Code = lists Code = strings Code manipulation = list Code manipulation = string manipulation funs. manipulation funs. Macro expansion time Eval at run time Friday, February 19, 2010
  • Alternatives: RubyAST, Ruby parser Code = AST objects Code Manipulation = Objects Manipulation Friday, February 19, 2010
  • No magic please Friday, February 19, 2010
  • References Friday, February 19, 2010
  • The Seasoned On Lisp, Schemer, Paul Graham Friedman Programming SICP, Clojure, Abelson et alt. Stuart Halloway Friday, February 19, 2010
  • λ Friday, February 19, 2010