Re: [racket-users] sharing a value between a DrRacket tool and a user program

2017-05-16 Thread Robby Findler
On Tue, May 16, 2017 at 7:07 PM, 'John Clements' via Racket Users
 wrote:
>
>> On May 16, 2017, at 11:26 AM, Robby Findler  
>> wrote:
>>
>> If you have control of the language<%> class, then you can do that via
>> the on-execute method. If you want to do that for all languages (which
>> is probably not a good idea, but you could use this approach and limit
>> it to a known set of languages), you could override the on-execute
>> method of the rep<%> object (you can add a mixin). Use this to attach
>> a module to the namespace of the user's program (e.g.,
>> #%my-private-state) that has minimal dependencies, and then some
>> library you write would require that module and provide a nice
>> interface, once it gets a hold of that minimal piece of state.
>
> Are there instances of language<%> that are used when the user has the 
> language level set to “use language declared in source” ? I’ve just spent a 
> few minutes looking over the DrRacket documentation for ‘read-language’, and 
> this documentation is suggesting to me that the language<%> interface is not 
> used for #lang-based languages, though I really can’t be sure. At a minimum, 
> I’m not seeing any references to language<%> in the section labeled "DrRacket 
> support for #lang-based Languages”.

There is a specific one that's used in that case.

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] sharing a value between a DrRacket tool and a user program

2017-05-16 Thread 'John Clements' via Racket Users

> On May 16, 2017, at 11:26 AM, Robby Findler  
> wrote:
> 
> If you have control of the language<%> class, then you can do that via
> the on-execute method. If you want to do that for all languages (which
> is probably not a good idea, but you could use this approach and limit
> it to a known set of languages), you could override the on-execute
> method of the rep<%> object (you can add a mixin). Use this to attach
> a module to the namespace of the user's program (e.g.,
> #%my-private-state) that has minimal dependencies, and then some
> library you write would require that module and provide a nice
> interface, once it gets a hold of that minimal piece of state.

Are there instances of language<%> that are used when the user has the language 
level set to “use language declared in source” ? I’ve just spent a few minutes 
looking over the DrRacket documentation for ‘read-language’, and this 
documentation is suggesting to me that the language<%> interface is not used 
for #lang-based languages, though I really can’t be sure. At a minimum, I’m not 
seeing any references to language<%> in the section labeled "DrRacket support 
for #lang-based Languages”. 

John



-- 
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] sharing a value between a DrRacket tool and a user program

2017-05-16 Thread 'John Clements' via Racket Users

> On May 16, 2017, at 11:23 AM, Vincent St-Amour 
>  wrote:
> 
> John, Austin,
> 
> You can use loggers for this. The `data` argument to `log-message`
> allows payloads to be carried along with log messages. Just have the
> user program log messages with a particular topic, and have the tool
> listen on that topic.
> 
> That's how the optimization coach (which is a DrRacket tool) gets info
> from the the user program.

Nice! Definitely would have taken us a long long time to think of something 
like that. Robby’s solution seems like the “right” solution, but this one 
sounds much easier to get right. Hmm….


John



-- 
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] How to discard an unknown number of (values) return?

2017-05-16 Thread David Storrs
Well, that was simpler than expected.  (As is usually the case with
Racket.)  Thanks, Ben.

On Tue, May 16, 2017 at 5:59 PM, Ben Greenman 
wrote:

> Try `(call-with-values func void)`
>
> http://docs.racket-lang.org/reference/values.html#%28def._
> %28%28quote._~23~25kernel%29._call-with-values%29%29
>
> On Tue, May 16, 2017 at 5:56 PM, David Storrs 
> wrote:
>
>> I have a macro that wraps a function call in some debugging information.
>> I would like to discard the results of the function call so that they don't
>> end up printed.  This usually works:
>>
>>   (void (func))
>>
>> ...but it fails if func uses (values) to return multiple values, since
>> void is variadic but not multiple-return tolerant.  I have solved the
>> problem with (the equivalent of) wrapping it in a thunk:  ((thunk (func)
>> (void)) but that's clumsy.
>>
>> This is a specific example of the more general question "how could I
>> capture the result of a function call without knowing how many values will
>> come back or if it's normal return / multiple return?"
>>
>> I've been through the docs on multiple return and I don't see a way to
>> handle this.  Is there one?
>>
>> --
>> 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] How to discard an unknown number of (values) return?

2017-05-16 Thread Ben Greenman
Try `(call-with-values func void)`

http://docs.racket-lang.org/reference/values.html#%28def._%28%28quote._~23~25kernel%29._call-with-values%29%29

On Tue, May 16, 2017 at 5:56 PM, David Storrs 
wrote:

> I have a macro that wraps a function call in some debugging information.
> I would like to discard the results of the function call so that they don't
> end up printed.  This usually works:
>
>   (void (func))
>
> ...but it fails if func uses (values) to return multiple values, since
> void is variadic but not multiple-return tolerant.  I have solved the
> problem with (the equivalent of) wrapping it in a thunk:  ((thunk (func)
> (void)) but that's clumsy.
>
> This is a specific example of the more general question "how could I
> capture the result of a function call without knowing how many values will
> come back or if it's normal return / multiple return?"
>
> I've been through the docs on multiple return and I don't see a way to
> handle this.  Is there one?
>
> --
> 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] How to discard an unknown number of (values) return?

2017-05-16 Thread David Storrs
I have a macro that wraps a function call in some debugging information.  I
would like to discard the results of the function call so that they don't
end up printed.  This usually works:

  (void (func))

...but it fails if func uses (values) to return multiple values, since void
is variadic but not multiple-return tolerant.  I have solved the problem
with (the equivalent of) wrapping it in a thunk:  ((thunk (func) (void))
but that's clumsy.

This is a specific example of the more general question "how could I
capture the result of a function call without knowing how many values will
come back or if it's normal return / multiple return?"

I've been through the docs on multiple return and I don't see a way to
handle this.  Is there one?

-- 
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] sharing a value between a DrRacket tool and a user program

2017-05-16 Thread Robby Findler
If you have control of the language<%> class, then you can do that via
the on-execute method. If you want to do that for all languages (which
is probably not a good idea, but you could use this approach and limit
it to a known set of languages), you could override the on-execute
method of the rep<%> object (you can add a mixin). Use this to attach
a module to the namespace of the user's program (e.g.,
#%my-private-state) that has minimal dependencies, and then some
library you write would require that module and provide a nice
interface, once it gets a hold of that minimal piece of state.

Loggers, as Vincent suggests, might be better (or might be worse), I'm not sure.

Robby


On Tue, May 16, 2017 at 11:38 AM, 'John Clements' via Racket Users
 wrote:
> Austin Sparks (cc:ed) and I are struggling with what I believe should be a 
> pretty simple problem; how can we share a value between a DrRacket tool and a 
> user’s program? Specifically, the value in question here is a channel 
> (probably an asynchronous channel) on which the user’s thread can place 
> musical-note-to-be-played values.
>
> The heavyweight way—I’m pretty confident this would work—is to provide our 
> own “run” button, allowing us to add existing module invocations to the 
> user’s namespace before the user’s module is expanded or invoked. However, 
> I’m thinking there’s … an easier way to do it?
>
> John
>
>
>
> --
> 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] sharing a value between a DrRacket tool and a user program

2017-05-16 Thread Vincent St-Amour
John, Austin,

You can use loggers for this. The `data` argument to `log-message`
allows payloads to be carried along with log messages. Just have the
user program log messages with a particular topic, and have the tool
listen on that topic.

That's how the optimization coach (which is a DrRacket tool) gets info
from the the user program.

Vincent



On Tue, 16 May 2017 11:38:32 -0500,
'John Clements' via Racket Users wrote:
> 
> Austin Sparks (cc:ed) and I are struggling with what I believe should be a 
> pretty simple problem; how can we share a value between a DrRacket tool and a 
> user’s program? Specifically, the value in question here is a channel 
> (probably an asynchronous channel) on which the user’s thread can place 
> musical-note-to-be-played values.
> 
> The heavyweight way―I’m pretty confident this would work―is to provide our 
> own “run” button, allowing us to add existing module invocations to the 
> user’s namespace before the user’s module is expanded or invoked. However, 
> I’m thinking there’s … an easier way to do it?
> 
> John
> 
> 
> 
> -- 
> 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] surprising [to me and students] printer behavior with #:transparent

2017-05-16 Thread Dan Grossman
Ah, got it, makes perfect sense through that lens -- thanks!

On Tue, May 16, 2017 at 9:37 AM, Philip McGrath 
wrote:

> The printer tries to produce an expression that you could copy, paste, and
> evaluate. Transparent structs aren't quotable but do support
> constructor-style printing, so the printer uses constructor-style printing
> for values that contain transparent structs. (Apparently you can configure
> this in DrRacket to use e.g. quasiquotation if you prefer:
> https://docs.racket-lang.org/drracket/output-syntax.html) Since opaque
> structs don't support any nice printing behavior by default, the printer
> gives up and uses the more concise quoted form with the non-expression
> printed form of the opaque value.
>
> The docs for prop:custom-print-quotable and gen:custom-write and the
> Reference section on The Printer
>  have more
> technical details.
>
> On Tue, May 16, 2017 at 9:21 AM, Dan Grossman 
> wrote:
>
>>
>> Hi all,
>>
>> In my course here on campus, I have students use #lang racket and we put
>> #:transparent on our struct definitions for easier REPL interactions.  A
>> student was confused by the different printer-behavior between a and b in
>> the attached screenshot, and I can't think of a reason for the different
>> behavior for b compared to a and c either.  Curious if there /is/ a decent
>> reason or if this is just one of those glitches.
>>
>> "No big deal" but worth asking...
>>
>> [image: Inline image 1]
>>
>> --
>> 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] sharing a value between a DrRacket tool and a user program

2017-05-16 Thread 'John Clements' via Racket Users
Austin Sparks (cc:ed) and I are struggling with what I believe should be a 
pretty simple problem; how can we share a value between a DrRacket tool and a 
user’s program? Specifically, the value in question here is a channel (probably 
an asynchronous channel) on which the user’s thread can place 
musical-note-to-be-played values.

The heavyweight way—I’m pretty confident this would work—is to provide our own 
“run” button, allowing us to add existing module invocations to the user’s 
namespace before the user’s module is expanded or invoked. However, I’m 
thinking there’s … an easier way to do it?

John



-- 
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] surprising [to me and students] printer behavior with #:transparent

2017-05-16 Thread Philip McGrath
The printer tries to produce an expression that you could copy, paste, and
evaluate. Transparent structs aren't quotable but do support
constructor-style printing, so the printer uses constructor-style printing
for values that contain transparent structs. (Apparently you can configure
this in DrRacket to use e.g. quasiquotation if you prefer:
https://docs.racket-lang.org/drracket/output-syntax.html) Since opaque
structs don't support any nice printing behavior by default, the printer
gives up and uses the more concise quoted form with the non-expression
printed form of the opaque value.

The docs for prop:custom-print-quotable and gen:custom-write and the
Reference section on The Printer
 have more technical
details.

On Tue, May 16, 2017 at 9:21 AM, Dan Grossman  wrote:

>
> Hi all,
>
> In my course here on campus, I have students use #lang racket and we put
> #:transparent on our struct definitions for easier REPL interactions.  A
> student was confused by the different printer-behavior between a and b in
> the attached screenshot, and I can't think of a reason for the different
> behavior for b compared to a and c either.  Curious if there /is/ a decent
> reason or if this is just one of those glitches.
>
> "No big deal" but worth asking...
>
> [image: Inline image 1]
>
> --
> 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] surprising [to me and students] printer behavior with #:transparent

2017-05-16 Thread Dan Grossman
Hi all,

In my course here on campus, I have students use #lang racket and we put
#:transparent on our struct definitions for easier REPL interactions.  A
student was confused by the different printer-behavior between a and b in
the attached screenshot, and I can't think of a reason for the different
behavior for b compared to a and c either.  Curious if there /is/ a decent
reason or if this is just one of those glitches.

"No big deal" but worth asking...

[image: Inline image 1]

-- 
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] Type Racket command-line #:ps causing type error

2017-05-16 Thread kay
Hi I feel this might be a bug, can anyone confirm or suggest a fix?

Here's a minimal usage of `command-line` form:

```
#lang typed/racket

(define *message* : (Parameterof (Listof String)) (make-parameter '()))
(define *verbose* : (Parameterof Boolean) (make-parameter #f))

(define (parse-cmdline)
(command-line
 #:program "q"
 #:once-each
 [("-v" "--verbose") "verbose mode" (*verbose* #t)]
 #:ps "foo bar" ; < causing type error
 #:args #{msg : String} (*message* msg)))

(parse-cmdline)
```

Note that it gives the below type error[1]. However, if you comment out the 
line with #:ps, type check passes.

I noticed that from the error prompt, for argument 3, the expected Union type 
doesn't include 'ps. This leads me to think it might be a bug. Please tell me 
it's not and there's a fix:)


[1]: type error:

test.rkt:6:0: Type Checker: Polymorphic function `parse-command-line' could not 
be applied to arguments:
Argument 1:
  Expected: Path-String
  Given:String
Argument 2:
  Expected: (U (Listof String) (Vectorof String))
  Given:(Vectorof String)
Argument 3:
  Expected: (Listof (Pairof (U 'final 'help-labels 'multi 'once-any 'once-each) 
(Listof (Listof Any
  Given:(List (List 'once-each (List (List String String) (-> Any Void) 
(Listof (List String (List 'ps String))
Argument 4:
  Expected: (-> Any a ... a b)
  Given:(-> Any String * Void)
Argument 5:
  Expected: (Listof String)
  Given:(List String)

  in: (define (parse-cmdline) (command-line #:program "q" #:once-each (("-v" 
"--verbose") "verbose mode" (*verbose* #t)) #:ps "foo bar" #:args msg 
(*message* msg)))

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