Re: [racket-users] servlet development in REPL

2018-10-04 Thread Greg Hendershott
I just wanted to chime in and say I share Philip's preference.

I think programming is hard enough without multiple sources of truth.


p.s. Replacing expensive startup items with a no-op is a good idea. Or
sometimes, keep the "real-op" but postpone using one of:

- `delay/sync` and `force` from `racket/promise`:


https://docs.racket-lang.org/reference/Delayed_Evaluation.html#(form._((lib._racket%2Fpromise..rkt)._delay%2Fsync))

- `lazy-require`:


https://docs.racket-lang.org/reference/lazy-require.html#(form._((lib._racket%2Flazy-require..rkt)._lazy-require))

The former for individual definitions, the latter for entire modules.

-- 
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] servlet development in REPL

2018-10-03 Thread Philip McGrath
While Jay and Sam have tried to answer the question you actually asked, my
advice would be to approach this differently. When I am developing web
server things interactively, I put them in the DrRacket definitions window
and run the program with the "Run" button. You can then poke at the running
server, see logging output, etc. at the DrRacket REPL. If I change
something, I change it in the DrRacket definitions window and press "Run"
again to re-start the server. (None of this is DrRacket-specific, but
that's how I do it, and I think it works especially well.)

I think this approach takes advantage of all of the generally nice things
about the Racket-style REPL. In particular, I could imagine getting
confused if I had `set!` part of the program to do something other than
what the definitions window said, and I could especially easily imagine
clicking run again without saving something I'd worked up interactively and
loosing that work.

The one place where this can be a downside is when the program has a very
long startup time. When I've had such cases, I've found it useful, even
beyond these circumstances, to give myself a hook to replace the expensive
parts with a noop when I don't actually care about them.

-Philip


On Wed, Oct 3, 2018 at 5:12 PM Cam  wrote:

>
> It looks like Sam's suggestion of racket-reloadable is exactly what I
> need, but I will play with this as well. Thanks!
>
> Jay McCarthy  writes:
>
> > You'd have to build it yourself, by doing a `set!` in the REPL to
> > inject the new function in.
> > On Wed, Oct 3, 2018 at 8:10 AM Cam  wrote:
> >>
> >>
> >> I am playing around with the built-in webserver functionality with
> >> `servlet/serve' and am wondering if there is a way to automatically
> >> "reload" the servlet, for lack of better terminology, when I am playing
> >> in the REPL. In other words, if I do something like this in the REPL:
> >>
> >> (define (about-page req)
> >>   (response/xexpr
> >>'(html (body (h1 "about")
> >>
> >> (define-values (dispatch handler->url)
> >>   (dispatch-rules
> >>[("about") about-page]))
> >>
> >> (serve/servlet
> >>  #:port 8088
> >>  #:listen-ip #f
> >>  #:servlet-path "/"
> >>  #:servlet-regexp #px".*"
> >>  dispatch)
> >>
> >> ...and then redefine `about-page' like this:
> >>
> >> (define (about-page req)
> >>   (response/xexpr
> >>'(html (body (h1 "something else")
> >>
> >> ...I would like to refresh my browser on the `/about' page and see
> >> "something else" instead of "about".
> >>
> >> Is there some way to achieve this?
> >>
> >> --
> >> 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.
> >
> >
> >
> > --
> > -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> > -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> > -=[ Moses 1:33: And worlds without number have I created; ]=-
>
> --
> 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] servlet development in REPL

2018-10-03 Thread Cam


It looks like Sam's suggestion of racket-reloadable is exactly what I
need, but I will play with this as well. Thanks!

Jay McCarthy  writes:

> You'd have to build it yourself, by doing a `set!` in the REPL to
> inject the new function in.
> On Wed, Oct 3, 2018 at 8:10 AM Cam  wrote:
>>
>>
>> I am playing around with the built-in webserver functionality with
>> `servlet/serve' and am wondering if there is a way to automatically
>> "reload" the servlet, for lack of better terminology, when I am playing
>> in the REPL. In other words, if I do something like this in the REPL:
>>
>> (define (about-page req)
>>   (response/xexpr
>>'(html (body (h1 "about")
>>
>> (define-values (dispatch handler->url)
>>   (dispatch-rules
>>[("about") about-page]))
>>
>> (serve/servlet
>>  #:port 8088
>>  #:listen-ip #f
>>  #:servlet-path "/"
>>  #:servlet-regexp #px".*"
>>  dispatch)
>>
>> ...and then redefine `about-page' like this:
>>
>> (define (about-page req)
>>   (response/xexpr
>>'(html (body (h1 "something else")
>>
>> ...I would like to refresh my browser on the `/about' page and see
>> "something else" instead of "about".
>>
>> Is there some way to achieve this?
>>
>> --
>> 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.
>
>
>
> -- 
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
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] servlet development in REPL

2018-10-03 Thread Sam Tobin-Hochstadt
You will probably be interested in the `reloadable` package:
https://github.com/tonyg/racket-reloadable/

Sam
On Wed, Oct 3, 2018 at 8:10 AM Cam  wrote:
>
>
> I am playing around with the built-in webserver functionality with
> `servlet/serve' and am wondering if there is a way to automatically
> "reload" the servlet, for lack of better terminology, when I am playing
> in the REPL. In other words, if I do something like this in the REPL:
>
> (define (about-page req)
>   (response/xexpr
>'(html (body (h1 "about")
>
> (define-values (dispatch handler->url)
>   (dispatch-rules
>[("about") about-page]))
>
> (serve/servlet
>  #:port 8088
>  #:listen-ip #f
>  #:servlet-path "/"
>  #:servlet-regexp #px".*"
>  dispatch)
>
> ...and then redefine `about-page' like this:
>
> (define (about-page req)
>   (response/xexpr
>'(html (body (h1 "something else")
>
> ...I would like to refresh my browser on the `/about' page and see
> "something else" instead of "about".
>
> Is there some way to achieve this?
>
> --
> 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] servlet development in REPL

2018-10-03 Thread Jay McCarthy
You'd have to build it yourself, by doing a `set!` in the REPL to
inject the new function in.
On Wed, Oct 3, 2018 at 8:10 AM Cam  wrote:
>
>
> I am playing around with the built-in webserver functionality with
> `servlet/serve' and am wondering if there is a way to automatically
> "reload" the servlet, for lack of better terminology, when I am playing
> in the REPL. In other words, if I do something like this in the REPL:
>
> (define (about-page req)
>   (response/xexpr
>'(html (body (h1 "about")
>
> (define-values (dispatch handler->url)
>   (dispatch-rules
>[("about") about-page]))
>
> (serve/servlet
>  #:port 8088
>  #:listen-ip #f
>  #:servlet-path "/"
>  #:servlet-regexp #px".*"
>  dispatch)
>
> ...and then redefine `about-page' like this:
>
> (define (about-page req)
>   (response/xexpr
>'(html (body (h1 "something else")
>
> ...I would like to refresh my browser on the `/about' page and see
> "something else" instead of "about".
>
> Is there some way to achieve this?
>
> --
> 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.



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
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] servlet development in REPL

2018-10-03 Thread Cam


I am playing around with the built-in webserver functionality with
`servlet/serve' and am wondering if there is a way to automatically
"reload" the servlet, for lack of better terminology, when I am playing
in the REPL. In other words, if I do something like this in the REPL:

(define (about-page req)
  (response/xexpr
   '(html (body (h1 "about")

(define-values (dispatch handler->url)
  (dispatch-rules
   [("about") about-page]))

(serve/servlet
 #:port 8088
 #:listen-ip #f
 #:servlet-path "/"
 #:servlet-regexp #px".*"
 dispatch)

...and then redefine `about-page' like this:

(define (about-page req)
  (response/xexpr
   '(html (body (h1 "something else")

...I would like to refresh my browser on the `/about' page and see
"something else" instead of "about".

Is there some way to achieve this?

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