SlideShare a Scribd company logo
Ruby is
an acceptable Lisp

            Vitaly Kushner
             astrails.com
Ruby is better
   then Lisp
Ruby is better
   then Lisp
    sometimes*
        ;-)
Language
http://www.flickr.com/photos/jantik/254695220/
Power
http://www.flickr.com/photos/lrargerich/4187318085/
Blub Language
   Paradox
             Paul Graham
        http://paulgraham.com/avg.html
Is Lisp the most
    powerful?
NO
It depends
Ruby is an Acceptable Lisp
• syntax
• syntax
• linguistic power
• syntax
• linguistic power
• domain
• syntax
• linguistic power
• domain
• libraries
• syntax
• linguistic power
• domain
• libraries
• community
Ruby
History
History

• Yukihiro Matsumoto (aka "Matz")
History

• Yukihiro Matsumoto (aka "Matz")
• Released in 1994
History

• Yukihiro Matsumoto (aka "Matz")
• Released in 1994
• Got known in US about 2000
History

• Yukihiro Matsumoto (aka "Matz")
• Released in 1994
• Got known in US about 2000
• Gained momentum around 2003-2005
more powerful
     than Perl
more object-oriented
   than Python.
Perl
Smalltalk
 Eiffel
  Ada
  Lisp
• Simple consistent syntax
• Dynamically typed
• Late binding
• Single Inheritance with Mixin support
• Everything is an object
• Closures
• Garbage Collection
• Multi platform
Ruby is Awesome
Clean Syntax
var # variable
$var # global variable
@var # instance variable
@@var # class variable
CONST # constant
Class # class
attrs = {
  :src => "foo.img",
  :width => 100,
  :height => 200,
  :class => Avatar
}
User.find params[:id],
 :limit => 10, :order => “name”
if @project.owned_by?(@user)
  return false unless @user.admin?
end
@project.complete!
Higher-order
 functions
Anonymous
 functions
def x_times(x, fun)
  for i in 1..x
    fun.call(i)
  end
end

x_times(10, lambda {|x| puts x})
def x_times(x)
  for i in 1..x
    yield i
  end
end

x_times(10) {|x| puts x}
def x_times(x)
  for i in 1..x
    yield i
  end
end

x_times(10) do |x|
  puts x
end
Everything is
 an Object
that you can extend
class Fixnum
  def x_times
    for i in 1..self
      yield i
    end
  end
end

5.x_times { |x| puts x }
5.times { |x| puts x }
map       {|x|   ...}
collect   {|x|   ...}
select    {|x|   ...}
reject    {|x|   ...}
find      {|x|   ...}
any?      {|x|   ...}
all?      {|x|   ...}
sort      {|a,   b| ...}
3.megabytes
=> 3145728
10.months.from_now
=> Thu Aug 12 03:25:40 0300 2010
5.minutes.ago
=> Mon Oct 12 03:21:02 0200 2009
Closures
def incrementor(increment)
  proc {|x| x + increment}
end

>>   i5 = incrementor(5)
=>   #<Proc:0x01874a78@(irb):46>
>>   i5.call(3)
=>   8
Compact
# ruby
def paidMore(amount)
  proc {|e| e.salary > amount}
end

// C#
public Predicate<Employee> PaidMore(int amount) {
  return delegate(Employee e) {
    return e.Salary > amount;
  }
}
// ruby
def foo(n) lambda {|i| n+=i} end

; lisp
(defun foo (n) (lambda (i) (incf n i)))
# ruby
[1,2,3].map {|n| n*n }.reject {|n| n%3==1 }

; lisp
(remove-if (lambda (n) (= (mod n 3) 1))
           (mapcar (lambda (n) (* n n))
                   '(1 2 3)))
Macros
Ruby fakes macros
   pretty well
OO
      +
Monkey Patching
class Person
  def self.defsay(sound)
    define_method("say_#{sound}") do
      puts sound
    end
  end

  defsay :hello
  defsay :hi
end
>> bob = Person.new
=> #<Person:0x185cba8>
>> bob.say_hello
hello
=> nil
>> bob.say_hi
hi
=> nil
class Plugin < ActiveRecord::Base
  validates_presence_of :name
  validates_presence_of :description
  validates_presence_of :author_id
  belongs_to :author, :class_name => "User"
  has_many :plugin_versions,
    :dependent => :destroy
  belongs_to :default_version,
    :class_name => "PluginVersion"
  acts_as_commentable
  acts_as_taggable
  ...
end
Magic
NoMethodError
method_missing
User.find_by_name_and_company(
   "Vitaly Kushner", "Astrails")
Ruby rewrite
require 'pp'
require 'parse_tree'
require 'parse_tree_extensions'

def print_ast(&block)
 pp block.to_sexp
end
print_ast do
 puts "hello"
end

s(:iter,
   s(:call, nil, :proc, s(:arglist)),
    nil,
     s(:call, nil, :puts, s(:arglist, s(:str, "hello"))))
Multiple inheritance
      is EVIL
         :-)
Modules
 a.k.a. Mixins
module FlyHome
  def set_home
    @home = position
  end

  def fly_home
    fly(@home)
  end
end
class Bird < Living
  include FlyHome
  def fly(direction) ...
  def position ...
end

class Airplane < Machine
  include FlyHome
  def fly(direction) ...
  def position ...
end
Libraries
Rubygems
➜

~

✗
sudo
gem
install
astrails‐safe
Successfully
installed
astrails‐safe‐0.2.7
1
gem
installed
Installing
ri
documentation
for
astrails‐safe‐0.2.7...
Building
YARD
(yri)
index
for
astrails‐safe‐0.2.7...
Installing
RDoc
documentation
for
astrails‐safe‐0.2.7...
➜

~

✗

Rubygems.org
 12,798 gems
Github.com
Community
  attitude
Testing
TDD
TDD
Test Driven Development
BDD
BDD
Behavior Driven Development
Pressure
TATFT
TATFT
Test All The Fucking Time
• Test::Unit
• RSpec
• Shoulda
• Cucumber
• Webrat
it "should be able to show media" do
  @media = stub_media
  Media.stub!(:find).and_return(@media)
  get :show, :id => @media.id
  response.should be_success
end
Ruby is Better
            then Lisp

            Q &A
                        Vitaly Kushner
                         astrails.com

@astrails               @vkushner

More Related Content

PDF
Vim Script Programming
PDF
Happy Go Programming
PPTX
Parse, scale to millions
PDF
Happy Go Programming Part 1
PPTX
Value protocols and codables
ODP
Turtle Graphics in Groovy
KEY
Incremental Development with Lisp: Building a Game and a Website
KEY
Joshua Wehner - Tomorrows Programming Languages Today
Vim Script Programming
Happy Go Programming
Parse, scale to millions
Happy Go Programming Part 1
Value protocols and codables
Turtle Graphics in Groovy
Incremental Development with Lisp: Building a Game and a Website
Joshua Wehner - Tomorrows Programming Languages Today

What's hot (20)

ZIP
Redis and Ohm
PDF
Serializing Ruby Objects in Redis
PPTX
Kotlin
PPT
Linux basics by Raj Miraje
PDF
It's the end of design patterns as we know it (and i feel fine)
PDF
Advanced Radiant
PDF
Smalltalk on rubinius
PDF
Raspberry pi a la cfml
PDF
Perl 5.10
PDF
TRICK2015 results
PDF
Fun with Ruby and Redis
PPTX
iSoligorsk #3 2013
PPTX
Kotlin For Android - Functions (part 3 of 7)
KEY
Redis, Resque & Friends
PDF
Dias do futuro presente da programação
PPTX
Hacking Go Compiler Internals / GoCon 2014 Autumn
PDF
Csp scala wixmeetup2016
PDF
Swift Study #7
KEY
YAPC::Tiny Introduction
PDF
My Adventures In Objective-C (A Rubyists Perspective)
Redis and Ohm
Serializing Ruby Objects in Redis
Kotlin
Linux basics by Raj Miraje
It's the end of design patterns as we know it (and i feel fine)
Advanced Radiant
Smalltalk on rubinius
Raspberry pi a la cfml
Perl 5.10
TRICK2015 results
Fun with Ruby and Redis
iSoligorsk #3 2013
Kotlin For Android - Functions (part 3 of 7)
Redis, Resque & Friends
Dias do futuro presente da programação
Hacking Go Compiler Internals / GoCon 2014 Autumn
Csp scala wixmeetup2016
Swift Study #7
YAPC::Tiny Introduction
My Adventures In Objective-C (A Rubyists Perspective)
Ad

Similar to Ruby is an Acceptable Lisp (20)

PPTX
Ruby for .NET developers
KEY
Introduction to Ruby
ZIP
Meta Programming in Ruby - Code Camp 2010
PPTX
Ruby for PHP developers
PDF
Ruby an overall approach
KEY
Ruby on Rails Training - Module 1
PDF
Workin On The Rails Road
PDF
IJTC%202009%20JRuby
PDF
IJTC%202009%20JRuby
PPTX
Ruby :: Training 1
PDF
The Joy Of Ruby
PPT
WorkinOnTheRailsRoad
PPT
Workin ontherailsroad
PDF
Ruby — An introduction
PDF
Rubinius - A Tool of the Future
PDF
Ruby training day1
PDF
ruby_vs_perl_and_python
PDF
ruby_vs_perl_and_python
ODP
PDF
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby for .NET developers
Introduction to Ruby
Meta Programming in Ruby - Code Camp 2010
Ruby for PHP developers
Ruby an overall approach
Ruby on Rails Training - Module 1
Workin On The Rails Road
IJTC%202009%20JRuby
IJTC%202009%20JRuby
Ruby :: Training 1
The Joy Of Ruby
WorkinOnTheRailsRoad
Workin ontherailsroad
Ruby — An introduction
Rubinius - A Tool of the Future
Ruby training day1
ruby_vs_perl_and_python
ruby_vs_perl_and_python
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ad

More from Astrails (12)

PDF
Building and deploying React applications
PDF
Accounting For Hackers
PDF
Machine Learning: Make Your Ruby Code Smarter
PDF
Migrating from Flux to Redux. Why and how.
PDF
Engineering esthetics
PDF
Lean Software Development
PDF
RubyMotion: Put your Dreams in Motion with Ruby
PDF
WTF is NoSQL
PDF
Cassandra intro
PDF
Ruby is Awesome
PDF
Rails missing features
PDF
Performance - When, What and How
Building and deploying React applications
Accounting For Hackers
Machine Learning: Make Your Ruby Code Smarter
Migrating from Flux to Redux. Why and how.
Engineering esthetics
Lean Software Development
RubyMotion: Put your Dreams in Motion with Ruby
WTF is NoSQL
Cassandra intro
Ruby is Awesome
Rails missing features
Performance - When, What and How

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf

Ruby is an Acceptable Lisp