Re: [racket-users] Why is struct/contract so much faster than a guard?

2020-09-03 Thread Christopher Lemmer Webber
Cool!  Thanks for sharing :)

-- 
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/87imcu8o2i.fsf%40dustycloud.org.


Re: [racket-users] Re: provide-if-not-defined

2020-09-03 Thread Sorawee Porncharoenwase
I want to propose another interface:

(my-provide
  #:default + - *
  #:override
  [my-+ +])

which expands to:

(provide - *)
(provide (rename-out [my-+ +]))

and checks that + must be in the #:default section (because we are
overriding it, it’d better already exist).

More generally:

(my-provide
  #:default  ...
  #:override
  [ ] ...)

expands to:

(provide (rename-out [ ] ...))
(provide  ...)

where ids* = ids - rhs, and with a check that rhs ⊆ ids
On Thu, Sep 3, 2020 at 10:12 AM Shriram Krishnamurthi 
wrote:

> Ah, I see, that's a nice idea!
>
> One problem is have well over a dozen of these that I want to
> pass-through, but I suppose I could write a
>
> (rename-prefix   ...)
>
> that turns into a bunch of define's. I'd have to be careful to not miss
> any.
>
> Another issue is that I have to redefine some of the language-definition
> primitives (like #%app), which will definitely make the module far more
> tricky.
>
> --
> 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/CAJUf2yQY-RVM%2BsH8%2BnHzFJFPwm5p5%3DGq%2BHGj42Ao7QQ0wJqnrQ%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/CADcuegvFaeSFFQspm8NwLsxbR3Bb-PYzwE4q0B5vwH%2B%3DVxBjxw%40mail.gmail.com.


Re: [racket-users] Re: provide-if-not-defined

2020-09-03 Thread Shriram Krishnamurthi
Ah, I see, that's a nice idea!

One problem is have well over a dozen of these that I want to pass-through,
but I suppose I could write a

(rename-prefix   ...)

that turns into a bunch of define's. I'd have to be careful to not miss any.

Another issue is that I have to redefine some of the language-definition
primitives (like #%app), which will definitely make the module far more
tricky.

-- 
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/CAJUf2yQY-RVM%2BsH8%2BnHzFJFPwm5p5%3DGq%2BHGj42Ao7QQ0wJqnrQ%40mail.gmail.com.


[racket-users] Re: provide-if-not-defined

2020-09-03 Thread Greg Hendershott
What if you instead rename the lang's imports (e.g. with prefix-in), and 
rely on the fact that your definitions override those supplied by the lang?

That way you could write the exact same provide for all the files: 
"provide-if-not-defined" is simply provide. However, you would need to 
manually use the renamed imports in your implmentation.

Rough sketch:

#lang racket/base

(module v1 racket/base
  (provide +))

(module v2 racket/base
  (provide +)
  (require (prefix-in rkt: racket/base))
  ;; At this point, both + and rkt:+ are aliases.
  ;; But after the the following definition, + is yours:
  (define (+ . vs) ;; like racket/base + but wrapped in a list
(list (apply rkt:+ vs

;; (require 'v1)
;; (+ 1 2) => 3

;; (require 'v2)
;; (+ 1 2) => '(3)


On Wednesday, September 2, 2020 at 10:29:12 AM UTC-4, Shriram Krishnamurthi 
wrote:
>
> Related to my previous post [
> https://groups.google.com/g/racket-users/c/OqyqDFxwhf0], I have several 
> cases where I have this kind of pattern:
>
> V1:
>
> #lang racket
> (provide +)
>
> V2:
>
> #lang racket
> (provide [rename-out (my-+ +)])
> (define my-+ …)
>
> Each variant provides some/all primitives directly from the module's lang, 
> while a sibling variant changes their behavior.
>
> Since there are a lot of names, it gets tiresome to remember which things 
> have and haven't been exported. Duplicates are of course caught statically, 
> but missing names are not "caught" at all at module definition time.
>
> It'd be nice to be able to write, say a block like
>
> #lang racket
> (provide-if-not-defined +)
>
> at the top of BOTH files. In V1, this turns into provide; in V2 I'd still 
> write the rename-out, but would only need to do this for the (usually) 
> small number of operations that I am overriding. Having a common block at 
> the top of each variant would ensure that the variants provide the same 
> language.
>
> Shriram
>

-- 
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/fbdc80bf-fe01-441d-af93-e7d614374b56o%40googlegroups.com.


Re: [racket-users] Why is struct/contract so much faster than a guard?

2020-09-03 Thread David Storrs
For the record, a self-plug:

#lang racket

(require struct-plus-plus)

(struct foo-guard (bar baz)
  #:guard (struct-guard/c any/c list?))


(struct/contract foo-contract ([bar any/c]
   [baz list?]))

(struct++ foo-spp  ([bar any/c]
[baz list?]))

(display "#:guard: ")

(time
 (for ([i 100])
   (foo-guard 'yeah '(buddy

(display "struct/contract: ")
(time
 (for ([i 100])
   (foo-contract 'yeah '(buddy

(display "struct++:")
(time
 (for ([i 100])
   (foo-spp++ #:bar 'yeah #:baz '(buddy

#:guard: cpu time: 3335 real time: 3361 gc time: 90
struct/contract: cpu time: 217 real time: 218 gc time: 3
struct++:cpu time: 1255 real time: 1262 gc time: 23

The struct++ version is slower at creation but gives you more security
guarantees later on in the form of functional setters, business rules, and
wrapper functions to normalize data.  For example:


; This accepts a symbol or string and forces it to string.

(struct++ baz-spp ([foo (or/c symbol? string?) ~a]) #:transparent)
(display "Result: ") (println (baz-spp++ #:foo 'bob))
Result: (baz-spp "bob")

; Any struct++ struct will throw an exception if given invalid data

(struct++ bar-spp ([foo integer?]))
(display "Throws: ") (bar-spp++ #:foo 'bob)
Throws:
; bar-spp++: contract violation

;   expected: integer?

;   given: 'bob

;   in: the #:foo argument of

;   (-> #:foo integer? bar-spp?)

;   contract from: (function bar-spp++)

;   blaming: /Users/dstorrs/bmtc_dev/app/test.rkt

;(assuming the contract is correct)

;   at: /Users/dstorrs/bmtc_dev/app/test.rkt

; Context:

;  "/Users/dstorrs/bmtc_dev/app/test.rkt":1:1 [running body]



; Example of more heavily verified struct.  It will accept a string or

; symbol for name and force it to string.  It will round the age down

; so it shows only years. It will default the 'gender' field to the

; symbol 'unknown.  It will make a database connection and verify that

; the department ID is valid.  (In practice you would want to check

; this against an in-RAM table instead of going to disk.)
;
(define (dbh) "mock function that should return a database handle")

(struct++ person ([name (or/c symbol? string?) ~a]
  [age  positive? (compose inexact->exact floor)]
  [(gender 'unknown) (or/c 'male 'female 'other 'unknown)]
  [user-id exact-positive-integer?])
  (#:rule ("department-id exists in the database"
   #:check (user-id)
   [(not (null? (query-rows (dbh) ; get database handle

"SELECT id FROM users WHERE
id=$1"
user-id)))]))
  #:transparent)
(display "Result: ")(println (person++ #:name 'bob #:age 18.5 #:user-id 2))

Result: (person "bob" 18 'unknown 2)

It also provides reflection, functional setters (dotted and dashed
versions), transformation rules, and other things.
https://docs.racket-lang.org/struct-plus-plus/index.html





On Wed, Sep 2, 2020 at 10:43 PM Christopher Lemmer Webber <
cweb...@dustycloud.org> wrote:

> Philip McGrath writes:
>
> > On Wed, Sep 2, 2020 at 3:41 PM Christopher Lemmer Webber <
> > cweb...@dustycloud.org> wrote:
> >
> >> Unfortunately I can't use #:methods with struct/contract so I'm stuck
> >> with the slow one if I want a contract on the struct?
> >>
> >
> > For another option (though you may already know this), I'd advocate for
> > using the `struct` sub-form of `contract-out` and drawing the module
> > boundary as tightly as needed to make it a sensible boundary for trust,
> > potentially by using submodules.
>
> Yes... probably what I should do in the future.
>
> > Since you mention `#:methods` in particular, you should be aware of some
> > subtle corners that make it tricky (and potentially expensive at runtime)
> > to protect  `racket/generic` methods comprehensively with contracts.
> (Here's
> > a pointer to some discussions.
> > ) I think just working
> with
> > struct-type properties can make sense when you don't really need most of
> > the features `racket/generic` gives you.
>
> :O
>
> --
> 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/87wo1ba8c1.fsf%40dustycloud.org
> .
>

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


Re: [racket-users] provide-if-not-defined

2020-09-03 Thread Shriram Krishnamurthi
Thank you both.

What I want is something closer to what Oak wrote, but that addresses only
*checking*, whereas I also want the convenience of defining the module.

So to use Oak's example, I want to be able to write

#lang racket/base

(provide-if-not-defined + - *)

at the top of *all three files*, but in test-b.rkt, also write

(provide [rename-out (my-+ +)])

So yes, if it turns out, say, `*` is not in racket/base, then all three
files will indeed give me an error (at definition), like Oak's checker
would. But this also reduces error by letting me duplicate the interface
across files, while still being able to override parts of it, like in
test-b.rkt, without producing an error that + is being exported twice.

Shriram

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


Re: [racket-users] Re: (chaperone RacketCon) 2020

2020-09-03 Thread Andrew Gwozdziewycz
Jay,

I was expecting this to be like PLDI, and that came with an amazing song: “This 
is Still PLDI” — https://youtu.be/hVMCl64Uhe8

Does Racket Con have an official song? 

Thanks,

Andrew



P.S. — yes, I am being a troll. However, I would genuinely love to see a Racket 
Con song. I have no talent for music, or production, but if I can lend my 
crappy voice, silly lyrics, or somehow help a passionate community member who 
thinks this is a fun idea, and wants to roll with it, let me know!

> On Sep 3, 2020, at 06:20, Jay McCarthy  wrote:
> 
> The site is up with speakers and times:
> 
> https://con.racket-lang.org/
> 
> Please get pumped and put the dates in your calendars.
> 
> And stay tuned for details about how technically the conference will work.
> 
> Thanks everyone!
> 
> <3
> 
> Jay
> 
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
> 
>> On Fri, Jun 5, 2020 at 7:25 PM Jay McCarthy  wrote:
>> 
>> In October 2020, we'll be holding a virtual RacketCon, rather than an
>> in-person meeting as usual. We hope to get back to normal in 2021. We
>> have not worked out the exact dates and details, but have a few
>> parameters.
>> 
>> We're thinking about following PLDI, where the general model is to
>> have pre-recorded talks, which I would help presenters prepare,
>> followed by live Q with an MC relaying questions from Slack. We'd
>> hope to have the usual State of Racket presentation from Matthew,
>> which would lead into a town hall Q/comment session with members of
>> the Racket team.
>> 
>> The main details we need to work out now are exactly which and how
>> many days to run it and in what time slots and in what time zones. I
>> would greatly appreciate any comments you have in response to this
>> form:
>> 
>> https://forms.gle/cYNNY9XhmEoUBBe19
>> 
>> Thank you!
>> 
>> Jay
>> 
>> --
>> Jay McCarthy
>> Associate Professor @ CS @ UMass Lowell
>> http://jeapostrophe.github.io
>> Vincit qui se vincit.
> 
> -- 
> 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/CAJYbDa%3DOuiuzM2oY4_4sYkeZiH%2BhriLSz4zZ6PC94pwhc8bGZA%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/27A5E834-781A-4122-8D02-8098AA64CFE6%40gmail.com.


Re: [racket-users] Create C functions for embedded Racket CS

2020-09-03 Thread Matthew Flatt
At Wed, 2 Sep 2020 14:05:11 -0700 (PDT), dotoscat wrote:
> There are a function such scheme_make_prim_w_arity 
>  _arity%29>
> for the CS version? The idea is to use Racket
> as a scripting language for a C program.

There's currently no support in the C API of Racket CS for constructing
a Scheme procedure that calls a C procedure. You have to work from the
Scheme side using `foreign-procedure` to create a wrapper for a C
function.


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


[racket-users] Re: (chaperone RacketCon) 2020

2020-09-03 Thread Jay McCarthy
The site is up with speakers and times:

https://con.racket-lang.org/

Please get pumped and put the dates in your calendars.

And stay tuned for details about how technically the conference will work.

Thanks everyone!

<3

Jay

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

On Fri, Jun 5, 2020 at 7:25 PM Jay McCarthy  wrote:
>
> In October 2020, we'll be holding a virtual RacketCon, rather than an
> in-person meeting as usual. We hope to get back to normal in 2021. We
> have not worked out the exact dates and details, but have a few
> parameters.
>
> We're thinking about following PLDI, where the general model is to
> have pre-recorded talks, which I would help presenters prepare,
> followed by live Q with an MC relaying questions from Slack. We'd
> hope to have the usual State of Racket presentation from Matthew,
> which would lead into a town hall Q/comment session with members of
> the Racket team.
>
> The main details we need to work out now are exactly which and how
> many days to run it and in what time slots and in what time zones. I
> would greatly appreciate any comments you have in response to this
> form:
>
> https://forms.gle/cYNNY9XhmEoUBBe19
>
> Thank you!
>
> Jay
>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.

-- 
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/CAJYbDa%3DOuiuzM2oY4_4sYkeZiH%2BhriLSz4zZ6PC94pwhc8bGZA%40mail.gmail.com.


Re: [racket-users] difference in struct printing from default #:transparent versus make-constructor-style-printer

2020-09-03 Thread Jeremy Siek
Thanks Ryan!

On Thursday, September 3, 2020 at 5:47:50 AM UTC-4 rmculp...@gmail.com 
wrote:

> The Racket printer uses a separate property to determine whether a struct 
> is quotable. If you add 
>
>   #:property prop:custom-print-quotable 'never
>
> to the declarations of Int2 and Prim2, your program should produce the 
> output you expect. I'll add a note to the docs for 
> make-constructor-style-printer.
>
> Ryan
>
>
> On Wed, Sep 2, 2020 at 10:07 PM Jeremy Siek  wrote:
>
>> I'm seeing some bad behavior from make-constructor-style-printer when
>> there are lists mixed in with the structs. It seems to switch from print 
>> mode to
>> write mode when going under a list. Whereas the default printer for 
>> transparent structs gets this right. The following program demonstrates the 
>> difference/problem.
>> Any thoughts on how to get the make-constructor-style-printer to behave
>> properly?
>>
>> #lang racket
>> (require racket/struct)
>>
>> (struct Int1 (value) #:transparent)
>> (struct Prim1 (op arg*) #:transparent)
>>
>> (struct Int2 (value) #:transparent
>>   #:methods gen:custom-write
>>   [(define write-proc
>>  (make-constructor-style-printer
>>   (lambda (obj) 'Int2)
>>   (lambda (obj) (list (Int2-value obj)])
>> (struct Prim2 (op arg*) #:transparent
>>   #:methods gen:custom-write
>>   [(define write-proc
>>  (make-constructor-style-printer
>>   (lambda (obj) 'Prim2)
>>   (lambda (obj) (list (Prim2-op obj) (Prim2-arg* obj)])
>>
>> (define p1 (Prim1 '+ (list (Int1 1) (Int1 2
>> (print p1)(newline)
>>
>> (define p2 (Prim2 '+ (list (Int2 1) (Int2 2
>> (print p2)(newline)
>>
>> The output is:
>>
>> (Prim1 '+ (list (Int1 1) (Int1 2)))
>> (Prim2 '+ '(# #))
>>
>> -Jeremy
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/bdeb1052-ea25-4dc0-8292-a13d15bf7870n%40googlegroups.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/f2e7dee9-af4b-4337-92c2-2b5790441b73n%40googlegroups.com.


Re: [racket-users] difference in struct printing from default #:transparent versus make-constructor-style-printer

2020-09-03 Thread Ryan Culpepper
The Racket printer uses a separate property to determine whether a struct
is quotable. If you add

  #:property prop:custom-print-quotable 'never

to the declarations of Int2 and Prim2, your program should produce the
output you expect. I'll add a note to the docs for
make-constructor-style-printer.

Ryan


On Wed, Sep 2, 2020 at 10:07 PM Jeremy Siek  wrote:

> I'm seeing some bad behavior from make-constructor-style-printer when
> there are lists mixed in with the structs. It seems to switch from print
> mode to
> write mode when going under a list. Whereas the default printer for
> transparent structs gets this right. The following program demonstrates the
> difference/problem.
> Any thoughts on how to get the make-constructor-style-printer to behave
> properly?
>
> #lang racket
> (require racket/struct)
>
> (struct Int1 (value) #:transparent)
> (struct Prim1 (op arg*) #:transparent)
>
> (struct Int2 (value) #:transparent
>   #:methods gen:custom-write
>   [(define write-proc
>  (make-constructor-style-printer
>   (lambda (obj) 'Int2)
>   (lambda (obj) (list (Int2-value obj)])
> (struct Prim2 (op arg*) #:transparent
>   #:methods gen:custom-write
>   [(define write-proc
>  (make-constructor-style-printer
>   (lambda (obj) 'Prim2)
>   (lambda (obj) (list (Prim2-op obj) (Prim2-arg* obj)])
>
> (define p1 (Prim1 '+ (list (Int1 1) (Int1 2
> (print p1)(newline)
>
> (define p2 (Prim2 '+ (list (Int2 1) (Int2 2
> (print p2)(newline)
>
> The output is:
>
> (Prim1 '+ (list (Int1 1) (Int1 2)))
> (Prim2 '+ '(# #))
>
> -Jeremy
>
> --
> 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/bdeb1052-ea25-4dc0-8292-a13d15bf7870n%40googlegroups.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/CANy33qkqaRZNAya8XAeUQ6AOg_WwjgEa-ccMqvq5_GMkGF%3D1Qg%40mail.gmail.com.