kink: developing a programming language on the jvm

8
2010-08-28 Kink: developing a programming language on the JVM @miyakawa taku

Upload: taku-miyakawa

Post on 13-Jul-2015

730 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Kink: developing a programming language on the JVM

2010-08-28

Kink: developing a programming

language on the JVM

@miyakawa taku

Page 2: Kink: developing a programming language on the JVM

What is Kink• A programming language on the JVM

• Hosted on Google Code

– http://code.google.com/p/kink-lang/

Page 3: Kink: developing a programming language on the JVM

What kind of language

• Prototype-based

– No classes, only constructor methods

– Like Lua and JavaScript

• Functional (not purely)

– First-class lambda

– List processing methods

– Like Lisps, especially Scheme

Page 4: Kink: developing a programming language on the JVM

Bank account example

&account = { %[ &INITIAL = 0 ]&BALANCE = INITIALvalue(

’balance’ : { BALANCE }’withdraw’ : { &BALANCE << BALANCE - __ }’deposit’ : { &BALANCE << BALANCE + __ }

)}&MY_ACCOUNT = account( 100 )MY_ACCOUNT.deposit( 32.5 )MY_ACCOUNT.balance.dump # => 132.5

Page 5: Kink: developing a programming language on the JVM

Swing example

@use ’Java’@use_class ’javax.swing.JFrame’@use_class ’javax.swing.JButton’@use_class ’javax.swing.JOptionPane’&BUTTON = JButton.new( ’Push me’ )BUTTON.addActionListener {{

JOptionPane.showMessageDialog( null ’Pushed!’ )}}&FRAME = JFrame.new( "Swingin’" )FRAME.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE )FRAME.getContentPane.add( BUTTON )FRAME.packFRAME.setVisible( true )

Page 6: Kink: developing a programming language on the JVM

Pros and cons• Pros: simple semantics/syntax

– No classes

– No semicolons and no commas

– Easy-to-write lambda: { * 2 }• Cons: VERY slow

– time tak(12, 6, 0)

JRuby 1.4 5 seconds

Kink 246 seconds

– But also JRuby WAS very slow

Page 7: Kink: developing a programming language on the JVM

What is great about JRuby

• Performance

• Compatibility

– With MRI and POSIX

– Write many, run anywhere!

Page 8: Kink: developing a programming language on the JVM

Developing a language on the JVM

• Good way to learn Java SE, JVM, and

programming

– Class loading

– Byte code generation

– Design patterns

• Write your language, it’s fun!