Skip to content

Instantly share code, notes, and snippets.

View Shinpeim's full-sized avatar

Shinpei Maruyama Shinpeim

View GitHub Profile
@Shinpeim
Shinpeim / osc.go
Last active August 29, 2015 14:05
package main
import (
"bufio"
"code.google.com/p/portaudio-go/portaudio"
"errors"
"fmt"
"os"
"strconv"
"strings"
  • にゃん
  • わん
sub nyan {
# $_[0] で第一引数にアクセ
$_[0] = 2;
}
my $i = 1;
nyan($i);
print $i; # => 2
string = "nyan"
def hoge(s)
s.gsub!("n", "")
end
hoge(string)
p string # => ya
class IntWrapper
attr_accessor :i
def initialize(i)
@i = i
end
end
nyan = IntWrapper.new(1)
def hoge(wrapper)
wrapper.i = 2
import scala.language.implicitConversions
// FlipFlap型クラスを定義
trait FlipFlap[T] {
// このメソッドはアドホック多相を実現する
def flipFlap(x: T): T
}
// Int をFlipFlap型クラスの型インスタンスとして定義
implicit val intFlipFlap = new FlipFlap[Int] {
// type erasure のせいでメソッドのオーバーロードができない
// 以下のようなコンパイルエラーになる
//
// error: double definition:
// method nyan:(x: Option[Boolean])Int and
// method nyan:(x: Option[Int])Int at line 2
// have same type after erasure: (x: Option)Int
def nyan(x: Option[Int]) = 0
def nyan(x: Option[Boolean]) = 1
var Nyan = (function () {
function Nyan() {
this.nyan = "nyan";
}
Nyan.prototype.functionStyle = function () {
return function () {
return this.nyan;
};
};
function compose(f, g) {
return function(x){
return g(f(x));
}
}
var increment = function(x) {
return x + 1;
}
var decrement = function(x) {
function flip(f){
return g; // flip' f = g
function g(x, y){ // where g x y = f y x
return f(y, x)
}
}
function nyan(a, b) {
console.log(a);