星期六, 1月 19, 2013

Yield commands

其實技巧很簡單,只是自己寫著暫記一下,要寫這個的原因是,Learn X The Hard Way 似乎要下架了,索性自己寫一個抓一抓比較快 XD。

mapM_ putStrLn $ map (\x -> "wget http://c.learncodethehardway.org/book/ex" ++ (show x) ++ ".html") [0..52]


---
我相信應該是沒有說明的必要 XD。



2013/01/19 21:03 經由 Josh Ko 建議應該可以執行 commands 的 System.Cmd,這行 code 可以改寫如下。


mapM_ system $ map (\x -> "wget http://c.learncodethehardway.org/book/ex" ++ (show x) ++ ".html") [0..52]

在 ghci 的執行結果如下

Prelude> import System.Cmd
Prelude System.Cmd> mapM_ system $ map (\x -> "wget http://c.learncodethehardway.org/book/ex" ++ (show x) ++ ".html") [0..52]
Loading package filepath-1.3.0.0 ... linking ... done.
Loading package old-locale-1.0.0.4 ... linking ... done.
Loading package old-time-1.1.0.0 ... linking ... done.
Loading package bytestring-0.9.2.1 ... linking ... done.
Loading package unix-2.5.1.1 ... linking ... done.
Loading package directory-1.1.0.2 ... linking ... done.
Loading package process-1.1.0.1 ... linking ... done.
--2013-01-19 20:34:37--  http://c.learncodethehardway.org/book/ex0.html
Resolving c.learncodethehardway.org... 71.19.145.23
Connecting to c.learncodethehardway.org|71.19.145.23|:80... connected.
HTTP request sent, awaiting response... 200 OK
...

朝著更便利性前進一步(其他程式語言都可以透過相關的函式來達成目的,只是我都很懶都是直接複製貼上 XD。)

張貼留言