On Wednesday, April 26, 2017 at 9:48:56 AM UTC-7, David K. Storrs wrote:
> On Wed, Apr 26, 2017 at 12:21 AM, Jon Zeppieri 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
>
>
On Wed, Apr 26, 2017 at 12:48 PM, David Storrs wrote:
>
>
> On Wed, Apr 26, 2017 at 12:21 AM, Jon Zeppieri 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
>>
On Wed, Apr 26, 2017 at 12:21 AM, Jon Zeppieri 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
#lang racket
(define read-conf
(let [(conf (delay (with-input-from-file “db.conf" (thunk (displayln "hello")
(read)]
(thunk
(force conf
(read-conf)
(read-conf)
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To
On Wednesday, April 26, 2017 at 5:21:41 AM UTC+1, Jon Zeppieri wrote:
> (define conf
> (delay
> (with-input-from-file ...)))
>
> Then just (force conf) whenever you want the value.
I tend to call promises xxx-promise (e.g. conf-promise),
to remind me not to use them without force'ing them.
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.
On Wed, Apr 26, 2017 at 12:12 AM, David Storrs wrote:
>
In this very simple case, I would probably not define a function at all,
just something like
(define conf
(with-input-from-file "db.conf"
read-json))
You may also find yourself wanting define-runtime-path from
racket/runtime-path.
On Tue, Apr 25, 2017 at 11:12 PM, David Storrs
Reading configuration files is a good example of a run-once function. It's
effectively self-memoizing -- it should run once, cache its result, and on
future calls just return the cached value. I could pull in
https://docs.racket-lang.org/memoize/index.html or
8 matches
Mail list logo