Re: [racket-users] Learning by doing Typed Racket

2016-06-11 Thread Ben Greenman
On Sat, Jun 11, 2016 at 12:46 AM, Daniel Prager 
wrote:

> Do you have an alternative recommendation in mind?


I guess you already solved this one, but for later it might help to avoid
macros.

-- 
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] Learning by doing Typed Racket

2016-06-11 Thread Daniel Prager
Hi Ben

I wrote:

> Do you have an alternative recommendation in mind?


At that point I was asking whether Sam (or others) recommended another set
of problems more conducive to learning Typed Racket than the 99 Lisp
Problems which Sam said were a tricky place to start.

I can see that staying clear of macros avoids an additional layer of
sophistication.

Dan


On Sat, Jun 11, 2016 at 5:13 PM, Ben Greenman 
wrote:

>
> On Sat, Jun 11, 2016 at 12:46 AM, Daniel Prager  > wrote:
>
>> Do you have an alternative recommendation in mind?
>
>
> I guess you already solved this one, but for later it might help to avoid
> macros.
>



-- 
*Daniel Prager*
Agile/Lean Coaching, Innovation, and Leadership
Profile: skillfire.co/dan
Startups: youpatch.com , skillfire.co
Twitter: @agilejitsu 
Blog: agile-jitsu.blogspot.com
Linkedin: au.linkedin.com/in/danielaprager

-- 
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] Learning by doing Typed Racket

2016-06-11 Thread Ben Greenman
Ah, okay. Well maybe try the Haskell or OCaml versions of the 99 problems?

https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems
https://ocaml.org/learn/tutorials/99problems.html


On Sat, Jun 11, 2016 at 3:28 AM, Daniel Prager 
wrote:

> Hi Ben
>
> I wrote:
>
>> Do you have an alternative recommendation in mind?
>
>
> At that point I was asking whether Sam (or others) recommended another set
> of problems more conducive to learning Typed Racket than the 99 Lisp
> Problems which Sam said were a tricky place to start.
>
> I can see that staying clear of macros avoids an additional layer of
> sophistication.
>
> Dan
>
>
> On Sat, Jun 11, 2016 at 5:13 PM, Ben Greenman  > wrote:
>
>>
>> On Sat, Jun 11, 2016 at 12:46 AM, Daniel Prager <
>> daniel.a.pra...@gmail.com> wrote:
>>
>>> Do you have an alternative recommendation in mind?
>>
>>
>> I guess you already solved this one, but for later it might help to avoid
>> macros.
>>
>
>
>
> --
> *Daniel Prager*
> Agile/Lean Coaching, Innovation, and Leadership
> Profile: skillfire.co/dan
> Startups: youpatch.com , skillfire.co
> Twitter: @agilejitsu 
> Blog: agile-jitsu.blogspot.com
> Linkedin: au.linkedin.com/in/danielaprager
>

-- 
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] interactive window in slideshow

2016-06-11 Thread Nick
Just updated to 6.5 on Ubuntu, but I can't get a control to focus. My issue is 
similar to http://lists.racket-lang.org/users/archive/2011-May/045317.html, I 
have a dialog with a choice% in it, and no matter when or how I (send choice 
focus), the choice will never focus without me having to type tab first. I've 
tried focus'ing before show'ing the dialog, and tried focus'ing in the dialog's 
on-activate, to no avail. Is there a workaround? Is there at least a way to 
fake a Tab key-event to the dialog to achieve the same effect? For my project 
I'm really hoping to have fast, seamless keyboard input.

On Monday, March 28, 2016 at 5:06:24 PM UTC-7, Byron Davies wrote:
> Thanks for looking into it.  No great hurry.
> 
> For now,  I just tell the kindergartners to click twice the first time 
> around, but  it will be a lot clearer once the  fix happens.
> 
> > On Mar 28, 2016, at 4:34 PM, Matthew Flatt  wrote:
> > 
> > At Mon, 28 Mar 2016 11:53:38 -0700, Byron Davies wrote:
> >> I have a single interactive pasteboard on a slideshow slide.  For a 
> >> learning 
> >> task, the user needs to click on objects on the pasteboard.  There’s a 
> >> little 
> >> glitch, however.  The user must first click on the pasteboard to make it 
> >> the 
> >> focus, and then click on the objects.  Is there a way to make the 
> >> pasteboard 
> >> become the focus when the mouse moves into it?
> > 
> > You should be able to use the `focus` method on the canvas after its
> > frame is shown (via `on-superwindow-show`) or when a mouse event is
> > received (via `on-event`). See below for an example.
> > 
> > But I see that `focus` doesn't work right for a canvas in a floating
> > frame, like the one used by `interactive`, so the example below doesn't
> > work with the current release or snapshot. I've pushed a repair to
> > `focus` for the next snapshot build. I don't have a workaround for the
> > current version, but I might be able to find one if that's needed.
> > 
> > 
> > 
> > #lang slideshow
> > (require racket/gui/base)
> > 
> > (define (make-pasteboard f)
> >  (define c%
> >(class editor-canvas%
> >  (super-new)
> >  (inherit focus)
> >  (define/override (on-superwindow-show on?)
> >(when on?
> >  (focus))
> >(super on-superwindow-show on?
> >  (define pb (new pasteboard%))
> >  (send pb insert-box) ; to demonstrate focus
> >  (new c% [parent f] [editor pb])
> >  void)
> > 
> > (slide)
> > 
> > (slide
> > #:title "Example"
> > (interactive (blank 500 500)
> >  make-pasteboard))
> >

-- 
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] interactive window in slideshow

2016-06-11 Thread Nick
Yea, workaround that works for me is to fake a Tab key-event:
(define/override (on-activate activated?)
  (super on-activate activated?)
  (send this on-subwindow-char this (new key-event% [key-code #\tab]))
)


On Saturday, June 11, 2016 at 8:15:18 AM UTC-7, Nick wrote:
> Just updated to 6.5 on Ubuntu, but I can't get a control to focus. My issue 
> is similar to 
> http://lists.racket-lang.org/users/archive/2011-May/045317.html, I have a 
> dialog with a choice% in it, and no matter when or how I (send choice focus), 
> the choice will never focus without me having to type tab first. I've tried 
> focus'ing before show'ing the dialog, and tried focus'ing in the dialog's 
> on-activate, to no avail. Is there a workaround? Is there at least a way to 
> fake a Tab key-event to the dialog to achieve the same effect? For my project 
> I'm really hoping to have fast, seamless keyboard input.
> 
> On Monday, March 28, 2016 at 5:06:24 PM UTC-7, Byron Davies wrote:
> > Thanks for looking into it.  No great hurry.
> > 
> > For now,  I just tell the kindergartners to click twice the first time 
> > around, but  it will be a lot clearer once the  fix happens.
> > 
> > > On Mar 28, 2016, at 4:34 PM, Matthew Flatt  wrote:
> > > 
> > > At Mon, 28 Mar 2016 11:53:38 -0700, Byron Davies wrote:
> > >> I have a single interactive pasteboard on a slideshow slide.  For a 
> > >> learning 
> > >> task, the user needs to click on objects on the pasteboard.  There’s a 
> > >> little 
> > >> glitch, however.  The user must first click on the pasteboard to make it 
> > >> the 
> > >> focus, and then click on the objects.  Is there a way to make the 
> > >> pasteboard 
> > >> become the focus when the mouse moves into it?
> > > 
> > > You should be able to use the `focus` method on the canvas after its
> > > frame is shown (via `on-superwindow-show`) or when a mouse event is
> > > received (via `on-event`). See below for an example.
> > > 
> > > But I see that `focus` doesn't work right for a canvas in a floating
> > > frame, like the one used by `interactive`, so the example below doesn't
> > > work with the current release or snapshot. I've pushed a repair to
> > > `focus` for the next snapshot build. I don't have a workaround for the
> > > current version, but I might be able to find one if that's needed.
> > > 
> > > 
> > > 
> > > #lang slideshow
> > > (require racket/gui/base)
> > > 
> > > (define (make-pasteboard f)
> > >  (define c%
> > >(class editor-canvas%
> > >  (super-new)
> > >  (inherit focus)
> > >  (define/override (on-superwindow-show on?)
> > >(when on?
> > >  (focus))
> > >(super on-superwindow-show on?
> > >  (define pb (new pasteboard%))
> > >  (send pb insert-box) ; to demonstrate focus
> > >  (new c% [parent f] [editor pb])
> > >  void)
> > > 
> > > (slide)
> > > 
> > > (slide
> > > #:title "Example"
> > > (interactive (blank 500 500)
> > >  make-pasteboard))
> > >

-- 
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] Potential small bugs on SEwPR

2016-06-11 Thread Matthias Felleisen

> On Jun 6, 2016, at 9:15 AM, lfacc...@jhu.edu wrote:
> 
> 1. On Section 14.4, The CK Machine, on page 243, there is a reference to
>   /part I(6.4)/, mentioning the specification for the CK Machine: "Comparing
>   the Redex specification with the specification in part I(6.4)".
> 
>   But I believe /part I(6.4)/ is about the CEK Machine. The CK Machine is the
>   subject of /part I(6.3)/.
> 
> 2. On Section 18.4, Rewriting Calls to Meta-functions, on page 290, it says 
> “In


I found this on page 292. 


>   part I, we use the notation `M{X := V}' to express the substitution of all 
> free
>   occurrences of `X' in `M' with `V'."
> 
>   But I believe the notation in part I was `M[X ← V]'.
> 
>   Also, on the last paragraph of the section, it says "Without this empty
>   string, Redex would insert a gap between the `[' and the `M' in the final
>   output. I believe this is referring to the `M[X ← V]' notation, and not the
>   `M{X := V}' notation.


I have pushed fixes for the above into the errata page. (It will take a few 
hours for this to appear on the book’s web page.) 


> Finally, I'd like to take the opportunity to ask a question:

I have cc-ed Robby who can answer this question. 

I am glad Redex and the intellectual framework are helpful to you — Matthias



> 
> The book says that, by default, Redex typesets meta-functions in
> small-caps. But, on my tests, running the latest version of Redex, I see
> proportional sans-serif instead.
> 
> Has this changed since the book was published, or am I doing something wrong? 
> Is
> there a way to restore the old behavior without having to add a compound
> rewriter for each meta-function?
> 
> Thanks a lot for SEwPR and Redex. I finished reading it this weekend and loved
> it!
> 
> Best.
> 
> -- 
> 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] function to recreate source string from syntax object?

2016-06-11 Thread Matthew Butterick
This seems like something that has been done before, but I'm not sure where to 
look for it:

I need something like `syntax->datum` — call it `syntax->source` — that uses 
the source locations and 'paren-shape property of the syntax to reconstitute 
the source with its whitespace (I suppose comments would be unrecoverable, but 
that's OK)

`typeset-code` in Scribble is close, but takes strings as input, not syntax 
objects.

`chunk` in `scribble/lp2` is close, but AFAICT demands cooperation from `#lang 
scribble/lp2`. 

-- 
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] function to recreate source string from syntax object?

2016-06-11 Thread Matthias Felleisen

> On Jun 11, 2016, at 10:26 PM, Matthew Butterick  wrote:
> 
> This seems like something that has been done before, but I'm not sure where 
> to look for it:
> 
> I need something like `syntax->datum` — call it `syntax->source` — that uses 
> the source locations and 'paren-shape property of the syntax to reconstitute 
> the source with its whitespace (I suppose comments would be unrecoverable, 
> but that's OK)
> 
> `typeset-code` in Scribble is close, but takes strings as input, not syntax 
> objects.
> 
> `chunk` in `scribble/lp2` is close, but AFAICT demands cooperation from 
> `#lang scribble/lp2`. 


Do you mean something like this: 

#lang racket

(require 2htdp/universe)

;; where-defined : Identifier -> (U Path Symbol)
;; returns the path of the module where the name is defined
;; a symbol for a built-in module
;; (originally due to Ryan)
(define (where-defined id)
  (unless (identifier? id)
(raise-type-error 'where-defined "identifier" id))
  (define binding (identifier-binding id))
  (cond [(list? binding) (resolved-module-path-name (module-path-index-resolve 
(car binding)))]
[else (raise-syntax-error 'where-defined "not from a module" id)]))

(where-defined #'cons)
(where-defined #'animate)

-- 
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] Learning by doing Typed Racket

2016-06-11 Thread Daniel Prager
Next example.

In Racket:

> (sort '((a 45) (b 13) (c 12) (d 16) (e 9) (f 5)) < #:key second)

'((f 5) (e 9) (c 12) (b 13) (d 16) (a 45))


In Typed Racket I couldn't get a version using #:key to type-check. Pulling
second into a comparison function works:

> (sort '((a 45) (b 13) (c 12) (d 16) (e 9) (f 5))
  (λ ([a : (List Symbol Natural)]
  [b : (List Symbol Natural)])
(< (second a) (second b

Is there a solution using #:key in Typed Racket?


Dan

-- 
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] function to recreate source string from syntax object?

2016-06-11 Thread Alex Knauth

> On Jun 11, 2016, at 10:26 PM, Matthew Butterick  wrote:
> 
> This seems like something that has been done before, but I'm not sure where 
> to look for it:
> 
> I need something like `syntax->datum` — call it `syntax->source` — that uses 
> the source locations and 'paren-shape property of the syntax to reconstitute 
> the source with its whitespace (I suppose comments would be unrecoverable, 
> but that's OK)

The syntax->string function from syntax/to-string formats a syntax object with 
its whitespace and indentation, but doesn't look at the paren-shapes:
http://docs.racket-lang.org/syntax/syntax-helpers.html#%28part._to-string%29

> (require syntax/to-string)
> (syntax->string
   #'((define (f x)
(for/list ([i (in-range x)])
  (+ (f i) x)
"(define (f x)\n  (for/list ((i (in-range x)))\n(+ (f i) x)))"
> (display
   (syntax->string
#'((define (f x)
 (for/list ([i (in-range x)])
   (+ (f i) x))
(define (f x)
  (for/list ((i (in-range x)))
(+ (f i) x)))
> (display
   (syntax->string
#'((define (f  x )
 (for/list ( [ i (in-range x) ])
(   +
   (f i)
x))
(define (f  x)
  (for/list ( ( i (in-range x)))
 (   +
(f i)
 x)))

It doesn't seem to handle whitespace before closing parens, but that makes 
sense, since there isn't any closing paren source location for it to look at.

> `typeset-code` in Scribble is close, but takes strings as input, not syntax 
> objects.
> 
> `chunk` in `scribble/lp2` is close, but AFAICT demands cooperation from 
> `#lang scribble/lp2`. 
> 
> -- 
> 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] Potential small bugs on SEwPR

2016-06-11 Thread Robby Findler
On Mon, Jun 6, 2016 at 8:15 AM,   wrote:
> Finally, I'd like to take the opportunity to ask a question:
>
> The book says that, by default, Redex typesets meta-functions in
> small-caps. But, on my tests, running the latest version of Redex, I see
> proportional sans-serif instead.
>
> Has this changed since the book was published, or am I doing something wrong? 
> Is
> there a way to restore the old behavior without having to add a compound
> rewriter for each meta-function?

Sorry for the delayed response. I can no longer recall if this was
false at the time the book was published or has become false since
then. Sorry about that.

But here's how you can do small caps.

#lang racket
(require redex)
(define-language L
  (t ::= (natural t t) natural))

(define-metafunction L
  Mirror : t -> t
  [(Mirror (natural t_1 t_2))
   (natural (Mirror t_2) (Mirror t_1))]
  [(Mirror natural) natural])

(test-equal (term (Mirror 0)) (term 0))
(test-equal (term (Mirror (1 (2 3 4) (5 6 7
(term (1 (5 7 6) (2 4 3

(parameterize ([metafunction-style (cons 'caps (metafunction-style))])
(render-metafunction Mirror))


> Thanks a lot for SEwPR and Redex. I finished reading it this weekend and loved
> it!

:)

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] function to recreate source string from syntax object?

2016-06-11 Thread Matthew Butterick

On Jun 11, 2016, at 8:39 PM, Alex Knauth  wrote:
> 
> The syntax->string function from syntax/to-string formats a syntax object 
> with its whitespace and indentation, but doesn't look at the paren-shapes:

Ah yes, thank you — I was so close.

I think probably it should handle newlines & paren shapes accurately. PR 
submitted; wiser minds can judge.



> It doesn't seem to handle whitespace before closing parens, but that makes 
> sense, since there isn't any closing paren source location for it to look at.

And there isn't supposed to be any whitespace there anyhow ;)

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