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

2017-04-26 Thread Jack Firth
A `define/delay` macro for this might be a good addition to `racket/promise`:

(define-simple-macro (define/delay id:id expr:expr)
  (begin (define p (delay expr)) (define (id) (force p

(define/delay conf
  (with-input-from-file "db.conf" read-json))

(conf) ;; forces promise

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2017-04-25 Thread Alex Harsanyi
On Wednesday, April 26, 2017 at 12:12:26 PM UTC+8, David K. Storrs wrote:

> 
> I could do it with a parameter but that's only sweeping the above ugliness 
> under the rug:
> 
> (define conf (make-parameter #f))
> 
> (define (read-conf)
>    (or (conf)
>  (begin
>    (conf (with-input-from-file "db.conf" (thunk (read-json
>    (conf

This is probably the wrong way, as the parameter will only be set in the 
current thread.  The code will read the contents of "db.conf" in every thread 
that `read-conf` is called.

Best Regards,
Alex.

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.