|
Kink is a prototype-based functional language on the JVM. The goal of the language is easy and elastic programming with handful number of simple mechanisms. Both the language and the implementation are now under development. There is no official release yet. KinkはJVM上で動くプロトタイプベースの関数的言語です。数少ない単純な仕組みで、簡潔かつ柔軟なプログラミングができることを目指しています。 言語および処理系ともに現在開発中です。公式のリリースはまだありません。 ExamplesBank account# Constructor of a bank account
&account = { (&INITIAL = 0)
&BALANCE = INITIAL
value(
'balance' { BALANCE }
'withdraw' { &BALANCE.replace(BALANCE - \0) }
'deposit' { &BALANCE.replace(BALANCE + \0) }
)
}
# Creates an account with $100, deposits $32.5,
# and displays the balance
&MY_ACCOUNT = account(100)
MY_ACCOUNT.deposit(32.5)
dump(MY_ACCOUNT.balance) # => 132.5Swinguseclass('javax.swing.JFrame')
useclass('javax.swing.JButton')
useclass('javax.swing.JOptionPane')
&BUTTON = JButton.new('Push').via {
\0.addActionListener {
JOptionPane.showMessageDialog(null 'You pushed!')
}
}
&FRAME = JFrame.new("Swingin'").via {
\0.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
\0.getContentPane.add(BUTTON)
\0.pack
\0.setSize(200 150)
\0.setLocationRelativeTo(null)
}
FRAME.setVisible(true)Fizz buzz# USAGE:
# $ kink fizzbuzz.kn 15
# 1 2 fizz 4 buzz fizz 7 8 fizz buzz
# 11 fizz 13 14 fizzbuzz
&message = { (&N)
switch(
{ N % 15 == 0 } => { 'fizzbuzz' }
{ N % 3 == 0 } => { 'fizz' }
{ N % 5 == 0 } => { 'buzz' }
any => { N }
)
}
&COUNT = _argv.first.int
&MESSAGES = 1.up.map($message).take(COUNT)
printline(MESSAGES.string(' '))Y combinator# Y combinator
&fix = { (&f)
&g = { (&x)
f { x($x).call(\0) }
}
g($g)
}
# Factorial with no recursion
&factorial = fix { (&ff)
proc1(
0 => { 1 }
&N => { N * ff(N - 1) }
)
}
&N = _argv.first.int
&F = factorial(N)
printline(expand('#N! = #F'))
|