NodeBoxでiSightを使う

ここみた。

test

NodeBoxも楽しいなぁ

Write Yourself a Scheme in 48 Hours

Write Yourself a Scheme in 48 Hoursを3章まで読んだ。RWHのParsecの章を読んでたのと、やさしい Lisp の作り方Mooseでトレースしたことがあるので割とすんなりと進んだ。

ProductName Real World Haskell―実戦で学ぶ関数型言語プログラミング
Bryan O'Sullivan,John Goerzen,Don Stewart
オライリージャパン / ¥ 3,990 ()
在庫あり。

Beginning the Evaluatorの章に

apply func args = maybe (Bool False) ($ args) $ lookup func primitives

ってのがあって、僕はちょっと前まで$を()の構文糖衣だと勘違いしてたのでなんか違和感が。

($ [1,2,3]) (map (1+)) :: map (1+) [1,2,3]

は見慣れれば楽なのかもしれないが。

Prelude> (($[1,2,3]).map) (2-)
[1,0,-1]

とかやるとmapがメソッドっぽく見える

平均値順にソート(Haskell)

mixiの課題丸投げ

import Data.List (sortBy,sort)
import Data.Ord (comparing)

meansort xs = sortBy (comparing (abs . ((average xs)-))) (sort xs)
    where
      average xs = sum xs `div` (length xs)

(続) 行番号付きでソースを出力(Haskellで)

前回の行番号付きでファイルの出力に、さらに5行出力するごとにファイル名行番号を反転表示した後、一時停止して、リターンを押したら出力を再開するプログラムをかけという問題が丸投げされていたのでやってみた。

import System
import System.Console.Readline (readline)

showNext xs file = showNext' 1 xs file

showNext' n xs f | next == [] = do mapM_ putStrLn $ zipWith (\n x -> show n ++ ": " ++  x) [n..]  this
                 | otherwise  = do mapM_ putStrLn $ zipWith (\n x -> show n ++ ": " ++  x) [n..]  this
                                   maybeLine <- readline $ "\ESC[7m" ++ f ++ "(" ++ show (n+4) ++"):\ESC[m"
                                   case maybeLine of
                                     Nothing   -> return ()
                                     Just ""   -> showNext' (n+5) next f
                 where
                   (this,next) = splitAt 5 xs

main = do
  file:_ <- getArgs
  content <- readFile file
  showNext (lines content) file

反転表示を戸惑ったのだけど、教えてもらって解決。

showNext'が冗長なので、もう少し綺麗に書きたい。Stateモナドとか使うといいのかなぁ。

pythonでユークリッド距離

haskellのK-meansのソース読んでたら

dist a b = sqrt . sum $ zipWith (\x y-> (x-y) ^ 2) a b

ってのがあって、pythonでzipWithってあったかなーと思って検索したら、自分のwikiが引っかかった。★付けたいところ。

これをつかうと

from math import *
zipWith = lambda f, xs, ys : [f(x, y) for x,y in zip(xs, ys)]
def dist(xs, ys): return sqrt(sum(zipWith(lambda x, y: (x-y)**2, xs, ys)))

となって、任意の次元にも対応出来る

>>> dist([1,2,3,4],[2,2,2,2])
2.4494897427831779

Arduinoでつぶやく

etherシールド買ったので早速つぶやいてみた

1263726722 1263726728

ProductName Arduinoをはじめようキット

スイッチサイエンス / ¥ 4,200 ()


ProductName Arduinoイーサネット・シールド

スイッチサイエンス / ()


ProductName Arduinoをはじめよう
Massimo Banzi
オライリージャパン / ¥ 2,100 ()
通常4~6日以内に発送

茶華でランチ

義母がチケットを持っているからいこうと誘われ、のこのこついて行った。

和風ダイニング 茶華

11穀米のリゾットというコース(1.7K)。

1263717781 1263717799

1263717775 1263717787

1263717793

全体的に量が少ないという周りの意見であったが、ランチだったらこのぐらいの分量でいいかなとも思う。あと、サラダのあとがなかなか出てこなくて多少持て余した。

10000までの完全数をもとめる(Haskell)

mixiの課題丸投げから「10000以下の完全数を求める」

[n|n <- [1..10000],sum [x | x <- [1..(n `div` 2)], n `mod` x == 0] == n]

Haskell勉強会+twitter飲み

Haskell勉強会の皆様お疲れ様でした。次回もよろしくお願いします。

ProductName Rubyで作る奇妙なプログラミング言語 ~Esoteric Language~
原 悠
毎日コミュニケーションズ / ¥ 2,814 ()
在庫あり。

Twitter飲みの皆様お疲れ様でした。次回もよろしくお願いします。

  • perlの話ができてよかった。DBIxで話が通じた
    • やっぱなんかサービス作っとかないと。
  • @Muchico 今度Arduinoでなんか遊べたらいいですね。遊びましょう。
  • @moa02 今度、沼津〜三島グルメめぐりでもしましょう。行きたいところは結構あります。お酒も前向きに検討する方向で。
  • @suamagoma あべし乙です。あとmooです。
  • ココイチフラグw
  • 職場が近いという事実
  • @canna 帰りに話してたのはこれです。Imaginary Folkloreは僕のlast.fmチャートでは堂々の一位です。

ProductName hydeout productions 2nd Collections
オムニバス,hydeout productions,emancipator,Shing02,Uyama Hiroto,DSK,Nujabes,clammbon by nujabes,Pase Rock,C.L.Smooth,Substantial,Five Deez
インディーズ・メーカー / ¥ 3,000 (2007-11-11)
在庫あり。

行番号付きでソースを出力(Haskellで)

mixiの課題丸投げから

$ runhaskell mixi100116.hs mixi100116.hs
1: import System
2: 
3: main = do
4:   file:_ <- getArgs
5:   content <- readFile file
6:   mapM_ putStrLn $ withNum 1 $ lines content
7:   where 
8:     withNum n [] = []
9:     withNum n (x:xs)  = ((show n) ++ ": " ++ x) : (withNum (n+1) xs)

追記

zipWithがあるじゃないか。忘れてた。

1: import System
2: 
3: main = do
4:   file:_ <- getArgs
5:   content <- readFile file
6:   mapM_ putStrLn $ zipWith (\n x -> show n ++ ": " ++  x) [1..]  (lines content)

数字の連番くっつけたいときはそういうリストを用意してまぜ合わせる。