Scheme

2010-03-16 : whining

I’ve been teaching myself Scheme, as a way to keep my brain occupied when I burn out on the math side of Project Euler. Unfortunately, I worry I may be losing my edge. When asked to implement (= m n) in terms of primitives previously constructed1, my first go was:

(define o=
  (lambda (m n)
    (cond
      ((and (zero? m) (zero? n)) #t)
      ((or (zero? m) (zero? n)) #f)
      (else (o= (sub1 m) (sub1 n))))))

When, of course, the obvious answer is:

(define o=
  (lambda (m n)
    (cond
      ((zero? m) (zero? n))
      ((zero? n) #f)
      (else (o= (sub1 m) (sub1 n))))))

What’s depressing is not that I don’t know Scheme, but that my ability to even put together some simple logic is completely broken.

1 (define sub1 (lambda (x) (- x 1)))

  1. So I don’t know scheme either, but ‘the obvious answer’ seems weird to me. You have to wait for n to become 0, instead of the first to become 0, don’t you? Why not use or instead and get the quicker solution. That ‘and’ and #t were superfluous is mildly irrelevant. shrug. Not sure why this bothers you, I guess.


    — カイル    16 March 2010    #
  2. “Not sure why this bothers you, I guess.”

    Agreed. I don’t know Scheme at all, but I was expecting there to be a huge difference between the solutions due to the self-bashing.

    Don’t be so hard on yourself. :]


    — Niki    19 March 2010    #
Name
E-mail
http://
Message
  Textile Help