Re: [racket-users] Suppress print lines from required modules

2017-08-27 Thread Matthew Butterick

> On Aug 27, 2017, at 7:30 PM, Shu-Hung You 
>  wrote:
> 
> Something along the line of (open-output-file
> "/dev/null") sounds a bit better but I'm not sure how to create a
> discard-everything output port.


`open-output-nowhere`?

https://docs.racket-lang.org/reference/port-lib.html?q=open-output-nowhere#%28def._%28%28lib._racket%2Fport..rkt%29._open-output-nowhere%29%29
 


-- 
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.


Re: [racket-users] Suppress print lines from required modules

2017-08-27 Thread Shu-Hung You
Parameterizing current-output-port to (open-output-string) redirects
the output to a string. Something along the line of (open-output-file
"/dev/null") sounds a bit better but I'm not sure how to create a
discard-everything output port.

(define ns (make-base-namespace))

(parameterize ([current-namespace ns])
  (eval '(module a racket
   (displayln "a line from module a")
   (provide x)
   (define x 5

(printf "value of x is ~a\n"
(parameterize ([current-namespace ns]
   [current-output-port (open-output-string)])
  (dynamic-require ''a 'x)))

Shu-Hung

On Mon, Aug 28, 2017 at 10:22 AM, Sam Waxman  wrote:
> Let's say I have a module that looks like
>
> (module a racket
>(provide result)
>(print "Annoying print line!")
>(define result 2))
>
> and I'd like the value of result in another module, so in another module, I 
> write
>
> (require a)
>
> or
>
> (dynamic-require ''a 'result)
>
> In both cases, I get the value of result, but by requiring the module, the 
> print line "Annoying print line!" will show up on my screen and be part of 
> the output of the program.
>
> Is there a way to get the value of result from module a without triggering 
> the print, or hiding it in some way? I've played around with print-handlers, 
> but it seems anything I do outside of module a won't affect the printer 
> inside module a.
>
> --
> 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.

-- 
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] Suppress print lines from required modules

2017-08-27 Thread Sam Waxman
Let's say I have a module that looks like

(module a racket
   (provide result)
   (print "Annoying print line!")
   (define result 2))

and I'd like the value of result in another module, so in another module, I 
write

(require a)

or

(dynamic-require ''a 'result)

In both cases, I get the value of result, but by requiring the module, the 
print line "Annoying print line!" will show up on my screen and be part of the 
output of the program.

Is there a way to get the value of result from module a without triggering the 
print, or hiding it in some way? I've played around with print-handlers, but it 
seems anything I do outside of module a won't affect the printer inside module 
a.

-- 
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.