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