Re: [racket-users] with-input-from-file question

2018-12-16 Thread Jonathan Simpson
Ah, thanks!

On Sunday, December 16, 2018 at 3:53:06 PM UTC-5, Jon Zeppieri wrote:
>
>
> On Sun, Dec 16, 2018 at 2:59 PM Jonathan Simpson  > wrote:
>
>> What is the difference between this code, which reads and returns "#lang" 
>> from the file:
>> (define in-file (open-input-file "adventure.rkt"))
>> (parameterize ([current-input-port in-file]) (read-string 5))
>>
>> and this code which appears to still read from stdin:
>>
>> (with-input-from-file "adventure.rkt" (read-string 5))
>>
>> I thought with-input-from-file would set the current-input-port to the 
>> file in basically the same way as the first code segment.
>>
>> I see this behavior from both DrRacket and Emacs racket-mode.
>>
>>
> `with-input-from-file` takes a thunk (that is, a procedure of 0 
> parameters) as its second argument, so your code should be:
>
> (with-input-from-file "adventure.rkt" (λ () (read-string 5)))
>
> I'd expect your code to read from stdin but then raise a contract error 
> when checking the arguments to `with-input-from-file`.
>
> - Jon
>
>>
>>

-- 
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] with-input-from-file question

2018-12-16 Thread Jon Zeppieri
On Sun, Dec 16, 2018 at 2:59 PM Jonathan Simpson  wrote:

> What is the difference between this code, which reads and returns "#lang"
> from the file:
> (define in-file (open-input-file "adventure.rkt"))
> (parameterize ([current-input-port in-file]) (read-string 5))
>
> and this code which appears to still read from stdin:
>
> (with-input-from-file "adventure.rkt" (read-string 5))
>
> I thought with-input-from-file would set the current-input-port to the
> file in basically the same way as the first code segment.
>
> I see this behavior from both DrRacket and Emacs racket-mode.
>
>
`with-input-from-file` takes a thunk (that is, a procedure of 0 parameters)
as its second argument, so your code should be:

(with-input-from-file "adventure.rkt" (λ () (read-string 5)))

I'd expect your code to read from stdin but then raise a contract error
when checking the arguments to `with-input-from-file`.

- Jon

>
>

-- 
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] with-input-from-file question

2018-12-16 Thread Jonathan Simpson
What is the difference between this code, which reads and returns "#lang" 
from the file:
(define in-file (open-input-file "adventure.rkt"))
(parameterize ([current-input-port in-file]) (read-string 5))

and this code which appears to still read from stdin:

(with-input-from-file "adventure.rkt" (read-string 5))

I thought with-input-from-file would set the current-input-port to the file 
in basically the same way as the first code segment.

I see this behavior from both DrRacket and Emacs racket-mode.

Thanks,
Jonathan

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