Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread Philip McGrath
On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt 
wrote:

> I think the key question is what you want to happen if you would need
> to re-run the "pre" thunk, because you re-enter the code via a
> continuation.
>
> In many cases, you don't want to support that at all …
>

Then you can use `call-with-continuation-barrier`, right?

(let* ([conn (connect-to-server)])
  (dynamic-wind
   void
   (λ ()
 (call-with-continuation-barrier
  (λ ()
(send-message conn "hi"
   (λ ()
 (finalize-connection conn

-- 
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/0100017981191578-b5eaa465-de2a-4f1f-a4f1-d2976db88de0-00%40email.amazonses.com.


Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread Sam Tobin-Hochstadt
I think the key question is what you want to happen if you would need
to re-run the "pre" thunk, because you re-enter the code via a
continuation.

In many cases, you don't want to support that at all, and then it's
pretty easy (although you still need mutation):

(let* ([conn (connect-to-server)]
[started? #f])
 (dynamic-wind
 (lambda () (when started? (error 'fail)) (set! started? #t))
 (lambda () (send-message conn "hi"))
 (lambda () (finalize-connection conn

You could just not do the check in the pre thunk, in which case you'd
get worse error messages but probably nothing else wrong.

Sam


On Tue, May 18, 2021 at 3:42 PM David Storrs  wrote:
>
> Thank you.  Is there a way to do it without the mutation?  I was hoping to 
> use this for macro generation that simplifies combining with-handlers and 
> dynamic-wind with setup/teardown code.
>
> (try [pre
>   (define db (connect-to-db))
>   (define conn (connect-to-server))]
>  [(send-message conn (query-value db "invalid SQL"))]
>  [catch ([exn:fail:contract? (lambda (e) (displayln "contract"))]
>  [exn:fail:network?  (lambda (e) (displayln "network"))]
>  [(and/c exn:fail? (compose1 (curry regexp-match #rx"query") 
> exn-message))
>   (lambda (e) (displayln "database"))])]  ; this should run
>  [finally
>   (finalize-db-connection db)
>   (finalize-server-connection conn)])
>
> The goal is to guarantee that the connections are created/released every time 
> we go in and out of the code (usually via an exception) and also to put the 
> happy path first so that it's easier to see what the code should do before 
> getting into the weeds of error handling.
>
> (I probably should have put these details in the original message but I was 
> trying to keep it simple so as not to make people burn brain cycles.)
>
> On Tue, May 18, 2021 at 2:34 PM Sam Tobin-Hochstadt  
> wrote:
>>
>> It's not quite as convenient, but here's a version of your program
>> that should work:
>>
>> (let ([conn #f])
>>   (dynamic-wind
>> (lambda () (set! conn (connect-to-server))
>> (lambda () (send-message conn "foo"))
>> (lambda () (finalize-connection conn
>>
>> Sam
>>
>> On Tue, May 18, 2021 at 2:08 PM David Storrs  wrote:
>> >
>> > dynamic-wind is nice because it guarantees that the pre- and 
>> > postconditions for a chunk of code will be run regardless of continuation 
>> > jumps, exceptions, etc.  The only issue I have is that the three thunks do 
>> > not share scope, making it difficult to do setup/teardown workflows.  I 
>> > feel like I should be able to make this work with nested dynamic-wind or 
>> > with-handlers but haven't been able to get there without losing the 
>> > guarantee of running.  Is there a way?
>> >
>> > Example of what I'd like to do:
>> >
>> > (my-dynamic-wind
>> >   (thunk (define conn (connect-to-server)))
>> >   (thunk (send-message conn "foo"))
>> >   (thunk (finalize-connection conn)))
>> >
>> > --
>> > 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/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%40mail.gmail.com.
>
> --
> 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/CAE8gKofbcigfJDFgU8AXVqomQYqmgGT_OEXwAx7m8BQyyoCHqQ%40mail.gmail.com.

-- 
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/CAK%3DHD%2Bb0j3Y4DDHJSBcA8LjjXm3bvRvRNwLrfrNq%3DOs9Z4HpKg%40mail.gmail.com.


Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread David Storrs
Thank you.  Is there a way to do it without the mutation?  I was hoping to
use this for macro generation that simplifies combining with-handlers and
dynamic-wind with setup/teardown code.

(try [pre
  (define db (connect-to-db))
  (define conn (connect-to-server))]
 [(send-message conn (query-value db "invalid SQL"))]
 [catch ([exn:fail:contract? (lambda (e) (displayln "contract"))]
 [exn:fail:network?  (lambda (e) (displayln "network"))]
 [(and/c exn:fail? (compose1 (curry regexp-match #rx"query")
exn-message))
  (lambda (e) (displayln "database"))])]  ; this should run
 [finally
  (finalize-db-connection db)
  (finalize-server-connection conn)])

The goal is to guarantee that the connections are created/released every
time we go in and out of the code (usually via an exception) and also to
put the happy path first so that it's easier to see what the code should do
before getting into the weeds of error handling.

(I probably should have put these details in the original message but I was
trying to keep it simple so as not to make people burn brain cycles.)

On Tue, May 18, 2021 at 2:34 PM Sam Tobin-Hochstadt 
wrote:

> It's not quite as convenient, but here's a version of your program
> that should work:
>
> (let ([conn #f])
>   (dynamic-wind
> (lambda () (set! conn (connect-to-server))
> (lambda () (send-message conn "foo"))
> (lambda () (finalize-connection conn
>
> Sam
>
> On Tue, May 18, 2021 at 2:08 PM David Storrs 
> wrote:
> >
> > dynamic-wind is nice because it guarantees that the pre- and
> postconditions for a chunk of code will be run regardless of continuation
> jumps, exceptions, etc.  The only issue I have is that the three thunks do
> not share scope, making it difficult to do setup/teardown workflows.  I
> feel like I should be able to make this work with nested dynamic-wind or
> with-handlers but haven't been able to get there without losing the
> guarantee of running.  Is there a way?
> >
> > Example of what I'd like to do:
> >
> > (my-dynamic-wind
> >   (thunk (define conn (connect-to-server)))
> >   (thunk (send-message conn "foo"))
> >   (thunk (finalize-connection conn)))
> >
> > --
> > 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/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%40mail.gmail.com
> .
>

-- 
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/CAE8gKofbcigfJDFgU8AXVqomQYqmgGT_OEXwAx7m8BQyyoCHqQ%40mail.gmail.com.


Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread Sam Tobin-Hochstadt
It's not quite as convenient, but here's a version of your program
that should work:

(let ([conn #f])
  (dynamic-wind
(lambda () (set! conn (connect-to-server))
(lambda () (send-message conn "foo"))
(lambda () (finalize-connection conn

Sam

On Tue, May 18, 2021 at 2:08 PM David Storrs  wrote:
>
> dynamic-wind is nice because it guarantees that the pre- and postconditions 
> for a chunk of code will be run regardless of continuation jumps, exceptions, 
> etc.  The only issue I have is that the three thunks do not share scope, 
> making it difficult to do setup/teardown workflows.  I feel like I should be 
> able to make this work with nested dynamic-wind or with-handlers but haven't 
> been able to get there without losing the guarantee of running.  Is there a 
> way?
>
> Example of what I'd like to do:
>
> (my-dynamic-wind
>   (thunk (define conn (connect-to-server)))
>   (thunk (send-message conn "foo"))
>   (thunk (finalize-connection conn)))
>
> --
> 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/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%40mail.gmail.com.

-- 
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/CAK%3DHD%2BYaP0GV4JppQs%2BpmoOomFskEY%3D7cJ82Ujero7QrzPst1w%40mail.gmail.com.


Re: [racket-users] recent sqlite3 versions (was Re: preview of a cross-compilation tool)

2021-05-18 Thread kamist...@gmail.com

>
> > (So I guess the only question that comes up is: is it possible to update 
> > the sqlite version?) 
> > [vaguely remember seeing a mailing list thread about this but, currently 
> I 
> > only find other ones] 
>
> My libsqlite3[1] package provides recent versions (currently 3.35.5) of 
> SQLite for Linux, macOS and Windows. If you add it to your app's 
> `deps`, everything should just work. 
>
> [1]: https://pkgd.racket-lang.org/pkgn/package/libsqlite3 
>
 
This package works great!
Now I could run my app without copying files. 

Some caveats though (am I doing something wrong here?):
because db-lib already has an old version of the sqlite library `raco pkg 
install` complains that there is a conflict if I depend on db-lib and 
libsqlite3
I used `raco pkg install --force` to make it ignore the conflict

I wonder whether racket has a way to tell db-lib to not include its version 
of sqlite.
(would this require to split db-lib into smaller packages so that you can 
depend on hypothetical: db-interface-lib and not on db-sqlite-lib?)
If the conflict is present tools like `raco setup --check-pkg-deps 
--unused-pkg-deps ...` 
don't understand that the db-lib version of sqlite is not wanted and has a 
different version, so it thinks libsqlite3 is not needed:

raco setup: unused dependency detected
  for package: "myapp"
  on package:
   "libsqlite3"

-- 
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/162dc097-5bce-455a-9869-399ee5457359n%40googlegroups.com.


[racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread David Storrs
dynamic-wind is nice because it guarantees that the pre- and postconditions
for a chunk of code will be run regardless of continuation jumps,
exceptions, etc.  The only issue I have is that the three thunks do not
share scope, making it difficult to do setup/teardown workflows.  I feel
like I should be able to make this work with nested dynamic-wind or
with-handlers but haven't been able to get there without losing the
guarantee of running.  Is there a way?

Example of what I'd like to do:

(my-dynamic-wind
  (thunk (define conn (connect-to-server)))
  (thunk (send-message conn "foo"))
  (thunk (finalize-connection conn)))

-- 
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/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%40mail.gmail.com.


Re: [racket-users] I want a package at installation scope but also to keep my install clean

2021-05-18 Thread Sam Tobin-Hochstadt
You might also be interested in the new `raco-pkg-env` tool:
https://github.com/samdphillips/raco-pkg-env/

Sam

On Tue, May 18, 2021 at 12:20 PM Matthew Flatt  wrote:
>
> Yes, this approach can work. I don't think the existing Racket tools
> will help much with persisting a configuration across versions, though,
> so you'd probably have to script that.
>
> One potential drawback of your approach is that executables,
> documentation, etc., associated with the extra package will get
> rendered into the main installation area instead of the "/opt/Racket"
> are. That may be fine for your purposes, but a more strictly layered
> installation is meant to be possible. It turns out that some pieces
> have been missing for layering, and fixing that is an area of current
> work (https://github.com/racket/racket/commit/dfbb7040a).
>
> At Sun, 16 May 2021 23:43:52 -0500, Nathaniel W Griswold wrote:
> > Hello,
> >
> > I was setting up Racket on my linux box and i realized that there are a lot 
> > of
> > options for path configuration and i forgot a lot of what i discovered last
> > time i dug into this. I was trying to set up installation scope but maybe a
> > little cleanly and figured someone might have some input.
> >
> > I want a package at roughly installation scope, but i kinda wanted to know 
> > what
> > was added by me and what was part of the default installation. Is this
> > reasonable or should i just deal with it and dump stuff in 
> > $RACKET/share/pkgs?
> > If it is reasonable then what is the best way to set this up?
> >
> > Just FYI I did an in-place install of Racket in "/opt/Racket/Racket\ 8.1"
> > symlinked to /opt/Racket...
> >
> > I think maybe what i want is to set  to something like
> >
> > (in /opt/Racket/etc/config.rktd)
> >
> > #hash(... (pkgs-search-dirs . "/opt/Racket 8.1/share/pkgs-system" #f)
> > (links-search-files . ("/opt/Racket/share/pkgs-system/links.rktd" #f)) ...)
> >
> > Then i just did a `sudo /opt/Racket/bin/raco pkg install --scope-dir
> > /opt/Racket/share/pkgs-system rash`
> >
> > ... and the new package seems to be working fine for my users.
> >
> > Is that what i wanted or is there something better? Is there a way to 
> > configure
> > config.rktd additions that will persist across upgrades or will i have to
> > update my config.rktd for every racket release? Do other people do this 
> > kind of
> > thing or just dump stuff in the installation scope? Maybe there are more
> > options with a unix-style install, i haven't really tried one yet.
> >
> > Thanks!
> >
> > Nate
>
> --
> 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/20210518102000.1b1%40sirmail.smtps.cs.utah.edu.

-- 
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/CAK%3DHD%2Ba2G41L5C3v1wPjackfsn0VwtRZEWO7XiW9POS7mWa85Q%40mail.gmail.com.


[racket-users] recent sqlite3 versions (was Re: preview of a cross-compilation tool)

2021-05-18 Thread Bogdan Popa


kamist...@gmail.com writes:

> (So I guess the only question that comes up is: is it possible to update
> the sqlite version?)
> [vaguely remember seeing a mailing list thread about this but, currently I
> only find other ones]

My libsqlite3[1] package provides recent versions (currently 3.35.5) of
SQLite for Linux, macOS and Windows.  If you add it to your app's
`deps`, everything should just work.

[1]: https://pkgd.racket-lang.org/pkgn/package/libsqlite3

-- 
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/m28s4casnh.fsf%40192.168.0.142.


Re: [racket-users] I want a package at installation scope but also to keep my install clean

2021-05-18 Thread Matthew Flatt
Yes, this approach can work. I don't think the existing Racket tools
will help much with persisting a configuration across versions, though,
so you'd probably have to script that.

One potential drawback of your approach is that executables,
documentation, etc., associated with the extra package will get
rendered into the main installation area instead of the "/opt/Racket"
are. That may be fine for your purposes, but a more strictly layered
installation is meant to be possible. It turns out that some pieces
have been missing for layering, and fixing that is an area of current
work (https://github.com/racket/racket/commit/dfbb7040a).

At Sun, 16 May 2021 23:43:52 -0500, Nathaniel W Griswold wrote:
> Hello,
> 
> I was setting up Racket on my linux box and i realized that there are a lot 
> of 
> options for path configuration and i forgot a lot of what i discovered last 
> time i dug into this. I was trying to set up installation scope but maybe a 
> little cleanly and figured someone might have some input.
> 
> I want a package at roughly installation scope, but i kinda wanted to know 
> what 
> was added by me and what was part of the default installation. Is this 
> reasonable or should i just deal with it and dump stuff in 
> $RACKET/share/pkgs? 
> If it is reasonable then what is the best way to set this up?
> 
> Just FYI I did an in-place install of Racket in "/opt/Racket/Racket\ 8.1" 
> symlinked to /opt/Racket...
> 
> I think maybe what i want is to set  to something like
> 
> (in /opt/Racket/etc/config.rktd)
> 
> #hash(... (pkgs-search-dirs . "/opt/Racket 8.1/share/pkgs-system" #f) 
> (links-search-files . ("/opt/Racket/share/pkgs-system/links.rktd" #f)) ...)
> 
> Then i just did a `sudo /opt/Racket/bin/raco pkg install --scope-dir 
> /opt/Racket/share/pkgs-system rash`
> 
> ... and the new package seems to be working fine for my users.
> 
> Is that what i wanted or is there something better? Is there a way to 
> configure 
> config.rktd additions that will persist across upgrades or will i have to 
> update my config.rktd for every racket release? Do other people do this kind 
> of 
> thing or just dump stuff in the installation scope? Maybe there are more 
> options with a unix-style install, i haven't really tried one yet.
> 
> Thanks!
> 
> Nate

-- 
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/20210518102000.1b1%40sirmail.smtps.cs.utah.edu.


Re: [racket-users] Re: preview of a cross-compilation tool

2021-05-18 Thread kamist...@gmail.com
utah has 32-bit Windows snapshots now again.
I did a cross build with:
>> Cross configuration
 Target:i386-win32
 Host:  x86_64-linux
 Version:   current
 VM:bc
 Workspace: /tmp/todays-snapshot

with `pkg install` `exe ...` `dist ...` moved dist over to windows vm and 
it ran fine, 
until it hit a sqlite syntax that was too new for the version that is 
included in racket i386-win32 
(it reported sql-lite version 3.22.0 from 2018-01-22).

I then downloaded 3.35.5 (current release) for windows replaced the 
sqlite3.dll in /tmp/todays-snapshot/i386-win32-bc/lib/ with the newer one,
repeated the exe and dist, after that the application worked without 
problems.
(So I guess the only question that comes up is: is it possible to update 
the sqlite version?)
[vaguely remember seeing a mailing list thread about this but, currently I 
only find other ones]

The build was pretty easy and working great (I guess with the next release 
it becomes even simpler, not having to use snapshots, but that is just one 
more command line argument anyway),
so thank you again, definitively makes distributing racket applications 
easier!

Simon

Matthew Flatt schrieb am Samstag, 15. Mai 2021 um 14:51:22 UTC+2:

> At Sat, 15 May 2021 05:18:22 -0700 (PDT), "kamist...@gmail.com" wrote:
> > Yes it didn't find the libiconv-2.dll in the distribution "lib" 
> sub-folder, 
> > only after I added that to my path.
>
> Oh, right... I had forgotten already that the current release does
> *not* cross-build correctly, even for a BC build, when the target needs
> native libraries. That problem should be fixed in snapshots.
>
> So, you were on the right track trying to use a snapshot, and it just
> happens that neither site at the moment manages to cover the
> combination of Linux and 32-bit Windows. We'll get the snapshot sites
> in line soon, I hope.
>
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/50590986-3614-4d68-a96d-eb8047e2490en%40googlegroups.com.