プロジェクト

全般

プロフィール

操作

SourceSecond » 履歴 » リビジョン 3

« 前 | リビジョン 3/4 (差分) | 次 »
Yuumi Yoshida, 2008-05-23 10:10


h1. 第2回目のソースコード

リスト1:ジャンケン(Javaの場合)

// Java
import static java.lang.Math.*;
public class Jyanken {

public static String guu_choki_pa(double r) {
   if (r < 0.33)  {
      return "Guu";
   } else if (r < 0.66) {
      return "Choki";
   } else {
      return "Pa";
   }
}

public static void jyanken() {
    System.out.println(guu_choki_pa(random()));
}

public static void main(String args[]) {
    for (int i = 0; i < 10; i++) {
        jyanken();
    }
}

}

リスト2:ジャンケン(Gaucheの場合)

(use srfi-27)

(define (guu-choki-pa r)
(cond ((< r 0.33) "Guu")
((< r 0.66) "Choki")
(else "Pa")))

(define (jyanken)
(print (guu-choki-pa (random-real))))

(dotimes (i 10) (jyanken))

リスト5:S式を与えると対応するHTMLを出力するプログラム

(define (print-html e)
(cond ((list? e)
(print-open-tag (car e))
(print-html-list (cdr e))
(print-close-tag (car e)))
(else (display e))))

(define (print-html-list s)
(cond ((null? s) #f)
(else
(print-html (car s))
(print-html-list (cdr s)))))

(define (print-open-tag tag)
(display "<")
(display tag)
(display ">"))

(define (print-close-tag tag)
(display "</")
(display tag)
(display ">"))

(define gauche-page
'(html
(head (title "Gauche Web"))
(body (h1 "Gauche Web Page")
(table (tr (td 1)(td "lisp"))
(tr (td 2)(td "scheme"))))))

(print-html gauche-page)

Yuumi Yoshida さんがほぼ16年前に更新 · 3件の履歴