Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: PART ONE: Lisp & Education: Re: Norvig's latest paper on Lisp

121 views
Skip to first unread message

WJ

unread,
Nov 15, 2012, 4:54:17 PM11/15/12
to
Ed L. Cashin wrote:

> Good luck. I'm happy so far. Some people diss the"loop" macro, but
> I've been delighted by it. This kind of thing is a real treat for me
> (it was ugly as sin when I did it in Java):
>
> (loop for c in player-cards
> sum (card-blackjack-value c) into n
> count (is-ace c) into n-aces
> finally (return (if (and (> n-aces 0) (< n 12))
> (+ n 10)
> n)))))

Clojure:


(let [n (apply + (map card-blackjack-value player-cards))]
(+ n (if (and (some is-ace player-cards) (< n 12)) 10 0)))

WJ

unread,
Nov 15, 2012, 6:16:25 PM11/15/12
to
Racket:

(let ((n (for/sum ([c player-cards]) (card-blackjack-value c))))
(+ n (if (and (ormap is-ace player-cards) (< n 12)) 10 0)))

WJ

unread,
Dec 20, 2014, 3:23:28 PM12/20/14
to
WJ wrote:

> > Good luck. I'm happy so far. Some people diss the"loop" macro, but
> > I've been delighted by it. This kind of thing is a real treat for me
> > (it was ugly as sin when I did it in Java):
> >
> > (loop for c in player-cards
> > sum (card-blackjack-value c) into n
> > count (is-ace c) into n-aces
> > finally (return (if (and (> n-aces 0) (< n 12))
> > (+ n 10)
> > n)))))

Gauche Scheme:

(use srfi-42)
(let1 total (sum-ec (: c player-cards) (card-blackjack-value c))
(if (and (< total 12) (find is-ace player-cards))
(+ 10 total)
total))
0 new messages