[racket-users] Does scribble/lp2 allow for test submodule

2015-06-02 Thread Tim Brown

In the distant past, I tried to use `scribble/lp' with a program with a
`test' sub-module (using that common pattern). There was some issue
with exporting the module that meant that I could not do it.

Now, in 2015, I notice that:
 a. time has passed, things have developed
 b. there is a `scribble/lp2' language

Is it now possible to write test cases in a `test' sub-module of a
literate program for testing with `raco test'?

Tim

--
Tim Brown CEng MBCS 

City Computing Limited · www.cityc.co.uk
  City House · Sutton Park Rd · Sutton · Surrey · SM1 2AE · GB
T:+44 20 8770 2110 · F:+44 20 8770 2130

City Computing Limited registered in London No:1767817.
Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE
VAT No: GB 918 4680 96

--
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] Iteration speed

2015-06-02 Thread Matthias Felleisen

On Jun 2, 2015, at 1:20 AM, Matthew Butterick  wrote:

> I've increasingly been using TR this way (= keeping code in a state where it 
> can be easily toggled between typechecked and not). It works, though I'm 
> still thinking about how to achieve better ergonomics with these issues, 
> which don't have automatic solutions:
> 
> Q1. How to toggle between `#lang typed/...` and `#lang typed/.../no-check` in 
> a group of files.


It is becoming clear to me that we need to integrate some of the file system 
into our module-level scope. At that point, we could expand refactoring (like 
alpha-renaming or this kind of type toggling) to these things. 



> Q2. How to `(require ...)` typed or untyped versions of other libraries 
> depending on whether I'm running in `no-check` mode.


The NU group is working on a performance evaluation experiment that needs just 
this kind of syntactic abstraction. We should probably work it into something 
useful. 



> Q3. How to preserve the semantics of type-derived predicates in `no-check`, 
> which otherwise all become false.


Well, that's the $10M question. At what price soundness? 

-- Matthias





> 
> (define-predicate foo? FooType)
> (foo? x) ;; in `no-check` this will always return #f, which breaks the code
> 
> 
> 
> 
> 
> On Jun 1, 2015, at 4:39 PM, Sam Tobin-Hochstadt  wrote:
> 
>> Yes, if you just change `#lang typed/racket/base` to `#lang
>> typed/racket/base/no-check`, that's what you'll get.
>> 
>> Sam
>> 
>> On Mon, Jun 1, 2015 at 10:34 PM, John Carmack  wrote:
>>> Is there an option to parse all the type annotations, but not do any of the 
>>> checking? Highly interactive tuning sessions could work without type 
>>> checking, then turn it back on for structural work.
>>> 
>>> 
>>> 
 On Jun 1, 2015, at 9:05 PM, Sam Tobin-Hochstadt  
 wrote:
 
 Unfortunately, Typed Racket typechecking is pretty slow, and so the
 times you have there are not out of the ordinary. The most significant
 thing that's slow in Typed Racket is type checking numeric operations,
 because both the numbers themselves and the operations have
 complicated types.
 
 If you can say more about the program in particular, I can maybe
 suggest something that would speed it up, but it's currently a
 combination of expensive-in-principle algorithms and not being
 designed for speed many years ago when I started.
 
 Sam
 
> On Mon, Jun 1, 2015 at 9:06 PM, John Carmack  wrote:
> I am working on a little project to remotely drive a VR headset with code
> written in Racket as an attempt to make a significantly faster development
> environment for certain types of VR apps.  I am worried about what appears
> to be the compile speed.
> 
> 
> 
> It takes over three seconds from hitting ctrl-R in DrRacket to executing 
> the
> first statement of a 350 line typed racket program.  It only uses:
> 
> #lang typed/racket/base
> 
> (require racket/tcp)
> 
> 
> 
> That seems to be about twice as slow as a larger untyped racket program
> using a bunch more stuff, but even that isn’t great:
> 
> #lang racket
> 
> (require 2htdp/universe)
> 
> (require 2htdp/image)
> 
> (require 2htdp/planetcute)
> 
> (require (only-in racket/gui/base play-sound))
> 
> 
> 
> Does Run from DrRacket  have a significant time penalty?
> 
> Are there any steps I can take to make typed racket compile faster?
> 
> In many cases I don’t care much about the execution speed.
> 
> 
> 
> I would like to think that compiling and running a few hundred lines of 
> code
> on a modern desktop system should be essentially instant.
> 
> 
> 
> 
> 
> --
> 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.
> 
> -- 
> 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...@g

Re: [racket-users] Does scribble/lp2 allow for test submodule

2015-06-02 Thread WarGrey Gyoudmon Ju
Yes, you can. I do it all the time.

BTW, lp2 is just the lp except that you do not need to wrap it in another
scribble file before requiring.

On Tue, Jun 2, 2015 at 8:43 PM, Tim Brown  wrote:

> In the distant past, I tried to use `scribble/lp' with a program with a
> `test' sub-module (using that common pattern). There was some issue
> with exporting the module that meant that I could not do it.
>
> Now, in 2015, I notice that:
>  a. time has passed, things have developed
>  b. there is a `scribble/lp2' language
>
> Is it now possible to write test cases in a `test' sub-module of a
> literate program for testing with `raco test'?
>
> Tim
>
> --
> Tim Brown CEng MBCS 
> 
> City Computing Limited · www.cityc.co.uk
>   City House · Sutton Park Rd · Sutton · Surrey · SM1 2AE · GB
> T:+44 20 8770 2110 · F:+44 20 8770 2130
> 
> City Computing Limited registered in London No:1767817.
> Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE
> VAT No: GB 918 4680 96
>
> --
> 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] can't quite reproduce this contract error involving an exported function

2015-06-02 Thread Robby Findler
Yes, it is supposed to do that correctly if you have the option turned on.

Robby


On Mon, Jun 1, 2015 at 3:50 PM, 'John Clements' via users-redirect
 wrote:
>
>> On Jun 1, 2015, at 1:46 PM, Robby Findler  
>> wrote:
>>
>> I think that if you don't have up to date .zo files, arbitrary badness
>> can ensue.
>
> Just to check my development model; generally, when I’m working on multiple 
> interdependent libraries in a collection, my experience has been that if I 
> make a change to one, DrR will recompile all of the ones that depend on it… 
> 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] Re: Get list of all predefined identifiers for use in vim syntax highlighting

2015-06-02 Thread Luke Miles
To provide some closure:

-The generator provided by Jens completely worked.
 I set up vim to have one color & indentation for keywords,
 and another color & indentation for builtins.

-The ambiguity brought up by Greg has shown not to be a problem.
 I only touched racket/base, as I nearly exclusively use it.
 The reader's distinction between keywords and builtins
 is good enough for me.

-Eventually, it would be nice to have keywords & builtins
 determined by the #lang line and any calls to require.
 However, I'm not sure if this is possible/practical in vim.

-- 
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] strange bug with racket/gui

2015-06-02 Thread Luke Miles
2 questions.


First, when the the attached code is run, `send` throws an error because `dc`
still has the value of void.

Strangely, if I execute the below line in the REPL after the code has run,
the rectangle is successfully displayed.
(send dc draw-rectangle 30 20 10 40)

Why is `dc` still void inside the code but not in the REPL afterwards?


Second, I have some *bad* code in the attached file:
(define canvas (void))
(define dc (void))
(new canvas% [parent frame]
 [paint-callback
   (λ (c d)
 (set! canvas c)
 (set! dc d))])
I couldn't find a direct way to get `dc` and `canvas`, and I didn't want to put
my entire code in the function that paint-callback calls.

Is there a more straightforward way to get these values?

Thanks!
-Luke

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


graphics-2.rkt
Description: Binary data


Re: [racket-users] strange bug with racket/gui

2015-06-02 Thread Alexis King
The problem here is that paint-callback is not called synchronously when you 
create a new canvas%, so before the callback code runs, the code following the 
creation of the canvas already attempts to use the drawing context.

Since canvas% implements canvas<%>, could you use the get-dc method of 
canvas<%> to retrieve the drawing context instead of using set! from inside 
paint-callback?

> On Jun 2, 2015, at 11:57, Luke Miles  wrote:
> 
> 2 questions.
> 
> 
> First, when the the attached code is run, `send` throws an error because `dc`
> still has the value of void.
> 
> Strangely, if I execute the below line in the REPL after the code has run,
> the rectangle is successfully displayed.
> (send dc draw-rectangle 30 20 10 40)
> 
> Why is `dc` still void inside the code but not in the REPL afterwards?
> 
> 
> Second, I have some *bad* code in the attached file:
> (define canvas (void))
> (define dc (void))
> (new canvas% [parent frame]
> [paint-callback
>   (λ (c d)
> (set! canvas c)
> (set! dc d))])
> I couldn't find a direct way to get `dc` and `canvas`, and I didn't want to 
> put
> my entire code in the function that paint-callback calls.
> 
> Is there a more straightforward way to get these values?
> 
> Thanks!
> -Luke
> 
> -- 
> 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] strange bug with racket/gui

2015-06-02 Thread John Smith
Alexis,
Thank you for the speedy answer.
I think I correctly implemented what you described. See attached.
In the new code, no error is thrown but the rectangle is not drawn.
Reorderings of displaying the window and drawing the rectangle appear to
have no effect.
The only way I can get anything to show up is if I enter it in the REPL
once the code is executed.

Any idea what might be causing this?

-Luke

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


graphics-3.rkt
Description: Binary data


[racket-users] Strange behavior when writing to a file

2015-06-02 Thread Mark Lee
To all,

I've been recently working on a database and I've encountered strange behavior
when I use "call-with-atomic-output-file" and "with-output-to-file". Attached
is a sample piece of code. The correct contents of the SOAP file should be :

*First-Name : John
*Last-Name : Doe
*Gender : male
*Phone-Number : 000-000-

Instead I get :

*First-Name : John
*Last-Name : Doe
*Phone-Number : 000-000-

In addition, If one uncomments the redirects to file, they get the correct
output (but it's not saved to a file):
*First-Name : John
*Last-Name : Doe
*Phone-Number : 000-000-

Regards,
Mark

database-test.rkt
Description: application/kdeuser1


signature.asc
Description: This is a digitally signed message part.


Re: [racket-users] strange bug with racket/gui

2015-06-02 Thread Alexander D. Knauth
I have never worked with a canvas% before (I have worked with a lot of other 
racket gui stuff), so I have no idea what’s going on, but watch what happens 
with this:
#lang racket
(require racket/gui/base)
(define frame (new frame%
   [label "Example"]
   [width 300]
   [height 300]))
(define canvas
  (new canvas% [parent frame]))
(define dc (send canvas get-dc))
(send frame show #t)
(sleep 1)
(send dc draw-rectangle 30 20 10 40)

And even better, with this:
#lang racket
(require racket/gui/base)
(define frame (new frame%
   [label "Example"]
   [width 300]
   [height 300]))
(define canvas
  (new canvas% [parent frame]))
(define dc (send canvas get-dc))
(send frame show #t)
(sleep 1)
(send dc draw-rectangle 30 20 10 40)
(sleep 2)


On Jun 2, 2015, at 3:17 PM, John Smith  wrote:

> Alexis,
> Thank you for the speedy answer.
> I think I correctly implemented what you described. See attached.
> In the new code, no error is thrown but the rectangle is not drawn.
> Reorderings of displaying the window and drawing the rectangle appear to have 
> no effect.
> The only way I can get anything to show up is if I enter it in the REPL once 
> the code is executed.
> 
> Any idea what might be causing this?
> 
> -Luke
> 
> -- 
> 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] strange bug with racket/gui

2015-06-02 Thread Matthias Felleisen

You want to override on-paint: 

#lang racket

(require racket/gui/base)

(define frame
  (new frame%
   [label "Example"]
   [width 300]
   [height 300]))

(define canvas
  ;; classes are first-class 
http://www.ccs.neu.edu/home/matthias/Tmp/Class/programming-with-class/
  (new (class canvas% 
 (super-new [parent frame])
 [define/override (on-paint)
   (send (send canvas get-dc) draw-rectangle 30 20 10 40)])))

(send frame show #t)




On Jun 2, 2015, at 3:31 PM, "Alexander D. Knauth"  wrote:

> I have never worked with a canvas% before (I have worked with a lot of other 
> racket gui stuff), so I have no idea what’s going on, but watch what happens 
> with this:
> #lang racket
> (require racket/gui/base)
> (define frame (new frame%
>[label "Example"]
>[width 300]
>[height 300]))
> (define canvas
>   (new canvas% [parent frame]))
> (define dc (send canvas get-dc))
> (send frame show #t)
> (sleep 1)
> (send dc draw-rectangle 30 20 10 40)
> 
> And even better, with this:
> #lang racket
> (require racket/gui/base)
> (define frame (new frame%
>[label "Example"]
>[width 300]
>[height 300]))
> (define canvas
>   (new canvas% [parent frame]))
> (define dc (send canvas get-dc))
> (send frame show #t)
> (sleep 1)
> (send dc draw-rectangle 30 20 10 40)
> (sleep 2)
> 
> 
> On Jun 2, 2015, at 3:17 PM, John Smith  wrote:
> 
>> Alexis,
>> Thank you for the speedy answer.
>> I think I correctly implemented what you described. See attached.
>> In the new code, no error is thrown but the rectangle is not drawn.
>> Reorderings of displaying the window and drawing the rectangle appear to 
>> have no effect.
>> The only way I can get anything to show up is if I enter it in the REPL once 
>> the code is executed.
>> 
>> Any idea what might be causing this?
>> 
>> -Luke
>> 
>> -- 
>> 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] strange bug with racket/gui

2015-06-02 Thread John Smith
Alexander,
Pretty strange overall.


This code displays nothing:

#lang racket
(require racket/gui/base)
(define frame (new frame%
   [label "Example"]
   [width 300]
   [height 300]))
(define canvas
  (new canvas% [parent frame]))
(define dc (send canvas get-dc))
(send frame show #t)
*;(thread (λ () (sleep 1/30) (send dc draw-rectangle 30 20 10 40)))*
*(sleep 1/30) (send dc draw-rectangle 30 20 10 40)*


But this code properly shows the rectangle:
#lang racket
(require racket/gui/base)
(define frame (new frame%
   [label "Example"]
   [width 300]
   [height 300]))
(define canvas
  (new canvas% [parent frame]))
(define dc (send canvas get-dc))
(send frame show #t)
*(thread (λ () (sleep 1/30) (send dc draw-rectangle 30 20 10 40)))*
*;(sleep 1/30) (send dc draw-rectangle 30 20 10 40)*

I have no idea why.
-Luke

-- 
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] strange bug with racket/gui

2015-06-02 Thread John Smith
Matthias,

The code you provided worked,  but this whole discussion was started to get
the code *out* of the body of a function.

Is there a way I could run your solution with
(send (send canvas get-dc) draw-rectangle 30 20 10 40)
running in the top level?

-Luke

On Tue, Jun 2, 2015 at 3:43 PM, Matthias Felleisen 
wrote:

>
> You want to override on-paint:
>
> #lang racket
>
> (require racket/gui/base)
>
> (define frame
>   (new frame%
>[label "Example"]
>[width 300]
>[height 300]))
>
> (define canvas
>   ;; classes are first-class
> http://www.ccs.neu.edu/home/matthias/Tmp/Class/programming-with-class/
>   (new (class canvas%
>  (super-new [parent frame])
>  [define/override (on-paint)
>(send (send canvas get-dc) draw-rectangle 30 20 10 40)])))
>
> (send frame show #t)
>
>
>
>
> On Jun 2, 2015, at 3:31 PM, "Alexander D. Knauth" 
> wrote:
>
> > I have never worked with a canvas% before (I have worked with a lot of
> other racket gui stuff), so I have no idea what’s going on, but watch what
> happens with this:
> > #lang racket
> > (require racket/gui/base)
> > (define frame (new frame%
> >[label "Example"]
> >[width 300]
> >[height 300]))
> > (define canvas
> >   (new canvas% [parent frame]))
> > (define dc (send canvas get-dc))
> > (send frame show #t)
> > (sleep 1)
> > (send dc draw-rectangle 30 20 10 40)
> >
> > And even better, with this:
> > #lang racket
> > (require racket/gui/base)
> > (define frame (new frame%
> >[label "Example"]
> >[width 300]
> >[height 300]))
> > (define canvas
> >   (new canvas% [parent frame]))
> > (define dc (send canvas get-dc))
> > (send frame show #t)
> > (sleep 1)
> > (send dc draw-rectangle 30 20 10 40)
> > (sleep 2)
> >
> >
> > On Jun 2, 2015, at 3:17 PM, John Smith  wrote:
> >
> >> Alexis,
> >> Thank you for the speedy answer.
> >> I think I correctly implemented what you described. See attached.
> >> In the new code, no error is thrown but the rectangle is not drawn.
> >> Reorderings of displaying the window and drawing the rectangle appear
> to have no effect.
> >> The only way I can get anything to show up is if I enter it in the REPL
> once the code is executed.
> >>
> >> Any idea what might be causing this?
> >>
> >> -Luke
> >>
> >> --
> >> 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] strange bug with racket/gui

2015-06-02 Thread Robby Findler
You can override on-paint to draw from a bitmap and then draw into the
bitmap.

The canvas DC is access directly to the OS-provided drawing context and you
add what you need as you see fit.

Robby

On Tuesday, June 2, 2015, John Smith  wrote:

> Matthias,
>
> The code you provided worked,  but this whole discussion was started to
> get the code *out* of the body of a function.
>
> Is there a way I could run your solution with
> (send (send canvas get-dc) draw-rectangle 30 20 10 40)
> running in the top level?
>
> -Luke
>
> On Tue, Jun 2, 2015 at 3:43 PM, Matthias Felleisen  > wrote:
>
>>
>> You want to override on-paint:
>>
>> #lang racket
>>
>> (require racket/gui/base)
>>
>> (define frame
>>   (new frame%
>>[label "Example"]
>>[width 300]
>>[height 300]))
>>
>> (define canvas
>>   ;; classes are first-class
>> http://www.ccs.neu.edu/home/matthias/Tmp/Class/programming-with-class/
>>   (new (class canvas%
>>  (super-new [parent frame])
>>  [define/override (on-paint)
>>(send (send canvas get-dc) draw-rectangle 30 20 10 40)])))
>>
>> (send frame show #t)
>>
>>
>>
>>
>> On Jun 2, 2015, at 3:31 PM, "Alexander D. Knauth" > > wrote:
>>
>> > I have never worked with a canvas% before (I have worked with a lot of
>> other racket gui stuff), so I have no idea what’s going on, but watch what
>> happens with this:
>> > #lang racket
>> > (require racket/gui/base)
>> > (define frame (new frame%
>> >[label "Example"]
>> >[width 300]
>> >[height 300]))
>> > (define canvas
>> >   (new canvas% [parent frame]))
>> > (define dc (send canvas get-dc))
>> > (send frame show #t)
>> > (sleep 1)
>> > (send dc draw-rectangle 30 20 10 40)
>> >
>> > And even better, with this:
>> > #lang racket
>> > (require racket/gui/base)
>> > (define frame (new frame%
>> >[label "Example"]
>> >[width 300]
>> >[height 300]))
>> > (define canvas
>> >   (new canvas% [parent frame]))
>> > (define dc (send canvas get-dc))
>> > (send frame show #t)
>> > (sleep 1)
>> > (send dc draw-rectangle 30 20 10 40)
>> > (sleep 2)
>> >
>> >
>> > On Jun 2, 2015, at 3:17 PM, John Smith > > wrote:
>> >
>> >> Alexis,
>> >> Thank you for the speedy answer.
>> >> I think I correctly implemented what you described. See attached.
>> >> In the new code, no error is thrown but the rectangle is not drawn.
>> >> Reorderings of displaying the window and drawing the rectangle appear
>> to have no effect.
>> >> The only way I can get anything to show up is if I enter it in the
>> REPL once the code is executed.
>> >>
>> >> Any idea what might be causing this?
>> >>
>> >> -Luke
>> >>
>> >> --
>> >> 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.
>

-- 
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] strange bug with racket/gui

2015-06-02 Thread Matthias Felleisen

I don't understand why you'd want this. But if you do, sleep/yield is the right 
way to wait for the frame to show up and to send drawing commands. 


On Jun 2, 2015, at 3:56 PM, John Smith  wrote:

> Matthias,
> 
> The code you provided worked,  but this whole discussion was started to get 
> the code out of the body of a function.
> 
> Is there a way I could run your solution with
> (send (send canvas get-dc) draw-rectangle 30 20 10 40)
> running in the top level?
> 
> -Luke
> 
> On Tue, Jun 2, 2015 at 3:43 PM, Matthias Felleisen  
> wrote:
> 
> You want to override on-paint:
> 
> #lang racket
> 
> (require racket/gui/base)
> 
> (define frame
>   (new frame%
>[label "Example"]
>[width 300]
>[height 300]))
> 
> (define canvas
>   ;; classes are first-class 
> http://www.ccs.neu.edu/home/matthias/Tmp/Class/programming-with-class/
>   (new (class canvas%
>  (super-new [parent frame])
>  [define/override (on-paint)
>(send (send canvas get-dc) draw-rectangle 30 20 10 40)])))
> 
> (send frame show #t)
> 
> 
> 
> 
> On Jun 2, 2015, at 3:31 PM, "Alexander D. Knauth"  
> wrote:
> 
> > I have never worked with a canvas% before (I have worked with a lot of 
> > other racket gui stuff), so I have no idea what’s going on, but watch what 
> > happens with this:
> > #lang racket
> > (require racket/gui/base)
> > (define frame (new frame%
> >[label "Example"]
> >[width 300]
> >[height 300]))
> > (define canvas
> >   (new canvas% [parent frame]))
> > (define dc (send canvas get-dc))
> > (send frame show #t)
> > (sleep 1)
> > (send dc draw-rectangle 30 20 10 40)
> >
> > And even better, with this:
> > #lang racket
> > (require racket/gui/base)
> > (define frame (new frame%
> >[label "Example"]
> >[width 300]
> >[height 300]))
> > (define canvas
> >   (new canvas% [parent frame]))
> > (define dc (send canvas get-dc))
> > (send frame show #t)
> > (sleep 1)
> > (send dc draw-rectangle 30 20 10 40)
> > (sleep 2)
> >
> >
> > On Jun 2, 2015, at 3:17 PM, John Smith  wrote:
> >
> >> Alexis,
> >> Thank you for the speedy answer.
> >> I think I correctly implemented what you described. See attached.
> >> In the new code, no error is thrown but the rectangle is not drawn.
> >> Reorderings of displaying the window and drawing the rectangle appear to 
> >> have no effect.
> >> The only way I can get anything to show up is if I enter it in the REPL 
> >> once the code is executed.
> >>
> >> Any idea what might be causing this?
> >>
> >> -Luke
> >>
> >> --
> >> 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] strange bug with racket/gui

2015-06-02 Thread Matthew Flatt
The documentation's discussion of drawing in a canvas may be helpful:

 http://docs.racket-lang.org/gui/canvas___.html

There was also a similar thread on this list in January, and the exampe
code I posted then may be helpful:

 http://lists.racket-lang.org/users/archive/2015-January/065764.html


At Tue, 2 Jun 2015 16:10:00 -0400, Matthias Felleisen wrote:
> 
> I don't understand why you'd want this. But if you do, sleep/yield is the 
> right 
> way to wait for the frame to show up and to send drawing commands. 
> 
> 
> On Jun 2, 2015, at 3:56 PM, John Smith  wrote:
> 
> > Matthias,
> > 
> > The code you provided worked,  but this whole discussion was started to get 
> the code out of the body of a function.
> > 
> > Is there a way I could run your solution with
> > (send (send canvas get-dc) draw-rectangle 30 20 10 40)
> > running in the top level?
> > 
> > -Luke
> > 
> > On Tue, Jun 2, 2015 at 3:43 PM, Matthias Felleisen  
> wrote:
> > 
> > You want to override on-paint:
> > 
> > #lang racket
> > 
> > (require racket/gui/base)
> > 
> > (define frame
> >   (new frame%
> >[label "Example"]
> >[width 300]
> >[height 300]))
> > 
> > (define canvas
> >   ;; classes are first-class 
> http://www.ccs.neu.edu/home/matthias/Tmp/Class/programming-with-class/
> >   (new (class canvas%
> >  (super-new [parent frame])
> >  [define/override (on-paint)
> >(send (send canvas get-dc) draw-rectangle 30 20 10 40)])))
> > 
> > (send frame show #t)
> > 
> > 
> > 
> > 
> > On Jun 2, 2015, at 3:31 PM, "Alexander D. Knauth"  
> wrote:
> > 
> > > I have never worked with a canvas% before (I have worked with a lot of 
> other racket gui stuff), so I have no idea what’s going on, but watch what 
> happens with this:
> > > #lang racket
> > > (require racket/gui/base)
> > > (define frame (new frame%
> > >[label "Example"]
> > >[width 300]
> > >[height 300]))
> > > (define canvas
> > >   (new canvas% [parent frame]))
> > > (define dc (send canvas get-dc))
> > > (send frame show #t)
> > > (sleep 1)
> > > (send dc draw-rectangle 30 20 10 40)
> > >
> > > And even better, with this:
> > > #lang racket
> > > (require racket/gui/base)
> > > (define frame (new frame%
> > >[label "Example"]
> > >[width 300]
> > >[height 300]))
> > > (define canvas
> > >   (new canvas% [parent frame]))
> > > (define dc (send canvas get-dc))
> > > (send frame show #t)
> > > (sleep 1)
> > > (send dc draw-rectangle 30 20 10 40)
> > > (sleep 2)
> > >
> > >
> > > On Jun 2, 2015, at 3:17 PM, John Smith  wrote:
> > >
> > >> Alexis,
> > >> Thank you for the speedy answer.
> > >> I think I correctly implemented what you described. See attached.
> > >> In the new code, no error is thrown but the rectangle is not drawn.
> > >> Reorderings of displaying the window and drawing the rectangle appear to 
> have no effect.
> > >> The only way I can get anything to show up is if I enter it in the REPL 
> once the code is executed.
> > >>
> > >> Any idea what might be causing this?
> > >>
> > >> -Luke
> > >>
> > >> --
> > >> 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.

-- 
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] Strange behavior when writing to a file

2015-06-02 Thread Matthew Flatt
If you uncomment the redirects to stdout and comment out the file
output, then nothing is written to the file, so that changes the
content of `(file->lines soap-file)` the second time around.

I think you wanted `(and (>=` in place of `(or (<`.

At Tue, 02 Jun 2015 15:25:07 -0400, Mark Lee wrote:
> To all,
> 
> I've been recently working on a database and I've encountered strange 
> behavior 
> when I use "call-with-atomic-output-file" and "with-output-to-file". Attached 
> is a sample piece of code. The correct contents of the SOAP file should be :
> 
> *First-Name : John
> *Last-Name : Doe
> *Gender : male
> *Phone-Number : 000-000-
> 
> Instead I get : 
> 
> *First-Name : John
> *Last-Name : Doe
> *Phone-Number : 000-000-
> 
> In addition, If one uncomments the redirects to file, they get the correct 
> output (but it's not saved to a file): 
> *First-Name : John
> *Last-Name : Doe
> *Phone-Number : 000-000-
> 
> Regards,
> Mark
> 
> -- 
> 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] Removing duplicates from a list while maintaining order

2015-06-02 Thread Paul Bian
Hi all,

Trying to learn a bit about recursion in racket.
The question is to remove duplicates from a list while maintaining the order of 
the list.

one function to remove duplicates from the left, 

i.e. 1 2 1 3 2 4 5 -> 1 2 3 4 5

and one from the right.

i.e. 1 2 1 3 2 4 5 -> 1 3 2 4 5

I've gotten the code to work by writing some helper functions, but my question 
is, is it possible to solve these problems WITHOUT:

- local definition (i.e. beginner student language in dr racket)
- loops
- built in 'remove', 'reverse', 'member?'
- writing your own 'remove', 'reverse', 'member?' functions

OR if 'member?' is allowed... I can figure out the right side case without 
additional functions, but not for the left case, is there a way to do this 
without the remove duplicates function that i wrote?

---
Code:

http://pastebin.com/h0dBdUaR

(define (RemoveElement element lst)
;if unique-left is applied to (list 1 4 2 1 5 4), the result would be (list 1 4 
2 5)
  (cond
[(empty? lst) empty]
[(= element (first lst)) (RemoveElement element (rest lst))]
[else (cons (first lst) (RemoveElement element (rest lst)))]))

(define (unique-left lst)
  (cond
[(empty? lst) empty]
[(member? (first lst) (rest lst)) (cons (first lst) (unique-left 
(RemoveElement (first lst) (rest lst] 
[else (cons (first lst) (unique-left (rest lst)))]
)
  )

(define (unique-right lst)
;the result of applying it to (list 1 4 2 1 5 4) would be (list 2 1 5 4)
  (cond
[(empty? lst) empty]
[(not (member? (first lst) (rest lst))) (cons (first lst) (unique-right 
(rest lst)))]
[else (unique-right (rest lst))]))

-- 
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] Parallelism / atomic?

2015-06-02 Thread Michael Tiedtke
I'm currently implementing a new parallel objects policy (SAKE: Skip Animation 
and Skedule) and I'm supposing that setting boolean values (even with an 
accessor via send) is atomic with respect to its reads. I can't remember where 
but the documentation (Guide or Reference) somewhere stated that most primitive 
operations are atomic ... Is there any way to find out about the atomicity of 
procedures / primitives in Racket?  The standards currently do not guarantee 
anything in this respect.

Some examples with the theoretical predicate atomic?:

(atomic? semaphore-try-wait?) => #t
(define my-boolean #f)
(atomic? {lambda () (set! my-boolean #t)} => #t
(atomic? {lambda () (if my-boolean 'yes 'no)} => #t
(atomic? {lambda () [when my-boolean (set! my-boolean #f)]} => #f


Parallelism in my current project is a result of nested event handling. But 
when it comes to threads I found the following statements about threads in the 
Guide (Parallelism):

 "Other functions, such as thread, support the creation of reliably concurrent 
tasks. However, threads never run truly in parallel, even if the hardware and 
operating system support parallelism."

Is there any good reason for this? It sounds like cooperative multitasking ... 


The Racket Foreign Interface describes another type of atomicity: "Disables and 
enables context switches and delivery of break exceptions at the level of 
Racket threads." One could even call this virtual atomicity.

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