Ruby is an Acceptable Lisp

  • 1,327 views
Uploaded on

Why ruby is a practical implementation of Lisp and why is a good replacement that actually can be used in production

Why ruby is a practical implementation of Lisp and why is a good replacement that actually can be used in production

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,327
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Ruby isan acceptable Lisp Vitaly Kushner astrails.com
  • 2. Ruby is better then Lisp
  • 3. Ruby is better then Lisp sometimes* ;-)
  • 4. Language
  • 5. http://www.flickr.com/photos/jantik/254695220/
  • 6. Power
  • 7. http://www.flickr.com/photos/lrargerich/4187318085/
  • 8. Blub Language Paradox Paul Graham http://paulgraham.com/avg.html
  • 9. Is Lisp the most powerful?
  • 10. NO
  • 11. It depends
  • 12. • syntax
  • 13. • syntax• linguistic power
  • 14. • syntax• linguistic power• domain
  • 15. • syntax• linguistic power• domain• libraries
  • 16. • syntax• linguistic power• domain• libraries• community
  • 17. Ruby
  • 18. History
  • 19. History• Yukihiro Matsumoto (aka "Matz")
  • 20. History• Yukihiro Matsumoto (aka "Matz")• Released in 1994
  • 21. History• Yukihiro Matsumoto (aka "Matz")• Released in 1994• Got known in US about 2000
  • 22. History• Yukihiro Matsumoto (aka "Matz")• Released in 1994• Got known in US about 2000• Gained momentum around 2003-2005
  • 23. more powerful than Perlmore object-oriented than Python.
  • 24. PerlSmalltalk Eiffel Ada Lisp
  • 25. • Simple consistent syntax• Dynamically typed• Late binding• Single Inheritance with Mixin support
  • 26. • Everything is an object• Closures• Garbage Collection• Multi platform
  • 27. Ruby is Awesome
  • 28. Clean Syntax
  • 29. var # variable$var # global variable@var # instance variable@@var # class variableCONST # constantClass # class
  • 30. attrs = { :src => "foo.img", :width => 100, :height => 200, :class => Avatar}
  • 31. User.find params[:id], :limit => 10, :order => “name”
  • 32. if @project.owned_by?(@user) return false unless @user.admin?end@project.complete!
  • 33. Higher-order functions
  • 34. Anonymous functions
  • 35. def x_times(x, fun) for i in 1..x fun.call(i) endendx_times(10, lambda {|x| puts x})
  • 36. def x_times(x) for i in 1..x yield i endendx_times(10) {|x| puts x}
  • 37. def x_times(x) for i in 1..x yield i endendx_times(10) do |x| puts xend
  • 38. Everything is an Objectthat you can extend
  • 39. class Fixnum def x_times for i in 1..self yield i end endend5.x_times { |x| puts x }
  • 40. 5.times { |x| puts x }
  • 41. map {|x| ...}collect {|x| ...}select {|x| ...}reject {|x| ...}find {|x| ...}any? {|x| ...}all? {|x| ...}sort {|a, b| ...}
  • 42. 3.megabytes=> 3145728
  • 43. 10.months.from_now=> Thu Aug 12 03:25:40 0300 2010
  • 44. 5.minutes.ago=> Mon Oct 12 03:21:02 0200 2009
  • 45. Closures
  • 46. def incrementor(increment) proc {|x| x + increment}end>> i5 = incrementor(5)=> #<Proc:0x01874a78@(irb):46>>> i5.call(3)=> 8
  • 47. Compact
  • 48. # rubydef paidMore(amount) proc {|e| e.salary > amount}end// C#public Predicate<Employee> PaidMore(int amount) { return delegate(Employee e) { return e.Salary > amount; }}
  • 49. // rubydef foo(n) lambda {|i| n+=i} end; lisp(defun foo (n) (lambda (i) (incf n i)))
  • 50. # 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)))
  • 51. Macros
  • 52. Ruby fakes macros pretty well
  • 53. OO +Monkey Patching
  • 54. class Person def self.defsay(sound) define_method("say_#{sound}") do puts sound end end defsay :hello defsay :hiend
  • 55. >> bob = Person.new=> #<Person:0x185cba8>>> bob.say_hellohello=> nil>> bob.say_hihi=> nil
  • 56. 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
  • 57. Magic
  • 58. NoMethodError
  • 59. method_missing
  • 60. User.find_by_name_and_company( "Vitaly Kushner", "Astrails")
  • 61. Ruby rewrite
  • 62. require pprequire parse_treerequire parse_tree_extensionsdef print_ast(&block) pp block.to_sexpend
  • 63. print_ast do puts "hello"ends(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, nil, :puts, s(:arglist, s(:str, "hello"))))
  • 64. Multiple inheritance is EVIL :-)
  • 65. Modules a.k.a. Mixins
  • 66. module FlyHome def set_home @home = position end def fly_home fly(@home) endend
  • 67. class Bird < Living include FlyHome def fly(direction) ... def position ...endclass Airplane < Machine include FlyHome def fly(direction) ... def position ...end
  • 68. Libraries
  • 69. Rubygems
  • 70. ➜

~

✗
sudo
gem
install
astrails‐safeSuccessfully
installed
astrails‐safe‐0.2.71
gem
installedInstalling
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...➜

~

✗

  • 71. Rubygems.org 12,798 gems
  • 72. Github.com
  • 73. Community attitude
  • 74. Testing
  • 75. TDD
  • 76. TDDTest Driven Development
  • 77. BDD
  • 78. BDDBehavior Driven Development
  • 79. Pressure
  • 80. TATFT
  • 81. TATFTTest All The Fucking Time
  • 82. • Test::Unit• RSpec• Shoulda• Cucumber• Webrat
  • 83. 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_successend
  • 84. Ruby is Better then Lisp Q &A Vitaly Kushner astrails.com@astrails @vkushner