timothy235 icon

sicp-1-3-2-constructing-procedures-using-lambda

timothy235 | PRO | 12/19/24 01:21:35 AM UTC (Edited) | 0 ⭐ | 386 👁️ | Never ⏰ | []
Racket |

470 B

|

None

|

0 👍

/

0 👎

#lang racket
 
;;;;;;;;;;
;; 1.34 ;;
;;;;;;;;;;
 
(define (f g)
  (g 2))
 
(f sqr)
;; 4
(f (lambda (z) (* z (add1 z))))
;; 6
 
;; (f f) reduces to (f 2) which reduces to (2 2) which produces an error because 2
;; is not a procedure.
 
;; (f f)
;; application: not a procedure;
 ;; expected a procedure that can be applied to arguments
  ;; given: 2
  ;; arguments...:
   ;; 2
  ;; context...:
   ;; C:\Program Files\Racket\collects\racket\private\misc.rkt:87:7

Comments