tag:blogger.com,1999:blog-24599054.post114025602732170438..comments2016-06-15T08:57:25.440-07:00Comments on On Ruby: Reading SICP 1.1.6pat eylerhttps://plus.google.com/112846625814605102746noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-24599054.post-4441385867667987762007-10-14T23:31:00.000-07:002007-10-14T23:31:00.000-07:00Factor? What does Factor have that Forth doesn't h...Factor? What does Factor have that Forth doesn't have? At least Forth has an ANS standard and some vendors and a few thousand person-decades of programmer experience.Ed Boraskyhttp://www.blogger.com/profile/03981870936822944690noreply@blogger.comtag:blogger.com,1999:blog-24599054.post-69207561512856176632007-10-10T13:59:00.000-07:002007-10-10T13:59:00.000-07:00(define (sq a) (* a a))(define (min a b) (if ((def...(define (sq a) (* a a))<BR/>(define (min a b) (if (< a b) a b))<BR/>(define (sumsq a b c)<BR/> (- (+ (sq a) (sq b) (sq c))<BR/> (sq (min (min a b) c))))Rob Mayoffnoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-35593231413545615392007-10-10T11:16:00.000-07:002007-10-10T11:16:00.000-07:00You're missing the point of exercise 1.3. You can ...You're missing the point of exercise 1.3. You can solve it very simply without lists or sorting:<BR/><BR/>(define (largest-two a b c)<BR/> (if (and (>= c a) (>= b a))<BR/> (+ (* b b) (* c c))<BR/> (largest-two b c a)))<BR/><BR/>I won't bother to translate it in to any other languages, because it would be basically the same.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-81206746071221828012007-10-09T23:44:00.000-07:002007-10-09T23:44:00.000-07:00Hehe, I just wrote exactly the same code as Fabio ...Hehe, I just wrote exactly the same code as Fabio Akita and was about to post. I was just intrigued as to why you wouldn't use idiomatic Ruby, when SICP tends to use Scheme very idiomatically.Peter Cooperhttp://www.petercooper.co.uk/noreply@blogger.comtag:blogger.com,1999:blog-24599054.post-23559147173341933442007-10-09T12:20:00.000-07:002007-10-09T12:20:00.000-07:00Anonymous, that looks like a clever way of doing i...Anonymous, that looks like a clever way of doing it, but what happens in the case when A == B == C? That will cause it to recurse for a while, no? :-)tonynoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-10832064296063819012007-10-09T03:00:00.000-07:002007-10-09T03:00:00.000-07:00I made a mistake, I meant:f(A,B,C) when A>C, B>C -...I made a mistake, I meant:<BR/><BR/>f(A,B,C) when A>C, B>C -> A*A + B*B;<BR/>f(A,B,C) -> f(B,C,A).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-53493377111091438822007-10-09T00:37:00.000-07:002007-10-09T00:37:00.000-07:00In Erlang, how about: f(A,B,C) when A>B; B>C -> A...In Erlang, how about: <BR/><BR/>f(A,B,C) when A>B; B>C -> A*A + B*B;<BR/>f(A,B,C) -> f(B,C,A).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-34321901254972324662007-10-08T20:07:00.000-07:002007-10-08T20:07:00.000-07:00I'm just learning Erlang too, but wouldn't this be...I'm just learning Erlang too, but wouldn't this be more idiomatic?:<BR/><BR/>abs(A) when (A<0) -> -A;<BR/>abs(A) -> A.Boyd Adamsonhttp://www.blogger.com/profile/02101020181793002884noreply@blogger.comtag:blogger.com,1999:blog-24599054.post-41289516711053903992007-10-08T17:40:00.000-07:002007-10-08T17:40:00.000-07:00Your first example would be better written off as:...Your first example would be better written off as:<BR/><BR/>def abs(num)<BR/> num < 0 ? -num : num<BR/>endFabio Akita, PMPhttp://www.blogger.com/profile/05539202931163964720noreply@blogger.comtag:blogger.com,1999:blog-24599054.post-68205882040607451762007-10-08T16:15:00.000-07:002007-10-08T16:15:00.000-07:00I'm just getting started with Erlang myself, but h...I'm just getting started with Erlang myself, but how about:<BR/><BR/>sq(X) -> X*X.<BR/><BR/>max(X,Y) when X > Y -> X;<BR/>max(_X,Y) -> Y.<BR/> <BR/>sumsq(A,B,C) when A > B -> sq(A) + sq(max(B,C));<BR/>sumsq(A,B,C) -> sq(B) + sq(max(A,C)).Tonynoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-90907319822230722622007-10-08T16:14:00.000-07:002007-10-08T16:14:00.000-07:00Is Factor "done"? Seems like it's still very much...Is Factor "done"? Seems like it's still very much a work in progress.<BR/><BR/>Can you comment on your choice of Factor and what has made it enjoyable for you?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-24599054.post-21322405649192349142007-10-08T15:49:00.000-07:002007-10-08T15:49:00.000-07:00I think I'd approach the Erlang slightly different...I think I'd approach the Erlang slightly differently. Particularly, while finding the greatest two values from a list *can* be done via sorting, it doesn't *need* sorting. Try the following definition of last_two/1:<BR/><BR/>last_two([], A, B) -><BR/> [A, B];<BR/><BR/>last_two([H|T], nil, _) -><BR/> last_two(T, H, A);<BR/><BR/>last_two([H|T], A, _) when H > A -><BR/> last_two(T, H, A);<Jacob Fugalnoreply@blogger.com