[racket-users] folding xml - reprise

2020-03-24 Thread Catonano
Hi,

I'm trying to do something like a fold, but over a tree instead of a list.
Is there anything like that?

If it's unclear what I mean, there's a mechanism like that in guile:
https://www.gnu.org/software/guile/manual/html_node/SXML-Tree-Fold.html

They use it e.g. for XML transformations, but it's really a generic
operation and quite useful.

Here's a paper on it by Andy Wingo if anyone wants to know the theory
behind:

https://pdfs.semanticscholar.org/d41a/175cf5bf19c795b940edf566988df05ee4a1.pdf

is there anything along those lines in Racket ?

Thanks in advance

-- 
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/CAJ98PDyVHDnpusBQ9g%3D26J4W7GF5%2Be9krPvUCDuJHY94-17G6w%40mail.gmail.com.


Re: [racket-users] Gradual Typed Racket?

2020-03-24 Thread unlimitedscolobb

On Monday, March 23, 2020 at 9:59:22 PM UTC+1, Hendrik Boom wrote:
>
> On Mon, Mar 23, 2020 at 12:16:45PM -0400, Ben Greenman wrote: 
>
> > 
> > Not sure about best practices, but I definitely prefer keeping typed 
> > and untyped code in separate modules. 
>
> It can be veru useful to be able to mix them while in transition from one 
> to the other. 
>
> -- hendrik 
>

Absolutely!

In my case I am writing code from scratch for my research (theoretical 
computer science), but I end up wanting to write some stuff which Typed 
Racket cannot type (converting to a polymorphic type variable, for 
example), or even stuff which is difficult to type without writing long 
dependent types.  For these cases, I'd prefer to just drop the types 
"temporarily", which the different modules approach should probably allow 
me to do.

-
Sergiu

-- 
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/9bce12f3-fbba-4dec-b849-235ef573602c%40googlegroups.com.


[racket-users] Best way to say "terminate unless received by X time"

2020-03-24 Thread David Storrs
I've got this code:

(thread
  (thunk
(let loop ()
  (define-values (len shost sport) (udp-receive! socket buffer))
  ...do stuff with the received message...
 (loop

I'd like to be able to say "If you haven't received a message in X time,
kill the thread".  I'm not sure how to enact that; sync/timeout won't do it
since the thread won't return.  I've thought of weird signaling systems
using channels or set! on some external value or etc, but they are all
terrible.

What's the right way to do 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKocoTTN0VfOToioMq3xK_0ysqAQVHmZ%2BmiFS9iutzY0sxQ%40mail.gmail.com.


Re: [racket-users] Best way to say "terminate unless received by X time"

2020-03-24 Thread Jay McCarthy
You can start a second thread that monitors the condition as well as a
timer; if the timer goes off first, then you kill the first thread; if
the condition happens first, then it continues. If you don't want the
second thread to have to monitor the condition, then the first thread
should tell the second thread that everything is okay, such as by
setting a semaphore.

Like this:

```
#lang racket/base

(define (kill-unless-sema-after-secs t sema secs)
  (thread
   (λ ()
 (sync sema
   (handle-evt (alarm-evt (+ (current-inexact-milliseconds)
 (* 1000 secs)))
   (λ _
 (kill-thread t)))

(module+ main
  (define t
(thread
 (thunk
   (let loop ()
 (define sema (make-semaphore))
 (kill-unless-sema-after-secs t sema secs)
 (define-values (len shost sport)
   (udp-receive! socket buffer))
 (semaphore-post sema)
 ;; xxx do stuff
 (loop))
```

--
Jay McCarthy
Associate Professor @ CS @ UMass Lowell
http://jeapostrophe.github.io
Vincit qui se vincit.

On Tue, Mar 24, 2020 at 4:03 PM David Storrs  wrote:
>
> I've got this code:
>
> (thread
>   (thunk
> (let loop ()
>   (define-values (len shost sport) (udp-receive! socket buffer))
>   ...do stuff with the received message...
>  (loop
>
> I'd like to be able to say "If you haven't received a message in X time, kill 
> the thread".  I'm not sure how to enact that; sync/timeout won't do it since 
> the thread won't return.  I've thought of weird signaling systems using 
> channels or set! on some external value or etc, but they are all terrible.
>
> What's the right way to do 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CAE8gKocoTTN0VfOToioMq3xK_0ysqAQVHmZ%2BmiFS9iutzY0sxQ%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/CAJYbDam%3D7teWJun3zg3c4MBtV4Ew%2Bgv6-Zj9xE7LTBew92u9RQ%40mail.gmail.com.


Re: [racket-users] Best way to say "terminate unless received by X time"

2020-03-24 Thread Jon Zeppieri
On Tue, Mar 24, 2020 at 4:03 PM David Storrs  wrote:
>
> I've got this code:
>
> (thread
>   (thunk
> (let loop ()
>   (define-values (len shost sport) (udp-receive! socket buffer))
>   ...do stuff with the received message...
>  (loop
>
> I'd like to be able to say "If you haven't received a message in X time, kill 
> the thread".  I'm not sure how to enact that; sync/timeout won't do it since 
> the thread won't return.  I've thought of weird signaling systems using 
> channels or set! on some external value or etc, but they are all terrible.
>
> What's the right way to do this?
>

Not quite sure what you mean when you say "sync/timeout won't do it
since the thread won't return." You'll know when you timed-out, so you
can return in that case. Wouldn't something like this work?

```
(thread
 (λ ()
   (let loop ()
 (match (sync/timeout timeout (udp-receive!-evt socket buffer))
   [(list len shost sport)
;; do stuff
(loop)]
   [#f
;; timed out; exit the loop and the thread
(void)]
```

Apologies if I've misunderstood you.

- Jon

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


Re: [racket-users] Best way to say "terminate unless received by X time"

2020-03-24 Thread David Storrs
Aha! I didn't know there was a udp-receive-evt. That's exactly what I
needed, thank you.

On Tue, Mar 24, 2020, 4:15 PM Jon Zeppieri  wrote:

> On Tue, Mar 24, 2020 at 4:03 PM David Storrs 
> wrote:
> >
> > I've got this code:
> >
> > (thread
> >   (thunk
> > (let loop ()
> >   (define-values (len shost sport) (udp-receive! socket buffer))
> >   ...do stuff with the received message...
> >  (loop
> >
> > I'd like to be able to say "If you haven't received a message in X time,
> kill the thread".  I'm not sure how to enact that; sync/timeout won't do it
> since the thread won't return.  I've thought of weird signaling systems
> using channels or set! on some external value or etc, but they are all
> terrible.
> >
> > What's the right way to do this?
> >
>
> Not quite sure what you mean when you say "sync/timeout won't do it
> since the thread won't return." You'll know when you timed-out, so you
> can return in that case. Wouldn't something like this work?
>
> ```
> (thread
>  (λ ()
>(let loop ()
>  (match (sync/timeout timeout (udp-receive!-evt socket buffer))
>[(list len shost sport)
> ;; do stuff
> (loop)]
>[#f
> ;; timed out; exit the loop and the thread
> (void)]
> ```
>
> Apologies if I've misunderstood you.
>
> - Jon
>

-- 
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/CAE8gKoct6X870TF1Djh9xv6JHeV40Q%3Dzczi313Kt8RUFwGavYQ%40mail.gmail.com.


[racket-users] TR: Occurrence Typing with custom predicate

2020-03-24 Thread mmcdan
Hello,

I'm trying to use occurrence typing for (Vectorof Symbol) or (Boxof Symbol).

Creating a custom predicate for (Listof Symbol) seems to work:
---
#lang typed/racket

(: los? (-> Any Boolean : (Listof Symbol)))
(define los?
  (lambda (seq) (and (list? seq) (andmap symbol? seq
---

However I haven't been able to create one for vectors or boxes. None of the 
things I've tried will typecheck. Any pointers?

-- 
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/4dc451fd-da2c-4a3c-8bb6-222e6b3b972b%40googlegroups.com.


Re: [racket-users] TR: Occurrence Typing with custom predicate

2020-03-24 Thread Ben Greenman
On 3/24/20, mmcdan  wrote:
> Hello,
>
> I'm trying to use occurrence typing for (Vectorof Symbol) or (Boxof
> Symbol).
>
> Creating a custom predicate for (Listof Symbol) seems to work:
> ---
> #lang typed/racket
>
> (: los? (-> Any Boolean : (Listof Symbol)))
> (define los?
>   (lambda (seq) (and (list? seq) (andmap symbol? seq
> ---
>
> However I haven't been able to create one for vectors or boxes. None of the
> things I've tried will typecheck. Any pointers?

Typed Racket can't be sure that untyped code won't change whats inside
a mutable vector or box

---
#lang racket
(define v (vector 'A))
(define (set-v!) (vector-set! v 0 0))
(provide v set-v!)

#lang typed/racket
(require/typed "path-to-untyped.rkt"
  (v : (Vectorof Any))
  (set-v! : (-> Void)))

;; suppose this worked
(: vos (-> Any Boolean : (Vectorof Symbol)))
(define (vos x) )

(cond
  [(vos? v)
;; v : (Vectorof Symbol)
(set-v!)
;; v now contains an integer!
]))
---

I don't know a work-around.

I was hoping it could work for (Immutable-Vectorof Symbol), but I
don't know what to use in place of `andmap`.

-- 
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/CAFUu9R6nYVHoKCFGbjD8Q%2Bs__z2Cep9rwvqRL6HyZCE5GnzyhA%40mail.gmail.com.


[racket-users] embedding Google Forms/YouTube/… in Scribble

2020-03-24 Thread E Comer
Thank you for your very useful and timely addition to the great Scribble 
functionality.

In this time of great need for on-line learning, it is much appreciated.
I hope other additions (e.g. Numbas quiz embedding), will follow in the near 
future.

Congratulations for all the great work, and good health for you all.

Sincerely,
E. Comer

-- 
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/0e83751e-1d91-46f8-9ecb-46a53611a77f%40googlegroups.com.


Re: [racket-users] TR: Occurrence Typing with custom predicate

2020-03-24 Thread mmcdan
Hello Ben,

Good call. I didn't think about the mutability of the container's contents 
with respect to types. My goal is to create a type that represents an 
immutable container. 

After exploring, it looks like there is a workaround:
In the case of Vector, I can create a struct to hold the vector-immutable. 
In the case of Box, the struct can itself can be considered the box. The 
struct automatically generates the occurrence type predicate.

---
#lang typed/racket

(struct VoS ([contents : (Immutable-Vectorof Symbol)]))

(define test-vos (VoS (vector-immutable 'A)))

(VoS? test-vos)
;; #t

(VoS-contents test-vos)
;; '#(A)
---

I'll start using structs more often, instead of the *of types directly.

Thanks!

On Tuesday, March 24, 2020 at 3:50:39 PM UTC-7, Ben Greenman wrote:
>
> On 3/24/20, mmcdan > wrote: 
> > Hello, 
> > 
> > I'm trying to use occurrence typing for (Vectorof Symbol) or (Boxof 
> > Symbol). 
> > 
> > Creating a custom predicate for (Listof Symbol) seems to work: 
> > --- 
> > #lang typed/racket 
> > 
> > (: los? (-> Any Boolean : (Listof Symbol))) 
> > (define los? 
> >   (lambda (seq) (and (list? seq) (andmap symbol? seq 
> > --- 
> > 
> > However I haven't been able to create one for vectors or boxes. None of 
> the 
> > things I've tried will typecheck. Any pointers? 
>
> Typed Racket can't be sure that untyped code won't change whats inside 
> a mutable vector or box 
>
> --- 
> #lang racket 
> (define v (vector 'A)) 
> (define (set-v!) (vector-set! v 0 0)) 
> (provide v set-v!) 
>
> #lang typed/racket 
> (require/typed "path-to-untyped.rkt" 
>   (v : (Vectorof Any)) 
>   (set-v! : (-> Void))) 
>
> ;; suppose this worked 
> (: vos (-> Any Boolean : (Vectorof Symbol))) 
> (define (vos x) ) 
>
> (cond 
>   [(vos? v) 
> ;; v : (Vectorof Symbol) 
> (set-v!) 
> ;; v now contains an integer! 
> ])) 
> --- 
>
> I don't know a work-around. 
>
> I was hoping it could work for (Immutable-Vectorof Symbol), but I 
> don't know what to use in place of `andmap`. 
>

-- 
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/a9b1f475-24df-4d05-b979-001763edd0c1%40googlegroups.com.