カテゴリ
全体プログラミング scheme verilog 未分類 以前の記事
2016年 04月2016年 03月 2016年 02月 2016年 01月 2015年 12月 2015年 11月 2015年 10月 2015年 09月 2015年 08月 2015年 07月 2015年 06月 2015年 03月 お気に入りブログ
PHPで競技プログラミングメモ帳
最新のトラックバック
ライフログ
検索
タグ
racket
その他のジャンル
ブログパーツ
最新の記事
外部リンク
ファン
記事ランキング
ブログジャンル
画像一覧
|
プログラミングHaskellを読んでいましたが、第8章以降で実行できないコードが多くなり、断念しました。
とはいえHaskellはぜひ習得したいと考えているので、やる気のあるときは「すごいHaskell」を一通り、やる気のないときはもっとライトなやつをやってみようと思っています。 Haskellでライトな解説ページを探していて、紫藤さんのHPがちょうどいいと感じたので、これをとりあえず。 TVを見ながらでもできるのがすばらしいですね。 今日は「2. プログラムを動かす」をやってみました。 HaskellでREPLする方法は知っていましたが、Haskellでコンパイルする方法は知らなかったので、ためになりました。GHCにはstripコマンドという実行ファイルを小さくするコマンドがあるのですね。3MBのexeが1MBになったので少し感動しました。 初心者のためにメモを残しておきます。 hi.hs〜hi2.lhsをGHCで動作させるには「import System」のところを「import System.Environment」に変更する必要があります。一般的に、ライブラリの関数がどのモジュールに入っているかを調べるにはHoogleかHayooで検索します。 また、hi.hs〜hs2.lhsをGHCIで実行する方法はすぐに見つけられなくて、GHCでコンパイルして実行しました。 #
by tempurature
| 2016-01-17 15:00
| プログラミング
#lang racket
(require rackunit) #| NTTドコモが2010年に「一番好きな数字ランキング」という ランキングを実施してました。ということで、 Racketでそれを実装してみようと思いました。 [一番好きな数字ランキング] 1位:7 2位:3 3位:2 4位:8 5位:5 6位:1 7位:6 8位:4 9位:9 10位:0 ソース:http://ranking.goo.ne.jp/ranking/category/999/faction_Opr7Tu7Tgqet_all/ |# ; ソースコード (define (number->ranking n) (list-ref (list 10 6 3 2 8 5 7 1 4 9) n)) (define (more-favorite? p q) (< (number->ranking p) (number->ranking q))) ; テストコード (check-equal? (number->ranking 7) 1) (check-equal? (number->ranking 3) 2) (check-equal? (number->ranking 2) 3) (check-equal? (number->ranking 8) 4) (check-equal? (number->ranking 5) 5) (check-equal? (number->ranking 1) 6) (check-equal? (number->ranking 6) 7) (check-equal? (number->ranking 4) 8) (check-equal? (number->ranking 9) 9) (check-equal? (number->ranking 0) 10) (check-true (more-favorite? 7 2)) (check-false (more-favorite? 9 4)) (check-false (more-favorite? 5 5)) #
by tempurature
| 2016-01-16 10:07
| scheme
Learn You a Haskell for Great Good! の日本語訳をWeb上に公開されているので紹介します。
プログラミングHaskell が8章で詰まり気味なので、こっちをやってみようかと。 #
by tempurature
| 2016-01-14 00:50
| プログラミング
この問題もビルドチェックしかしてません。しかも8章の生成プロシージャも使っています。
E7.4 note
description: "2-dimentional polar coordinate system" class POINT2 create make_cartesian, make_polar feature make_cartesian(x1, y1: REAL) local m: SINGLE_MATH do create m rho := m.sqrt(sqr(x1)+sqr(y1)) if y1 = 0.0 then if x1 >= 0.0 then theta := 0.0 else theta := pi end elseif (y1/x1).is_nan then if (y1 < 1.0 and x1 < 1.0) then theta := 0.0 else theta := y1.nan end elseif y1.is_positive_infinity then theta := 0.0 elseif y1.is_negative_infinity then theta := pi else theta := m.arc_tangent (y1/x1) end end make_polar(r, th: REAL) do rho := r theta := th end feature rho, theta: REAL x: REAL -- x-coordinate local m: SINGLE_MATH do create m Result := rho * m.cosine (theta) end y: REAL -- y-coordinate local m: SINGLE_MATH do create m Result := rho * m.sine (theta) end distance(p: POINT): REAL -- distance to p local m: SINGLE_MATH do create m Result := m.sqrt(sqr(x-p.x)+sqr(y-p.y)) end translate(a, b: REAL) -- move a horizontally, b virtically local x1, y1: REAL do x1 := x y1 := y make_cartesian(x1+a, y1+b) end rotate(p:POINT; angle: REAL) -- rotate around p do translate(-p.x, -p.y) theta := theta + angle translate(p.x, p.y) end scale(factor: REAL) -- magnify by factor do rho := rho * factor end feature{NONE} sqr(r: REAL): REAL -- square of a number do Result := r * r end pi: REAL local m: SINGLE_MATH do create m Result := m.pi.truncated_to_real end end #
by tempurature
| 2016-01-13 23:42
| プログラミング
#
by tempurature
| 2016-01-13 00:27
| プログラミング
| ||||||||||||||||||||
ファン申請 |
||