Re: [racket-users] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Alex Knauth

> On Aug 10, 2016, at 9:08 AM, Robby Findler  
> wrote:
> 
> On Wed, Aug 10, 2016 at 8:10 AM, Alex Knauth  wrote:
>>> I believe this fixes a bug in DrRacket but the way these handlers are
>>> set up is pretty complicated. Here's an example program that behaves
>>> differently in 6.6 and the version with those commits. I think the 6.6
>>> behavior is wrong (i.e. the newlines between the three numbers should
>>> be appearing). My inference is based on a reading of the docs and some
>>> experimentation with the racket binary. In particular, the docs say
>>> that `print` should be printing a newline, and they say that `print`
>>> should be calling the global-port-print-handler. Thus, even when the
>>> global-port-print-handler doesn't print a newline we should still see
>>> one.
>> 
>> When I read the docs to see what `#lang constructor-style-print` should do, 
>> it
>> said two things. One, that `current-print` should print a newline. Two, that
>> `global-port-print-handler` and `print` should do the same thing, which is
>> *not* print a newline, because `print` doesn't print one (that's `println`'s 
>> job).
> 
> Sorry: I wrote print but meant current-print.
> 
> Regardless, DrRacket's current behavior seems to be in line with the
> racket binary and the documentation.

It seems to be using `global-port-print-handler`, not `current-print`. If I 
comment out my overridden `current-print`, I get the same no-newline behavior, 
and if I add a debugging printf to my new `global-port-print-handler`, I get 
the output:

(global-port-print-handler)#t(global-port-print-handler)#f(global-port-print-handler)(list
 2 3)

Alex Knauth

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Robby Findler
On Wed, Aug 10, 2016 at 8:10 AM, Alex Knauth  wrote:
>> I believe this fixes a bug in DrRacket but the way these handlers are
>> set up is pretty complicated. Here's an example program that behaves
>> differently in 6.6 and the version with those commits. I think the 6.6
>> behavior is wrong (i.e. the newlines between the three numbers should
>> be appearing). My inference is based on a reading of the docs and some
>> experimentation with the racket binary. In particular, the docs say
>> that `print` should be printing a newline, and they say that `print`
>> should be calling the global-port-print-handler. Thus, even when the
>> global-port-print-handler doesn't print a newline we should still see
>> one.
>
> When I read the docs to see what `#lang constructor-style-print` should do, it
> said two things. One, that `current-print` should print a newline. Two, that
> `global-port-print-handler` and `print` should do the same thing, which is
> *not* print a newline, because `print` doesn't print one (that's `println`'s 
> job).

Sorry: I wrote print but meant current-print.

Regardless, DrRacket's current behavior seems to be in line with the
racket binary and the documentation.

Robby

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Alex Knauth

> On Aug 10, 2016, at 8:04 AM, Robby Findler  
> wrote:
> 
> This is the change to DrRacket:
> 
>  
> https://github.com/racket/drracket/commit/edfea2c649d4d1cfdc2c9facf4dbdb4663be0a07
> 
> (you'll want the subsequent commit too, tho).
> 
> I believe this fixes a bug in DrRacket but the way these handlers are
> set up is pretty complicated. Here's an example program that behaves
> differently in 6.6 and the version with those commits. I think the 6.6
> behavior is wrong (i.e. the newlines between the three numbers should
> be appearing). My inference is based on a reading of the docs and some
> experimentation with the racket binary. In particular, the docs say
> that `print` should be printing a newline, and they say that `print`
> should be calling the global-port-print-handler. Thus, even when the
> global-port-print-handler doesn't print a newline we should still see
> one.

When I read the docs to see what `#lang constructor-style-print` should do, it 
said two things. One, that `current-print` should print a newline. Two, that 
`global-port-print-handler` and `print` should do the same thing, which is 
*not* print a newline, because `print` doesn't print one (that's `println`'s 
job).

> #lang racket
> (global-port-print-handler
> (λ (val port [depth 0])
>   (fprintf port "~s" val)))
> 
> 1 2 3
> 
> Robby
> 
> 
> On Wed, Aug 10, 2016 at 7:50 AM, Alex Knauth  wrote:
>> 
>>> On Aug 10, 2016, at 7:34 AM, Delphine Demange  
>>> wrote:
>> 
 The `constructor-style-print` function isn't supposed to add a newline.
>>> 
>>> Okay, I got confused because in DrRacket, running
>>> 
>>> --
>>> #lang constructor-style-print racket
>>> true
>>> false
>>> (cdr (list 1 2 3))
>>> --
>>> 
>>> was resulting in
>>> --
>>> #t#f(list 2 3)
>>> --
>>> (no whitespace, no newline) in the interaction window. But here again, 
>>> maybe the initial use case was not including this kind of program either.
>>> 
>>> From the racket REPL, which is what I really need, it does behaves 
>>> correctly without the call to pretty-write.
>> 
>> Oh, that's really weird...
>> 
>> And not just on the repl, running `racket test-constructor-style-print.rkt` 
>> with that text also prints newlines. I guess DrRacket is doing something 
>> weird now, that it wasn't doing before.
>> 
>> In 6.0, it prints the newlines properly, but in 6.6.0.2 it works on the 
>> command-line but not in DrRacket. Did DrRacket change it's behavior recently?
>> 
>> Alex Knauth
>> 
>>> Thanks for the feedback, Alex.
>>> 
>>> Delphine
>> 
>> --
>> 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.

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Robby Findler
This is the change to DrRacket:

  
https://github.com/racket/drracket/commit/edfea2c649d4d1cfdc2c9facf4dbdb4663be0a07

(you'll want the subsequent commit too, tho).

I believe this fixes a bug in DrRacket but the way these handlers are
set up is pretty complicated. Here's an example program that behaves
differently in 6.6 and the version with those commits. I think the 6.6
behavior is wrong (i.e. the newlines between the three numbers should
be appearing). My inference is based on a reading of the docs and some
experimentation with the racket binary. In particular, the docs say
that `print` should be printing a newline, and they say that `print`
should be calling the global-port-print-handler. Thus, even when the
global-port-print-handler doesn't print a newline we should still see
one.

#lang racket
(global-port-print-handler
 (λ (val port [depth 0])
   (fprintf port "~s" val)))

1 2 3

Robby


On Wed, Aug 10, 2016 at 7:50 AM, Alex Knauth  wrote:
>
>> On Aug 10, 2016, at 7:34 AM, Delphine Demange  
>> wrote:
>
>>> The `constructor-style-print` function isn't supposed to add a newline.
>>
>> Okay, I got confused because in DrRacket, running
>>
>> --
>> #lang constructor-style-print racket
>> true
>> false
>> (cdr (list 1 2 3))
>> --
>>
>> was resulting in
>> --
>> #t#f(list 2 3)
>> --
>> (no whitespace, no newline) in the interaction window. But here again, maybe 
>> the initial use case was not including this kind of program either.
>>
>> From the racket REPL, which is what I really need, it does behaves correctly 
>> without the call to pretty-write.
>
> Oh, that's really weird...
>
> And not just on the repl, running `racket test-constructor-style-print.rkt` 
> with that text also prints newlines. I guess DrRacket is doing something 
> weird now, that it wasn't doing before.
>
> In 6.0, it prints the newlines properly, but in 6.6.0.2 it works on the 
> command-line but not in DrRacket. Did DrRacket change it's behavior recently?
>
> Alex Knauth
>
>> Thanks for the feedback, Alex.
>>
>> Delphine
>
> --
> 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.


Re: [racket-users] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Alex Knauth

> On Aug 10, 2016, at 7:34 AM, Delphine Demange  
> wrote:

>> The `constructor-style-print` function isn't supposed to add a newline.
> 
> Okay, I got confused because in DrRacket, running 
> 
> --
> #lang constructor-style-print racket 
> true
> false
> (cdr (list 1 2 3))
> --
> 
> was resulting in 
> --
> #t#f(list 2 3)
> --
> (no whitespace, no newline) in the interaction window. But here again, maybe 
> the initial use case was not including this kind of program either.
> 
> From the racket REPL, which is what I really need, it does behaves correctly 
> without the call to pretty-write.

Oh, that's really weird...

And not just on the repl, running `racket test-constructor-style-print.rkt` 
with that text also prints newlines. I guess DrRacket is doing something weird 
now, that it wasn't doing before.

In 6.0, it prints the newlines properly, but in 6.6.0.2 it works on the 
command-line but not in DrRacket. Did DrRacket change it's behavior recently?

Alex Knauth

> Thanks for the feedback, Alex.
> 
> Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Robby Findler
The lack of newlines is probably because of a bug that I pushed a fix
for. Maybe try a shapshot build?

https://pre.racket-lang.org/installers/

Robby

On Wed, Aug 10, 2016 at 7:34 AM, Delphine Demange
 wrote:
>
>> Yes, DrRacket's "constructor" mode does this. This code was based on the 
>> teaching languages though, and the teaching languages set 
>> `booleans-as-true/false` to false here:
>> https://github.com/racket/htdp/blob/master/htdp-lib/htdp/bsl/runtime.rkt#L15
>>
>> Neither one is really more "constructor"-y than the other.
>
> I see. Thanks for the clarification.
>
>> The `constructor-style-print` function isn't supposed to add a newline.
>
> Okay, I got confused because in DrRacket, running
>
> --
> #lang constructor-style-print racket
> true
> false
> (cdr (list 1 2 3))
> --
>
> was resulting in
> --
> #t#f(list 2 3)
> --
> (no whitespace, no newline) in the interaction window. But here again, maybe 
> the initial use case was not including this kind of program either.
>
> From the racket REPL, which is what I really need, it does behaves correctly 
> without the call to pretty-write.
>
> Thanks for the feedback, Alex.
>
> Delphine
>
> --
> 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.


Re: [racket-users] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Delphine Demange

> Yes, DrRacket's "constructor" mode does this. This code was based on the 
> teaching languages though, and the teaching languages set 
> `booleans-as-true/false` to false here:
> https://github.com/racket/htdp/blob/master/htdp-lib/htdp/bsl/runtime.rkt#L15
> 
> Neither one is really more "constructor"-y than the other.

I see. Thanks for the clarification.

> The `constructor-style-print` function isn't supposed to add a newline.

Okay, I got confused because in DrRacket, running 

--
#lang constructor-style-print racket 
true
false
(cdr (list 1 2 3))
--

was resulting in 
--
#t#f(list 2 3)
--
(no whitespace, no newline) in the interaction window. But here again, maybe 
the initial use case was not including this kind of program either.

>From the racket REPL, which is what I really need, it does behaves correctly 
>without the call to pretty-write.

Thanks for the feedback, Alex.

Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Alex Knauth

> On Aug 10, 2016, at 4:53 AM, Delphine Demange  
> wrote:
> 
> Hi,
> 
> Just for the sake of completeness.
> 
> In constructor-style-print.rkt, I've switched on the printing of booleans as 
> "true" and "false" as follows (editing line 14):
> 
> ;; print-convert/constructor-style : Any -> Any
> (define (print-convert/constructor-style v)
>  (parameterize ([constructor-style-printing #true]
> [booleans-as-true/false #true])
>(print-convert v)))

Yes, DrRacket's "constructor" mode does this. This code was based on the 
teaching languages though, and the teaching languages set 
`booleans-as-true/false` to false here:
https://github.com/racket/htdp/blob/master/htdp-lib/htdp/bsl/runtime.rkt#L15

Neither one is really more "constructor"-y than the other.

> and also turned a write into a pretty-write at line 24, so that a newline is 
> printed after each value:
> ;; constructor-style-print : Any [Output-Port] [(U 0 1)] -> Void
> ;; Prints v using constructor-style printing (without pretty-printing).
> (define (constructor-style-print v [out (current-output-port)] [qdepth 0])
>  (parameterize ([print-reader-abbreviations #true])
>(pretty-write (print-convert/constructor-style v) out)))

The `constructor-style-print` function isn't supposed to add a newline.

I added a `constructor-style-println` function that does pretty-print it 
though, with the newline:
https://github.com/AlexKnauth/quote-bad/blob/master/constructor-style-print/constructor-style-print.rkt#L26-L31

At one point I had a pull request to allow pretty-printing without newlines at 
the end, but I had forgotten about it.
https://github.com/racket/racket/pull/1137

I need to update it and change it to add a keyword argument to each function. 
Then `constructor-style-print` could pretty-print it without needing the 
newline.

Alex Knauth

> This is closer to the behavior of drracket's constructor style printing.
> Maybe there are better ways to achieve the same result, though.
> 
> Best,
> Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-08-10 Thread Delphine Demange
Hi,

Just for the sake of completeness.

In constructor-style-print.rkt, I've switched on the printing of booleans as 
"true" and "false" as follows (editing line 14):

;; print-convert/constructor-style : Any -> Any
(define (print-convert/constructor-style v)
  (parameterize ([constructor-style-printing #true]
 [booleans-as-true/false #true])
(print-convert v)))

and also turned a write into a pretty-write at line 24, so that a newline is 
printed after each value:
;; constructor-style-print : Any [Output-Port] [(U 0 1)] -> Void
;; Prints v using constructor-style printing (without pretty-printing).
(define (constructor-style-print v [out (current-output-port)] [qdepth 0])
  (parameterize ([print-reader-abbreviations #true])
(pretty-write (print-convert/constructor-style v) out)))


This is closer to the behavior of drracket's constructor style printing.
Maybe there are better ways to achieve the same result, though.

Best,
Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-07-28 Thread Delphine Demange
Cool, I've updated the package, and it works great now!

Thanks again,
Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-07-28 Thread Alex Knauth

> On Jul 28, 2016, at 12:32 PM, Delphine Demange  
> wrote:
> 
> 
>> I have just added `constructor-style-print/racket/init` to the `quote-bad` 
>> package so that you can do this:
>> 
>> $ racket -I constructor-style-print/racket/init
>> [...]
>> What it does is require `racket/init` and 
>> `constructor-style-print/lang/runtime-config`, and then call the `configure` 
>> function from that.
>> 
> Wow, thanks!
> 
> If that is useful (not sure how dependencies are handled by the package 
> manager): just updating the package was not enough. I had to manually install 
> sweet-exp to get it to work.

Oh, sorry. I shouldn't have used `sweet-exp`. It was actually changing the 
reader as well, to use the sweet-exp reader. I've fixed that now.

>> I'm not sure why it requires two newlines after input expressions though.
> Strange indeed :-) The same happens for me (both on v6.0 and v.6.6). But I 
> can live with that for a while.

Now that it doesn't use the sweet-exp reader any more, it only requires one 
newline. 

Alex Knauth


-- 
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] racket command-line REPL: Constructor style printing mode?

2016-07-28 Thread Delphine Demange

> I have just added `constructor-style-print/racket/init` to the `quote-bad` 
> package so that you can do this:
> 
> 
> $ racket -I constructor-style-print/racket/init
> [...]
> What it does is require `racket/init` and 
> `constructor-style-print/lang/runtime-config`, and then call the `configure` 
> function from that.
>
Wow, thanks!

If that is useful (not sure how dependencies are handled by the package 
manager): just updating the package was not enough. I had to manually install 
sweet-exp to get it to work.
 
> I'm not sure why it requires two newlines after input expressions though.
Strange indeed :-) The same happens for me (both on v6.0 and v.6.6). But I can 
live with that for a while.

Thanks again!
Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-07-27 Thread Delphine Demange
Thanks for the prompt reply!

I managed to install the package.

For my current use-case, using the racket in module mode, with the right #lang 
directive at the top of the .rkt file is enough.

For the interactive mode, however, I was expecting something like 

racket -I 'constructor-style-print racket'

to behave similarly.

But it leads to:

Welcome to Racket v6.0.
module-declared?: contract violation
  expected: (or/c module-path? module-path-index? resolved-module-path?)
  given: '(submod (lib "constructor-style-print racket") configure-runtime)
  argument position: 1st
  other arguments...:
   #t
> 

Just out of curiosity, what would be the adequate "-I" syntax, if any?
(what I read in quote-bad/constructor-style-print/lang/runtime-config.rkt
is too advanced racket code for me to find out how to change dynamically the 
printer in the repl.)

Best,
Delphine

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-07-27 Thread Jens Axel Søgaard
One option is to use Alex Knauth's package quote-bad.

https://docs.racket-lang.org/quote-bad/index.html?q=constructor#%28part._.Changing_the_printing_style_to_avoid_printing_bad_uses_of_quote%29

If you want to see how he sets the print handler:

https://github.com/AlexKnauth/quote-bad/blob/master/constructor-style-print/lang/runtime-config.rkt

/Jens Axel


2016-07-27 20:37 GMT+02:00 Delphine Demange :

> Hi,
>
> I'd like to use the Constructor printing style in the command-line REPL,
> so that it behaves the same as in my current DrRacket config, e.g.
>
> > (list 1 2 3)
> (list 1 2 3)
>
> Using https://docs.racket-lang.org/reference/printing.html, I've been
> trying to set (interactively) the right parameters to the printer, without
> success.
>
> Is there any way to achieve this (either manually, or using a file similar
> to org.racket-lang.prefs.rktd)?
>
> I may have missed something in the documentation.
> I'm running DrRacket 6.0.
>
> Thanks for your help,
> Delphine
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] racket command-line REPL: Constructor style printing mode?

2016-07-27 Thread Delphine Demange
Hi,

I'd like to use the Constructor printing style in the command-line REPL, so 
that it behaves the same as in my current DrRacket config, e.g.

> (list 1 2 3)
(list 1 2 3)

Using https://docs.racket-lang.org/reference/printing.html, I've been trying to 
set (interactively) the right parameters to the printer, without success.

Is there any way to achieve this (either manually, or using a file similar to 
org.racket-lang.prefs.rktd)?

I may have missed something in the documentation.
I'm running DrRacket 6.0.

Thanks for your help,
Delphine

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