Re: [racket-users] Assigning actions to any key on a terminal

2017-12-09 Thread Rickard Andersson
> Hi, OK, I'll look for the console API, or installing Linux/BSD on a 
> virtual machine, or even go experiment with racket/gui, since it's just 
> a little project mostly for fun. :)
> 
> Greetings
> Cleverson
> 

`racket/gui` is amazing and works super well on Windows indeed, so I
would definitely recommend it even for small stuff. Windows doesn't have
a great CLI experience anyway, so running things in a GUI makes more
sense.

-- 
With regards,
Rickard Andersson

-- 
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] pragmatics of exhaustiveness checking in TR

2017-12-09 Thread 'John Clements' via users-redirect
TR doesn’t really do exhaustiveness checking, really, … except sorta. I’m 
mostly just writing this to summarize my thinking and to see if there’s 
something obvious I’m missing.

I spent some time this morning debugging code that looked something like this:

#lang typed/racket

(define-type Format (U 'fmt-a 'fmt-b 'fmt-c))

(define (process-num [a : Number] [f : Format]) : Number
  (match f
['fmt-a (+ a 1)]
['fnt-b (* a 2)]
[_ (+ a 1234)]))

(process-num 2431 'fmt-b)


The problem is that the call winds up in the third case rather than the second, 
because I’ve misspelled ‘fmt-b’ in the second clause of the match.

I figured out the bug, of course, but then I had a moment of mild panic, 
because that bug lived in the bin in my brain labeled “don’t worry, TR will 
catch this kind of problem.” And, of course, that’s not true; TR is perfectly 
happy to allow equality checks between elements of type Format and Symbol, 
because *Racket* is perfectly happy to allow these comparisons, and that’s kind 
of the whole point of TR.

My thought process:

1) I looked for a “dead code” indication in TR, and the closest I could get was 
hovering over the dead code for a tooltip.  Currently, it appears that the 
tooltip for dead code is… well, there is no tooltip.  Maybe it would be a good 
idea for the tooltip for dead code to signal “unreachable code” somehow? 

2) I looked for a “dead code” indication in the Optimization 
coach…unfortunately, I couldn’t figure out how to get the Optimization Coach to 
signal dead code. Is it in there? I couldn’t find it.

So then I started trying to figure out if I could code differently in order to 
get around this.

3) Clearly the wildcard match is a problem; if I want TR to tell me something 
about not being able to match, I’ve got to let TR know that falling off the end 
is possible. So I can change the third pattern to ‘fmt-c’. Unfortunately, I now 
discover that the very thing I *like* about match—namely, the fact that it 
signals an error for no match—is going to kill the TR checking of this, because 
of course errors don’t return, so the presence of the error *helps* the code to 
type-check. 

4) Instead, I can use a conditional, or a case. This is fragile, because I’ll 
only get a type error if Void isn’t in the stated return type. My recollection 
is that there’s an expression which has the type “Nothing”, but I can’t 
remember what it is… and I can't seem to find it in the docs.  


So, at the end of the day, if I want to get exhaustiveness checking for things 
like this, it looks like my best practice is: a) use a case expression, and b) 
mentally check that ‘void’ is not in the return type.  Does this sound right?

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.


[racket-users] TR can't generate contracts for prefab structs?

2017-12-09 Thread 'John Clements' via users-redirect
It looks to me like TR can’t generate contracts for prefab structs in a way 
that I would expect it to. Specifically, here’s a TR file and a Racket file 
that uses a TR-defined prefab structure:

makes-foo.rkt:

#lang typed/racket

(provide (struct-out Foo)
 get-a-foo)

(struct Foo ([a : String]) #:prefab)

(define (get-a-foo)
  (Foo "oeuth”))


uses-foo.rkt:

#lang racket

(require "makes-foo.rkt")

(define a (get-a-foo))


This doesn’t typecheck (at least not in version  6.11.0.2--2017-11-05, tell me 
if I should just upgrade), with the message:

Type Checker: could not convert type to a contract;
 contract generation not supported for this type
  identifier: get-a-foo
  type: (-> Foo) in: (get-a-foo)

My first thought was that this was related to mutability, but the docs and my 
experiments suggest that prefab structures are default-immutable, and that this 
is reflected in a way that should be visible to the type-checker. Am I missing 
something, or is this just something that we haven’t yet had time to implement?


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] pragmatics of exhaustiveness checking in TR

2017-12-09 Thread Alex Knauth


> On Dec 9, 2017, at 1:04 PM, 'John Clements' via users-redirect 
>  wrote:
> 
> TR doesn’t really do exhaustiveness checking, really, … except sorta. I’m 
> mostly just writing this to summarize my thinking and to see if there’s 
> something obvious I’m missing.

The Utilities section of the TR reference has the form `typecheck-fail`, with 
an example of a `cond`-like macro that does exhaustiveness checking.

http://docs.racket-lang.org/ts-reference/Utilities.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._typecheck-fail%29%29
 


I tried using it for `match`, but it seems to fail on everything, not just on 
incomplete matches. This is because `match` doesn't cooperate with occurrence 
typing enough for it to know that if a pattern succeeds then it can eliminate 
"that type" from clauses after that. It's like having only the #:+ propositions 
and not the #:- ones. And `match` features like (=> fail-id) and (failure-cont) 
will make that even harder.

> I spent some time this morning debugging code that looked something like this:
> 
> #lang typed/racket
> 
> (define-type Format (U 'fmt-a 'fmt-b 'fmt-c))
> 
> (define (process-num [a : Number] [f : Format]) : Number
>  (match f
>['fmt-a (+ a 1)]
>['fnt-b (* a 2)]
>[_ (+ a 1234)]))
> 
> (process-num 2431 'fmt-b)
> 
> 
> The problem is that the call winds up in the third case rather than the 
> second, because I’ve misspelled ‘fmt-b’ in the second clause of the match.
> 
> I figured out the bug, of course, but then I had a moment of mild panic, 
> because that bug lived in the bin in my brain labeled “don’t worry, TR will 
> catch this kind of problem.” And, of course, that’s not true; TR is perfectly 
> happy to allow equality checks between elements of type Format and Symbol, 
> because *Racket* is perfectly happy to allow these comparisons, and that’s 
> kind of the whole point of TR.
> 
> My thought process:
> 
> 1) I looked for a “dead code” indication in TR, and the closest I could get 
> was hovering over the dead code for a tooltip.  Currently, it appears that 
> the tooltip for dead code is… well, there is no tooltip.  Maybe it would be a 
> good idea for the tooltip for dead code to signal “unreachable code” somehow? 
> 
> 2) I looked for a “dead code” indication in the Optimization 
> coach…unfortunately, I couldn’t figure out how to get the Optimization Coach 
> to signal dead code. Is it in there? I couldn’t find it.
> 
> So then I started trying to figure out if I could code differently in order 
> to get around this.
> 
> 3) Clearly the wildcard match is a problem; if I want TR to tell me something 
> about not being able to match, I’ve got to let TR know that falling off the 
> end is possible. So I can change the third pattern to ‘fmt-c’. Unfortunately, 
> I now discover that the very thing I *like* about match—namely, the fact that 
> it signals an error for no match—is going to kill the TR checking of this, 
> because of course errors don’t return, so the presence of the error *helps* 
> the code to type-check. 
> 
> 4) Instead, I can use a conditional, or a case. This is fragile, because I’ll 
> only get a type error if Void isn’t in the stated return type. My 
> recollection is that there’s an expression which has the type “Nothing”, but 
> I can’t remember what it is… and I can't seem to find it in the docs.  
> 
> 
> So, at the end of the day, if I want to get exhaustiveness checking for 
> things like this, it looks like my best practice is: a) use a case 
> expression, and b) mentally check that ‘void’ is not in the return type.  
> Does this sound right?
> 
> 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.


[racket-users] Is there a predicate for structs in general?

2017-12-09 Thread David Storrs
(struct fruit (name color))

-> (struct? (fruit 'apple 'red))
#f

This surprised me.  I'm trying to wrap my head around the docs for
struct? and struct-info? and not having a lot of success.  Is there a
way to simply say "is this a struct of some sort?"

Context:

I'm playing around with structs that contain information about structs
and I'd like to be able to validate the information that's going in:

(struct field-info (field-name predicate getter setter required?
default on-update)
  #:guard (lambda  (field-name predicate getter setter required?
default on-update type)
(define/contract (init-field-info field-name predicate
getter setter required? default on-update)
  (-> symbol?   ; field name
  (-> any/c   boolean?) ; predicate
  (-> struct? any/c); getter
  (-> struct? struct?)  ; setter
  boolean?  ; required
  (or/c (not/c procedure?)  ; default
  (-> struct? any/c))
  (-> struct? any/c any); on-update
  any ; unchecked return value
  )
  (when (and required? (not-equal? default
'no-default-specified-by-field-info))
(raise-arguments-error 'init-field-info
   "Cannot specify a default for a
required field"
   "default" default))
  (values field-name predicate getter setter required?
default on-update))
;
(init-field-info field-name predicate getter setter
required? default on-update)))

-- 
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] Is there a predicate for structs in general?

2017-12-09 Thread Robby Findler
One hopefully helpful piece of information is that _all_ values in Racket
are structs. So this predicate is telling you that this kind of value is
revealing its inherent "structness" to you or not.

In this case, the struct isn't transparent so it isn't revealing it. (Just
like cons pairs don't reveal their structs, neither do rational numbers or
procedures, etc.)

Hopefully this helps the docs make more sense.

Robby

On Sat, Dec 9, 2017 at 2:27 PM David Storrs  wrote:

> (struct fruit (name color))
>
> -> (struct? (fruit 'apple 'red))
> #f
>
> This surprised me.  I'm trying to wrap my head around the docs for
> struct? and struct-info? and not having a lot of success.  Is there a
> way to simply say "is this a struct of some sort?"
>
> Context:
>
> I'm playing around with structs that contain information about structs
> and I'd like to be able to validate the information that's going in:
>
> (struct field-info (field-name predicate getter setter required?
> default on-update)
>   #:guard (lambda  (field-name predicate getter setter required?
> default on-update type)
> (define/contract (init-field-info field-name predicate
> getter setter required? default on-update)
>   (-> symbol?   ; field name
>   (-> any/c   boolean?) ; predicate
>   (-> struct? any/c); getter
>   (-> struct? struct?)  ; setter
>   boolean?  ; required
>   (or/c (not/c procedure?)  ; default
>   (-> struct? any/c))
>   (-> struct? any/c any); on-update
>   any ; unchecked return value
>   )
>   (when (and required? (not-equal? default
> 'no-default-specified-by-field-info))
> (raise-arguments-error 'init-field-info
>"Cannot specify a default for a
> required field"
>"default" default))
>   (values field-name predicate getter setter required?
> default on-update))
> ;
> (init-field-info field-name predicate getter setter
> required? default on-update)))
>
> --
> 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] Is there a predicate for structs in general?

2017-12-09 Thread David Storrs
Ah.  Yes, that makes more sense.  Thanks.

On Sat, Dec 9, 2017 at 3:32 PM, Robby Findler
 wrote:
> One hopefully helpful piece of information is that _all_ values in Racket
> are structs. So this predicate is telling you that this kind of value is
> revealing its inherent "structness" to you or not.
>
> In this case, the struct isn't transparent so it isn't revealing it. (Just
> like cons pairs don't reveal their structs, neither do rational numbers or
> procedures, etc.)
>
> Hopefully this helps the docs make more sense.
>
> Robby
>
> On Sat, Dec 9, 2017 at 2:27 PM David Storrs  wrote:
>>
>> (struct fruit (name color))
>>
>> -> (struct? (fruit 'apple 'red))
>> #f
>>
>> This surprised me.  I'm trying to wrap my head around the docs for
>> struct? and struct-info? and not having a lot of success.  Is there a
>> way to simply say "is this a struct of some sort?"
>>
>> Context:
>>
>> I'm playing around with structs that contain information about structs
>> and I'd like to be able to validate the information that's going in:
>>
>> (struct field-info (field-name predicate getter setter required?
>> default on-update)
>>   #:guard (lambda  (field-name predicate getter setter required?
>> default on-update type)
>> (define/contract (init-field-info field-name predicate
>> getter setter required? default on-update)
>>   (-> symbol?   ; field name
>>   (-> any/c   boolean?) ; predicate
>>   (-> struct? any/c); getter
>>   (-> struct? struct?)  ; setter
>>   boolean?  ; required
>>   (or/c (not/c procedure?)  ; default
>>   (-> struct? any/c))
>>   (-> struct? any/c any); on-update
>>   any ; unchecked return value
>>   )
>>   (when (and required? (not-equal? default
>> 'no-default-specified-by-field-info))
>> (raise-arguments-error 'init-field-info
>>"Cannot specify a default for a
>> required field"
>>"default" default))
>>   (values field-name predicate getter setter required?
>> default on-update))
>> ;
>> (init-field-info field-name predicate getter setter
>> required? default on-update)))
>>
>> --
>> 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] "Live" REPL to cooperate with event loops?

2017-12-09 Thread Christopher Lemmer Webber
Hello!  I'm fairly new to Racket, but not to Scheme.  I'm very impressed
with everything that's available.

One thing I miss from Guile is the cooperative REPL support:
  
https://www.gnu.org/software/guile/manual/html_node/Cooperative-REPL-Servers.html

It's possible to spawn a REPL that runs in such a way that coordinates
with an event loop, or (egads) runs inside its own thread.  This turns
out to be very helpful when doing web development or game
development... *especially* networked game development.  If you see the
video on this page (scroll down a bit):

  https://www.gnu.org/software/8sync/

you can see me giving a talk where the talk is itself a multiplayer text
adventure, in which the audience is participating.  Thanks to Guile's
cooperative REPL, I'm able to change components of the world in response
to players' suggestions, without kicking everyone out.

I looked and I couldn't find such a thing in Racket.  Does it exist and
I'm just missing it?  How hard would it be to integrate with a program?

Thanks!
 - Christopher Lemmer Webber

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