-
Notifications
You must be signed in to change notification settings - Fork 0
2015.02.28 アンダースタンディングコンピュテーション 読書会 第1回
HIGAKI, Masaru edited this page Mar 2, 2015
·
17 revisions
- 件 名:「アンダースタンディングコンピュテーション」 読書会 第1回の案内
- 日 時: 2月28日(土)13時00分~17時00分
- 場 所: 尼崎 小田公民館 学習室4
- 申込み:http://kokucheese.com/event/index/258232/
https://github.com/tomstuart/computationbook
> width, height, depth = [1000, 2250, 250]
=> [1000, 2250, 250]
> width, height, depth = 1000, 2250, 250
=> [1000, 2250, 250]
class Point < Struct.new(:x, :y)
def +(other_point)
Point.new(x + other_point.x, y + other_point.y)
end
end
という記法に違和感がある、という疑問。
案外、 each とか便利メソッドが定義済みなので、有益という結論。
この書籍では Struct#== を利用している。
to_s : #{} などで使われる。そのオブジェクトの文字列表現 to_str : 文字列と同等に扱いたいクラスを自分で定義するときに使う。
p obj # obj.inspect
"#{obj}" # obj.to_s
"abc" + obj # obj.to_str
String(obj) # obj.to_str
などで、暗黙的に型変換されるときに使われます。
字句解析: lex パーサジェネレータ: yacc
関数型言語ではよく使うという話
-> x, y { x + y }
ではなく
-> ( x, y ) { x + y }
と書く方が一般的なのではないか
class Sequence
def reducible?
true
end
def reduce(environment)
case first
when DoNothing.new
[second, environment]
else
reduced_first, reduced_environment = first.reduce(environment)
[Sequence.new(reduced_first, second), reduced_environment]
end
end
end
DoNothing#=== first
ではなく
class Sequence
def reducible?
true
end
def reduce(environment)
case first
when DoNothing
[second, environment]
else
reduced_first, reduced_environment = first.reduce(environment)
[Sequence.new(reduced_first, second), reduced_environment]
end
end
end
DoNothing.=== first
でもいいかも。
田辺農園のバナナはエクアドル産です。 https://www.ana-foods.co.jp/tanabe_farm/