Dodaj to do powyższych odpowiedzi:
pracy poprzez SICP section on Streams. Daje dobre objaśnienie zarówno nazwy wywoławczej, jak i połączenia telefonicznego. Pokazuje również, jak wdrożyć te w Schemacie. BTW, jeśli szukasz szybkiego rozwiązania Oto podstawowe call-by-potrzeby realizowanego na schemacie:
;; Returns a promise to execute a computation. (implements call-by-name)
;; Caches the result (memoization) of the computation on its first evaluation
;; and returns that value on subsequent calls. (implements call-by-need)
(define-syntax delay
(syntax-rules()
((_ (expr ...))
(let ((proc (lambda() (expr ...)))
(already-evaluated #f)
(result null))
(lambda()
(if (not already-evaluated)
(begin
(display "computing ...") (newline)
(set! result (proc))
(set! already-evaluated #t)))
result)))))
;; Forces the evaluation of a delayed computation created by 'delay'.
(define (my-force proc) (proc))
Trasa próbki:
> (define lazy (delay (+ 3 4)))
> (force lazy)
computing ... ;; Computes 3 + 4 and memoizes the result.
7
> (my-force lazy)
7 ;; Returns the memoized value.
mam już wdrożone wezwanie potrzebie, a kiedy Robiłem to pierwsze wdrożenie bez buforowania, nie ma dla mnie sensu, że profesor prosi mnie o zrobienie czegoś, co już zrobiłem, ponieważ chcę zrozumieć prawdziwą różnicę między wezwaniem przez potrzebę a wywołaniem po imieniu – forellana
Potwierdziłem to z profesorem, to jest po nazwisku, byłem zdezorientowany, ponieważ już napisaliśmy ten kod i teraz on prosi nas ponownie o to – forellana