SICP Lite #5 × 第1回チキチキ もっと素人臭いSICP読書会 in Java-jaに行ってきた。



java-ja来てた??


問題1.3


問題1.3はJavaScriptとSchemeで考えながら解いた。


帰宅してから解答がおおよそ浮かび、翌日の朝やっと完了。


Gauche


(define (proc1 a b c)
(if (and (<= a b)(<= a c))
(+ (proc2 b)(proc2 c))
(proc1 b c a)))

(define (proc2 x)
(* x x))

(print (proc1 1 2 3))
;=>13
(print (proc1 2 4 3))
;=>25
(print (proc1 5 4 3))
;=>41
(print (proc1 1 1 1))
;=>2

JavaScript



  • defineはvarで宣言した変数に束縛する。function宣言だと書いてみたけどないわー。

  • 原則returnで返す。



var proc1 = function(a,b,c){
if(a <= b && a <= c){
return proc2(b) + proc2(c);
}
return proc1(b,c,a);
};
var proc2 = function(x){
return x * x;
};

alert(proc1(1,2,3));
//=>13
alert(proc1(2,4,3));
//=>25
alert(proc1(5,4,3));
//=>41
alert(proc1(1,1,1));
//=>2

トラックバック(0)

このブログ記事を参照しているブログ一覧: SICP Lite #5 × 第1回チキチキ もっと素人臭いSICP読書会 in Java-jaに行ってきた。

このブログ記事に対するトラックバックURL: http://www.rokujyouhitoma.com/mt/mt-tb.cgi/159

あわせて読みたい

  • あわせて読みたいブログパーツ

Lingr java-ja

ウェブページ

Powered by Movable Type 4.1