On Wed, Apr 26, 2017 at 12:48 PM, David Storrs <[email protected]> wrote:
>
>
> On Wed, Apr 26, 2017 at 12:21 AM, Jon Zeppieri <[email protected]> wrote:
>>
>> I don't know that there's a right way, but if your functions are
>> nullary, then promises are a decent fit:
>>
>> (define conf
>>   (delay
>>     (with-input-from-file ...)))
>>
>> Then just (force conf) whenever you want the value.
>
>
> Yeah, that works well.  Thanks!
>
> Any thoughts on how to do it for non-nullary functions?
>>

The more complicated your function signatures get, the more worthwhile
it will be to use the memoize package. But for, say, unary functions
you can easily use a hash table:

#lang racket

(define read-conf
  (let ([h (make-hash)])
    (λ (arg)
      (hash-ref! h
                 arg
                 (thunk ...)))))

You can extend this to multiple arguments by using lists as keys, if
you want. Of course, you need to make sure that `equal?` is usefully
defined on your argument types.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to