Re: [racket-users] Structured Concurrency in Racket

2019-10-08 Thread Luke Whittlesey
I think the ceu language has a nice model of what I would consider
"structured". http://ceu-lang.org/ It has automatic cancellation and
finalization. Racket can easily support this model. Await statements
are captured through delimited continuations and processes are managed
in a tree. If a parent process exits the children are canceled and
finalized.

On Mon, Oct 7, 2019 at 4:08 PM George Neuner  wrote:
>
>
> On 10/7/2019 1:46 PM, jab wrote:
> > Coming across 
> > https://trio.discourse.group/t/structured-concurrency-and-delimited-continuations/
> >  just provoked me to search for discussion of structured concurrency in 
> > Racket. I didn’t immediately find much.* I hope that doesn’t mean that the 
> > interesting work that’s being discussed over in 
> > https://trio.discourse.group/c/structured-concurrency etc. has been largely 
> > unknown by the Racket community. Trio is having a profound impact on the 
> > future of concurrency, not just in Python but in many other languages. 
> > There’s even a post on Wikipedia now: 
> > https://en.wikipedia.org/wiki/Structured_concurrency
> >
> > (For anyone new to the term, 
> > https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/
> >  might be the best starting point. One persuasive example shows Nathaniel 
> > live coding a correct implementation of RFC 655 “Happy Eyeballs” in 40 
> > lines of Python: 
> > https://github.com/python-trio/trio-talks/tree/master/njsmith-async-concurrency-for-mere-mortals
> >   (For comparison, Twisted’s implementation took hundreds of lines and 
> > still had a logic bug after years of work.) There is also some related 
> > reading in https://github.com/python-trio/trio/wiki/Reading-list.)
> >
> > I hope this post provokes discussion of structured concurrency in Racket. 
> > It’d be fascinating to read more of your thoughts!
> >
> > Thanks,
> > Josh
> >
> > * For example, Googling “structured concurrency racket” turned up mostly 
> > just a brief mention of Racket’s custodians in the bottom-most comment on 
> > this post: http://250bpm.com/blog:71
>
> "Structured concurrency" as defined by those articles really applies
> only to programs that operate in distinct phases -  which is a pretty
> good description of many science programs  - but such programs represent
> a (important, but) small subset of all parallel programs.
>
> Racket's APIs are designed to support general parallelism, not just
> phased parallelism.
>
> I suppose an argument could be made for syntax explicitly aimed at
> phased parallelism ... but using macros, such syntax could be built on
> top of the existing parallel (future, thread, place) APIs - so there is
> nothing stopping you, or anyone else, from creating a "structured
> concurrency" package that everyone can use.
>
>
> One problem I foresee is defining a reasonable syntax and semantics.
> Most of the languages that promote "structured" concurrency have C-like
> syntax.  Moreover they vary considerably in semantics - in some of them
> the spawning thread stops immediately and can't continue until its
> children exit, but other allow the spawning thread to continue until it
> executes an explicit join / wait for its children.
>
> The Lisp/Scheme based idioms of S-expr Racket are very different from
> those of C-like languages, and whether or not some "Racket2"
> materializes having a more C-like syntax, many people like Racket just
> the way it is.  I can envision heated debates about what should be the
> proper "structuring" semantics and what syntax best represents them.
>
> YMMV,
> 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/8b83ff75-7b57-f3f1-0514-46170c9c3141%40comcast.net.

-- 
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/CA%2Bce6i39GYb8fVnb%2B91iGEdyTCnegaZLx%3DSHfuZ5zY1wqn%3D2-w%40mail.gmail.com.


[racket-users] DrRacket back button

2019-07-15 Thread Luke Whittlesey
In DrRacket I like being able to right click on an identifier and `Jump to
Binding Occurance". Is there a way to "jump back" to where you jumped from?

-- 
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/CA%2Bce6i007%3D-jkv%2BwUfkoJg-5YaJsXGgHn6jDUp%2BfPKHL3iK_Ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] catch and bind an unbound id in a macro

2019-04-19 Thread Luke Whittlesey
`identifier-binding` might be useful if a binding can be defined outside of
set/define

https://docs.racket-lang.org/reference/stxcmp.html?q=identifier-binding#%28def._%28%28quote._~23~25kernel%29._identifier-binding%29%29

On Fri, Apr 19, 2019 at 4:55 PM Matthias Felleisen 
wrote:

>
> I had the impression that you want to create the hashtable when it’s not
> there and use it when it is:
>
> #lang racket
>
> (define-syntax (set/define stx)
>   (syntax-case stx ()
> [(_ id key val)
>  (syntax-local-value #'id (lambda () #f))
>  (with-syntax ([h (car (syntax-local-value #'id (lambda () #f)))])
>#`(begin
>(hash-set! h 'key val)
>h))]
> [(_ id key val)
>  #'(begin
>  (define-syntax id (cons #'h 0))
>  (define h (make-hash))
>  (set/define id key val))]))
>
> (set/define h a 1)
> (set/define h a 2)
>
>
> To make sure you can see the hashtable, I also return it after every
> set/define.
>
>
>
> On Apr 19, 2019, at 4:17 PM, zeRusski  wrote:
>
> Here's what I've been trying and failing to do in Racket. The smallest
> example I
> could think of is a macro that sets a key in a hash-table, so basically
> this
> transformation:
>
>   (set/define ht 'key 42)
>   ;; =>
>   (hash-set! ht 'key 42)
>
>
> but if ht there is an unbound identifier it must bind it to a fresh hash
> table. So
> basically introduce a (define ht (make-hash)) before setting the key.
> Assume we
> run in a context where define is allowed.
>
> Please, don't ask why I want something like this, I just do. So far tricks
> I could
> use in other lisps failed in Racket. Here's one silly idea: catch unbound
> identifier exn. You can do it as per below or in the handler itself but it
> doesn't
> matter cause that define is local (I think) and doesn't happen in the
> macro use
> context.
>
>   (require (only-in syntax/macro-testing convert-compile-time-error))
>
>   (define (unbound-id-error? err)
> (and (exn:fail:syntax? err)
>  (regexp-match #rx"unbound identifier" (exn-message err
>
>   (define-syntax-rule (set/define id key val)
> (unless (let/ec k
>   (with-handlers ((unbound-id-error? (λ (_) (k #f
> (convert-compile-time-error
>  (hash-set! id key val
>   (displayln "escaped")
>   (define id (make-hash))
>   (hash-set! id key val)))
>
>   (set/define ht 'key 42)
>   ;; =>
>   ;; runs but appears that the (define ht ..) doesn't happen at top-level
>
> This is already all sorts of ugly and it doesn't even work.
>
> Another idea is to replace #%top for the extent of that transformer,
> perform
> local-expand (or some equivalent) so that #%top expansion does the job.
> I've no
> idea how to do that, but I'm sure Racket could be persuaded. Incidentally,
> I'm
> curious how to create such local transformers e.g. something like
> (let-transformer((#%top ...)) body).
>
> Even if I knew how to do the above (local-expand #'(set/define ht 'key
> 42) '())
> run at compile time doesn't seem to wrap unbound ht in #%top. I thought it
> should?
>
> So then, two questions:
>
> 1. What's the Racket way of getting what I want?
>
> 2. Is there a way to torture the above code into submission? Put
> differently is
>there a way to ensure (define id (make-hash)) runs in appropriate
> context?
>
> --
> 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.


[racket-users] Re: syntax rewriting bindings

2019-02-01 Thread Luke Whittlesey
I think I figured it out in case others are interested. See
https://gist.github.com/wluker/329f85ec193b386d89f618bd02796611


On Thu, Jan 31, 2019 at 4:50 PM Luke Whittlesey 
wrote:

> I see that there is the local-expand/capture-lifts and
> syntax-local-lift-expression for expressions, but is there a way to lift
> bindings as well? ... something akin to local-expand/capture-lift-defines
> maybe ...
>
> Basically I want to rewrite a syntax so any (MyDefine ...) is lifted into
> a definition context. Something like..
> (let ()
>   (list (begin (MyDefine a 0) 1) a))
> .. into ..
> (let ()
>   (define a 0)
>   (list 1 a))
>
> I have a fuzzy idea a solution might involve
> syntax-local-make-definition-context, but all my attempts have failed thus
> far. Could anybody give me some hints as to how something like this might
> be accomplished?
>

-- 
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] syntax rewriting bindings

2019-01-31 Thread Luke Whittlesey
I see that there is the local-expand/capture-lifts and
syntax-local-lift-expression for expressions, but is there a way to lift
bindings as well? ... something akin to local-expand/capture-lift-defines
maybe ...

Basically I want to rewrite a syntax so any (MyDefine ...) is lifted into a
definition context. Something like..
(let ()
  (list (begin (MyDefine a 0) 1) a))
.. into ..
(let ()
  (define a 0)
  (list 1 a))

I have a fuzzy idea a solution might involve
syntax-local-make-definition-context, but all my attempts have failed thus
far. Could anybody give me some hints as to how something like this might
be accomplished?

-- 
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] updated Racket-on-Chez status

2019-01-30 Thread Luke Whittlesey
This is really impressive work!

On Tue, Jan 29, 2019 at 9:49 AM Matthew Flatt  wrote:

> Here's a new status report on Racket CS:
>
>  http://blog.racket-lang.org/2019/01/racket-on-chez-status.html
>
> Short version: Racket CS is done in a useful sense, but we'll wait
> until it gets better before making it the default Racket
> implementation.
>
>
> Matthew
>
> --
> 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] Web server hits "Sorry, this page has expired. Please go back."

2018-10-17 Thread Luke Whittlesey
Interesting conversation.. I want to add that #lang web-server does have
file-boxes (
https://docs.racket-lang.org/web-server/stateless.html?q=web-server#%28part._lang%2Ffile-box%29)
for when one might want to preserve data like you would in the store. To
run across multiple machines I would imagine one could also write a
file-box-ish approach to a database, but I haven't gotten there yet.
I think one of the exciting aspects for me regarding stateless
continuations is the idea of running on multiple servers with the only
shared state being cookies and file-boxes. I imagine being able to easily
scale with something like Amazon Lambda. Although I haven't tried that yet
either, so maybe there are roadblocks there.

On Sun, Oct 14, 2018 at 7:55 PM George Neuner  wrote:

> Hi Philip,
>
> Sorry for the delay in responding ... busy day.
>
>
> On 10/14/2018 7:09 AM, Philip McGrath wrote:
>
> On Sun, Oct 14, 2018 at 5:30 AM George Neuner 
> wrote:
>
>> You are absolutely correct that in typical usage globals are not closed
>> over ... normally they are considered mutable shared "communication"
>> state.
>>
>> However, I was speaking more generally:  to be persisted long duration,
>> and be made portable across separate runtime instances, the continuation
>> must close over AND deep copy ANY VALUE the current call chain references.
>> You don't (necessarily) want to restart the continuation a week later, on a
>> different machine, with different values than when it started.
>>
>
> I am definitely not an expert on continuations or PL generally, so I could
> be very wrong. My understanding, though, has been that continuations not
> closing over non-local variables is a property of continuations in general:
> not only in a web context, and not only of the serializable continuations
> from `#lang web-server`. (I used those in my example just because it is
> easy to see what values they do in fact close over.)
>
>
> In the most basic form, the continuation is just "what to do next" - e.g.,
> a pointer to the next code to be executed.  That is [more or less] all that
> is required for a local (within a function) escape continuation because
> [barring stack corruption] all of the EC's stack context is guaranteed to
> exist if/when the continuation is invoked, and that state is needed anyway
> because the program will continue on regardless of how it leaves the scope
> of the EC.
>
> For a non-local EC, you need to return to the stack frame that was current
> when the continuation was created [the rest of the stack can be
> discarded].  In any case, an EC can very compact - just a couple of
> pointers.
>
> [Aside: a Lisp-style exception requires that the entire call stack be kept
> until you know where execution will continue.  You need to return to the
> EC's call frame (to find the exception handler), but Lisp allows exceptions
> to introspect/modify the environment and then to return control to the
> point of the exception (where the intrinsic EC was invoked).  Scheme
> doesn't have this capability.]
>
>
> General continuations - such as can implement coroutines - need to capture
> much more state.  The entire stack state of the current function call chain
> at the point where the continuation is created must be preserved in order
> to reenter the continuation.
> [this is where stateful and stateless part company - more below]
>
>
> Winding continuations are an extension of general continuations to the
> requirements of dynamic-wind.  In addition to whatever is required for a
> general continuation, a winding continuation has preamble code that must be
> executed whenever a continuation enters the winding scope, and postamble
> code to be executed whenever (and how ever) execution leaves the winding
> scope.
>
>
> The long winded point here is that continuations have no canon
> implementation - if you want more functionality from them, you need to
> capture/preserve more state.
>
>
>
> The web-server is multi-threaded, and the stack state of each thread is
> unique - so for each thread in which a continuation is created in the
> stateful server, the thread's call stack must be preserved.
>
> The stateless server is a different case.  CPS code doesn't use a call
> stack ... or rather its "stack" only ever contains one useful frame - the
> current one.  So there's only one call frame per thread that needs to be
> preserved rather than a (maybe large) stack of them.  This is why stateless
> server continuations - in general - use much less memory than stateful
> server continuations.
>
> [The above is a bit simplistic because Scheme supports nested functions
> with non-local variable access.  [Scheme also supports 1st class closures
> based on nested functions, but that is not what this is about.]   To
> support non-local access without a stack, CPS code needs to construct
> shared environments on the fly as the program executes to communicate
> values from producers to consumers, and these environments (where
> 

Re: [racket-users] question on quasisyntax/loc

2018-05-08 Thread Luke Whittlesey
Very nice explanation. Thank you!

On Tue, May 8, 2018 at 11:08 AM, Alexis King <lexi.lam...@gmail.com> wrote:

> This behavior is intentional, though it could perhaps be more clearly
> documented. The behavior is hinted at in the documentation for
> syntax/loc:
>
> > Like syntax, except that the immediate resulting syntax object takes
> > its source-location information from the result of stx-expr (which
> > must produce a syntax object), unless the template is just a pattern
> > variable, or both the source and position of stx-expr are #f.
>
> Note the “unless the template is just a pattern variable” condition. The
> idea is that syntax/loc and quasisyntax/loc only ever adjust the source
> location information on fresh syntax introduced in the template, never
> on syntax from external pattern variables or syntax objects inserted
> with unsyntax. For this reason, (quasisyntax/loc stx #,x) is always
> equivalent to x.
>
> If you do actually want to modify the source location information on a
> syntax object, you can do it with syntax-e and datum->syntax:
>
>   (define (replace-outer-srcloc src-stx stx)
> (datum->syntax stx (syntax-e stx) src-stx stx))
>
> Then you could write (replace-outer-srcloc here y) to get the behavior
> you want.
>
> Alexis
>
> > On May 8, 2018, at 09:56, Luke Whittlesey <luke.whittle...@gmail.com>
> > wrote:
> >
> > I'm having trouble understanding quasisyntax/loc in some cases.
> >
> > If I have the following example code:
> >
> > 
> > #lang racket
> >
> > (define here #'here)
> > (define stx0 (syntax/loc here #'Y))
> > (define y #'Y)
> > (define stx1 (quasisyntax/loc here #,y))
> >
> > (displayln (format "here : line ~a" (syntax-line here)))
> > (displayln (format "stx0 : line ~a" (syntax-line stx0)))
> > (displayln (format "stx1 : line ~a" (syntax-line stx1)))
> > 
> >
> > It prints :
> > 
> > here : line 3
> > stx0 : line 3
> > stx1 : line 5
> > 
> >
> > I expect stx1 to also be at line 3 where `here` is defined. Is this
> > example an incorrect use of quasisyntax/loc? What am I missing?
> >
> > 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.


[racket-users] question on quasisyntax/loc

2018-05-08 Thread Luke Whittlesey
I'm having trouble understanding quasisyntax/loc in some cases.

If I have the following example code:


#lang racket

(define here #'here)
(define stx0 (syntax/loc here #'Y))
(define y #'Y)
(define stx1 (quasisyntax/loc here #,y))

(displayln (format "here : line ~a" (syntax-line here)))
(displayln (format "stx0 : line ~a" (syntax-line stx0)))
(displayln (format "stx1 : line ~a" (syntax-line stx1)))


It prints :

here : line 3
stx0 : line 3
stx1 : line 5


I expect stx1 to also be at line 3 where `here` is defined. Is this example
an incorrect use of quasisyntax/loc? What am I missing?

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.


Re: [racket-users] Simple Interdependent Units?

2015-05-25 Thread Luke Whittlesey
Would lazy-require work here?

http://docs.racket-lang.org/reference/lazy-require.html

On Mon, May 25, 2015 at 3:56 PM, Matthias Felleisen matth...@ccs.neu.edu
wrote:


 On May 25, 2015, at 3:19 PM, Michael Tiedtke michael.tied...@o2online.de
 wrote:

  See, you're doing away with the class definitions and substitute them
 with unit definitions.
  This is what I meant when I wrote you recreated encapsulation and
 inheritance. (Because
  linking somehow resembles multiple inheritance.)


 #lang racket/gui

 (define-signature model^ (setter get))
 (define-signature view^ (error))

 ;; decoupled model-view
 (define model@
   (unit (import view^)
 (export model^)

 (define model%
   (class object%
 (super-new)
 (define the-number 12)
 (define/public (setter v)
   (when (or ( v 0) ( 0 100))
 (error can't do that))
   (displayln `(setting to ,v))
   (set! the-number v))
 (define/public (get)
   the-number)))

 (define model (new model%))

 (define (setter v) (send model setter v))
 (define (get) (send model get

 (define view@
   (unit (import model^)
 (export view^)

 (define view%
   (class object%
 (super-new)
 (define frame (new frame% [width 100][height 200][label VW]))
 (define vpane (new vertical-pane% [parent frame]))
 (define value0 (get))
 (define slide
   (new slider%
[parent vpane] [label %]
[min-value 0] [init-value value0] [max-value 100]
[style '(vertical)]
[callback (lambda (self _e) (setter (send self
 get-value)))]))
 (define/public (error msg)
   (displayln msg))
 (send frame show #t)))

 (define (error msg) (send view error msg))
 (define view (new view%

 (define completly-linked-program@
   (compound-unit
 (import)
 (export)
 (link
  [((model : model^)) model@ view]
  (((view : view^)) view@ model

 (define (run)
   (invoke-unit completly-linked-program@))



  Include works best after a cutpaste operation on an over-grown file.
  My favourite module system for now!


 Please see previous email.

  Yes, I was thinking about things like these in my other message. But
  this alreaddy depends on the evaluation order which can be reversed.
  Right in this example one would like to mix in lazy evaluation.
 
  (define the-view
{with-lazy-evaluation (new view% #model: (new model% #view: the-view))
 })

 There is a difference between lazy evaluation and cyclic references.
 And it's huge.


  One might even think about an interpreter that automatically tries ...

 See shared. That's NOT laziness. Repeat, it's NOT laziness.


 Here is what it takes (in principle) to extend it to objects:

 (define-syntax (object-shared stx)
   (syntax-case stx (new)
 [(_ [(x x-field (new x% [x-field_ x0]))
  (y y-field (new y% [y-field_ y0]))]
 body)
  #'(letrec ([x (new x% [x-field '*undefined-x*])]
  [y (new y% [y-field y0])])
  (set-field! x-field x x0)
  #;
  (set-field! y-field y y0)
  body)]))

 (define the-view
   (object-shared [(the-model view (new model% [view the-view]))
   (the-view model (new view% [model the-model]))]
  the-view))


 Git pull request for complete extension welcome.









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