Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread Jack Firth
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 > >  

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread Jon Zeppieri
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 >>

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread David Storrs
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

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread Matthias Felleisen
#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

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread Tim Brown
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.

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-25 Thread Jon Zeppieri
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: >

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-25 Thread Philip McGrath
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

[racket-users] Best way to write run-once-and-cache functions?

2017-04-25 Thread 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