Re: [racket-users] TCP listening & custodians

2017-02-23 Thread Matthew Flatt
The difference is the state that the TCP port is left in at the
protocol level as managed by the OS. For more information, look for
"TIME_WAIT" in a TCP reference, such as "TCP/IP Illustrated" by
Stevens.

The "More" tutorial avoids the problem by passing #t as the third
argument to `tcp-listen`:

  (define listener (tcp-listen port 5 #t))

The documentation for `tcp-listen` includes a caveat for this way of
avoiding the error, but it leaves the details to Stevens.

Hope that helps,
Matthew

At Thu, 23 Feb 2017 09:54:56 -0800, Jordan Johnson wrote:
> Hi all,
> 
> The code below is a simple server based on the web server in the “More: 
> Systems programming in Racket” tutorial.
> 
> This behavior is puzzling me:
> I run the server (from the OS X Terminal) and connect a client.
> After a wait, the client is disconnected by the timeout (shown in red).
> I halt the server with ^C, by triggering the thunk shown in blue.
> I start the server again — same way, from the Terminal — and get an “Address 
> already in use” error.
> 
> This behavior happens consistently.
> 
> What’s perplexing is that if I close the connection from the client side 
> instead of waiting in step (2) — in which case I understand the bold purple 
> expression to be closing the connection — I consistently do not get an error.
> 
> I’m puzzled because my current understanding is that the two identical calls 
> to custodian-shutdown-all should both be shutting down the same threads and 
> I/O ports that were created under the custodian cust — and that even if this 
> weren’t the case, the (custodian-shutdown-all main-cust) call should be 
> cleaning up those same resources (in addition to shutting down the listener), 
> because cust is subordinate to main-cust.
> 
> So my question is: What difference between the two cases accounts for the 
> different behavior?
> 
> Thanks,
> Jordan
> 
> ; Example server ;
> 
> #!/usr/local/racket/bin/racket
> #lang racket/base
> 
> (require racket/tcp)
> 
> (define (serve port)
>   (define main-cust (make-custodian))
>   (parameterize ([current-custodian main-cust])
> (define listener (tcp-listen port))
> (define (loop) (accept/handle listener) (loop))
> (thread loop)
> ;; Hook to shutdown the server:
> (lambda ()
>   (printf "Exiting...~n")
>   (custodian-shutdown-all main-cust)
>   (exit 0
> 
> (define (accept/handle l)
>   (define cust (make-custodian))
>   (parameterize ([current-custodian cust])
> (define-values (in out) (tcp-accept l))
> (thread (lambda ()
>   (let loop ([s (read-line in)])
> (unless (eof-object? s)
>   (fprintf out "Got it.~n")
>   (flush-output out)
>   (loop (read-line
>   (custodian-shutdown-all cust)))
> ;; Timeout:
> (thread (lambda () (sleep 5) (custodian-shutdown-all cust)
> 
> (define stop (serve 9001))
> 
> (with-handlers ([exn:break? (lambda (e) (stop))])
>   (let loop () (sleep 10) (loop)))
> 
> -- 
> 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] TCP listening & custodians

2017-02-23 Thread Jordan Johnson
Hi all,

The code below is a simple server based on the web server in the “More: Systems 
programming in Racket” tutorial.

This behavior is puzzling me:
I run the server (from the OS X Terminal) and connect a client.
After a wait, the client is disconnected by the timeout (shown in red).
I halt the server with ^C, by triggering the thunk shown in blue.
I start the server again — same way, from the Terminal — and get an “Address 
already in use” error.

This behavior happens consistently.

What’s perplexing is that if I close the connection from the client side 
instead of waiting in step (2) — in which case I understand the bold purple 
expression to be closing the connection — I consistently do not get an error.

I’m puzzled because my current understanding is that the two identical calls to 
custodian-shutdown-all should both be shutting down the same threads and I/O 
ports that were created under the custodian cust — and that even if this 
weren’t the case, the (custodian-shutdown-all main-cust) call should be 
cleaning up those same resources (in addition to shutting down the listener), 
because cust is subordinate to main-cust.

So my question is: What difference between the two cases accounts for the 
different behavior?

Thanks,
Jordan

; Example server ;

#!/usr/local/racket/bin/racket
#lang racket/base

(require racket/tcp)

(define (serve port)
  (define main-cust (make-custodian))
  (parameterize ([current-custodian main-cust])
(define listener (tcp-listen port))
(define (loop) (accept/handle listener) (loop))
(thread loop)
;; Hook to shutdown the server:
(lambda ()
  (printf "Exiting...~n")
  (custodian-shutdown-all main-cust)
  (exit 0

(define (accept/handle l)
  (define cust (make-custodian))
  (parameterize ([current-custodian cust])
(define-values (in out) (tcp-accept l))
(thread (lambda ()
  (let loop ([s (read-line in)])
(unless (eof-object? s)
  (fprintf out "Got it.~n")
  (flush-output out)
  (loop (read-line
  (custodian-shutdown-all cust)))
;; Timeout:
(thread (lambda () (sleep 5) (custodian-shutdown-all cust)

(define stop (serve 9001))

(with-handlers ([exn:break? (lambda (e) (stop))])
  (let loop () (sleep 10) (loop)))

-- 
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] Adding right-click functionality in a list-box%

2017-02-23 Thread Matthew Flatt
You could get approximately the right behavior using
`get-first-visible-item` and `number-of-visible-items` to compute the
item under the mouse. I think we'd have to add new things to
`list-box%` to get the right answer reliably, though.

At Thu, 23 Feb 2017 12:59:59 +, Erich Rast wrote:
> While I'm working on GUI issues another question came up. Is
> there a way to add right-click functionality to a list-box?
> 
> I'd like the selection to jump to the respective row on a right-click
> (btw, right-clicking does change the selection when the list-box gets
> focus but not afterwards), and *then* display a popup-menu based on that
> selection. But the official API does not seem to offer any direct way
> of getting the row index below the current mouse cursor position.
> 
> Possible or not?
> 
> Best,
> 
> Erich
> 
> -- 
> 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] TFPIE 2017 CFP

2017-02-23 Thread Marco Morazan

TFPIE 2017

Trends in Functional Programming in Education, 2017

https://www.cs.kent.ac.uk/people/staff/sjt/TFPIE2017/

The sixth workshop on Trends in Functional Programming in Education, 2017, 
which is 
to be held on the Canterbury campus of the University of Kent on Thursday, 22 
June, 
following the 2017 TFP meeting on 19–21 June. TFPIE workshops have previously 
been 
held in St Andrews, Scotland (2012), Provo Utah, USA (2013), Soesterberg, The 
Netherlands (2014), and Sophia-Antipolis, France (2015), College Park, USA 
(2016).



The goal of TFPIE is to gather researchers, teachers and professionals that 
use, or 
are interested in the use of, functional programming in education. TFPIE aims 
to be a 
venue where novel ideas, classroom-tested ideas and work-in-progress on the use 
of 
functional programming in education are discussed. The one-day workshop will 
foster a 
spirit of open discussion by having a review process for publication after the 
workshop. 
The program chair of TFPIE 2017 will screen submissions to ensure that all 
presentations 
are within scope and are of interest to participants. After the workshop, 
presenters 
will be invited to submit revised versions of their articles for publication in 
the 
journal Electronic Proceedings in Theoretical Computer Science (EPTCS). 

Call for papers

TFPIE 2017 welcomes submissions describing techniques used in the classroom, 
tools used 
in and/or developed for the classroom and any creative use of functional 
programming (FP) 
to aid education in or outside Computer Science. Topics of interest include, 
but are not 
limited to:

 
- FP and beginning CS students
 
- FP and Computational Thinking
 
- FP and Artificial Intelligence
 
- FP in Robotics
 
- FP and Music 
 
- Advanced FP for undergraduates
 
- FP in graduate education
 
- Engaging students in research using FP
 
- FP in Programming Languages
 
- FP in the high school curriculum
 
- FP as a stepping stone to other CS topics
 
- FP and Philosophy
 
- The pedagogy of teaching FP
 
- FP and e-learning: MOOCs, automated assessment etc.
 
- Best Lectures – more details below



In addition to papers, we are requesting best lecture presentations. What’s 
your best 
lecture topic in an FP related course? Do you have a fun way to present FP 
concepts to 
novices or perhaps an especially interesting presentation of a difficult topic? 
In 
either case, please consider sharing it. Best lecture topics will be selected 
for 
presentation based on a short abstract describing the lecture and its interest 
to TFPIE 
attendees.

Submission

Potential presenters are invited to submit an extended abstract 
(4-6 pages) or a draft paper (up to 16 pages) in EPTCS style. The authors of 
accepted 
presentations will have their preprints and their slides made available on the 
workshop's website.  



Papers and abstracts can be submitted via easychair at the following link: 
https://easychair.org/conferences/?conf=tfpie2017

After the workshop, 
presenters will be invited to submit (a revised version of) their article for 
review. 
The PC will select the best articles for publication in the journal Electronic 
Proceedings in Theoretical Computer Science (EPTCS). Articles rejected for 
presentation 
and extended abstracts will not be formally reviewed by the PC.

Programme committee

Dr Laura Castro, University of A Coruña

Prof Ralf Lämmel, University of Koblenz-Landau

Dr Elena Machkasova, University of Minnesota, Morris

Prof Michel Mauny, Inria, Paris

Dr Jeremy Singer, University of Glasgow

Prof Simon Thompson, University of Kent (chair)



Important dates

Submissions of draft papers: 10 May, 2017

Notification: 17 May, 2017

Registration: 11 June, 2017
Workshop: 22 June 2017
Submission for formal review: 18 August, 2017
Notification of acceptance: 6 October, 2017
Camera ready paper: 3 November, 2017

-- 
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] Adding right-click functionality in a list-box%

2017-02-23 Thread Erich Rast
While I'm working on GUI issues another question came up. Is
there a way to add right-click functionality to a list-box?

I'd like the selection to jump to the respective row on a right-click
(btw, right-clicking does change the selection when the list-box gets
focus but not afterwards), and *then* display a popup-menu based on that
selection. But the official API does not seem to offer any direct way
of getting the row index below the current mouse cursor position.

Possible or not?

Best,

Erich

-- 
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] Resize panels inside panels

2017-02-23 Thread Erich Rast
Your example works and made me realize that I've
accidentally removed a list-box *inside* the panel rather than the
panel itself in my application. No wonder it didn't work!

Thank you so much!

Best,

Erich

 On Thu, 23 Feb 2017 05:17:23 -0700
Matthew Flatt  wrote:

> If so, is there a change that makes it behave like your program?
> 
> 
> 
> #lang racket/gui
> 
> (define f (new frame% [label "Stretch"]))
> 
> (define B (new vertical-panel%
>[parent f]))
> 
> (define A (new editor-canvas%
>[parent B]))
> 
> (define C (new vertical-panel%
>[parent B]))
> 
> (void
>  (new button%
>   [parent C]
>   [label "Remove Me"]
>   [callback (lambda (c e)
>   (send B change-children (lambda (l) (list A]))
> 
> (send f show #t)
> 

-- 
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] Resize panels inside panels

2017-02-23 Thread Matthew Flatt
At Thu, 23 Feb 2017 10:09:59 +, Erich Rast wrote:
> I have an editor-canvas A subclasses inside a vertical-panel subclass B
> and below A there is another vertical-panel subclass C in B. C is shown
> or hidden by removing and adding it via change-children in B. 
> 
> However, even though A has stretchable-height set to #t, it does not
> resize to fill the whole area of B automatically when the C is removed.
> (C itself is not stretchable-height.)
> 
> I tried refresh but it didn't have any visible effect and on-size does
> nothing by default. Is there a way to programmatically trigger the same
> size calculation and display adjustment as when the panels/canvases are
> created? Or do I have to do this manually?

Does the editor canvas in the example below stretch when the button
removes its parent vertical panel? (If not, you're seeing a bug...)

If so, is there a change that makes it behave like your program?



#lang racket/gui

(define f (new frame% [label "Stretch"]))

(define B (new vertical-panel%
   [parent f]))

(define A (new editor-canvas%
   [parent B]))

(define C (new vertical-panel%
   [parent B]))

(void
 (new button%
  [parent C]
  [label "Remove Me"]
  [callback (lambda (c e)
  (send B change-children (lambda (l) (list A]))

(send f show #t)

-- 
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] generate sentences

2017-02-23 Thread Nguyen Linh Chi
Wow, it's really a good curriculum.
Just have to drop in to say something, im not doing this exercise for some
course, there is no teacher.

I was just massively sad and when i got up i need to do something that
makes some sense. After lots of thinking, i just assume that there is this
kind of exercise for beginner somewhere.

To all racket students: a well-structured school is a fortunate thing. You
get a well-packaged sense of purpose. People are broken, mostly because
after family and school, reality hits. With lessons of survival, betrayal,
responsibility, rejection.. we realise that life is apathetically vast and
the universe is just "radically indifferent" about everything. These
useless ponderings would eat away our meaningness. And doctors start to
have to prescribe antidepressants.

So do exercises when you still know that there are good teachers around
pushing you :)
Have a good day,

On Feb 21, 2017 16:23, "Nguyen Linh Chi"  wrote:

> Thank you Matthias,
>
> It seems that you all have developed a well structured path of programming
> experience for beginners. Great! Coding can be somewhat therapeutic, i
> start to think so.
>
> I'll check (and complain later :)
>
> Good day everyone !
>
> On Feb 21, 2017 15:32, "Matthias Felleisen"  wrote:
>
>>
>> Dear Linh Chi,
>>
>> the exercise is basically Lab 7 from the last instance of the
>> Northeastern beginners course:
>>
>>  http://www.ccs.neu.edu/course/cs2500f16/lab7.html
>>
>> If you work through this lab, you will get a performant solution based on
>> lists. Once you have that, it should be fairly obvious how to replace the
>> ‘table’ with a hashtable in this solution, though you have to bump the
>> language to ASL and include the 2htdp/abstraction teachpack to get the
>> style your teacher wants.
>>
>> For help with the solution, consider working through Part III of the text
>> book:
>>
>>   http://www.ccs.neu.edu/home/matthias/HtDP2e/
>>
>> For your own learning experience, it might be best if you followed the
>> design recipe and then ask questions about specific problems with function
>> design. People on the list will gladly help then.
>>
>> — Matthias
>>
>>
>>
>>
>>
>> > On Feb 21, 2017, at 3:55 AM, Linh Chi Nguyen 
>> wrote:
>> >
>> > hello,
>> > i'm doing this exercise and would appreciate any comments. i want to
>> create a machine to scan a text, then split the text into elements (storing
>> in a hash table). then we connect these hash keys in a probabilistic way,
>> so that if we start from a word, we can jump to other words in a
>> probabilistic way. hence, we can generate a sentence that is sufficiently
>> independent from our bias. the point is, if these probability makes sense
>> (for example, it is real statistics from real high quality text, i.e. from
>> famous writers), i hope that the machine can generate one or two sentences
>> that is entertaining.
>> >
>> > (require 2htdp/batch-io)
>> > (require racket/hash)
>> >
>> > (define input (read-file "sample.txt"))
>> > (define data (remove-duplicates (string-split input)))
>> >
>> > to make it very easy at first, i dont use the frequency of the elements
>> (words mostly) just yet. i just make a hash table that take each element as
>> a key, the associated value will be a dispatching rule. to begin with, the
>> dispatching rule is simple: the current key will be connected to two other
>> keys, with probability. for example: the element "run" is connected to
>> "instead." with probability .48 and "helmets" with probability .08.
>> >
>> > (hash "run" (hash 0.48 "instead." 0.08 "helmets"))
>> >
>> >
>> > (struct state (word dispatch) #:transparent)
>> >
>> > (define (random-member lst)
>> >  (list-ref lst (random (length lst
>> >
>> > (define (make-sample-machine lst)
>> >  (define l (length lst))
>> >  (define (make-transition)
>> >(hash (round-2 (random)) (random-member lst)
>> >  (round-2 (random)) (random-member lst)))
>> >  (foldl (lambda (word h) (hash-union h (hash word (make-transition
>> > (hash) lst))
>> >
>> > (define (round-n x n)
>> >  (/ (round (* x (expt 10 n))) (expt 10 n)))
>> > (define (round-2 x)
>> >  (round-n x 2))
>> >
>> > (define m (make-sample-machine data))
>> >
>> > data of the machine looks like this:
>> >
>> > '#hash(("spread" . #hash((0.9 . "right") (0.21 . "deep")))
>> >   ("instead" . #hash((0.64 . "then") (0.19 . "dark")))
>> >   ("through" . #hash((0.3 . "meadow") (0.95 . "white,")))
>> >   ("their" . #hash((0.56 . "instead") (0.98 . "valley,")))
>> >
>> > now i try to generate a sentence of 10 words, i guess it is some kind
>> of loops, but when it write the function, it is super slow.
>> >
>> > the idea is that, we randomise to choose the first word, then this
>> first word has an associated dispatching rule. we use the probability in
>> this rule to randomise for the next word..
>> >
>> > is it because i use too much randomisation that 

[racket-users] Resize panels inside panels

2017-02-23 Thread Erich Rast
I have an editor-canvas A subclasses inside a vertical-panel subclass B
and below A there is another vertical-panel subclass C in B. C is shown
or hidden by removing and adding it via change-children in B. 

However, even though A has stretchable-height set to #t, it does not
resize to fill the whole area of B automatically when the C is removed.
(C itself is not stretchable-height.)

I tried refresh but it didn't have any visible effect and on-size does
nothing by default. Is there a way to programmatically trigger the same
size calculation and display adjustment as when the panels/canvases are
created? Or do I have to do this manually?

Best,

Erich

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