SourceSecond » 履歴 » バージョン 3
Yuumi Yoshida, 2008-05-23 10:10
1 | 1 | Yuumi Yoshida | |
---|---|---|---|
2 | 3 | Yuumi Yoshida | h1. 第2回目のソースコード |
3 | |||
4 | |||
5 | 1 | Yuumi Yoshida | リスト1:ジャンケン(Javaの場合) |
6 | 3 | Yuumi Yoshida | <pre> |
7 | 1 | Yuumi Yoshida | // Java |
8 | import static java.lang.Math.*; |
||
9 | public class Jyanken { |
||
10 | |||
11 | public static String guu_choki_pa(double r) { |
||
12 | if (r < 0.33) { |
||
13 | return "Guu"; |
||
14 | } else if (r < 0.66) { |
||
15 | return "Choki"; |
||
16 | } else { |
||
17 | return "Pa"; |
||
18 | } |
||
19 | } |
||
20 | |||
21 | public static void jyanken() { |
||
22 | System.out.println(guu_choki_pa(random())); |
||
23 | } |
||
24 | |||
25 | public static void main(String args[]) { |
||
26 | for (int i = 0; i < 10; i++) { |
||
27 | jyanken(); |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 | 3 | Yuumi Yoshida | </pre> |
32 | 1 | Yuumi Yoshida | |
33 | リスト2:ジャンケン(Gaucheの場合) |
||
34 | 3 | Yuumi Yoshida | <pre> |
35 | 1 | Yuumi Yoshida | (use srfi-27) |
36 | |||
37 | (define (guu-choki-pa r) |
||
38 | (cond ((< r 0.33) "Guu") |
||
39 | ((< r 0.66) "Choki") |
||
40 | (else "Pa"))) |
||
41 | |||
42 | (define (jyanken) |
||
43 | (print (guu-choki-pa (random-real)))) |
||
44 | |||
45 | (dotimes (i 10) (jyanken)) |
||
46 | 3 | Yuumi Yoshida | </pre> |
47 | 1 | Yuumi Yoshida | |
48 | リスト5:S式を与えると対応するHTMLを出力するプログラム |
||
49 | 3 | Yuumi Yoshida | <pre> |
50 | 1 | Yuumi Yoshida | (define (print-html e) |
51 | (cond ((list? e) |
||
52 | (print-open-tag (car e)) |
||
53 | (print-html-list (cdr e)) |
||
54 | (print-close-tag (car e))) |
||
55 | (else (display e)))) |
||
56 | |||
57 | (define (print-html-list s) |
||
58 | (cond ((null? s) #f) |
||
59 | (else |
||
60 | (print-html (car s)) |
||
61 | (print-html-list (cdr s))))) |
||
62 | |||
63 | (define (print-open-tag tag) |
||
64 | (display "<") |
||
65 | (display tag) |
||
66 | (display ">")) |
||
67 | |||
68 | (define (print-close-tag tag) |
||
69 | (display "</") |
||
70 | (display tag) |
||
71 | (display ">")) |
||
72 | |||
73 | (define gauche-page |
||
74 | '(html |
||
75 | (head (title "Gauche Web")) |
||
76 | (body (h1 "Gauche Web Page") |
||
77 | (table (tr (td 1)(td "lisp")) |
||
78 | (tr (td 2)(td "scheme")))))) |
||
79 | |||
80 | (print-html gauche-page) |
||
81 | 3 | Yuumi Yoshida | </pre> |