Upload
others
View
16
Download
0
Embed Size (px)
Citation preview
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp to Ruby to Rubinius
ネットワーク応用通信研究所 楽天 技術研究所
Rubyアソシエーション@yukihiro_matz
Yukihiro "Matz" Matsumoto
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp1/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
one of the oldest
O-Partsout of place artifact
2/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
O-Parts of the language
oldest but newest
symbolic computation
garbage collection
objects
exceptions
3/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
S-expression
macros
everything object
meta-programming
4/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Dark side of Lisp
Parentheses
dangling language
there's no lisp language
CLOSpowerful but complex
5/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby
Lispy, but
no S-expression
no macros
no CLOS
6/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby
Algol-ish syntax
Smalltalk-ish OO
Language for ordinary programmers
7/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
(defun fact (n) (if (= n 1) 1 (* n (fact (1- n)))))(print (format "6!=~D" (fact 6))); => 6!=720
8/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
;; move parens(defun fact (n) (if (= n 1) 1 (* n (fact (1- n))) ))(print (format "6!=~D" (fact 6)))
9/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
;; operator syntax(defun fact (n) (if (n == 1) 1 (n * (fact (n - 1))) ))(print (format "6!=~D" (fact 6)))
10/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
;; move argument parens(defun fact (n) (if (n == 1) 1 (n * fact(n - 1)) ))print(format("6!=~D", fact(6)))
11/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
;; move argument parens(defun fact (n) (if (n == 1) 1 (n * fact(n - 1)) ))print(format("6!=~D", fact(6)))
12/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
# syntax structuresdefun fact (n) if (n == 1) 1 else (n * fact(n - 1)) endendprint(format("6!=~D", fact(6)))
13/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp
# reduce parensdefun fact (n) if n == 1 1 else n * fact(n - 1) endendprint(format("6!=~D", fact(6)))
14/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby
def fact (n) if n == 0 1 else n * fact(n - 1) endendprintf "6!=%d", fact(6), "\n"# => 6!=720
15/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp vs Ruby
Syntax
Less parentheses
Many 'end's
special forms vs syntax structures
16/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp vs Ruby
Semantics
Quite similar
nearly one to one translation
auto conversion from fixnums to bignums
fact 200
17/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
MatzLisp
18/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
MatzLisp
not MacLisp
not FranzLisp
19/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby
Lisp without S-expression
sprinkled with syntax sugar
with OO from Smalltalk
operators from C
strings/regexp from Perl
20/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Lisp without S-expr
Remember M-expression
21/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby = Weak Lisp?
No S-expression
No Macro
Who cares.
22/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Language Power ≠ Programming Power
23/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Personal History
BASIC to Lisp
24/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
BASIC
25/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
BASIC
26/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Got tired of BASIC
No user defined functions
No user defined data types
27/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Aristocracy
Language Designers
Implementers
−−−−−−−−−−−−−−−−−−−−−−−−
Programmers
28/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
I met Lisp
in an AI book
Lisp made my eyes open
users can do everything
29/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Users can do Everything
define functions
define data types
enhance the language
30/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Democracy
no discrimination
users can be language implementers
31/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
But, wait
Unlike politics (or like politics)
freedom comes with responsibility
ordinary people hate (too much) responsibility
or too much power
32/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Too much power
smart people love power
smart people underestimate ordinarity of ordinary people
33/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
中庸Happy Medium
34/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Happy Medium
There should be somewhere in between language
aristocracy and democracy, where ordinary people can live happily, without feeling
fear.
35/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Balance
It's quite easy to pursue extreme, but seeking
'something in-between' is far more difficult.
36/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby37/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Ruby
My answer to the ultimate question.
38/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Result
39/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Self-sustaining languages
C
Lisp
MFTL
Ruby
40/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
My Favorite Toy Language
n. Describes a language about which the developers are passionate but no one else cares about.
--Jargon File
41/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
My Favorite Toy Language
The first great goal in the mind of the designer of an MFTL is usually to write a compiler for it
--Jargon File
42/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
I am not a fan of meta-circular implementation
43/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Switching the brain
C → Core mode
Ruby → App mode
44/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Self-sustaining systems
C
Compiler written in C
Compiled code does not rely on the language
45/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Self-sustaining systems
Squeak
Bootstrap
Core written in Slangsubset of Smalltalk
compiles to C
libraries in Smalltalk
46/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Rubinius
Ruby implementation influenced by Smalltalk
47/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Rubinius
small VM in C++
libraries written in Ruby
48/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Bootstrap
VM1.
alpha2.
bootstrap3.
platform4.
common5.
delta6. 49/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
VM
The virtual machine is able to load and execute bytecode, send messages (i.e. look up
and execute methods), and all primitive functions are
available, but not yet hooked up as Ruby methods.
50/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
VM
At this point there is enough defined behavior to begin to
load up the rest of the runtime kernel which is all
defined in ruby. This has to be done in several passes as the
language grows.
51/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
alpha
This starts the loading of Ruby code. The ability to open classes and modules and
define methods exists. Also, it is possible to raise exceptions
and cause the running process to exit. This stage lays the foundation for the
next two stages.52/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
bootstrap
This stage continues to add the minimum functionality to support loading platform and
common. The primitive functions are added for most
of the kernel classes.
53/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
platform
The FFI system is implemented and Ruby
method interfaces to platform-specific functions are
created. Once this is set up, platform specific things such
as file access, math, and POSIX commands are
attached.54/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
common
The vast majority of the Ruby core library classes are
implemented. The Ruby core classes are kept as
implementation-neutral as possible.
55/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
delta
Implementation-specific versions of methods that
override the versions provided in common are added.
56/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Problems
performance
open class
57/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
(Possible) Solution
JIT (LLVM)
selector namespace / classbox
58/59
Lisp to Ruby to Rubinius Powered by Rabbit 0.6.4
Thank you!
59/59