Skip to content

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/

読書会

Example Code は原本のGitHubからDL可能

https://github.com/tomstuart/computationbook

1.6.1 のローカル変数と代入で、配列でなくても多重代入できます。

> width, height, depth = [1000, 2250, 250]
=> [1000, 2250, 250]
> width, height, depth = 1000, 2250, 250
=> [1000, 2250, 250]

1.6.8 の Struct.new

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, String(obj)

to_s : #{} などで使われる。そのオブジェクトの文字列表現 to_str : 文字列と同等に扱いたいクラスを自分で定義するときに使う。

p obj         # obj.inspect
"#{obj}"      # obj.to_s
"abc" + obj   # obj.to_str
String(obj)   # obj.to_str

などで、暗黙的に型変換されるときに使われます。

コンパイラコンパイラ

字句解析: lex パーサジェネレータ: yacc

flat_map

関数型言語ではよく使うという話

-> 文法

-> x, y { x + y }

ではなく

-> ( x, y ) { x + y }

と書く方が一般的なのではないか

while

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/

オススメのパーサ

パースレット https://github.com/kschiess/parslet