Scheme: Why is there a need to use cond here?

I tried to write a function (simple, i.e. without eqan?) one?, such as:

(define one?
  (lambda (n)
    ((= 1 n))))

But the above does not work, though, when I call it the following:

(one? 1)

I welcome this error:

procedure application: expected procedure, given: #t (no arguments)

The correct way (from The Little Schemer) to write:

(define one?
  (lambda (n)
    (cond
      (else (= 1 n)))))

Why is there a need to use condwith a sentence elseinstead of just returning (= 1 n)?

+3
source share
2 answers

, . TLS, , , , , cond - .

: , .

(lambda (n) (= 1 n))

, , #t #f, .

+6

Little Schemer, , . , cond . psudeo-C ( cond):

int
one(int n)
{     
    switch (foo) {
        default:
           return  1 == n;
    }
}
0

Source: https://habr.com/ru/post/1726742/


All Articles