2008-07-08から1日間の記事一覧
SICPの2.2.3 Sequences as Conventional Interfaces(慣習的な作用する配列) の Sequence Operations(配列操作) あたりを Python でやってみた scheme ;2.2.3 Sequences as Conventional Interfaces ;Sequence Operations (define (filter predicate sequ…
早くもSICPの2章でわけわからんと思ってたら、なんかSequenceの扱いを勘違いしてただけだったかも(||゚Д゚) scheme の cons や append と python の appendとか なので確認してみる。 scheme gosh> (cons (list 1 2 3 4 5) (list 1 2 3 4 5)) ((1 2 3 4 5) 1 …
以下WikipediaからダックタイピングのRubyでの単純な例を引用 Ruby def test(foo) puts foo.sound end class Duck def sound 'quack' end end class Cat def sound 'myaa' end end test(Duck.new) test(Cat.new) 結果 quack myaa で、これをPythonでやってみ…
なんとなく知ってるような知らないような三項演算子を使ってPythonでやってみた 奇数か偶数か判定する関数 def odd_or_even(n): return "odd" if n % 2 else "even" print odd_or_even(1) #odd(奇数) print odd_or_even(100) #even(偶数) 結果 odd even …