Re: [racket-users] Arbitrary property types on structs?

2020-03-25 Thread David Storrs
Got it. I'm actually relieved that this isn't possible, since it means I
wasn't simply being dumb.



On Wed, Mar 25, 2020, 7:41 PM Sam Phillips  wrote:

> On 2020-03-25 14:16, David Storrs wrote:
> > This would let me use a struct as an output port:
> >
> > (struct foo (name out) #:property prop:output-port (struct-field-index
> out))
> >
> > I'd like to be able to set up a struct such that I can use it as a UDP
> > socket, something like the following pseudo-code:
> >
> > (struct foo (socket) #:property prop:udp (struct-field-index socket))
> >
> > I see that Racket defines prop:input-port and prop:output-port, but
> > there's no prop:udp, nor can I figure out how to do it through the
> > structure type properties or generic interfaces.  (I feel like I'm
> > missing something on those two, so maybe it's just poor understanding.)
> >
> > Is there a way to do this?
>
> The way those properties work is that functions that use input-ports and
> outputs-ports have knowledge about the properties and check if it is a
> struct with those properties.  There is no prop:udp though.  You could
> make one (like the following), but you would need to make your own
> wrappers of the existing udp-* functions and have them do the coercion
> before passing arguments to the existing racket functions.
>
> Cheers,
> Sam
>
> --- >8 --- >8 ---
>
> #lang racket/base
>
> (require (prefix-in - racket/udp))
>
> (define-values (prop:udp prop:udp? udp-socket-ref)
>(make-struct-type-property
> 'prop:udp
> (lambda (val struct-info)
>   (cond
> [(procedure? val) val]
> [(exact-nonnegative-integer? val)
>  ; XXX: check for valid index
>  (let ([struct-ref (list-ref struct-info 3)])
>(lambda (a-struct-value)
>  (struct-ref a-struct-value val)))]
>
> (define (->udp-socket v)
>(cond
>  [(-udp? v) v]
>  [else
>   (->udp-socket ((udp-socket-ref v) v))]))
>
> ;; Something like this for every udp function
> (define (udp-bind! socket hostname-string port-no [reuse? #f])
>(-udp-bind! (->udp-socket socket)
>hostname-string
>port-no
>reuse?))
>
> (struct server (socket)
>#:property
>prop:udp (struct-field-index socket)
>#:transparent)
>
> (define (make-server)
>(let ([udp (-udp-open-socket)])
>  (server udp)))
>
> --
> 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/34622180-8073-1e61-8187-f7d9dc48b236%40gmail.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/CAE8gKofUwGm7YexxvLJkMA9gtfRoW_ixr948WNwMShD_0-iA1g%40mail.gmail.com.


Re: [racket-users] Arbitrary property types on structs?

2020-03-25 Thread Sam Phillips

On 2020-03-25 14:16, David Storrs wrote:

This would let me use a struct as an output port:

(struct foo (name out) #:property prop:output-port (struct-field-index out))

I'd like to be able to set up a struct such that I can use it as a UDP 
socket, something like the following pseudo-code:


(struct foo (socket) #:property prop:udp (struct-field-index socket))

I see that Racket defines prop:input-port and prop:output-port, but 
there's no prop:udp, nor can I figure out how to do it through the 
structure type properties or generic interfaces.  (I feel like I'm 
missing something on those two, so maybe it's just poor understanding.)


Is there a way to do this?


The way those properties work is that functions that use input-ports and 
outputs-ports have knowledge about the properties and check if it is a 
struct with those properties.  There is no prop:udp though.  You could 
make one (like the following), but you would need to make your own 
wrappers of the existing udp-* functions and have them do the coercion 
before passing arguments to the existing racket functions.


Cheers,
Sam

--- >8 --- >8 ---

#lang racket/base

(require (prefix-in - racket/udp))

(define-values (prop:udp prop:udp? udp-socket-ref)
  (make-struct-type-property
   'prop:udp
   (lambda (val struct-info)
 (cond
   [(procedure? val) val]
   [(exact-nonnegative-integer? val)
; XXX: check for valid index
(let ([struct-ref (list-ref struct-info 3)])
  (lambda (a-struct-value)
(struct-ref a-struct-value val)))]

(define (->udp-socket v)
  (cond
[(-udp? v) v]
[else
 (->udp-socket ((udp-socket-ref v) v))]))

;; Something like this for every udp function
(define (udp-bind! socket hostname-string port-no [reuse? #f])
  (-udp-bind! (->udp-socket socket)
  hostname-string
  port-no
  reuse?))

(struct server (socket)
  #:property
  prop:udp (struct-field-index socket)
  #:transparent)

(define (make-server)
  (let ([udp (-udp-open-socket)])
(server udp)))

--
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/34622180-8073-1e61-8187-f7d9dc48b236%40gmail.com.


Re: [racket-users] Separate compilation/caching for Scribble?

2020-03-25 Thread William J. Bowman
We're getting a little far from my real question, since caching the examples is
IMHO a hack to cache the most expensive part of the computation, while the whole
'doc ought to be cachable, but

I forgot what my own code was doing.
That's basically what I'm doing:
(define (make-cached-eval name . rest)
  (define ev
(make-log-based-eval
 (cachefile name)
 (if (file-exists? (cachefile name))
 'replay
 'record)))
  (for ([r rest])
(ev r))
  ev)

I'm using with-cache's `cachefile` just to generate and manage the file path, so
it ends up in have a good place.
I was trying to do something more complex earlier, but it didn't work.

On Wed, Mar 25, 2020 at 09:59:15PM +0100, Ryan Culpepper wrote:
> I'm not clear on what `with-cache` is doing in this setup, but it seems
> like a potential source of errors. If the goal is to automatically use
> `'replay` if the log file exists and `'record` otherwise, why not do the
> following?
> 
> (make-log-based-eval the-log-file (if (file-exists? the-log-file)
> 'replay 'record))
> 
> Ryan
> 
> 
> On Wed, Mar 25, 2020 at 8:57 PM William J. Bowman 
> wrote:
> 
> > On Wed, Mar 25, 2020 at 08:51:18PM +0100, Ryan Culpepper wrote:
> > > You can use `raco make` (or `raco setup` for docs of installed packages)
> > to
> > > compile the Scribble files, but that won't compile the examples. Those
> > are
> > > dynamically evaluated when the Scribble documents are run.
> > Yeah, I was thinking of "compilation" as in caching the output document
> > from
> > each module.
> >
> > > For `make-log-based-eval`, are you using a separate evaluator (and
> > separate
> > > log file) for each Scribble file?
> > Yes. However, I'm using `with-cache` and a wrapper to detect whether a
> > cache
> > file exists (separate cache file each evaluator), and use 'replay mode if
> > the
> > cache file exists, so I don't have to manually switch to 'replay mode, or
> > manually re-record if I alter an example (instead, just clear the cache).
> >

-- 
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/20200325220252.GA31619%40williamjbowman.com.


[racket-users] Arbitrary property types on structs?

2020-03-25 Thread David Storrs
This would let me use a struct as an output port:

(struct foo (name out) #:property prop:output-port (struct-field-index out))

I'd like to be able to set up a struct such that I can use it as a UDP
socket, something like the following pseudo-code:

(struct foo (socket) #:property prop:udp (struct-field-index socket))

I see that Racket defines prop:input-port and prop:output-port, but there's
no prop:udp, nor can I figure out how to do it through the structure type
properties or generic interfaces.  (I feel like I'm missing something on
those two, so maybe it's just poor understanding.)

Is there a 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/CAE8gKoeYqP3TRDHX%3DqLh9GxB6AJ6KF--9g-fVbMQ8c0oFvD_Bw%40mail.gmail.com.


Re: [racket-users] Separate compilation/caching for Scribble?

2020-03-25 Thread Ryan Culpepper
I'm not clear on what `with-cache` is doing in this setup, but it seems
like a potential source of errors. If the goal is to automatically use
`'replay` if the log file exists and `'record` otherwise, why not do the
following?

(make-log-based-eval the-log-file (if (file-exists? the-log-file)
'replay 'record))

Ryan


On Wed, Mar 25, 2020 at 8:57 PM William J. Bowman 
wrote:

> On Wed, Mar 25, 2020 at 08:51:18PM +0100, Ryan Culpepper wrote:
> > You can use `raco make` (or `raco setup` for docs of installed packages)
> to
> > compile the Scribble files, but that won't compile the examples. Those
> are
> > dynamically evaluated when the Scribble documents are run.
> Yeah, I was thinking of "compilation" as in caching the output document
> from
> each module.
>
> > For `make-log-based-eval`, are you using a separate evaluator (and
> separate
> > log file) for each Scribble file?
> Yes. However, I'm using `with-cache` and a wrapper to detect whether a
> cache
> file exists (separate cache file each evaluator), and use 'replay mode if
> the
> cache file exists, so I don't have to manually switch to 'replay mode, or
> manually re-record if I alter an example (instead, just clear the cache).
>

-- 
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/CANy33qnePkB3LERw-s8kmGWi4e%2B0T%3D%3D0Tgy%3Da5mHE9odkpFFrQ%40mail.gmail.com.


[racket-users] Switch off type checking via typed/racket/no-check fails on typed big-bang

2020-03-25 Thread Marc Kaufmann
Hi,

I am trying to switch off type checking on a file so that I can prototype 
faster without the wait for the type checker. However, my code also uses 
typed/2htdp/universe and typed/2htdp/image, and I get an error on 
`big-bang`:

> Type Checker: Macro big-bang from typed module used in untyped code in: 
(big-bang ...

So, is there a to run the program without running the type checker? 
Relatedly, is there a way of reloading a *typed* racket file in the REPL (I 
can't get it to work with ,reload-require which just chokes somehow). 

I could hack around this by having the big-bang be in an untyped submodule 
- but doing this only so that I can have a faster developing loop (I will 
already have to switch between #lang typed/racket and #lang 
typed/racket/no-check enough) seems a bit dodgy.

Cheers,
Marc

-- 
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/650c64c5-370e-4bc6-855c-5e6745ef53e8%40googlegroups.com.


Re: [racket-users] Separate compilation/caching for Scribble?

2020-03-25 Thread William J. Bowman
On Wed, Mar 25, 2020 at 08:51:18PM +0100, Ryan Culpepper wrote:
> You can use `raco make` (or `raco setup` for docs of installed packages) to
> compile the Scribble files, but that won't compile the examples. Those are
> dynamically evaluated when the Scribble documents are run.
Yeah, I was thinking of "compilation" as in caching the output document from
each module.

> For `make-log-based-eval`, are you using a separate evaluator (and separate
> log file) for each Scribble file?
Yes. However, I'm using `with-cache` and a wrapper to detect whether a cache
file exists (separate cache file each evaluator), and use 'replay mode if the
cache file exists, so I don't have to manually switch to 'replay mode, or
manually re-record if I alter an example (instead, just clear the cache).

-- 
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/20200325195723.GN26958%40williamjbowman.com.


Re: [racket-users] Separate compilation/caching for Scribble?

2020-03-25 Thread Ryan Culpepper
You can use `raco make` (or `raco setup` for docs of installed packages) to
compile the Scribble files, but that won't compile the examples. Those are
dynamically evaluated when the Scribble documents are run.

For `make-log-based-eval`, are you using a separate evaluator (and separate
log file) for each Scribble file?

Ryan

On Wed, Mar 25, 2020 at 7:56 PM William J. Bowman 
wrote:

> Does Scribble support separate compilation or some kind of caching and I'm
> just
> missing it?
>
> I'm building a multi-page website using Scribble, with many @examples that
> take
> a while to run.
> If I touch *any page*, all the other pages have to rebuild, re-running the
> long
> running examples.
>
> I've hacked up a caching system for examples using make-log-based-eval and
> with-cache, but it's completely unreliable, occasionally giving 'could not
> replay log' when nothing has changed in that file.
>
> Am I missing something?
>
> --
> William J. Bowman
>
> --
> 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/20200325185631.GK26958%40williamjbowman.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/CANy33q%3DZ7nfiF%3DqntgSnaD%3D8%2B4L%3DR4CTb73K_T8mzfoXJxXrFQ%40mail.gmail.com.


[racket-users] Separate compilation/caching for Scribble?

2020-03-25 Thread William J. Bowman
Does Scribble support separate compilation or some kind of caching and I'm just
missing it?

I'm building a multi-page website using Scribble, with many @examples that take
a while to run.
If I touch *any page*, all the other pages have to rebuild, re-running the long
running examples.

I've hacked up a caching system for examples using make-log-based-eval and
with-cache, but it's completely unreliable, occasionally giving 'could not
replay log' when nothing has changed in that file.

Am I missing something?

-- 
William J. Bowman

-- 
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/20200325185631.GK26958%40williamjbowman.com.