[racket-users] Wrap long text in 2htdp/image

2017-07-22 Thread kay
When using 2htdp/image to create a text image, is this possible to specify a 
"bounding box" for the image, so that the text could be wrapped to fit that box?

E.g., below line:

  (text "This wide, sharp telescopic view reveals galaxies scattered beyond the 
stars of the Milky Way at the northern boundary of the high-flying 
constellation Pegasus. Prominent at the upper right is NGC 7331. A mere 50 
million light-years away, the large spiral is one of the brighter galaxies not 
included in Charles Messier's famous 18th century catalog. The disturbed 
looking group of galaxies at the lower left is well-known as Stephan's Quintet. 
About 300 million light-years distant, the quintet dramatically illustrates a 
multiple galaxy collision, its powerful, ongoing interactions posed for a brief 
cosmic snapshot. On the sky, the quintet and NGC 7331 are separated by about 
half a degree." 10 "black")


creates a super long line text image without wrapping, when I want to overlay 
it on another image, it's mostly useless. I want to specify a "size" (aka 
bounding box) for it so it wraps properly.

Is that possible?

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

2017-05-22 Thread kay
Cool thanks for the clarification Vincent!

On Monday, May 22, 2017 at 9:39:15 AM UTC-7, Vincent St-Amour wrote:
> Hi Kay,
> 
> On Sun, 21 May 2017 23:30:50 -0500,
> kay wrote:
> > 
> > Hi Vincent,
> > 
> > Thanks for fixing it. Is there a Github commit that you can refer me
> > to? Or does Racket development actually happen on Github?
> 
> Yes, Racket development does happen on github.
> 
> The relevant commit is this one:
> https://github.com/racket/typed-racket/commit/c0af5235d255ca1a9622249c0ca26ad5349ccefa
> 
> > In addition, MORE IMPORTANTLY, now that it looks like a bug that I
> > found, is there a workaround to this problem without waiting for a new
> > release that contains the fix?
> 
> I see two potential solutions here:
> - You could use a nightly build (from pre.racket-lang.org) instead of a
>   released version, until 6.10 comes out (planned for July).
> - You could use `require/typed` to import `parse-command-line` at the
>   type that you need. That's the procedure version of the `command-line`
>   syntax, which should support all the same options, but with a
>   different interface. Since it's a procedure, you can ascribe it a type
>   yourself.
> 
> > How stable is Typed Racket? I know you guys are doing an awesome job
> > and I really love it - but just trying to put my expectation right, as
> > I'm totally new to TR and this is my first TR problem and I
> > encountered this bug, leading me to wonder this question.
> 
> I'll let Sam answer this one, or one of TR's users. :)
> 
> In general, though, it's possible for TR to lag a bit behind untyped
> Racket for some things. If a Racket function, say, gains an extra
> keyword argument, we're usually pretty good at adding it to its type
> quickly. Sometimes things fall through the cracks; #:ps must have been
> one of them.
> 
> Vincent
> 
> 
> 
> > On Thursday, May 18, 2017 at 1:51:14 PM UTC-7, Vincent St-Amour wrote:
> > > I just pushed a fix. Thanks for the report!
> > > 
> > > Vincent
> > > 
> > > 
> > > On Wed, 17 May 2017 01:47:11 -0500,
> > > lu wrote:
> > > > 
> > > > On Tuesday, May 16, 2017 at 12:47:37 AM UTC-7, kay wrote:
> > > > > 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: (->

Re: [racket-users] Re: Type Racket command-line #:ps causing type error

2017-05-21 Thread kay
Hi Vincent,

Thanks for fixing it. Is there a Github commit that you can refer me to? Or 
does Racket development actually happen on Github?

In addition, MORE IMPORTANTLY, now that it looks like a bug that I found, is 
there a workaround to this problem without waiting for a new release that 
contains the fix?

How stable is Typed Racket? I know you guys are doing an awesome job and I 
really love it - but just trying to put my expectation right, as I'm totally 
new to TR and this is my first TR problem and I encountered this bug, leading 
me to wonder this question. 


Thanks,
Kefei



On Thursday, May 18, 2017 at 1:51:14 PM UTC-7, Vincent St-Amour wrote:
> I just pushed a fix. Thanks for the report!
> 
> Vincent
> 
> 
> On Wed, 17 May 2017 01:47:11 -0500,
> lu wrote:
> > 
> > On Tuesday, May 16, 2017 at 12:47:37 AM UTC-7, kay wrote:
> > > 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)))
> > 
> > Ping... can anyone help with this problem?
> > 
> > -- 
> > 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] 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.


[racket-users] How to type annotate for bindings in complex syntax forms

2017-03-05 Thread kay
For a complex syntax form like `command-line`, I have difficulty correctly 
annotate the bindings it defines.

More specifically, in the below code, for variable `msg`, even the document[1] 
says the `#:args` binds as list of **strings**, but the error indicates that it 
somehow is declared as `Listof Any`.

Similarly, for variable `ch` bound in line 11, I believe it should always be 
`String`, but it somehow is declared to be `Any`.

What should I do with this type of error, if I want my varaibles to be more 
precisely typed than just `Any`?


[1]: 
https://docs.racket-lang.org/reference/Command-Line_Parsing.html?q=command-line#%28form._%28%28lib._racket%2Fcmdline..rkt%29._command-line%29%29

```
 1  #lang typed/racket
 2  
 3  (define *channel* (make-parameter "#general"))
 4  (define *message* : (Parameterof (Listof String)) (make-parameter '()))
 5  
 6  
 7  (define (parse-cmdline)
 8  (command-line
 9   #:program "q"
10   #:once-each
11   [("-c" "--channel") ch "slack channel to post (default: use .qrc 
setting or default)" (*channel* ch)]
12   #:args msg
13   (*message* msg)))
14  
15  
16  #|
17  tr.rkt:11:91: Type Checker: Wrong argument to parameter - expected 
String and got Any in: (*channel* ch)
18  tr.rkt:13:5: Type Checker: Wrong argument to parameter - expected 
(Listof String) and got (Listof Any) in: (*message* msg)
19  |#
```

-- 
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] Typed Racket: Polymorphic function `dynamic-wind' could not be applied to arguments

2017-03-05 Thread kay
Thanks for pointing it out. I also figured later that the multiple return 
values was the problem here.

Is this a TR type system limitation that polymorphic functions don't like 
multiple return values? Looks like it might be worth mentioning somewhere in 
the documentation or better in the error message.


On Sunday, March 5, 2017 at 1:54:54 AM UTC-8, WarGrey Gyoudmon Ju wrote:
> The problem is not the `AnyValues` since it accepts all types, but you cannot 
> instantiate a polymorphic type to return multiple values, so you have to 
> return (cons ... ...) in dynamic-wind then extract that pair as two return 
> values of the function.   
> 
> 
> On Sun, Mar 5, 2017 at 3:23 PM, kay <klu...@gmail.com> wrote:
> I have the following simple module that I'm converting to typed/racket. I got 
> a type check error that I don't know how to fix. More specifically, it's 
> related to the polymorphic function dynamic-wind's arguments. I read from 
> document [1] that type inference doesn't work for a lambda that is an 
> argument to a polymorphic function. But since here the three arguments are 
> all thunks (without input argument), I don't know how to properly annotate 
> them.
> 
> 
> 
> Note that I tried to even annotate the first argument:
> 
> 
> 
>   (λ () (ann #f AnyValues))
> 
> 
> 
> And the type checker complained:
> 
> 
> 
>   Argument 1:
> 
>     Expected: (-> AnyValues)
> 
>     Given:    (-> AnyValues)
> 
> 
> 
> which is really weird.
> 
> 
> 
> 
> 
> [1]: 
> https://docs.racket-lang.org/ts-guide/more.html#%28part._when-annotations~3f%29
> 
> 
> 
> 
> 
> 
> 
> Here's the module:
> 
> --
> 
> 
> 
> #lang typed/racket
> 
> 
> 
> ;;(require racket/string racket/list racket/match racket/system racket/port 
> racket/function)
> 
> (provide execute)
> 
> 
> 
> (: execute (-> String * (Values String String)))
> 
> (define (execute . args)
> 
>   (define cmdln (string-join args))
> 
>   (displayln (format "running ~a" cmdln))
> 
>   (match (process cmdln)
> 
>     [(list out in pid err f)
> 
> 
> 
>      (define cust (make-custodian))
> 
>      (dynamic-wind
> 
>       (λ () (ann #f AnyValues))
> 
> 
> 
>       (thunk
> 
>        (parameterize ([current-custodian cust])
> 
>          (define buf_stdout (open-output-string))
> 
>          (define buf_stderr (open-output-string))
> 
> 
> 
>          (thread (λ () (copy-port out buf_stdout (current-output-port
> 
>          (thread (λ () (copy-port err buf_stderr (current-error-port
> 
> 
> 
>          (displayln (f 'status))
> 
>          (f 'wait)
> 
> 
> 
>          (values (get-output-string buf_stdout) (get-output-string 
> buf_stderr
> 
> 
> 
>       (thunk (custodian-shutdown-all cust)))
> 
>      ]))
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Here's the type error:
> 
> --
> 
> 
> 
> . executor.rkt:14:5: Type Checker: Polymorphic function `dynamic-wind' could 
> not be applied to arguments:
> 
> Argument 1:
> 
>   Expected: (-> AnyValues)
> 
>   Given:    (-> AnyValues)
> 
> Argument 2:
> 
>   Expected: (-> a)
> 
>   Given:    (-> (values (String : (Top | Bot)) (String : (Top | Bot
> 
> Argument 3:
> 
>   Expected: (-> AnyValues)
> 
>   Given:    (-> Void)
> 
> 
> 
> Result type:     a
> 
> Expected result: (values String String)
> 
>  in: (dynamic-wind (λ () (ann #f AnyValues)) (thunk (parameterize 
> ((current-custodian cust)) (define buf_stdout (open-output-string)) (define 
> buf_stderr (open-output-string)) (thread (λ () (copy-port out buf_stdout 
> (current-output-port (thread (λ () (copy-port err buf_stderr 
> (current-error-port (displayln (f (quote status))) (f (quote wait)) 
> (values (get-output-string buf_stdout) (get-output-string buf_stderr 
> (thunk (custodian-shutdown-all cust)))
> 
> 
> 
> --
> 
> 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...@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] Typed Racket: Polymorphic function `dynamic-wind' could not be applied to arguments

2017-03-04 Thread kay
I have the following simple module that I'm converting to typed/racket. I got a 
type check error that I don't know how to fix. More specifically, it's related 
to the polymorphic function dynamic-wind's arguments. I read from document [1] 
that type inference doesn't work for a lambda that is an argument to a 
polymorphic function. But since here the three arguments are all thunks 
(without input argument), I don't know how to properly annotate them. 

Note that I tried to even annotate the first argument:

  (λ () (ann #f AnyValues))

And the type checker complained:

  Argument 1:
Expected: (-> AnyValues)
Given:(-> AnyValues)

which is really weird.


[1]: 
https://docs.racket-lang.org/ts-guide/more.html#%28part._when-annotations~3f%29



Here's the module:
--

#lang typed/racket

;;(require racket/string racket/list racket/match racket/system racket/port 
racket/function)
(provide execute)

(: execute (-> String * (Values String String)))
(define (execute . args)
  (define cmdln (string-join args))
  (displayln (format "running ~a" cmdln))
  (match (process cmdln)
[(list out in pid err f)

 (define cust (make-custodian))
 (dynamic-wind
  (λ () (ann #f AnyValues))
  
  (thunk 
   (parameterize ([current-custodian cust])
 (define buf_stdout (open-output-string))
 (define buf_stderr (open-output-string))
   
 (thread (λ () (copy-port out buf_stdout (current-output-port
 (thread (λ () (copy-port err buf_stderr (current-error-port

 (displayln (f 'status))
 (f 'wait)
   
 (values (get-output-string buf_stdout) (get-output-string 
buf_stderr
  
  (thunk (custodian-shutdown-all cust)))
 ]))




Here's the type error:
--

. executor.rkt:14:5: Type Checker: Polymorphic function `dynamic-wind' could 
not be applied to arguments:
Argument 1:
  Expected: (-> AnyValues)
  Given:(-> AnyValues)
Argument 2:
  Expected: (-> a)
  Given:(-> (values (String : (Top | Bot)) (String : (Top | Bot
Argument 3:
  Expected: (-> AnyValues)
  Given:(-> Void)

Result type: a
Expected result: (values String String)
 in: (dynamic-wind (λ () (ann #f AnyValues)) (thunk (parameterize 
((current-custodian cust)) (define buf_stdout (open-output-string)) (define 
buf_stderr (open-output-string)) (thread (λ () (copy-port out buf_stdout 
(current-output-port (thread (λ () (copy-port err buf_stderr 
(current-error-port (displayln (f (quote status))) (f (quote wait)) (values 
(get-output-string buf_stdout) (get-output-string buf_stderr (thunk 
(custodian-shutdown-all cust)))

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