Scheme define/lambda shorthand

Posted by incrediman on Stack Overflow See other posts from Stack Overflow or by incrediman
Published on 2010-05-31T16:54:11Z Indexed on 2010/05/31 17:03 UTC
Read the original article Hit count: 320

Filed under:
|

In Scheme, how can I make use of the define/lambda shorthand for nested lambda expressions within my define?

For example given the following procedure...

(define add
  (lambda (num1 num2)
    (+ num1 num2)))

One can shorten it to this:

(define (add num1 num2)
  (+ num1 num2))


However, how can I shorten the following function similarly ?

(define makeOperator
  (lambda (operator)
    (lambda (num1 num2)
      (operator num1 num2))))

;example useage - equivalent to (* 3 4):
((makeOperator *) 3 4)

© Stack Overflow or respective owner

Related posts about Scheme

Related posts about define