2

this is motivated by the 'art of the propagator' paper by Radul and Sussman at:

http://web.mit.edu/~axch/www/art.pdf

when they are building a compound progator, they say:

a compound propagator is implemented with a procedure that will construct the propagator’s body on demand. We take care that it is constructed only if some neighbor actually has a value, and that it is constructed only once

the code on page 10 is:

(define (compound-propagator neighbors to-build)
  (let ((done? #f) (neighbors (listify neighbors)))
    (define (test)
      (if done?
          ’ok
        (if (every nothing? (map content neighbors))
            ’ok
          (begin (set! done? #t)
                 (to-build)))))
    (propagator neighbors test)))

How do we do this using clojure's persistent data structures?


a simplified version of this maybe:

(def m {:a (delayed (some-object-constructor))})

where (:a m) constructs the object on the first call and gives and then subsequent calls to (:a m) will access the object.

its sort of like memoize but on values rather than functions..

1 Answer 1

1

As far as delayed execution, delay might be a place to start. It could be used to evaluate the constructor only on the first dereference. It might look something like this:

(defn some-object-constructor
  []
  (println "Making something!")
  :something)

(def m {:a (delay (some-object-constructor))})

(println "Doing some intermediate work.")

(println (deref (:a m)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.