Re: [racket-users] Running user-supplied code in a place

2021-04-07 Thread David Storrs
Thanks, George.  This helped a lot.

On Wed, Apr 7, 2021 at 9:03 PM George Neuner  wrote:
>
>
> On 4/7/2021 5:34 PM, David Storrs wrote:
> > I'm trying to expand a task manager to optionally use places and I'm
> > having some trouble understanding the issue.
> >
> > ; test.rkt
> > #lang racket
> > (provide start)
> > (define (start thnk)
> >(sync (place ch  (place-channel-put ch  (thnk)
> >
> > ; x.rkt
> > #lang racket
> > (require "test.rkt")
> > (start (thunk 'ok))
> >
> > Result:  ; identifier used out of context: #<[...]/test.rkt:5:19 thnk>
> >
> > I know that the place is creating a submodule which closes over the
> > place id ('ch') and the top level declarations, meaning only 'start'.
> > The argument to start is not at top level so it's invisible in the
> > submodule, meaning that the place code can't use it.
> >
> > I feel like parallelizing a function at runtime should be a primary
> > use case for places but I'm not sure how to progress.
> > Things I tried:
> >
> > *) Passing the thunk in via place-channel-put, but functions are
> > place-message-allowed? #f.
> > *) Creating a top-level parameter into which I put the thnk at
> > runtime.  Same problem.
> >
> > Am I fundamentally misunderstanding something?
>
> It helps if you think about places as being separate processes (even
> when they aren't).
>
> Dynamic places (threads in same process) can see code that is in scope
> at the point where the place is created.  This includes top level
> functions in the module that created the place.  In your example 'thunk'
> was created in a different module so the place didn't know about it.
>
> There are ways to communicate new code to a place - very useful for
> distributed (separate process) places, but also works with dynamic
> places if you can't arrange that everything they need is visible to them
> at creation.
>
> 1.  send the name of a (local to the place) file to be dynamically required
> 2.  send the file itself and have the place save it locally before
> requiring it
> 3.  send serialized functions and have the place instantiate them
>
> Obviously, the place must have startup code available to it which
> understands how to load / execute new code.
>
>
> Take a look at  'serialize', 'serial-lambda', and 's-exp->fasl'.   Also
> see Tony Garnok's racket-reloadable project:
> https://github.com/tonyg/racket-reloadable
>
>
> Hope this helps,
> George
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKod%3D78B5Ls6ybZESsbYs5RVw4yf7xRniaoiyNpG_nG6jmg%40mail.gmail.com.


Re: [racket-users] Running user-supplied code in a place

2021-04-07 Thread George Neuner



On 4/7/2021 5:34 PM, David Storrs wrote:

I'm trying to expand a task manager to optionally use places and I'm
having some trouble understanding the issue.

; test.rkt
#lang racket
(provide start)
(define (start thnk)
   (sync (place ch  (place-channel-put ch  (thnk)

; x.rkt
#lang racket
(require "test.rkt")
(start (thunk 'ok))

Result:  ; identifier used out of context: #<[...]/test.rkt:5:19 thnk>

I know that the place is creating a submodule which closes over the
place id ('ch') and the top level declarations, meaning only 'start'.
The argument to start is not at top level so it's invisible in the
submodule, meaning that the place code can't use it.

I feel like parallelizing a function at runtime should be a primary
use case for places but I'm not sure how to progress.
Things I tried:

*) Passing the thunk in via place-channel-put, but functions are
place-message-allowed? #f.
*) Creating a top-level parameter into which I put the thnk at
runtime.  Same problem.

Am I fundamentally misunderstanding something?


It helps if you think about places as being separate processes (even 
when they aren't).


Dynamic places (threads in same process) can see code that is in scope 
at the point where the place is created.  This includes top level 
functions in the module that created the place.  In your example 'thunk' 
was created in a different module so the place didn't know about it.


There are ways to communicate new code to a place - very useful for 
distributed (separate process) places, but also works with dynamic 
places if you can't arrange that everything they need is visible to them 
at creation.


1.  send the name of a (local to the place) file to be dynamically required
2.  send the file itself and have the place save it locally before 
requiring it

3.  send serialized functions and have the place instantiate them

Obviously, the place must have startup code available to it which 
understands how to load / execute new code.



Take a look at  'serialize', 'serial-lambda', and 's-exp->fasl'.   Also 
see Tony Garnok's racket-reloadable project:  
https://github.com/tonyg/racket-reloadable



Hope this helps,
George

--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5559332c-4849-795c-94b5-884dfb29d75f%40comcast.net.


[racket-users] Running user-supplied code in a place

2021-04-07 Thread David Storrs
I'm trying to expand a task manager to optionally use places and I'm
having some trouble understanding the issue.

; test.rkt
#lang racket
(provide start)
(define (start thnk)
  (sync (place ch  (place-channel-put ch  (thnk)

; x.rkt
#lang racket
(require "test.rkt")
(start (thunk 'ok))

Result:  ; identifier used out of context: #<[...]/test.rkt:5:19 thnk>

I know that the place is creating a submodule which closes over the
place id ('ch') and the top level declarations, meaning only 'start'.
The argument to start is not at top level so it's invisible in the
submodule, meaning that the place code can't use it.

I feel like parallelizing a function at runtime should be a primary
use case for places but I'm not sure how to progress.  Things I tried:

*) Passing the thunk in via place-channel-put, but functions are
place-message-allowed? #f.
*) Creating a top-level parameter into which I put the thnk at
runtime.  Same problem.

Am I fundamentally misunderstanding something?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKoc2v81%2BAHTn0YniCS8SEqYT0Ngz5qztTNh%3D0LUZyWeoGQ%40mail.gmail.com.