Re: [racket-users] Re: Functional object-oriented programming

2017-02-08 Thread Philip McGrath
Note, though, that struct-copy needs to be given the type of the resulting
structure statically, at compile time, and "the result of *struct-expr* can
be an instance of a sub-type of *id*, but the resulting copy is an
immediate instance of *id* (not the sub-type)." [1] If you have a complex
hierarchy of struct types (as might be the case if you're using structs in
an OOP-inspired sort of way), this can get a little annoying.

Personally, I tend to end up defining helper functions to do functional
update (often with optional keyword arguments to address the
fields-that-stay-the-same issue). Generics in the sense of racket/generic
can be helpful for this if using structs. I may then implement the helper
function using struct-copy, but I can hide away its idiosyncrasies.

[1]
http://docs.racket-lang.org/reference/struct-copy.html?q=struct-copy#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct-copy%29%29

On Wed, Feb 8, 2017 at 6:14 PM Alex Harsanyi  wrote:

> Structures support this style of updating:
>
> (struct foo (bar baz) #:transparent)
>
> (define one (foo "hello" 1))
>
> ;; Copy all fields from "one" and update baz to 2
> (define two (struct-copy foo one (baz 2)))
>
> They also have immutable fields by default.
>
> Best Regards,
> Alex.
>
> --
> 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] ->* contracts not enforcing #:pre/desc pre-conditions

2017-02-05 Thread Philip McGrath
Contracts created with ->* don't seem to be enforcing their #:pre/desc
pre-conditions.

Given this program:

> #lang racket
> (module private racket
>   (provide get-apples-allowed?
>get-apples)
>   (define get-apples-allowed?
> (make-parameter #f))
>   (define (get-apples)
> 'apples))
> (module broken racket
>   (require (submod ".." private))
>   (provide
>(contract-out
> [rename get-apples broken-get-apples
> (->* ()
>  ()
>  #:pre/desc (or (get-apples-allowed?)
> "get-apples not allowed")
>  any)])))
> (module working racket
>   (require (submod ".." private))
>   (provide
>(contract-out
> [rename get-apples working-get-apples
> (->i ()
>  ()
>  #:pre/desc () (or (get-apples-allowed?)
>"get-apples not allowed")
>  any)])))
> (require (submod "." working)
>  (submod "." broken))


Evaluating (working-get-apples) produces an error as expected, but
evaluating (broken-get-apples) produces 'apples.

-- 
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] Basic macro question

2017-02-05 Thread Philip McGrath
You need to have the lexical context information of x, y, and z come from
stx: otherwise, they will be protected by macro expansion (as a matter of
hygiene).

Here's one way to do it:

> (define-syntax (a stx)
>   (syntax-parse stx
> [(a)
>  (with-syntax ([x (datum->syntax stx 'x)]
>   [y (datum->syntax stx 'y)]
>   [z (datum->syntax stx 'z)])
>#`(begin
>(define x 97)
>(define y 98)
>(define z 99)))]))


You may also want to look at format-id.

Also, I found Greg Hendershott's *Fear of Macros* (
http://www.greghendershott.com/fear-of-macros/index.html) a useful
supplement to the Racket Guide/Reference in understanding the macro system:
ch. 4 addresses some of these issues.

-Philip

On Sun, Feb 5, 2017 at 8:41 PM,  wrote:

> I must be missing something simple here.
>
> 229> (define-syntax a (lambda (stx) (syntax-parse stx [(a) #`(begin
> (define x 97) (define y 98) (define z 99))])))
> 230>(a)
> 231>y
> 232; y:undefined;
> 233; cannot reference undefined identifier
> 234; [,bt for context]
>
> If the macro is given these ids, like (a x y z), then it will work, but
> can't I also pick standard names like this in advance, or is that somehow
> fundamentally "unhygienic"? Perhaps I have to generate the names in a place
> visible to both the definition and use or something...
>
>
> ## Peter
>
> --
> 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] Client side web applications in Racket

2017-01-22 Thread Philip McGrath
My understanding is that implementation is still lagging, but I believe ES6
specifies proper tail calls, yes?

-Philip


On Sun, Jan 22, 2017 at 3:17 PM, Neil Van Dyke  wrote:

> Quoting "https://github.com/vishesh/racketscript/blob/master/README.md":
>
>> RacketScript doesn't support Racket features which are expensive, for
>> example proper tail calls and continuations.
>>
>
> Do you have plans to revist the tail call question within RacketScript?
> TCO is essential to idiomatic Scheme, and (while Racket is not Scheme, and
> has grown other noteworthy strengths, and people have less interest in
> learning algorithm crafting than they used to) I think TCO still has a lot
> of merit, and should not be discarded lightly.
>
> Not many people will mind if you discard first-class continuations,
> however. :)
>
>
> --
> 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] Re: [ANN] Simple, Deterministic Dictionaries (ddict)

2017-01-23 Thread Philip McGrath
Have you considered implementing the gen:dict generic interface?

-Philip

On Mon, Jan 23, 2017 at 7:58 AM, Greg Trzeciak  wrote:

> On Monday, January 23, 2017 at 2:18:53 PM UTC+1, Andrew Kent wrote:
>
> > ddict seeks to mimic Racket's `hash` API as much as possible and is
> hopefully a a convenient "drop in" replacement for `hash` when you'd like
> deterministic iteration order.
>
> Thank you, just when I need it!
> One minor issue regarding the API - I understand you wanted to mimic hash
> api but I personally wonder if moving away from keywordless api for both
> hash and ddict wouldn't be a better idea.
>
> --
> 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] Re: Package layout in docs

2017-01-30 Thread Philip McGrath
I was also going to suggest the ring system as a way of giving more
information without imposing an unnecessary artificial distinction. In
general I'm enthusiastic about the benefits of not having a sharp dividing
line, but it would be useful to show more clearly in the documentation
which packages have been vetted to "ring zero" standards.



On Mon, Jan 30, 2017 at 8:46 PM, Jack Firth  wrote:

> Rather than splitting "core packages" from "community packages", what if
> we used the package ring system? [1] We could establish a way for the
> Racket community to bless packages with "ring zero" status, then provide a
> --catalog argument to Scribble to lookup ring information in when deciding
> how to style package documentation. The docs would remain unified, we'd
> have a centralized place to curate packages, and there's no artificial
> barrier that prevents user-contributed packages from living alongside
> main-distribution packages.
>
> [1] http://docs.racket-lang.org/pkg/Future_Plans.html?q=ring
>
> --
> 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] Deserialization broken for class-based objects with contracted interfaces

2017-01-21 Thread Philip McGrath
Deserialization appears to be broken for class-based objects that implement
interfaces with contracted methods.

Given this example module:

#lang racket
(require racket/class
 racket/serialize)
(define foo<%>
  (interface ()
[foo-method (->m any/c)]))
(define-serializable-class* foo% object% (foo<%>)
  (inspect #f)
  (init-field [v #hasheq()])
  (define/public (foo-method)
'result)
  (super-new))
(define inst
  (new foo%))


deserialize appears to produce a different type of object than the original:

>  inst
(wrapper-object:foo% '#hasheq())
>  (deserialize (serialize inst))
(object:foo% '#hasheq())
>  (equal? inst (deserialize (serialize inst)))
#f


Also, foo-method does not work on deserialized instances:

>  (send inst foo-method)
'result
>  (send (deserialize (serialize inst)) foo-method)
application: not a procedure;
 expected a procedure that can be applied to arguments
  given: '(# ((#m any/c)> (interface foo<%>) (class foo%) #f)))
  arguments...:

-- 
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] IMAP with racket

2017-02-11 Thread Philip McGrath
I have used net/imap with gmail, though it does require enabling "less
secure apps" (the link George sent has instructions). I believe the only
"less secure" part is that you want to use IMAP for authentication and not
OAuth.

-Philip

On Sat, Feb 11, 2017 at 7:55 AM, George Neuner  wrote:

>
> On 2/11/2017 7:04 AM, Tim Hanson wrote:
>
> I have successfully connected to two of the mail servers I use this way, but 
> not yet to gmail. Has anyone successfully connected to gmail using either of 
> the approaches tested here? Maybe someone can point out what I'm doing wrong?
>
>
> I haven't messed with IMAP.  I have successfully used SMTP and POP with
> gmail.
>
> (I remember gmail was finicky a while back when I tried connecting to it 
> using Thunderbird; at some point it broke, with google warning some insecure 
> app was trying to access my mail (same thing happens with my racket attempts 
> so far). I was later able to connect after sufficiently upgrading 
> Thunderbird. (More at 
> https://support.mozilla.org/t5/Set-up-email/Thunderbird-and-Gmail/ta-p/14181)).
>
>
> See:   https://support.google.com/accounts/answer/6010255
>
>
> 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.
> 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] scribble defproc?

2017-01-17 Thread Philip McGrath
I came up with a fairly boring example that does use places. Note that you
have to put this in a module and save the file:

> #lang racket
> (require racket/serialize
>  web-server/lang/serial-lambda
>  )
> (define current-place
>   (make-parameter 'initial))
> (define (main)
>   (define p
> (place ch
>(parameterize ([current-place 'p])
>  (define proc
>(deserialize (place-channel-get ch)))
>  (place-channel-put ch (proc)
>   (place-channel-put/get p (serialize
> (serial-lambda ()
>   (format "I was run on place ~a."
>   (current-place))


Then at the REPL, you can do:

> > (main)
> "I was run on place p."


-Philip

On Tue, Jan 17, 2017 at 9:07 PM, Philip McGrath <phi...@philipmcgrath.com>
wrote:

> For a quick example (without places), if you enter this in the definitions
> window of Dr. Racket:
>
>> #lang racket
>> (require web-server/lang/serial-lambda
>>  racket/serialize
>>  )
>> (define serialized-proc
>>   (serialize (serial-lambda (x)
>>(printf "Your number is: ~a" x
>> serialized-proc
>> ((deserialize serialized-proc) 42)
>
> This is what you will get when you run the program:
>
>> '((3) 1 (('anonymous-module . "lifted.3")) 0 () () (0))
>> Your number is: 42
>
>
> There are a few caveats with serial-lambda. A big one is that you can't
> use it in the REPL: it has to be in a module context, so that there's a way
> to use the serialization information later. A second caveat is that any
> lexical values in the closure of serial-lambda must themselves be
> serializable: this is an instance of the general rule that, for serialize
> to succeed, all the nested contents of the data structure to be serialized
> must be serializable, not just the outermost container. Here's an example:
>
> #lang racket
>> (require web-server/lang/serial-lambda
>>  racket/serialize)
>> (define (make-proc lexical-value)
>>   (serial-lambda (immediate-arg)
>> (printf (string-append "This value is part of the closure, so \n"
>>"it must be serializable:\n\t ~a\n")
>> lexical-value)
>> (printf "The immediate argument can be anything:\n\t ~a\n"
>> immediate-arg)))
>> (struct opaque ())
>> (define works
>>   (make-proc (list 'apples 'peaches 'pears)))
>> ;; calling works on an non-serializable argument succeeds
>> (works (opaque))
>> ;; you can see that the lexical arg shows up
>> ;; in the serialized representation
>> (serialize works)
>> (newline)
>> (define broken
>>   (make-proc (opaque)))
>> ;; make-proc will succeed, and broken
>> ;; will appear to work as expected
>> (broken 42)
>> ;; however, attempting to serialize broken
>> ;; will raise an exn:fail
>> (serialize broken)
>
>
> If you have specific questions, I am happy to try to help!
>
> -Philip
>
> On Mon, Jan 16, 2017 at 11:13 PM, Andreas Olsson <photoguy@gmail.com>
> wrote:
>
>> Strangely I can't get the example working from the docs and serial lambda
>> isn't a cakewalk ether. So if you got a working example please share it!
>>
>> --
>> 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] scribble defproc?

2017-01-17 Thread Philip McGrath
For a quick example (without places), if you enter this in the definitions
window of Dr. Racket:

> #lang racket
> (require web-server/lang/serial-lambda
>  racket/serialize
>  )
> (define serialized-proc
>   (serialize (serial-lambda (x)
>(printf "Your number is: ~a" x
> serialized-proc
> ((deserialize serialized-proc) 42)

This is what you will get when you run the program:

> '((3) 1 (('anonymous-module . "lifted.3")) 0 () () (0))
> Your number is: 42


There are a few caveats with serial-lambda. A big one is that you can't use
it in the REPL: it has to be in a module context, so that there's a way to
use the serialization information later. A second caveat is that any
lexical values in the closure of serial-lambda must themselves be
serializable: this is an instance of the general rule that, for serialize
to succeed, all the nested contents of the data structure to be serialized
must be serializable, not just the outermost container. Here's an example:

#lang racket
> (require web-server/lang/serial-lambda
>  racket/serialize)
> (define (make-proc lexical-value)
>   (serial-lambda (immediate-arg)
> (printf (string-append "This value is part of the closure, so \n"
>"it must be serializable:\n\t ~a\n")
> lexical-value)
> (printf "The immediate argument can be anything:\n\t ~a\n"
> immediate-arg)))
> (struct opaque ())
> (define works
>   (make-proc (list 'apples 'peaches 'pears)))
> ;; calling works on an non-serializable argument succeeds
> (works (opaque))
> ;; you can see that the lexical arg shows up
> ;; in the serialized representation
> (serialize works)
> (newline)
> (define broken
>   (make-proc (opaque)))
> ;; make-proc will succeed, and broken
> ;; will appear to work as expected
> (broken 42)
> ;; however, attempting to serialize broken
> ;; will raise an exn:fail
> (serialize broken)


If you have specific questions, I am happy to try to help!

-Philip

On Mon, Jan 16, 2017 at 11:13 PM, Andreas Olsson 
wrote:

> Strangely I can't get the example working from the docs and serial lambda
> isn't a cakewalk ether. So if you got a working example please share it!
>
> --
> 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] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
Not the question you asked, but instead of with-output-to-string, if you're
discarding the output, you might prefer:

(parameterize ([current-output-port (open-output-nowhere)])
  ...)


-Philip

On Thu, Jan 19, 2017 at 4:51 PM, Philip McGrath <phi...@philipmcgrath.com>
wrote:

> I haven't looked in detail, but two quick thoughts:
>
>- When I evaluate (find-system-path 'run-file) in Dr. Racket, either
>inside a module or in the REPL, I get #v6.7/DrRacket.app/Contents/MacOS/DrRacket>
>- Have you looked at (current-directory)? In Dr. Racket, if the file
>has been saved, that returns the path to the directory of the file being
>run, which might give you what you need. (Of course, if you manipulate
>current-directory, or run the program from the shell when your working
>directory is not the directory of the file being run, you will get
>different results.)
>- Greg Hendershott's "__FILE__ and __LINE__ in Racket" might be
>relevant, though I don't think it does exactly what you want (
>http://www.greghendershott.com/2014/06/-file-and-line-in-racket.html
><http://www.greghendershott.com/2014/06/-file-and-line-in-racket.html>)
>
>
> -Philip
>
> On Thu, Jan 19, 2017 at 4:36 PM, David Storrs <david.sto...@gmail.com>
> wrote:
>
>> For the record, I know I can pass an absolute path (defined with
>> define-runtime-path) to load-initial-data.  My question is more about
>> "why is this different between the shell and Dr Racket?"
>>
>> On Thu, Jan 19, 2017 at 5:23 PM, David Storrs <david.sto...@gmail.com>
>> wrote:
>> > define-runtime-path is based on the enclosing file, not the running
>> file.
>> >
>> >
>> >
>> > ;; file:  app/lib/db/initial_test_data.sql
>> > ...various SQL commands...
>> >
>> >
>> > ;; file:  app/lib/t/testing_utils.rkt
>> > (define-runtime-path thisdir ".")
>> > (define cmd (string-append "psql -d biomantica < "
>> >  (path->string (build-path thisdir where
>> >   (say "shelling out in order to load initial data into DB. Command
>> > is: \n\t" cmd)
>> >   (system cmd)
>> > )
>> >
>> >
>> > ;;  file:  app/test_1.rkt
>> > (require "lib/t/testing_utils.rkt")
>> > (load-initial-data "lib/db/initial_test_data.sql")
>> >
>> >
>> > ;;  file:  app/lib/db/test_2.rkt
>> > (require "../t/testing_utils.rkt")
>> > (load-initial-data "./initial_test_data.sql")
>> >
>> >
>> > $ ./test_1.rkt
>> > shelling out in order to load initial data into DB. Command is:
>> > psql -d biomantica < ./lib/db/initial_test_data.sql
>> > INSERT 0 0
>> > ...lots of other SQL results...
>> >
>> > $  ./lib/db/test_2.rkt
>> > shelling out in order to load initial data into DB. Command is:
>> > psql -d biomantica < ././initial_test_data.sql
>> > /bin/sh: ././initial_test_data.sql: No such file or directory
>> > #f
>> >
>> >
>> > Note that both test_N.rkt files worked when I used the prior version.
>> >
>> > On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
>> > <ro...@eecs.northwestern.edu> wrote:
>> >> define-runtime-path is designed for this problem, IIUC. Let me know if
>> >> the docs don't help.
>> >>
>> >> Robby
>> >>
>> >> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs <david.sto...@gmail.com>
>> wrote:
>> >>> Short form:  When using Dr Racket, how do I write something that says
>> >>> "Here is a path to a file that I care about.  The path is relative to
>> >>> you, the script that is running the code" ?
>> >>>
>> >>> Long form:
>> >>>
>> >>> I have a file, testing_utils.rkt, that includes the following snippet
>> of code:
>> >>>
>> >>> (define (load-initial-data where)
>> >>>   (define cmd (string-append "psql -d biomantica < "
>> >>>  (path->string
>> >>>   (path-only
>> >>>(path->complete-path
>> >>> (find-system-path 'run-file
>> >>>  where))
>> >>>   (say "shelling out in order to load initial 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
I haven't looked in detail, but two quick thoughts:

   - When I evaluate (find-system-path 'run-file) in Dr. Racket, either
   inside a module or in the REPL, I get #
   - Have you looked at (current-directory)? In Dr. Racket, if the file has
   been saved, that returns the path to the directory of the file being run,
   which might give you what you need. (Of course, if you manipulate
   current-directory, or run the program from the shell when your working
   directory is not the directory of the file being run, you will get
   different results.)
   - Greg Hendershott's "__FILE__ and __LINE__ in Racket" might be
   relevant, though I don't think it does exactly what you want (
   http://www.greghendershott.com/2014/06/-file-and-line-in-racket.html)


-Philip

On Thu, Jan 19, 2017 at 4:36 PM, David Storrs 
wrote:

> For the record, I know I can pass an absolute path (defined with
> define-runtime-path) to load-initial-data.  My question is more about
> "why is this different between the shell and Dr Racket?"
>
> On Thu, Jan 19, 2017 at 5:23 PM, David Storrs 
> wrote:
> > define-runtime-path is based on the enclosing file, not the running file.
> >
> >
> >
> > ;; file:  app/lib/db/initial_test_data.sql
> > ...various SQL commands...
> >
> >
> > ;; file:  app/lib/t/testing_utils.rkt
> > (define-runtime-path thisdir ".")
> > (define cmd (string-append "psql -d biomantica < "
> >  (path->string (build-path thisdir where
> >   (say "shelling out in order to load initial data into DB. Command
> > is: \n\t" cmd)
> >   (system cmd)
> > )
> >
> >
> > ;;  file:  app/test_1.rkt
> > (require "lib/t/testing_utils.rkt")
> > (load-initial-data "lib/db/initial_test_data.sql")
> >
> >
> > ;;  file:  app/lib/db/test_2.rkt
> > (require "../t/testing_utils.rkt")
> > (load-initial-data "./initial_test_data.sql")
> >
> >
> > $ ./test_1.rkt
> > shelling out in order to load initial data into DB. Command is:
> > psql -d biomantica < ./lib/db/initial_test_data.sql
> > INSERT 0 0
> > ...lots of other SQL results...
> >
> > $  ./lib/db/test_2.rkt
> > shelling out in order to load initial data into DB. Command is:
> > psql -d biomantica < ././initial_test_data.sql
> > /bin/sh: ././initial_test_data.sql: No such file or directory
> > #f
> >
> >
> > Note that both test_N.rkt files worked when I used the prior version.
> >
> > On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
> >  wrote:
> >> define-runtime-path is designed for this problem, IIUC. Let me know if
> >> the docs don't help.
> >>
> >> Robby
> >>
> >> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs 
> wrote:
> >>> Short form:  When using Dr Racket, how do I write something that says
> >>> "Here is a path to a file that I care about.  The path is relative to
> >>> you, the script that is running the code" ?
> >>>
> >>> Long form:
> >>>
> >>> I have a file, testing_utils.rkt, that includes the following snippet
> of code:
> >>>
> >>> (define (load-initial-data where)
> >>>   (define cmd (string-append "psql -d biomantica < "
> >>>  (path->string
> >>>   (path-only
> >>>(path->complete-path
> >>> (find-system-path 'run-file
> >>>  where))
> >>>   (say "shelling out in order to load initial data into DB. Command
> >>> is: \n\t" cmd)
> >>>
> >>>   (void
> >>>(with-output-to-string  ;; silence the output
> >>>  (thunk
> >>>   (system cmd)
> >>>
> >>>
> >>> The way this gets used is that one of our test scripts (e.g.
> >>> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
> >>> call the load-initial-data function as follows:
> >>>
> >>> (load-initial-data "../initial_test_data.sql")
> >>>
> >>> I operate in Emacs via the shell, while my cofounder James uses Dr
> >>> Racket.  The above sequence works for me but not for him.  When I run
> >>> endpoints.t it locates the endpoints.t file, generates the path from
> >>> there to the initial_test_data.sql file, and shells out to run that
> >>> SQL through psql in order to load the database for testing.  When
> >>> James tries it it fails.
> >>>
> >>> The failure seems to be that for me "the running script" is the
> >>> endpoints.t file, while for him it's the Dr Racket executable.  I'm
> >>> not sure where to even begin sorting this out, so I was hoping for
> >>> some help.
> >>>
> >>> Any thoughts?
> >>>
> >>> Dave
> >>>
> >>>
> >>> PS:  James had to step out for something else or he would be sending
> >>> this himself.
> >>>
> >>> --
> >>> 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 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
Assuming I understand it correctly, I think the problem in the original is
that, in Dr. Racket, (find-system-path 'run-file) returns the path of Dr.
Racket, whereas at the shell it returns the path of the file being run.

It's a hack, but I think you could make a quick and dirty solution to
finding the directory of the running module in either case by checking if
the program is running in Dr. Racket and, if it is, taking advantage of the
way Dr. Racket initializes current-directory. This seems to work, assuming
that your program isn't supposed to have "DrRacket" anywhere in its path
and that Dr. Racket does (it does on MacOS, at least):

(let ([run-file (path->complete-path (find-system-path 'run-file))])
  (cond
[(regexp-match? #rx"DrRacket" run-file)
 (path->complete-path
  (current-directory))]
[else
 (path-only run-file)]))


-Philip

On Thu, Jan 19, 2017 at 5:45 PM, Robby Findler 
wrote:

> In DrRacet, current-directory in initialized to the directory
> containing the file where you hit "Run" and in the shell it is
> initialized to the current directory as understood by the shell.
>
> Is that what you're asking?
>
> Robby
>
>
> On Thu, Jan 19, 2017 at 4:36 PM, David Storrs 
> wrote:
> > For the record, I know I can pass an absolute path (defined with
> > define-runtime-path) to load-initial-data.  My question is more about
> > "why is this different between the shell and Dr Racket?"
> >
> > On Thu, Jan 19, 2017 at 5:23 PM, David Storrs 
> wrote:
> >> define-runtime-path is based on the enclosing file, not the running
> file.
> >>
> >>
> >>
> >> ;; file:  app/lib/db/initial_test_data.sql
> >> ...various SQL commands...
> >>
> >>
> >> ;; file:  app/lib/t/testing_utils.rkt
> >> (define-runtime-path thisdir ".")
> >> (define cmd (string-append "psql -d biomantica < "
> >>  (path->string (build-path thisdir where
> >>   (say "shelling out in order to load initial data into DB. Command
> >> is: \n\t" cmd)
> >>   (system cmd)
> >> )
> >>
> >>
> >> ;;  file:  app/test_1.rkt
> >> (require "lib/t/testing_utils.rkt")
> >> (load-initial-data "lib/db/initial_test_data.sql")
> >>
> >>
> >> ;;  file:  app/lib/db/test_2.rkt
> >> (require "../t/testing_utils.rkt")
> >> (load-initial-data "./initial_test_data.sql")
> >>
> >>
> >> $ ./test_1.rkt
> >> shelling out in order to load initial data into DB. Command is:
> >> psql -d biomantica < ./lib/db/initial_test_data.sql
> >> INSERT 0 0
> >> ...lots of other SQL results...
> >>
> >> $  ./lib/db/test_2.rkt
> >> shelling out in order to load initial data into DB. Command is:
> >> psql -d biomantica < ././initial_test_data.sql
> >> /bin/sh: ././initial_test_data.sql: No such file or directory
> >> #f
> >>
> >>
> >> Note that both test_N.rkt files worked when I used the prior version.
> >>
> >> On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
> >>  wrote:
> >>> define-runtime-path is designed for this problem, IIUC. Let me know if
> >>> the docs don't help.
> >>>
> >>> Robby
> >>>
> >>> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs 
> wrote:
>  Short form:  When using Dr Racket, how do I write something that says
>  "Here is a path to a file that I care about.  The path is relative to
>  you, the script that is running the code" ?
> 
>  Long form:
> 
>  I have a file, testing_utils.rkt, that includes the following snippet
> of code:
> 
>  (define (load-initial-data where)
>    (define cmd (string-append "psql -d biomantica < "
>   (path->string
>    (path-only
> (path->complete-path
>  (find-system-path 'run-file
>   where))
>    (say "shelling out in order to load initial data into DB. Command
>  is: \n\t" cmd)
> 
>    (void
> (with-output-to-string  ;; silence the output
>   (thunk
>    (system cmd)
> 
> 
>  The way this gets used is that one of our test scripts (e.g.
>  'endpoints.t') will (require "path/to/testing_utils.rkt") and then
>  call the load-initial-data function as follows:
> 
>  (load-initial-data "../initial_test_data.sql")
> 
>  I operate in Emacs via the shell, while my cofounder James uses Dr
>  Racket.  The above sequence works for me but not for him.  When I run
>  endpoints.t it locates the endpoints.t file, generates the path from
>  there to the initial_test_data.sql file, and shells out to run that
>  SQL through psql in order to load the database for testing.  When
>  James tries it it fails.
> 
>  The failure seems to be that for me "the running script" is the
>  endpoints.t file, while for him it's the Dr Racket executable.  I'm
>  not 

Re: [racket-users] Serializing macro transformer procedures

2017-01-19 Thread Philip McGrath
It might help if you could explain in more detail what you're trying to do:
I'm not sure I understand what you mean by "bring macro transformer
procedures down to run-time".

-Philip

On Wed, Jan 18, 2017 at 6:24 PM, Alex Knauth  wrote:

> I'm trying to use serial-lambda in macro transformer procedures so that I
> can serialize them and bring them down to run-time. However, serial-lambda
> isn't working within a define-syntax. It says:
>
> syntax-local-lift-provide: not expanding in a module run-time body
>
> This seems to be a lie; it works fine in a begin-for-syntax (as long as
> you don't try to deserialize). What's the real reason it doesn't work in a
> define-syntax? Is there another way to bring macro transformer procedures
> down to run-time?
>
> Alex Knauth
>
> --
> 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] How to watch the filesystem

2017-01-19 Thread Philip McGrath
Because you mentioned "the user moved the mouse", note that mouse-event%
and other things referred to as "events" in the GUI library are not
synchronizable events that can be used with sync.

-Philip

On Thu, Jan 19, 2017 at 2:58 PM, Neil Van Dyke  wrote:

> David Storrs wrote on 01/19/2017 03:08 PM:
>
>> of events but I still know nothing about detecting filesystem change
>> events.  I've looked through PLaneT and found nothing that seems like
>> an FS-monitoring package.  Can anyone suggest how to do this?
>>
>
> Here's a simple example, using `sync`:
>
> #lang racket
> (define my-fs-change-evt (filesystem-change-evt "/home/user"))
> (printf "sync...~n")
> (sync my-fs-change-evt)
> (printf "synced!~n")
>
> I ran this example on GNU/Linux, and then used the command `touch
> /home/user/x`, which caused the `sync` procedure to return.
>
> See the documentation in the vicinity of that for `sync`, for other other
> ways to use synchronizable objects.  They're essential for some kinds of
> I/O programming, not just GUI.
>
> Don't be scared away by the events (and ports documentation.  I've done a
> bunch of low-level programming in C, of I/O and such, and I still find some
> of the Racket documentation for related concepts to be intimidating.
> (Well, there is one big thing in there that's scared me off the few times
> I've wanted to use it, but each time, I was on the clock for a consulting
> client, so I did things in the known-quantity way instead.  Much of the
> primitives are simple, however, and the work is in building correct and
> efficient programs around the primitives.)
>
> BTW, You don't want "PLaneT", which was the old (and wise) package
> system.  Almost all current development has moved from PLaneT to "
> pkgs.racket-lang.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.
> 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] Serializing macro transformer procedures

2017-01-20 Thread Philip McGrath
How would you intend to use the macro transformer functions in the
debug-repl? Do you intend to call them as functions on syntax objects? I'm
not sure I understand what you're trying to achieve.

-Philip

On Fri, Jan 20, 2017 at 3:40 AM, Alex Knauth <alexan...@knauth.org> wrote:

>
> On Jan 19, 2017, at 8:44 PM, Philip McGrath <phi...@philipmcgrath.com>
> wrote:
>
> It might help if you could explain in more detail what you're trying to
> do: I'm not sure I understand what you mean by "bring macro transformer
> procedures down to run-time".
>
>
> My goal is to have a debug-repl that includes everything in it's scope.
> Debug-repl can use syntax-local-value access to the macro transformers in
> it's scope, but they are compile-time objects; if I just embed them in the
> expanded code it won't compile.  However, I these things at run-time to
> attach them to the namespace.
>
> If I could serialize the lambda in
> (define-syntax m
>   (lambda (stx) ))
> I could recover it at run-time and add it to the debug-repl namespace.
>
> (define (f x)
>   (define-syntax m
> (serial-lambda (stx) ; syntax-local-lift-provide: not expanding in a
> module run-time body
>   (syntax-case stx () [(_ e) #'e])))
>   (debug-repl))
>
> Alex Knauth
>
> -Philip
>
> On Wed, Jan 18, 2017 at 6:24 PM, Alex Knauth <alexan...@knauth.org> wrote:
>
>> I'm trying to use serial-lambda in macro transformer procedures so that I
>> can serialize them and bring them down to run-time. However, serial-lambda
>> isn't working within a define-syntax. It says:
>>
>> syntax-local-lift-provide: not expanding in a module run-time body
>>
>> This seems to be a lie; it works fine in a begin-for-syntax (as long as
>> you don't try to deserialize). What's the real reason it doesn't work in a
>> define-syntax? Is there another way to bring macro transformer procedures
>> down to run-time?
>>
>> Alex Knauth
>
>

-- 
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] Re: Scrolling in racket/gui

2017-03-01 Thread Philip McGrath
Almost — thanks! (I'm sure I read over that page of the docs, but I somehow
missed 'vscroll.)

The one thing that isn't working is scrolling with the mouse/trackpad. It
seems like I might need to override on-subwindow-char to listen for
'wheel-up and 'wheel-down, which I can do, but I'm not finding how to
change the scrolling position of the panel if I do catch one of those
events. (Or maybe there's a way to do it without implementing it myself?)

-Philip

On Wed, Mar 1, 2017 at 5:39 PM, Alex Harsanyi <alexharsa...@gmail.com>
wrote:

> On Thursday, March 2, 2017 at 4:16:47 AM UTC+8, Philip McGrath wrote:
> > This seems like it should be a simple question, but I can't figure out
> how to get a scroll bar in a gui application like this one:
> >
> >
> > #lang racket/gui
> > (define frame
> >   (new frame% [label "Example"]))
> > (for ([letter '("A" "B" "C" "D")])
> >   (define grp
> > (new group-box-panel%
> >  [parent frame]
> >  [label letter]))
> >   (for ([i (in-range 0 10)])
> > (new button%
> >  [parent grp]
> >  [label (number->string i)])))
> > (send frame show #t)
> >
> >
> > I can see something like what I have in mind in Dr. Racket's
> "Colors">"Color Schemes" preferences tab (at least on Mac OS), but I can't
> figure out how to do it.
> >
> >
> > Thanks,
> > Philip
>
> Does this do what you want?
>
> #lang racket/gui
>
> (define frame
>   (new frame% [label "Example"] [height 300]))
> (for ([letter '("A" "B" "C" "D")])
>   (define grp
> (new group-box-panel%
>  [parent frame]
>  [min-height 100]
>  [label letter]))
>   (define panel
> (new vertical-panel%
>  [parent grp]
>  [style '(vscroll)]
>  [alignment '(left top)]))
>   (for ([i (in-range 0 10)])
> (new button%
>  [parent panel]
>  [label (number->string i)])))
> (send frame show #t)
>
> Best Regards,
> Alex.
>
> --
> 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] udelim package -- more parens than you can shake a stick at

2016-09-25 Thread Philip McGrath
I second the idea that the documentation could be clearer on the difference
between "#lang scribble/base" and friends and what can be done with the
at-reader in general, as shown in languages like "scribble/text" and
"scribble/html". Despite having used both "scribble/base"-family languages
and tools like "make-at-readtable", I didn't realize until reading this
thread that "scribble/text" may be a better basis for several things I've
been trying to do.

On a related note, make-at-readtable accepts options for
"#:command-readtable" and "#:datum-readtable", but not for reading the body
of the @-form — though as I think about it, I guess that could be done
using "#:syntax-post-processor", right?

I'm still not 100% clear on what is supposed to happen at read-time vs.
expand-time vs. runtime in this example:
(filter foo?
(python-ish-list-comprehend
 «thing for x in sqlish(«select * from foo») where some_pred(x)»))
but I think those options might be able to construct something closer to
the udelim goal than plain at-epressions.

On Sun, Sep 25, 2016 at 3:50 PM Dupéron Georges 
wrote:

> If I understand you well, the intended use of your nested delimiters can
> be more or less described as syntactic sugar for #reader, with
> auto-detection of where the string ends:
>
> (filter foo?
> (python-ish-list-comprehend
>  «thing for x in sqlish(«select * from foo») where some_pred(x)»))
>
> could be rewritten as:
>
> (filter foo?
> #reader"python-ish-list-comprehend.rkt" thing for x in
> #reader"sqlish.rkt" select * from foo where
> some_pred(x)
>
> --
> Georges
>
> --
> 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] set! in #lang web-server

2016-10-04 Thread Philip McGrath
In #lang web-server, set! seems to behave differently with local vs.
top-level variables. For example:

> #lang web-server/base

(define x 0)
> (displayln x) ;; displays 0
> (set! x (add1 x))
> (displayln x) ;; displays 1
> (let ()
>   (define y 0)
>   (displayln y) ;; displays 0
>   (set! y (add1 y))
>   (displayln y)) ;; still displays 0


There is an obvious solution — don't use set! — but it was still not what I
was expecting.

The documentation does say that "… the store is *not* serialized. If you
rely on the store you will be taking huge risks. You will be assuming that
the serialized continuation is invoked on the same server before the server
is restarted or the memory is garbage collected." But this doesn't seem to
have to do with serialization per se. The line "(set! y (add1 y))" expands
to this (thanks to the macro stepper):

> (let-values:130 ([(y) (#%app:178 (#%app:179 CLOSURE-ref:130 clsr:130 '0))])
>   (let-values:180 (((l111640:181)
> (lambda:182 (x111632)
>
> (with-continuation-mark lifted.0:31 '(#t (lambda (x111632))) (set! y
> x111632)
> (#%app:183 keyword-apply:130
> l111640:181 kws:130 kw-vals:130 rst:130)))

which as best as I can tell will have no effect, because it's "y" is local.

Does anyone have a deeper standing of what's going on?

If set! is supposed to work this way, I would propose at least adding a
note to the "usage considerations" for #lang web-server, and I might
consider more drastic action (e.g. having set! raise an syntax error if
it's used in a local context.

Doing without set! is not a problem, but the fact that it *does* work as
usual at the top level (and REPL) makes it difficult to realize you have a
bug, e.g. when porting existing code.

--
-Philip

-- 
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] git-checkout-credentials

2016-10-27 Thread Philip McGrath
I'm excited by the ability to use authentication-required git repositories
with the package system.

> - The package system supports authentication when installing packages
>   from git, using the `raco pkg config git-checkout-credentials`
>   configuration option.
>
What is the value to be provided for git-checkout-credentials? It doesn't
seem to have made it into the docs yet (or, at least, I haven't found it).
Thanks,
Philip

-- 
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] Putting Racket into the database or, more sanely, storing continuations

2016-10-29 Thread Philip McGrath
If you want to go this way (and I suspect that there may be a better way),
rather than using eval, I would look at serial-lambda from
web-server/lang/serial-lambda, which lets you create closures (like the
values produced by lambda) that could be put into a TEXT field using
serialize and write. The benefit is that once you read and deserialize, you
have a value that can be directly applied to arguments or called as a
thunk, not source code that needs to be evaluated.

For one approach to security, see web-server/stuffers/hmac-sha1
.
There are probably additional considerations in your case, but it would at
least ensure that your serialized closures in the database are not forged.

But I wonder why you need to save these "tasks" to disk. Unless they need
to persist across runs of the application, it seems like you might be
better served using threads (and possibly custodians
 and/or will
executors , which
I haven't had much cause to play with yet). For example, to do something in
5 minutes, you could write:
(thread
 (λ ()
   (sleep (* 60 5))
   ;; do work
   ))
Then you could leave all the work of making sure your "tasks" actually run
at the appropriate moment to Racket. (In fact, even if some of your tasks
do need to persist across runs of your application, you could still use
this approach for actually running them if you include a step in your
startup sequence to re-spawn any tasks that remain in your database.)

On Sat, Oct 29, 2016 at 6:27 AM Tony Garnock-Jones 
wrote:

> On 10/28/2016 08:21 PM, David Storrs wrote:
> > Is it possible to take (e.g.) a procedure object and decompose it back
> > into its original source code?
>
> I don't believe this is possible without murky unsafe programming, but...
>
> > One (bad) idea that came to mind was to simply shove some Racket code
> > into a TEXT field in the database, then eval it when the time comes.
>
> ... this isn't actually so bad. From what you write, I think you're
> already seeing the potential pitfalls: what should be in scope of the
> code to be eval'd?
>
> > Now, this is horrible for a lot of reasons (security and error
> > handling being two of them)
>
> Security will be a problem no matter what, but I don't see that error
> handling gives undue difficulty! What am I missing?
>
> > suppose I already had a function that did what I needed and I
> > wanted to use that
>
> Instead of storing a list-representing-code-to-eval, you could store
>
>  - the name of a module
>  - the name of a function
>  - a list of argument values
>
> and use `dynamic-require` in your task runner to find the given function:
>
>   > (dynamic-require 'racket/list 'filter-map)
>   #
>
> and then `apply` with the arguments...
>
> Erlang uses essentially this approach in many places where actually
> passing a closure around would be problematic (e.g.: code upgrades;
> serialization to databases; etc). Erlang terminology is to call the
> triple of module name, function name, and arguments an "MFA".
>
> Cheers,
>   Tony
>
> --
> 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] Re: Building regexen in at-exp

2016-10-28 Thread Philip McGrath
*@pregexp{^@a}* is read as *(pregexp "^" a)* [you can test this by
evaluating the quoted form, '*@pregexp{^@a}* ], but the function pregexp
expects a single string as its first argument (and, apparently, a function
or #f as its optional second argument).
More generally, the body part of an @-expression is read as several strings
(i.e. a list, or several arguments to a function), not a single string.
You could get what you want by writing, for example, *(pregexp @~a{^@a})*

On Fri, Oct 28, 2016 at 2:41 PM David Storrs  wrote:

> On Fri, Oct 28, 2016 at 3:24 PM, Ken MacKenzie 
> wrote:
> > In a future version of what I am working on I see regex being an
> excellent solution.  My search is against a file I load into a list at
> program initialization.  However for other parts of this to load a list
> based on a partial file filtered with regex may be a better solution.
>
> So you're doing something like "load the whole file, then search for
> all lines that start with prefix X"?
>
> You might try something like this:
>
> (define prefix #px"^foo")  ;; Construct this however you like
>
> (for ((line (file->lines "/path/to/file)))
>   (when (pregexp-match prefix l)
>   (do-the-thing-with line)))
>
> Code not tested.
> >
> > There is also the case that I eventually switch to a DB backend, but at
> prototype stage I have been skipping that.
> >
> > Sorry not an answer to your query, but I think I could make use of the
> answer so inserting myself into the thread.
> >
> > Ken
> >
> > On Friday, October 28, 2016 at 3:18:14 PM UTC-4, David K. Storrs wrote:
> >> tl;dr :  Why is the following an error?
> >>
> >> #lang at-exp racket
> >> (define a "this")
> >> @pregexp{^@a}  ;; Should produce #px"^this" but errors out
> >> @pregexp{@(~a "^" a)}  ;; This works but is clumsy
> >>
> >> Long version:
> >>
> >> The at-exp language
> >> (http://www.greghendershott.com/2015/08/at-expressions.html and
> >> https://docs.racket-lang.org/scribble/reader-internals.html) allows
> >> for (among other things) more convenient construction of regexen, like
> >> so:
> >>
> >> (pregexp "\\d\\d\\.\\d\\d") ;; base racket. Ugh.
> >> @pregexp{\d\d\.\d\d}  ;; at-exp...ah, much better
> >>
> >> I started to reply to Ken MacKenzie's recent post about string
> >> prefixes with a suggestion that, although string-prefix was what he
> >> wanted in this case, a regex would be a more general solution.  When I
> >> went to test the code I was suggesting, I was surprised to find it
> >> didn't work as expected.  I thought maybe "^@" was a function or
> >> special form in Racket, but a quick search of the docs revealed
> >> nothing.  I tried various forms of quoting inside the at-exp but
> >> nothing worked.
> >>
> >> What am I missing?
> >
> > --
> > 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.


Re: [racket-users] Funtional programming and the maximum of something

2016-10-22 Thread Philip McGrath
I'm not sure if I understand what you're tying to do correctly, but here's
one way to do it (or one way to do something, at least):

(define (process-list-of-lists list-of-lists)
  (apply map
(λ args
   (apply max args))
list-of-lists))
(process-list-of-lists
  `((55 1 2)
(8 13 7)
(3 9 42
;; returns '(55 13 42)


Of course, you could also use explicit recursion instead of map and apply,
but you don't "overwrite" the result of a previous recursive call in either
case.

On Sat, Oct 22, 2016 at 2:04 PM  wrote:

> Hi,
>
> (I am still a newbie ... )
>
> If I remember  one rule of functional programming
> correctly, it says:
> Instead of changeing data - create new data.
>
> Suppose I have a list of list. Each "sublist" is
> made of a greater amount (but identical count) of
> exact numbers (integers).
>
> I want to process these data recursively and if
> all is done I want to get back a list of numbers
> (same count of numbers as in each sublist), which
> represents the maximum of all numbers of that "position"
> in all sublists.
>
> If I want to make this purely (may be inpractical) functional,..
> I see (as a newbie) the following problem.
> From two numbers as input I have to build a maximum and
> have to feed that into the next circle of recursion as
> one of the numbers to compare.
> Each time a new maximum is found I have to overwrite the
> old one.
> This contradicts the rule "Dont change data, create new one."
>
> How can I get out of this?
>
> Cheers
> Meino
>
>
>
>
> --
> 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] flat-contract-with-reason (should be flat-contract-with-explanation ?)

2016-10-23 Thread Philip McGrath
The Racket Reference documents
 a
function "flat-contract-with-reason"; however, in #lang racket, I get an
unbound identifier error for "flat-contract-with-reason".
I noticed that racket/contract/base does export a function
"flat-contract-with-explanation", which seems to do what the docs say
"flat-contract-with-reason" does — I'm guessing it somehow came to be
documented under the wrong name?
Philip

-- 
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] Error ("assignment disallowed") when deserializing class-based objects

2016-10-20 Thread Philip McGrath
I'm looking into whether Racket's class/object system might be useful for
one of my projects, and I am stumped by an error when deserializing
objects. I've managed to produce the error a few different ways, but here
is a fairly minimal example:
> (define-serializable-class ok% object%
  (inspect #f)
  (init-field [my-field null])
  (super-new))
> (define-serializable-class broken% object%
  (inspect #f)
  (super-new)
  (init-field [my-field null]))
> (deserialize (serialize (new ok%)))
(object:ok% '())
> (deserialize (serialize (new broken%)))
my-field: assignment disallowed;
  cannot assign field before initialization
I am guessing there is some subtlety of the way new instances are
initialized that I don't properly understand. Can anyone explain what is
going wrong? (and, ideally, how to avoid the problem in other situations?)
Many thanks,
Philip

-- 
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] filesystem-change-evt and thread-suspend

2016-11-14 Thread Philip McGrath
Thanks very much for the quick workaround (and ultimately for the repair) — 
it's always a relief to know I haven't overlooked some detail!

On Monday, November 14, 2016 at 9:30:17 AM UTC-6, Matthew Flatt wrote:
> No, that's not supposed to happen. I've pushed a repair.
> 
> 
> I was able to replicate the problem on Mac OS X, and it looks like the
> problem with filesystem events is specific to that platform. But the
> filesystem-event problem is due to a more general bug in the scheduler,
> and the same bug shows up with
> 
>(sync (wrap-evt s (lambda (v) 'ok)))
> 
> on all platforms.
> 
> The problem is related to `thread-suspend`, a semaphore becoming ready
> while the thread is suspended, and having a wrapper (in the sense of
> `wrap-evt`) around the semaphore. That pattern happens internally with
> filesystem events on Mac OS X. I think `thread-suspend` probably isn't
> used that much, which would explain how this scheduler bug survived for
> so long.
> 
> 
> You can work around the bug by creating a dummy pipe and waiting for
> the input end of the pipe in addition to the filesystem event, like
> this:
> 
>(define-values (dummy-i dummy-o) (make-pipe))
>(sync dummy-i (wrap-evt s (lambda (v) 'ok)))
> 
> Having a pipe in the set of events sends the scheduler into a path that
> doesn't have the bug.
> 
> 
> At Sun, 13 Nov 2016 17:43:43 -0800 (PST), Philip McGrath wrote:
> > Hi everyone,
> > 
> > I've been trying to get to know Racket's threads and particularly 
> > filesystem-change-evt, and I've come to a point of confusion. I thought 
> > that a 
> > filesystem-change-evt's synchronization result was supposed to be the event 
> > itself, which it is most of the time, but in combination with 
> > thread-suspend 
> > it seems to produce #f, and I'm not sure why.
> > 
> > Here's a tiny example:
> > 
> > > (define t
> >(thread (λ ()
> >(println (sync (filesystem-change-evt "test"))
> > > (thread-suspend t)
> > ;; at this point I go and do something like "echo foo >test"
> > > (thread-resume t)
> > ;; prints #f
> > 
> > Is this supposed to happen?
> > 
> > What's particularly confusing is that the same thing happens (i.e. #f is 
> > printed) if I instead define t to be:
> > 
> > (thread
> >(λ ()
> >  (println
> >(sync (wrap-evt (filesystem-change-evt "test")
> >(λ (x) 'my-result))
> > 
> > Does anyone know what's going on?
> > 
> > Thanks,
> > Philip
> > 
> > -- 
> > 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] raco run but (please) dont process the docs

2016-11-14 Thread Philip McGrath
On the subject of package documentation, 
http://docs.racket-lang.org/pkg/catalog-protocol.html appears to be incorrect 
when it says that:
The source for the PLT-hosted package catalog is in the 
(collection-file-path "pkg-catalog" "meta") directory of the 
full Racket distribution.

My installation tells me that collection is not found.

It looks like the source is actually provided by the package "pkg-index".

Philip


On Sunday, October 23, 2016 at 11:43:58 AM UTC-5, Matthew Flatt wrote:
> I'll bring that FAQ up-to-date to explain that built packages are now
> provided by the catalog
> 
>  https://pkg-build.racket-lang.org/server/built/catalog/
> 
> See also
> 
>  https://pkg-build.racket-lang.org/about.html
> 
> 
> At Sun, 23 Oct 2016 12:16:02 +0200, Daniel Brunner wrote:
> > Hi Meino,
> > 
> > have a look at this FAQ:
> > 
> > http://docs.racket-lang.org/pkg/FAQ.html#%28part._.How_can_.I_install_a_package
> > _without_its_documentation_%29
> > 
> > For some packages there exist two "sub" packages: One with "...-lib"
> > which does not contain any documentation and does not depend on scribble
> > etc. and a package which includes only the docoumentation "...-doc".
> > 
> > This does not work for all packages. Those who do not seperate the code
> > from the documentation you could stick with "binary" or "built"
> > packages: http://docs.racket-lang.org/pkg/strip.html
> > 
> > At the moment you have to build these packages yourself and put them on
> > your device for installation. As far as I know there are future plans to
> > provide these packages online.
> > 
> > 
> > Best wishes,
> > Daniel
> > 
> > 
> > Am 23.10.2016 um 11:09 schrieb meino.cra...@gmx.de:
> > > Hi,
> > > 
> > > I have installed racket on my Android tablet.
> > > For this I have the device rooted
> > > and installed a chrooted Archlinux,
> > > which in turn provides the prebuild
> > > racket-package 6.6.
> > > By the way: The tablet has a x86 iIntel CPU
> > > but nothing "big iron"-like. About 400MB
> > > free RAM is available.
> > > 
> > > BUT:
> > > When I install an additional package like csv-reading
> > > via raco pkg install it also processes the scribble
> > > docs to pdf via TeX of that package.
> > > And that's much too much for my little tablet.
> > > It instantly kills the terminal app and resets.
> > > 
> > > It there any way to tell raco what kind
> > > of doc processing is wanted and what don't?
> > > 
> > > Cheers,
> > > Meino
> > > 
> > > 
> > > 
> > 
> > -- 
> > 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] filesystem-change-evt and thread-suspend

2016-11-13 Thread Philip McGrath
Hi everyone,

I've been trying to get to know Racket's threads and particularly 
filesystem-change-evt, and I've come to a point of confusion. I thought that a 
filesystem-change-evt's synchronization result was supposed to be the event 
itself, which it is most of the time, but in combination with thread-suspend it 
seems to produce #f, and I'm not sure why.

Here's a tiny example:

> (define t
   (thread (λ ()
   (println (sync (filesystem-change-evt "test"))
> (thread-suspend t)
;; at this point I go and do something like "echo foo >test"
> (thread-resume t)
;; prints #f

Is this supposed to happen?

What's particularly confusing is that the same thing happens (i.e. #f is 
printed) if I instead define t to be:

(thread
   (λ ()
 (println
   (sync (wrap-evt (filesystem-change-evt "test")
   (λ (x) 'my-result))

Does anyone know what's going on?

Thanks,
Philip

-- 
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] When to use functions vs macros

2016-10-11 Thread Philip McGrath
This doesn't address functions vs macros, but have you considered
call-with-transaction

?

On Tue, Oct 11, 2016 at 1:10 PM Greg Hendershott 
wrote:

> 1. "Both" is sometimes a good answer: Write the function. Then maybe
> write a macro to do only what only a macro can do -- here, the
> "de-lambda" sugar, and just call the function to do the real work.
>
> 2. Maybe `with-handlers` would work better?
>
> --
> 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] Re: Operations that create objects

2016-12-16 Thread Philip McGrath
The outer function must return the inner function (or otherwise make it
reachable, perhaps inside some data structure). For example:

> (define (make-counter init)
(define (counter)
  (set! init (add1 init))
  init)
(displayln "Making a counter!")
counter)
> (define count-from-five
(make-counter 5))
Making a counter!
> (count-from-five)
6
> (count-from-five)
7
> (count-from-five)
8
> (define count-from-two
(make-counter 2))
Making a counter!
> (count-from-two)
3
> (count-from-five)
9


On Fri, Dec 16, 2016 at 11:15 AM, Jan Hondebrink 
wrote:

> Thank you so much. This is extremely helpful and instructive.
>
> One thing I don't understand: how do you call or access an inner function
> after its outer function has completed?
>
> On Fri, Dec 16, 2016 at 5:41 AM, George Neuner 
> wrote:
>
>> On Thu, 15 Dec 2016 06:03:54 -0800 (PST), NeverTooOldToCode
>>  wrote:
>>
>> >Racket Reference section 1.1.5 states: "Operations that create
>> >objects, such as vector, add to the set of objects" followed
>> >by a nice and instructive step-by-step evaluation example.
>> >Further on, lambda is used as another example of an operation
>> >creating an object.
>> >
>> >How can I tell which operations create objects?
>>
>> It is safe to assume that most operations will create new objects.  If
>> you're just beginning to learn the language, it isn't something you
>> need to worry about yet.
>>
>>
>> Racket is in the Lisp family of languages: most types of data are
>> "boxed".  Boxed data is stored in an object on the heap, together with
>> a "tag" that describes the type of the data.  Variables in your
>> program will contain references (pointers) to boxed values.
>>
>> Racket does not distinguish between the boxed object and the reference
>> to it.  Any time you try to look at the reference, you see the data
>> inside the box instead.  In this way Racket is _not_ like other
>> languages in which pointers and/or references can examined and/or
>> manipulated separately.
>>
>> The above is a bit simplistic: some types like characters and small
>> integers are "immediate" - stored directly in variables (or list
>> nodes, array slots, structure fields, etc.).  But it is safe to assume
>> that *most* types of data will be an object on the heap.
>>
>>
>> When you get to the point of needing to optimize programs for speed,
>> Racket does offer typed vectors and arrays which store numeric values
>> unboxed.  There is also a typed version of Racket which tries to
>> eliminate boxing data as much as is possible.
>>
>>
>>
>> Explaining why lambda creates an object is a bit more complicated.
>>
>> Lisp family languages, including Racket, support the concept of
>> "nested" functions: in other words, they permit functions to be
>> declared inside the scope of other functions.
>> [If you're familar with Algol or Pascal, etc., in general the nested
>> functions in Racket will act very similarly.]
>>
>> Inner functions can access local variables of the outer functions that
>> enclose them.  This type of access is known as "non-global,
>> non-local", usually shortened in the literature to just "non-local".
>> It requires having a way to locate the variables that belong to the
>> enclosing functions.
>>
>> Now, Racket also is in the Scheme language family.  In Scheme,
>> functions are "1st class", which means that they may create and return
>> new functions, be stored in data structures, be passed as arguments to
>> other functions, etc.
>>
>> In particular, Scheme - and Racket - allows the creation of inner
>> functions that persist and can be called *after* their outer functions
>> have completed.
>>
>> Executing a function requires not just its code, but also external
>> data needed by the function: it's so-called "environment".  In many
>> languages, the environment consists only of global data and arguments
>> passed directly to the function - but the environment of an inner
>> function includes local variables of enclosing outer functions.
>>
>> If an inner function is to persist after its enclosing outer function
>> has completed, the local variables of the outer function must *also*
>> persist.
>>
>> To accomplish this, lambda creates an object called a "closure".  The
>> closure contains data defined by the outer function(s) that is needed
>> by the inner function, together with a pointer to the code of the
>> inner function.  The closure, being an object itself, can be
>> referenced by other data structures, passed as an argument, etc.
>>
>> Closures permit functions to have persistent private data.  By sharing
>> closures, multiple functions can share data without the data being
>> defined globally.
>>
>>
>> If this sounds quite like the objects in your favorite OO language ...
>> well, it *is*.  The major difference is that closures are more general
>> than objects in most OO lanuages.   Lambda permits ad hoc associations
>> of data and 

[racket-users] Scribble equivalent of rowspan

2016-11-29 Thread Philip McGrath
A very rookie question: I am trying to figure out how to specify the
equivalent of HTML's rowspan attribute for tabular from scribble/base: that
is, to have a cell which spans more than one row. In LaTeX, I think I would
use "multirow" (but I'm no LaTeX expert).

I know so know about 'cont, but I believe that only lets a cell span
multiple columns: I'm looking for the a vertical version. Is there a
built-in way to do this? Or otherwise, if it's not too daunting to
implement myself, could someone point me in the right direction?

Here's some ASCII art of what I'm going for, if that's clearer:

-
| | Date: | Nov 29 | Dec 30 |
| |---|||
| | Time: | 12:18  |  3:06  |
|---|
| | Expected: |   3|   1|
| Apples  |---|||
| | Actual:   |   2|   1|
|---|
| Pears & | Expected: |   4|   9|
| |---|||
|  Plums  | Actual:   |   6|   3|
-

-- 
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] Traits, inspectors, and serializable classes

2017-01-02 Thread Philip McGrath
Is there (or, if not, could there be) a way to specify the inspector when
working with traits (from racket/trait)?

I can write

> (mixin () ()
>   (inspect #f)

  ... )

but "inspect" does not seem a valid clause inside the "trait" form. (I
could also imagine that this might need to be determined at the point when
I would call trait->mixin.)

Perhaps there is a way to do this already that I could figure out if I
played with the details of current-inspector and such? Really my only use
for inspectors thus far has been to make things be transparent.

My objective would be to use a class produced using traits as a super-class
with define-serializable-class*, and keeping the super-class transparent
would preserve automatic serialization (and incidental benefits, like
support for cycles of instances).

-Philip

-- 
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] Errors in (Dr)Racket

2017-01-02 Thread Philip McGrath
Stephen's mention of web server code reminded of me one of the very few
situations when I've struggled with Racket error messages, so I'll both
share an example and explain why I haven't complained about it before.

Here's a buggy program:

> #lang web-server
> (require web-server/servlet-env
>  web-server/formlets
>  racket/date)
> (define (start request)
>   (response/xexpr
>`(html (head (title "Output"))
>   (body (p "You entered this date: "
>(b ,(get-date)))
> (define (get-date)
>   (define the-formlet
> (make-date-formlet))
>   (formlet-process
>the-formlet
>(send/suspend
> (λ (k-url)
>   (response/xexpr
>`(html (head (title "Get Input"))
>   (body (h1 "Enter Some Date")
> (form ([method "POST"]
>[action ,k-url])
>   ,@(formlet-display
>  the-formlet)
> (define (make-date-formlet)
>   (formlet
>(#%# ,{=> (text-input #:value (date->string
>   (current-date))
>  #:attributes `([required ""]))
>  date-str}
> (input ([type "submit"])))
>date-str))
> (serve/servlet start #:stateless? #t)


Trying to run this program produces an error message that is in many ways
quite good: the message says:

stuff-url: Cannot stuff (kont #)
into a URL because it contains non-serializable pieces. Convert
# to a serializable struct

In a tiny example like this, that's enough for me to pinpoint the bug:
formlets are represented internally as procedures, so the output of
(make-date-formlet) cannot be serialized when it's called in (get-date).

However, in larger #lang web-server programs, and especially in earlier
stages of my becoming familiar with #lang web-server, the stack trace is
unhelpful and a bit intimidating: it begins with

select-handler/no-breaks at:
  line 163, column 2, in file /Applications/Racket
v6.7/collects/racket/private/more-scheme.rkt

and runs through a list of ""s until concluding with

 at:
  line 131, column 8, in file /Applications/Racket
v6.7/share/pkgs/web-server-lib/web-server/private/dispatch-server-with-connect-unit.rkt

At no point do any of the modules named or anything like that refer to my
code.

So why have I not complained about this?

First, most generally, because the bug is clearly my fault. Even when I was
at a stage of learning when I would have struggled to debug this, the
documentation makes it very clear that "the values in the lexical scope of
your continuations must be serializable for the continuations itself to be
serializable." Likewise, the formlet documentation explains that formlets
are implemented as procedures, and there are even old posts on this mailing
list specifically discussing the fact that formlets are not serializable.
So it would seem a bit decadent, I suppose, to complain about an error
message that is (especially by the standards of other languages) not
terrible at all, and which is sufficient to make it clear that, even if I'm
not immediately sure what the problem is, it's something I need to find and
fix in my code, not something the author of the library did wrong. (In
fact, it is something that the author of the library specifically warned me
not to do, though that makes it even more perplexing when I can't
immediately figure out how I managed to do it anyway.)

Second, in the specific case of #lang web-server, I considered the
extensive transformations that run on the source-text of my code to get
serializable continuations, and which seem to have something to do with the
fact that stack traces and errors in #lang web-server are generally harder
to understand than in #lang racket (certainly they do not have Dr. Racket
highlight the offending passages of my program in red, with beautiful
arrows to show me the context in which they occurred — but that is quite a
high standard indeed). As Stephen said, the internals seemed intimidating
and I felt a bit out of my depth, but also, specifically, it seemed like
improving this situation might be more of a hard technical problem than
just using contract-out at the right place.

I'll end with a thank you for all of the thought you all have given to
useful error messages, and for contracts specifically. It certainly is one
of the reasons I have been doing so much of my programming in Racket
lately. I took an HtDP-based course after many years of programming in
traditional/imperative languages, and one of the many transformative things
I learned from it was the importance of thinking specifically about the
legal inputs and outputs of each function. I have come more and more to use
contracts internally in the code I write, because whatever hypothetical
performance cost I may incur is almost always worth it to take advantage of
this incredible infrastructure for pinpointing the problem when (not if) I
produce runtime errors.

Happy New 

Re: [racket-users] Fix Ctr+F search on the new website?

2016-12-29 Thread Philip McGrath
I can confirm that Command F searching for "extensive" with
Chrome 55.0.2883.95 on Mac OS Sierra 10.12.1 gives me this problem: it
finds one match (under the "Batteries Included") image, but I can't see the
highlighting until I hover over the image.

-Philip

On Thu, Dec 29, 2016 at 11:42 AM, Leif Andersen 
wrote:

> > (For instance, Chrome on Mac OS does not have this problem.)
>
> Really? I get the same problem on Chrome on Mac OS. That's bizarre.
>
> Namely, chrome 55.0.2883.95, and OS X El Capitan.
>
> I also get it with Firefox 50.1 on OS X El Capitan
>
> I have not tried it anywhere else.
>
> > What are you doing on the Racket home page anyhow? ;)
>
> Tee hee. Well, in that specific instance I was helping someone find the
> mailing list page.
>
> But since I'm nearly blind I like to test our stuff for accessibility
> concerns.
>
>
> ~Leif Andersen
>
> On Thu, Dec 29, 2016 at 12:29 PM, Matthew Butterick  wrote:
>
>>
>> On Dec 28, 2016, at 6:18 AM, Leif Andersen  wrote:
>>
>> I noticed that Ctr+F based searching is kind of uncomfortable on the new
>> website. Namely, if I am searching for a word that is located below one of
>> the images, it gets highlighted like you would expect, but the image
>> doesn't actually disappear. Thus I need to play whack-a-mole to find the
>> highlighted text myself.
>>
>> Instead, would it be possible to have the image disappear when the
>> relevant text is highlighted?
>>
>>
>> It's helpful to me if reports like this include browser / OS details, as
>> they don't all behave the same way. (For instance, Chrome on Mac OS does
>> not have this problem.)
>>
>> As Georges said, I don't know of any way to reveal-as-you-search.
>>
>> I think I can change it so the hover-box text doesn't show up in the
>> search results* though I'm not sure that would necessarily be an
>> improvement.
>>
>> What are you doing on the Racket home page anyhow? ;)
>>
>> * a div set to "display: none" will not be searched
>>
>
> --
> 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] Errors in (Dr)Racket

2017-01-02 Thread Philip McGrath
I understand entirely that this was not the sort of case you seemed to have
in mind, but I'll follow up because I worry that, in the process of making
a minimal example, I may have obscured the actual problem. "The fix can be
easily located in [my] code" in the sense that it's clear that the error is
not the fault of the library writer, but I'm not sure I'd say that it can
be "easily located" in general — though obviously "easily" is a relative
term, and, again, it is only having seen just how good a great error
message can be that I can dream of a better world.

The problem with locating the error is more pronounced if the call to
serve/servlet is not in the same module as the non-serializable value, and
especially if the program being run incorporates several modules written in
#lang web-server. In larger programs like that (unfortunately I don't have
a great specific example to send right now) I have encountered error
messages with which it has not even been entirely clear which module is to
blame, let alone where within the module to start looking. (Perhaps there
is, in fact, some way to extract this information from existing messages:
all I can say is that there have been times when it has not been clear to
me.) Also, I have not found a good way to get more specific messages
through the contract system.

Certainly "(kont #)" doesn't help
much with tracking down the problem, and
"#", while it makes it sufficiently
clear that the offending value was a formlet, doesn't tell me where the
formlet is, or even where to start looking for it. If this were the first
time I were seeing this error message, I might also be confused by the fact
that stuff-url is not only not a function I called, I do not believe it is
a documented part of the API.

If there were some way of getting the error message to show, for example,
which call to send/suspend failed (in this case: the one within get-date,
which was called within start — it just happens that my tiny example only
called send/suspend once), that would be a great improvement. But, again, I
feel spoiled by the excellence of Racket's error reporting overall, and I
suspect the incremental improvements I have in mind are easier said than
done.

-Philip

P.S.: As I wrote this, I glanced at the implementation of stuff-url and saw
that it generates these error messages by using a "with-handlers" form that
runs a regexp against the message of any "exn:fail" it catches. Perhaps it
would be worth creating an exn:fail:serialize, as I know I have also
written regular expressions against that error message … I could even
imagine something like a lazily-enforced "serializable/c", especially as
"serializable?" doesn't check the contents of nested values. All just pipe
dreams, though!

On Mon, Jan 2, 2017 at 9:12 AM, Matthias Felleisen <matth...@ccs.neu.edu>
wrote:

>
> On Jan 2, 2017, at 7:25 AM, Philip McGrath <phi...@philipmcgrath.com>
> wrote:
>
>
> So why have I not complained about this?
>
> First, most generally, because the bug is clearly my fault.
>
>
>
> Hi Philip, thanks for this example. What Robby and I had in mind are calls
> to errors inside a library that baffle client programmers. When (1) it is
> clear from the error message how to fix the mistake and (2) the fix can be
> easily located in your code, there’s no problem. Our goal is to eliminate
> situations when either (1), (2) or both are unclear due to error "from the
> guts”.
>
>
> hank you for all of the thought you all have given to useful error
> messages, and for contracts specifically.
>
>
> We owe this aspect of our work to our original goal of spreading the word
> about reading, ‘riting, ‘rogramming but it turns out, it’s generally
> useful.
>
> Errors matter, POPL 2002 :-)
>
> — Matthias
>
>

-- 
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] Add fns or at least sample code for getting column names from table?

2016-12-28 Thread Philip McGrath
Something like this would be really good. I also, relatively recently,
discovered the "name" fields when I happened to look at a rows-result
directly, and being able to work with columns by name rather than by
position is much better. I guess I should have realized there was some way
of doing this, because rows->dict and the library functions that accept
a #:group argument can use column names. More documentation would
definitely be helpful: for example, I've noticed that I need to convert all
of my strings for #:group arguments to lower case, at least with postgresql.

On Wed, Dec 28, 2016 at 10:21 AM 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

> For the last few years, I’ve believed that there was no way to get the
> column names of tables using the db interface. Today I discovered
> that—using both postgresql and sqlite3, at least—I can extract these from
> the “name” fields of the “headers” field of the row-response to a “SELECT *
> FROM table_name LIMIT 0;”. The documentation suggests that these header
> fields are fragile and undocumented… but it would be nice to have known
> that it was there. Would it make sense to add a library function that
> returns column name information if it’s available, or at least add some
> sample code to the documentation?
>
> John
>
>
>
> --
> 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] Mobile Friendly HTML in Scribble?

2016-12-27 Thread Philip McGrath
Has something changed recently in the CSS for the Racket documentation? I
thought that formerly the phone layout was equivalent to what happens if
you manually resize a desktop/laptop browser window to be quite narrow: the
sidebar / table of contents goes away and a navigation bar appears at the
top of the page (with a search box and "top"/"prev"/"up"/"next"). However,
when I just tried to simulate a smartphone viewport with the Chrome
developer tools, I got the "non-mobile friendly" behavior Michael
described. (I don't have my phone on me right now, so I haven't checked
that.)

While we're on the subject of the narrow-width Scribble CSS, I've
occasionally had the thought that it would be nice to have a way to view
the table of contents, perhaps as a drop-down sort of thing, from the
sidebar-less view. (Currently the only way seems to be to make the window
wider, and I encounter that layout reasonably often when I have the
documentation open next to a Dr. Racket window.)

-Philip

P.S.: As a web designer, I find it curious how the conception of "mobile
friendly" design has changed: I remember Steve Jobs showing off tap-to-zoom
as a feature on the New York Times home page. As a user, I actually prefer
tap-to-zoom as a UI over some bad designs that meet Google's "mobile
friendly" standards.

On Tue, Dec 27, 2016 at 11:25 AM Michael Rossi 
wrote:

> Hi all,
>
> I asked this question over at stackoverflow and this seemed to be the
> place to ask.
>
> I was wondering if there is a built in way to create mobile friendly HTML
> in Scribble?  Given Google's current mobile friendly policy (
> https://webmasters.googleblog.com/2015/04/rolling-out-mobile-friendly-update.html)
> and the fact that devices with small screens are everywhere now, this seems
> like something which would not only make the Racket's documentation look
> better on mobile devices, but for any other HTML generated in Scribble.
>
> I understand I could probably hack on the CSS to create a custom layout
> (which sounds like utter hell), but I was wondering if such a thing already
> exists or is in the works already?  If not, how do we go about making a
> feature request for this?
>
> As an example of what I mean by "non-mobile friendly," if you go to the
> Racket docs on a smartphone, you end up having to zoom in and scroll to the
> right on every page because of the navigation on the left. Sure, it's
> doable, but it's not like going to a page that's like this:
>
>
> https://w3layouts.com/preview/?l=/mr-hotel-hotel-category-flat-bootstrap-responsive-web-template/
>
> Click on the device pictures on the top to see what I'm getting at.
>
> So, am I correct that Scribble cannot currently do this?  If so, who do we
> bug to get this added?
>
> Thanks everyone!
> Michael
>
> --
> 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] Spreadsheet-style tables with Scribble

2017-01-14 Thread Philip McGrath
I am trying to use Scribble to produce nicely-formatted tables of data.
Some of these tables are both longer and wider than one printed page.

I would like to handle this similarly to typical spreadsheet programs,
which automatically create page breaks. Ideally, I'd also like to repeat
"header" rows and columns on each page. However, I'm not sure how to do
this in Scribble, or even if it can be done. (I don't know how to do this
in LaTeX, either.)

This little program demonstrates default Scribble behavior with massive
tables:

> #lang scribble/base
> @(require racket/list)
> @(define X 100)
> @(tabular #:sep " "
> (make-list X (map number->string (range X

The table is paginated vertically, but the excess width is simply truncated.

Is there a good way to get closer to what I'm looking for?

If not, it seems like the best thing for me to do would be to decide on a
maximum number of rows and columns per page and write code to produce
multiple tables, but this is far from ideal, especially as the results
would make little sense in HTML output. Better work-arounds would also be
welcome!

Thanks,
Philip McGrath

-- 
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] scribble defproc?

2017-01-15 Thread Philip McGrath
I would strongly consider using serial-lambda (from the web server
libraries:
http://docs.racket-lang.org/web-server-internal/closure.html?q=serial-lambda),
which creates a procedure that can be serialized using racket/serialize and
sent to a place, rather than (I assume) relying on eval. Alternatively, you
could implement a serializable-struct with prop:procedure that can be used
as a procedure.

-Philip

On Sun, Jan 15, 2017 at 10:32 PM, Andreas Olsson 
wrote:

> The function sends the lambda to a place, and places don't accept
> procedures, so a quoted lambda is the only option.
>
> --
> 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] Contracts not enforced with serial-lambda

2017-03-27 Thread Philip McGrath
I've been playing around with trying to attach contracts to serializable
procedures created with serial-lambda. What I've been trying to do hasn't
been working, and I've also come across some surprising behavior. For
example, this program:

> #lang racket
> (require web-server/lang/serial-lambda
>  racket/serialize
>  )
> (define/contract serial-add1
>   (-> number? number?)
>   (serial-lambda (i)
> "broken"))
> (serial-add1 "bad arg")

prints "broken", rather than raising an error for either the domain part or
the range part of the contract (neither of which pass).

I was expecting to potentially run into trouble with things like
deserialization, but I'm not at all sure why the contract in this simple
example isn't enforced.

Thanks,
Philip

-- 
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] A new OOP programming construct? [slightly long post]

2017-03-30 Thread Philip McGrath
I also find this problem annoying and would be very interested in a
linguistic solution (or alternatively a reason why I shouldn't be getting
myself into this problem so often).

Recently I've been trying to work this by writing functions like this,
which at least abstract out the boilerplate:

> (define (make-foo-mixin foo-field-key)
>   (define-member-name the-foo foo-field-key)
>   (mixin () ()
> (inspect #f)
> (super-new)
> (inherit-field the-foo)
> (public*
>  [my-method (λ () (send the-foo my-method))]
>  [another-method (λ (arg) (send the-foo another-method arg))]
>  )))


I would also note that essentially the same issue applies to programming
with racket/generic.




-Philip

On Thu, Mar 30, 2017 at 8:10 AM, Erich Rast  wrote:

> Dear all,
>
> This is something I've been wondering for a long time and at the same
> time it's a suggestion for implementation, since I'm not familiar
> enough with higher Racket macrology.
>
> Often when I define a class it contains instances of other classes. To
> access them as a user of an instance of the embedding class, you usually
> either (i) have to write an access wrapper method in the embedding
> class, or (ii) have to provide a getter method that returns the
> instance, so the 'client code' can access it directly. I believe (ii)
> is the general guideline used in the Racket source. Both result in a
> lot of boilerplate, (i) in the class definition and (ii) in the 'client
> code', especially if you have to additionally check that the object is
> initialized.
>
> My idea to reduce the boilerplate is to introduce a 'using' clause - or
> maybe there is a better term - that allows you to specify a class and
> some clauses similar to module exports. For example (maybe not the
> best syntax):
>
> (define foo%
>  (class object%
>   (using bar bar% (prefix-out bar: method1 method2))
>...
>   (super-new)))
>
> This would define an instance bar of bar% in a field and methods
> bar:method1 and bar:method2 within foo% that automatically are handed
> down to bar, i.e., they should be equivalent to:
>
> (define/public (bar:method1 ...)
>   (send bar method1 ...))
>
> Of course, the normal case would be to use the embedded object without
> any renaming, if there are no name conflicts, and it should allow
> for arbitrary renaming and generally the same amount of control as
> module declarations. I assume that some fine control over initialization
> methods of classes that are embedded that way is also needed, e.g. a
> way is needed to use bar%'s initialization arguments as initialization
> arguments of foo% with optional renaming, and a way  similar to
> super-new to provide bar's initialization arguments explicitly during
> initialization of foo%.
>
> I don't know of any OOP language that explicitly contains this kind of
> programming construct (maybe Java or Smalltalk?). Instead, I've seen a
> lot of boilerplate code in various languages to access embedded
> objects, and I have to admit that I write a lot of such code in Racket.
> Traits and Mixins get you closer to a solution, but do not seem to
> exemplify the same use pattern in general.
>
> Maybe this is not done because it violates some OOP principles or leads
> to an antipattern? If so, I'd be interested in hearing about it. If not,
> maybe some graduate student could implement it and write a paper about
> it? ;-) Anyway, I'd be interested in comments and in any case would love
> to have this an option in Racket's class system unless someone has a
> good argument against it.
>
> Best,
>
> Erich
>
>
>
> --
> Dr. Erich H. Rast, Research Fellow
> IFILNOVA Institute of Philosophy
> Av. de Berna, 26 - 4º Piso
> 1069-061 Lisbon, PORTUGAL
> http://home.snafu.de/erich/
> https://fcsh-unl.academia.edu/ErichRast
>
> --
> 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] syntax-parse: using expr/c with ~optional

2017-03-20 Thread Philip McGrath
Using expr/c to attach a contract to a macro sub-pattern doesn't seem to
work with ~optional, even when the attribute is bound with #:defaults.

For example, this program:

> #lang racket

(require (for-syntax syntax/parse))
> (define-syntax (example stx)
>   (syntax-parse stx
> [(_ (~optional (~seq #:return val)
>#:defaults ([val #'42])))
>  #:declare val (expr/c #'(or/c list? #f))
>  #'val.c]))
> (example)

reports the following error:

> val.c: bad attribute value for syntax template
>   attribute value: #f
>   expected for attribute: syntax
>   sub-value: #f
>   expected for sub-value: syntax in: val.c


Is there a better 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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Philip McGrath
I would do:
(with-input-from-string from-db
(λ () (deserialize (read
On Tue, Mar 21, 2017 at 4:48 PM Jon Zeppieri  wrote:

> On Tue, Mar 21, 2017 at 5:44 PM, Jon Zeppieri  wrote:
> > However, postgres (if that's what you're using)
> > has multidimensional arrays as a native type, so you could use those
> > [https://www.postgresql.org/docs/current/static/arrays.html]. The
> > Racket db package has a `pg-array` struct with conversion to/from
> > lists to help you.
> >
>
> Ah, except apparently `pg-array` only supports arrays with dimension
> 1. So... that won't help.
>
> --
> 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] syntax-parse: using expr/c with ~optional

2017-03-21 Thread Philip McGrath
Thanks! Is there an equivalent approach that works to replace ~optional as
a repetition constraint? Given:

(define-syntax (prefix stx)
>   (syntax-parse stx
> [(_ (~or (~seq nat:exact-nonnegative-integer)
>  (~optional (~seq #:tail tail)
> #:defaults ([tail #'null])))
> ...)
>  #:declare tail (expr/c #'(listof natural-number/c))
>  #'(list* nat ... tail.c)]))
> (define-syntax (prefix/parse stx)
>   (syntax-parse stx
> [(_ (~or (~seq nat:exact-nonnegative-integer)
>  (~or (~seq #:tail tail)
>   (~and (~seq) (~parse tail #'null
> ...)
>  #:declare tail (expr/c #'(listof natural-number/c))
>  #'(list* nat ... tail.c)]))


(prefix 6 5 4) raises the same error as before, and the definition of
prefix/parse complains "syntax-parse: duplicate attribute in: tail".

On Mon, Mar 20, 2017 at 1:18 PM Alex Knauth <alexan...@knauth.org> wrote:

>
> On Mar 20, 2017, at 11:04 AM, Philip McGrath <phi...@philipmcgrath.com>
> wrote:
>
> Using expr/c to attach a contract to a macro sub-pattern doesn't seem to
> work with ~optional, even when the attribute is bound with #:defaults.
>
> For example, this program:
>
> #lang racket
>
> (require (for-syntax syntax/parse))
> (define-syntax (example stx)
>   (syntax-parse stx
> [(_ (~optional (~seq #:return val)
>#:defaults ([val #'42])))
>  #:declare val (expr/c #'(or/c list? #f))
>  #'val.c]))
> (example)
>
> reports the following error:
>
> val.c: bad attribute value for syntax template
>   attribute value: #f
>   expected for attribute: syntax
>   sub-value: #f
>   expected for sub-value: syntax in: val.c
>
>
> Is there a better way to do this?
>
>
> This is because the `val` in the #:defaults is treated as just an
> attribute name, not a variable pattern, and syntax-classes like `expr/c`
> can only apply to variable patterns. One way to work around this is to use
> ~or and ~parse to put it in a pattern position:
>
> #lang racket
> (require (for-syntax syntax/parse))
> (define-syntax example
>   (syntax-parser
> [(_ (~or (~seq #:return val)
>  (~and (~seq) (~parse val #'42
>  #:declare val (expr/c #'(or/c list? #f))
>  #'val.c]))
> (example)
>
> This raises the contract violation you expected.
>
> Alex Knauth
>

-- 
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] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-22 Thread Philip McGrath
To work with strings for the database, do something like this:

(define (serialize-to-string v)
  (with-output-to-string
   (λ () (write (serialize v)
(define (deserialize-from-string str)
  (with-input-from-string str
   (λ () (deserialize (read)

On Tuesday, March 21, 2017 at 8:52:55 PM UTC-5, Marc Kaufmann wrote:
> Thanks, I will give that a try in the future, once I have time to look at PG 
> database (as I have some experience with Mysql, but none with PG). But that 
> would be exactly the kind of thing I was looking for.
> 
> 
> Cheers,
> 
> Marc
> 
> 
> 
> On Tue, Mar 21, 2017 at 8:47 PM, George Neuner  wrote:
> 
>   
> 
>   
>   
> 
> 
> 
> 
> On 3/21/2017 8:36 PM, Marc Kaufmann
>   wrote:
> 
> 
> 
>   
> 
> 
> Thanks. But I have to turn it into a
> string before storing it in the database; when I tried to
> store a serialized list in it (in a VARCHAR field), it
> complained that it expected a string. That's where all the
> trouble came from. The trouble I had was parsing the string
> back into the serialized form, which 'with-input-from-string
> does (because, I presume, it treats the contents of the
> string as the input, rather than the string itself). 
> 
> 
> 
>   
> Of course, if there is a way to store
>   serialized data directly in the database, that would be great
>   - but -- except for arrays in a Postgre database -- that
>   doesn't seem to be the case.
> 
>   
> 
> 
> 
> Serialize produce a list.  You might try storing it as JSON. 
> Postgresql can parse and search JSON values.
> 
> 
> 
> https://www.postgresql.org/docs/current/static/datatype-json.html
> 
> https://www.postgresql.org/docs/current/static/functions-json.html
> 
> 
> 
> 
> 
> 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.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Package documentation link issue

2017-04-11 Thread Philip McGrath
I recently posted a package "recaptcha", and I noticed a problem with the
documentation link that I'm not sure how to fix. Google stylizes the name
as reCAPTCHA, and I've capitalized it that way in the title of the
documentation, but I called the actual package "recaptcha" so that you can
"raco pkg install recaptcha" and "(require recaptcha)" as Racketeers would
expect.

The link from docs.racket-lang.org correctly points to
http://docs.racket-lang.org/reCAPTCHA/index.html; however, from
http://pkgs.racket-lang.org, the link points to
http://docs.racket-lang.org/recaptcha/index.html, which shows a 404 error
page. Is there something I need to specify in the package metadata to make
this work correctly? Or is this a problem with the catalog?

Thanks,
Philip

-- 
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] Names for flat-contract-with-explanation contracts

2017-04-11 Thread Philip McGrath
Is it possible to give a name to a contract created with
contract-with-explanation?

To illustrate, this example:

> #lang racket
> (define has-explanation/c
>   (flat-contract-with-explanation
>(λ (val)
>  (λ (blame)
>(raise-blame-error blame val
>   '(expected:
> "nothing would pass this"
> given: "~e")
>   val)
> (define/contract sample-violation
>   has-explanation/c
>   42)

prints this error message:

> sample-violation: broke its own contract
>   promised: nothing would pass this
>   produced: 42
>   in: anonymous-flat-contract
>   contract from: (definition sample-violation)
>   blaming: (definition sample-violation)
>(assuming the contract is correct)

which is wonderful, except for the "anonymous-flat-contract" part.

If I try to give it a name with rename-contract, it loses the custom error
reporting: e.g. this example:

> (define/contract sample-violation/renamed
>   (rename-contract has-explanation/c
>'renamed:has-explanation/c)
>   42)

prints this:

> sample-violation/renamed: broke its own contract
>   promised: renamed:has-explanation/c
>   produced: 42
>   in: renamed:has-explanation/c
>   contract from:
>   (definition sample-violation/renamed)
>   blaming: (definition sample-violation/renamed)
>(assuming the contract is correct)


The same thing happens with flat-named-contract: e,g, this

> (define/contract sample-violation/flat-named
>   (flat-named-contract 'flat-named:has-explanation/c
>has-explanation/c)
>   42)

prints this:

> sample-violation/flat-named: broke its own contract
>   promised: flat-named:has-explanation/c
>   produced: 42
>   in: flat-named:has-explanation/c
>   contract from:
>   (definition sample-violation/flat-named)
>   blaming: (definition sample-violation/flat-named)
>(assuming the contract is correct)

-- 
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] Scribbling documentation for a module beginning with _

2017-04-13 Thread Philip McGrath
I'm trying to write documentation for a module named _-exp, and I'm running
into a problem because (I think) of the way underscores are treated by
racketblock

.

Using @defmodule[_-exp #:lang] or @racketmodname[_-exp] typesets the name
as *-exp .*

I can work around this for defmodule by doing

@defmodule[@racketmodfont{_-exp}
   #:module-paths (_-exp)
   #:lang]

but I haven't found a solution for linking to the definition. I'm currently
trying @racketmodlink[_-exp @racketmodfont["_-exp"]], but this causes raco
setup to complain:

WARNING: undefined tag in /_-exp/scribblings/_-exp.scrbl:
raco setup:  (mod-path "_-exp")

and indeed the link does not work.

In my local documentation search results, _-exp  language shows up as
expected, so I think the problem is with the link, not the definition, but
I'm not sure how to fix this.

Philip

-- 
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] Preventing browser frame from terminating evaluation thread?

2017-04-18 Thread Philip McGrath
I don't have an explanation (I just guessed exit was being called
somewhere), but the exit handler did have an effect. The example program
quit with "Interactions disabled" in DrRacket, whereas this program does
not (and does display "Called exit"):

#lang racket

(require browser)

(define really-hyper-frame%
  (class hyper-frame%

(super-new)

(define (on-close)
  (displayln "Closing!")
  ;; But, how do I prevent the evaluation thread
  ;; from terminating? For example, if I want to launch
  ;; a browser frame from interactions in a GUI application?
  )
(augment on-close)
))

(exit-handler
 (λ (x) (displayln "Called exit")))

;; I'm aware the example is from the module level, but the same issue
applies if
;; I create the frame as a result of, say, a button% click.
(new really-hyper-frame%
 [label "The Frame"]
 [start-url "https://racket-lang.org/;])


Also, closing the frame in this tiny example:

#lang racket/gui

(exit-handler
 (λ (x) (displayln "Called exit")))

(send (new frame%
   [label "hypo-frame"])
  show
  #t)

neither disables interactions not displays "Called exit".

-Philip

On Tue, Apr 18, 2017 at 7:11 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> I don't think setting the exit handler will have an effect. The example
> application quits because an implicit `yield` finishes when the window
> is closed, and then the GUI handler thread has nothing else to do, so
> it exits.
>
> You could add an explicit `yield`, to allow events to be handled, and
> then do more after that `yield` returns:
>
>  (require racket/gui/base)
>  (yield (current-eventspace))
>
>  (printf "do more here...\n")
>
> Or you could make `yield` wait on a semaphore that is never posted, so
> that the application doesn't quit until `exit` is called.
>
> At Mon, 17 Apr 2017 23:53:49 -0500, Philip McGrath wrote:
> > It's a little ugly, but you can change the exit handler:
> > (exit-handler
> >  (λ (x) (displayln "Called exit")))
> >
> > -Philip
> >
> > On Mon, Apr 17, 2017 at 8:57 PM, Matt Jadud <jad...@gmail.com> wrote:
> >
> > > Hi all,
> > >
> > > I would like to spawn a browser frame, but I'd like it if the frame did
> > > not terminate the thread when I close it. I'm having a hard time
> figuring
> > > out what I should override/augment or catch so that I can spawn the
> frame
> > > from within a GUI application, let the user close the frame, and not
> have
> > > the whole application terminate.
> > >
> > > Cheers,
> > > Matt
> > >
> > > #lang racket
> > >
> > > (require browser)
> > >
> > > (define really-hyper-frame%
> > >   (class hyper-frame%
> > >
> > > (super-new)
> > >
> > > (define (on-close)
> > >   (printf "Closing!")
> > >   ;; But, how do I prevent the evaluation thread
> > >   ;; from terminating? For example, if I want to launch
> > >   ;; a browser frame from interactions in a GUI application?
> > >   )
> > > (augment on-close)
> > > ))
> > >
> > > ;; I'm aware the example is from the module level, but the same issue
> > > applies if
> > > ;; I create the frame as a result of, say, a button% click.
> > > (new really-hyper-frame%
> > >  [label "The Frame"]
> > >  [start-url "https://racket-lang.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.
> > > 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.
>

-- 
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] macro definitions with #lang racket/base vs #lang racket

2017-03-14 Thread Philip McGrath
#lang racket also provides racket/base in the transformer environment.

-Philip

On Tue, Mar 14, 2017 at 5:45 AM, NeverTooOldToCode 
wrote:

> From Fear of Macros again, all input in the DrRacket definition window.
>
> This works:
>
> #lang racket/base
>
> (require (for-syntax racket/base))
>
> (define-syntax (show-me stx)
>   (display stx)
>   #'(void))
>
> If you mouse-hover over the keywords, define-syntax is imported from #lang
> racket/base, and display and #' are imported (require (for-syntax
> racket/base)).
> Because display and #' are needed at compile time, not run time.
>
> Therefore, logically, this doesn't work:
>
> #lang racket/base
>
> (define-syntax (show-me stx)
>   (display stx)
>   #'(void))
>
> Gives the error:
> display: unbound identifier in the transformer environment; also, no #%app
> syntax transformer is bound in: display
> And if we remove the display statement, the same error for #'
>
> So far so good.
>
> BUT
>
> Why does this work?
>
> #lang racket
>
> (define-syntax (show-me stx)
>   (display stx)
>   #'(void))
>
> Now define-syntax *and* display *and* #' are directly imported from #lang
> racket. What about compile time vs run time? What does #lang racket do
> apart from including many libraries on top of racket/base?
>
> --
> 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] refactoring help/tools?

2017-03-13 Thread Philip McGrath
raco check-requires might do some of what you want.

-Philip

On Mon, Mar 13, 2017 at 12:18 PM, Jay McCarthy 
wrote:

> racket-mode in Emacs does this
>
> Jay
>
> On Mon, Mar 13, 2017 at 1:17 PM Dan Liebgold 
> wrote:
>
>> Hi -
>>
>> In refactoring a some Racket code I'd love to have a "require and provide
>> only what you need" tool to help trim down the require and provide lists.
>> Is there such a thing? Or at least a better approach for this than
>> inspection or trial and error?
>>
>> Thanks,
>> Dna
>>
>> --
>> 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.
>>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-
>
> --
> 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] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-13 Thread Philip McGrath
Numbers in x-expressions are interpreted as XML entities, not as the string
representation of the number. The value of (xexpr->string '(html 1)), to
use your example, is "". The 1 represents the character
that Racket would represent as #\u0001, i.e. the value of (integer->char
1). In contrast, (char->integer #\1) produces 49.

-Philip

On Mon, Mar 13, 2017 at 8:38 PM, Marc Kaufmann 
wrote:

> Hi,
>
> I am creating matrices of 0s and 1s that I display in HTML-tables and
> somewhat surprisingly I found out that 0s are not permissible in
> X-expressions, while 1s are:
>
> (require web-server/http)
>
> (response/xexpr '(html 1)) ; Fine, no trouble.
> (response/xexpr '(html 0)) ; Blow-up.
>
> The specific violation is the following:
>
> "response/xexpr: contract violation;
>  Not an Xexpr. Expected a string, symbol, valid numeric entity, comment,
> processing instruction, or list, given 0"
>
> After some digging around, it turns out that only numbers that satisfy
> valid-char? are acceptable, which means "exact-nonnegative-integer whose
> character interpretation under UTF-8 is from the set ([#x1-#xD7FF] |
> [#xE000-#xFFFD] | [#x1-#x10]), in accordance with section 2.2 of
> the XML 1.1 spec."
>
> First, should 0 really not be accepted? (I am not going to try and figure
> out the UTF-8 interpretation...) And second, is the reason that negative
> numbers are not acceptable that they are not under the XML spec above? This
> took me by surprise and means I have to put number->string in a bunch of
> places.
>
> 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.
> 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] How to build new formlets that allow passing default values (such as hidden)?

2017-03-14 Thread Philip McGrath
In this case it will work despite being a hack, because you know that your
id argument affects only the display stage, not the processing stage:
however, you can't know in general that this will work for dynamically
generated formlets, and personally I would therefore be reluctant to rely
on this, both because it is fragile in terms of changes to your
implementation of matrix-formlet that you might make later.

If you are using native continuations (i.e. not the stateless #lang
web-server), you can use send/formlet or embed-formlet to deal with this
correctly and easily. (At a lower level, you could also do something like

> (define-values (xexpr-forest bindings->result i)
>   ((matrix-formlet "3") 0))

to access the low-level rendering, processing function, and next allowable
input integer directly.)

It is a little more tricky in #lang web-server, because your formlet and
it's generated processing function are plain functions, and thus not
serializable (see this old thread for discussion:
https://groups.google.com/d/topic/racket-users/lMYWjodgpmo/discussion). The
easy work-around is to keep the arguments you need to reproduce your
formlet around as part of the closure, e.g. by rewriting your
matrix-submission like this:

> (define (matrix-submission req id)
>   (define-values (number-of-ones user-id)
>   (formlet-process (matrix-formlet id) req))
>   ...)

The alternative is to either recompile the formlet library using #lang
web-server/base or to implement your formlet at a low level using
serial-lambda and not use any of the library tools.

In this specific case, though, if you are using this hidden input field
just to remember the user id from one request to the next (i.e. you
wouldn't ever change it on the client side with JavaScript or something),
the best solution is not to put it in the form at all, but have it be part
of the continuation. This could also have security advantages, if you
cryptographically sign your continuations or store them on the server. If
that works for your use case, you could simply write:
(define matrix-formlet
  input-string)
display it with

> (matrix-submission
>  (send/suspend
>   (λ (k-url)
> (response/xexpr
>  `(html (body (form
>((action "/the-matrix-submitted")
> (method "post"))
>,@(formlet-display matrix-formlet)
>(input ([type "submit"]
>  user-id)

and then define matrix-submission as

> (define (matrix-submission req user-id)
>   (define number-of-ones
>   (formlet-process matrix-formlet req))
>   ...)


-Philip

On Tue, Mar 14, 2017 at 12:01 PM, Marc Kaufmann 
wrote:

> Hi,
>
> I have created a formlet like so:
>
> (define (matrix-formlet id)
>   (formlet
> (#%# ,{input-string . => . ones}
>  ,{(to-string (required (hidden id))) . => . user-id}
>  )
> (values ones user-id)))
>
> I display this as follows:
>
> `(form
>   ((action "/the-matrix-submitted")
>(method "post"))
>  ,@(formlet-display (matrix-formlet user-id))
>  (input ([type "submit"]
>
> and process it like this:
>
> (define (matrix-submission req)
>   (define-values (number-of-ones user-id)
>  (formlet-process (matrix-formlet "3") req))
>   ...)
>
> While this works, the formlet I use to display and process are not really
> the same, since they are created on the spot, and created with different
> parameters. So far it seems to work, but I am worried that this will break
> down, and clearly this isn't the right way to go about creating
> parametrizable formlets.
>
> The questions are (i) is the above going to work despite being a hack, and
> (ii) is there a correct and easy way to do the same thing?
>
> 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.
> 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] Scrolling in racket/gui

2017-03-01 Thread Philip McGrath
This seems like it should be a simple question, but I can't figure out how
to get a scroll bar in a gui application like this one:

#lang racket/gui
> (define frame
>   (new frame% [label "Example"]))
> (for ([letter '("A" "B" "C" "D")])
>   (define grp
> (new group-box-panel%
>  [parent frame]
>  [label letter]))
>   (for ([i (in-range 0 10)])
> (new button%
>  [parent grp]
>  [label (number->string i)])))
> (send frame show #t)


I can see something like what I have in mind in Dr. Racket's
"Colors">"Color Schemes" preferences tab (at least on Mac OS), but I can't
figure out how to do it.

Thanks,
Philip

-- 
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] Preventing browser frame from terminating evaluation thread?

2017-04-17 Thread Philip McGrath
It's a little ugly, but you can change the exit handler:
(exit-handler
 (λ (x) (displayln "Called exit")))

-Philip

On Mon, Apr 17, 2017 at 8:57 PM, Matt Jadud  wrote:

> Hi all,
>
> I would like to spawn a browser frame, but I'd like it if the frame did
> not terminate the thread when I close it. I'm having a hard time figuring
> out what I should override/augment or catch so that I can spawn the frame
> from within a GUI application, let the user close the frame, and not have
> the whole application terminate.
>
> Cheers,
> Matt
>
> #lang racket
>
> (require browser)
>
> (define really-hyper-frame%
>   (class hyper-frame%
>
> (super-new)
>
> (define (on-close)
>   (printf "Closing!")
>   ;; But, how do I prevent the evaluation thread
>   ;; from terminating? For example, if I want to launch
>   ;; a browser frame from interactions in a GUI application?
>   )
> (augment on-close)
> ))
>
> ;; I'm aware the example is from the module level, but the same issue
> applies if
> ;; I create the frame as a result of, say, a button% click.
> (new really-hyper-frame%
>  [label "The Frame"]
>  [start-url "https://racket-lang.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.
> 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] Trouble with "on delete cascade" using sqlite

2017-04-18 Thread Philip McGrath
The following program returns '(#("demo" "j...@example.com")), whereas I
think it should return '(), because I expect deleting the row from "tUsers"
to delete the corresponding row in "tEmail". Is this a bug in the db
library (or elsewhere, or am I doing something wrong)?

#lang at-exp racket

(require db)

(define db
  (sqlite3-connect #:database 'memory))

(query-exec db
@~a{
CREATE TABLE tUsers (
userUUID TEXT NOT NULL,
userName TEXT NOT NULL,
PRIMARY KEY (userUUID)
)
})

(query-exec db
@~a{
CREATE TABLE tEmail (
userUUID TEXT NOT NULL,
userEmail TEXT NOT NULL,
PRIMARY KEY (userUUID,userEmail),
FOREIGN KEY (userUUID) REFERENCES tUsers
ON DELETE CASCADE ON UPDATE CASCADE
)
})

(query-exec db
"INSERT INTO tUsers (userUUID,userName) VALUES (?,?)"
"demo"
"Jane Doe")

(query-exec db
"INSERT INTO tEmail (userUUID,userEmail) VALUES (?,?)"
"demo"
"j...@example.com")

(query-exec db
"DELETE FROM tUsers WHERE userUUID = ?"
"demo")

(query-rows db "SELECT * FROM tEmail")

-- 
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] Trouble with "on delete cascade" using sqlite

2017-04-18 Thread Philip McGrath
Thanks, that solved it!

-Philip

On Tue, Apr 18, 2017 at 4:54 PM, David Storrs <david.sto...@gmail.com>
wrote:

> IIRC, SQLite defaults to PRAGMA foreign_keys = OFF when you open a
> database.  Without FKs being on there is nothing for the CASCADE to trigger
> on.  You'll need to turn the FKs on before it will work.
>
> Just add this line before the first 'insert into tUsers' and then it will
> work:
>
> (query-exec db "PRAGMA foreign_keys = ON")
>
>
> On Tue, Apr 18, 2017 at 5:33 PM, Philip McGrath <phi...@philipmcgrath.com>
> wrote:
>
>> The following program returns '(#("demo" "j...@example.com")), whereas I
>> think it should return '(), because I expect deleting the row from "tUsers"
>> to delete the corresponding row in "tEmail". Is this a bug in the db
>> library (or elsewhere, or am I doing something wrong)?
>>
>> #lang at-exp racket
>>
>> (require db)
>>
>> (define db
>>   (sqlite3-connect #:database 'memory))
>>
>> (query-exec db
>> @~a{
>> CREATE TABLE tUsers (
>> userUUID TEXT NOT NULL,
>> userName TEXT NOT NULL,
>> PRIMARY KEY (userUUID)
>> )
>> })
>>
>> (query-exec db
>> @~a{
>> CREATE TABLE tEmail (
>> userUUID TEXT NOT NULL,
>> userEmail TEXT NOT NULL,
>> PRIMARY KEY (userUUID,userEmail),
>> FOREIGN KEY (userUUID) REFERENCES tUsers
>> ON DELETE CASCADE ON UPDATE CASCADE
>> )
>> })
>>
>> (query-exec db
>> "INSERT INTO tUsers (userUUID,userName) VALUES (?,?)"
>> "demo"
>> "Jane Doe")
>>
>> (query-exec db
>> "INSERT INTO tEmail (userUUID,userEmail) VALUES (?,?)"
>> "demo"
>> "j...@example.com")
>>
>> (query-exec db
>> "DELETE FROM tUsers WHERE userUUID = ?"
>> "demo")
>>
>> (query-rows db "SELECT * FROM tEmail")
>>
>> --
>> 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] Setting parameters between files does not work as expected

2017-04-24 Thread Philip McGrath
Another thing that might be relevant:
>
> In contrast, direct assignment to a parameter (by calling the parameter
> procedure with a value) changes the value in a thread cell, and therefore
> changes the setting only for the current thread.
> http://docs.racket-lang.org/reference/parameters.html


Also, do you want multiple underlying connections of the same virtual
connection to potentially use different values for the
user/database/password/port?

If not, the most recent way I've dealt with this sort of thing is to come
up with some type of "database connection spec" — for a quick example, I'll
use a hash table — and then do some things with parameter guards, opaque
structures, and a tiny macro to keep the details away from higher-level
code.

I think code might be clearer than a description, so here's a minimal
sketch:

#lang racket

(require db
 )

(struct database-handle (promise))

(define database-spec/c
  (or/c database-handle?
(hash/dc [k (or/c 'user 'database 'password 'port)]
 [v (k)
(case k
  [(user database password)
   string?]
  [(port)
   natural-number/c]
  [else none/c])])))

(define default-database-spec
  #hasheq([user . "postgres"]
  [database . "test-db"]
  [password . "mellon"]
  [port . 5433]))


(define/contract current-database-handle
  (parameter/c database-spec/c database-handle?)
  (let ([initialize
 (λ (spec)
   (if (database-handle? spec)
   spec
   (let ([u (hash-ref spec 'user)]
 [d (hash-ref spec 'database)]
 [p (hash-ref spec 'password)]
 [prt (hash-ref spec 'port)])
 (database-handle
  (delay (virtual-connection
  (connection-pool
   (λ ()
 (postgresql-connect
  #:user u
  #:database d
  #:password p
  #:port prt
  )])
(make-parameter (initialize default-database-spec)
initialize)))

(define-syntax db
  (syntax-id-rules ()
[_ (force (database-handle-promise (current-database)))]))

(provide database-handle? ;keep constructor & accessor private
 database-spec/c
 current-database-handle
 db
 )



On Mon, Apr 24, 2017 at 7:19 PM, David Storrs 
wrote:

>
>
> On Mon, Apr 24, 2017 at 4:43 PM, Scott Moore  wrote:
>
>> Parameters are thread local, and from reading the docs of
>> virtual-connection and connection-pool, I think they create new threads to
>> handle the connections. These threads are probably created before you
>> parameterize, and thus see the original values.
>>
>> Try replacing the virtual-connection stuff with a single call to
>> do-connect, and see if that works. (Obviously not the real fix, but may
>> help identify the error).
>>
>>
> This was exactly it.  Thanks, Scott.
>
> Now I just need to figure out how to work around it.
>
>
>> On Apr 24, 2017, 4:35 PM -0400, David Storrs ,
>> wrote:
>>
>> I'm finding parameters confusing and was hoping someone could explain
>> them for me.  The following is a simplified version of our production code;
>> I'm expecting it to fail but it does not.  What am I not understanding?
>>
>> The sequence goes:
>>
>> *) db.conf creates and provides some parameters (db username, db
>> password, db name, db port) and a function for creating database
>> connections using those parameters
>>
>> *) dbstuff.rkt requires db.conf, re-provides the parameters from db.conf,
>> and also provides a wrapper around the db connector from db.conf
>>
>> *) bar.rkt parses the command line, uses that command line data to set
>> the parameters that were imported from db.conf by way of dbstuff.rkt and
>> makes a DB call
>>
>> *) I run bar.rkt from the command line with an invalid username for the
>> database, expecting it to fail to connect, but it works fine???
>>
>>
>>
>> My first guess was that since I was using the parameters as default
>> values perhaps they were being evaluated at compile time instead of
>> runtime.  I tried changing the default value to #f and then doing (or u
>> (db-user)) in the body of the function, but that had no effect.
>>
>> I am utterly baffled at this point.  Any help would be much appreciated.
>>
>>
>>
>> # file: "db.conf"
>> #lang racket
>>
>> (require db)
>>
>> (define db-user (make-parameter "postgres"))
>> (define db-name (make-parameter "test-db"))
>> (define db-password (make-parameter "mellon"))
>> (define db-port-num (make-parameter 5433))
>>
>> (define (do-connect #:u [u (db-user)]
>> #:d [d (db-name)]

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-28 Thread Philip McGrath
Specifically, as Robby said earlier, `list?` is memoized, so e.g. (first
(rest (build-list 10 values))) only pays this price once. And `list?`
rejects pairs that have cycles.

-Philip

On Fri, Jul 28, 2017 at 5:51 AM, Matthias Felleisen 
wrote:

>
> first and rest were introduced in the teaching languages first when we
> decided it was about principles of design and cadadar was cute but nobody
> should have care.
>
> first and rest are about lists in other languages and the names say so.
> car and cdr are about pairs (not that their names say so) and should be
> called left and right.
>
> first and rest were applied to immutable cons-es in *SL, so we knew that
> no checks were needed.
>
> first and rest migrated to racket but we wanted them to be like those in
> *SL. So we checked. Fortunately, lists became immutable so
>
> list? is essentially O(1) and has negligible cost.
>
>
>
>
>
> On Jul 28, 2017, at 6:40 AM, Robby Findler 
> wrote:
>
> It could have been. I am not sure why (but it probably had something to do
> with better checking for the teaching languages, Matthias may recall more).
>
> Robby
>
> On Fri, Jul 28, 2017 at 4:19 AM Daniel Prager 
> wrote:
>
>> Interesting stuff, but if I may probe a little deeper into scheme
>> history, why couldn't first have simply been defined as a synonym for car
>> (i.e. first item in a pair) and rest a synonym for cdr?
>>
>> Dan
>>
>>
>> On Fri, Jul 28, 2017 at 6:09 PM, Neil Van Dyke 
>> wrote:
>>
>>> Daniel Prager wrote on 07/28/2017 01:03 AM:
>>>
 > `first` and `rest` need to check if the input is a list.

 Why is that?

>>>
>>> When Racket/Scheme/Lisp people speak of checking whether something is a
>>> list, I think they usually mean in the sense of the predicate `list?` (or
>>> `listp`), which is usually an O(n) test for whether a value is a
>>> properly-formed list of pairs (or cons cells) terminated by a null.
>>>
>>> One reason people sometimes do the expensive list check is because it
>>> can be good practice (to have your procedure check its arguments at entry,
>>> so it can say the bug is not its fault, as early as possible).  Teaching
>>> languages are one place I don't think anyone would question whether this is
>>> good practice.
>>>
>>> Another possible reason is that, unless the cost of `list?` has
>>> previously been pointed out to you, it's easy to just use it without even
>>> considering whether it might be expensive.  Even once I knew this, I still
>>> did this at least once, myself.
>>>
>>> When writing list-processing code that has to deal with potentially
>>> large lists, if you're not using a type system that avoids the expensive
>>> `list?` cost, IMHO, it's usually OK for an initial argument type check to
>>> use a `pair?`/`null?` in lieu of `list?`, or possibly do no initial check
>>> at all.  If you want to provide better exceptions on improper lists, you
>>> can check for list correctness as you proceed with your algorithm, and
>>> raise an exception yourself (such as including the original argument value,
>>> which info would not be in the exception if, say, `cdr` raised it).
>>>
>>> BTW, if you want to be professional about list-processing code you write
>>> for use with potentially arbitrary lists, it's good to remember that lists
>>> can have cycles, and... uh, you can usually just document that "behavior is
>>> undefined" for lists with cycles. :) Especially since today you're usually
>>> dealing with immutable pairs, in modern Racket, where cycles are much less
>>> likely than they were when we used `set-cdr!`.  (Or, if you can't afford to
>>> hang in an infinite loop on cycles that are reasonably plausible, and you
>>> don't mind slowing down and complicating things a little, and you don't
>>> mind having a maximum list size for your procedure, you can keep a counter
>>> during what could otherwise be an infinite loop in your algorithm, which
>>> you can then keep checking, to decide whether to raise an exception.  Or
>>> you can do it a harder way, like one of "https://en.wikipedia.org/
>>> wiki/Cycle_detection".[1]  Or you could use a less-basic
>>> language/platform facility, and raise an exception if some limit of compute
>>> resource or time is reached for that procedure call.)
>>>
>>>
>>> [1] Tangential story about school and industry.  The first time that I
>>> hit a speed bump in a software development interview was a long time ago,
>>> when some CS student co-founder of a video game startup asked me how to
>>> detect whether a linked list had cycles.  So, having some schooling and
>>> experience by that time, but not recalling this problem from when I took
>>> Data Structures & Algorithms years earlier, I started working through the
>>> problem, while trying to ignore distracting social cues that the
>>> interviewer might not have realized he was making--  Then the interviewer
>>> tells me he'd recently 

Re: [racket-users] Menu bar won't show

2017-08-14 Thread Philip McGrath
I suspect the confusion is that on Mac OS, the menu-bar% is drawn at the
top of the screen (the same as DrRacket's "File" menu etc.), not inside the
window itself. This code is working for me with Racket 6.9 on Mac OS
10.12.5.

-Philip

On Mon, Aug 14, 2017 at 7:09 PM, James  wrote:

> I'm having trouble getting a simple example of a menu bar to work.  The
> window appears with the correct frame size but no menus.  This happens
> whether I follow the example on the Stack Overflow page below or the
> example code I have shown below.  Is this a bug or do I need to do
> something more to make the menu bar show?  I am using DrRacket 6.10 macOS
> 10.11.6 "El Capitan."  To be on the safe side, I also tried it on an older
> machine with Racket 6.6 and Mac OS X 10.6.8 "Snow Leopard" but I got the
> same result.
>
> https://stackoverflow.com/questions/37583997/basic-code-
> editor-functionality-in-racket
>
> ;Example code:
>
> #lang racket
>
> (require racket/gui)
>
> (define frame (new frame%
>  [label "Example"]
>  [width 600]
>  [height 300]))
>
>
> (define menu-bar (new menu-bar%
>   (parent frame)))
> (define file-menu (new menu%
>  (label "")
>  (parent menu-bar)))
>
> (define edit-menu (new menu%
>  (label "")
>  (parent menu-bar)))
>
> (define help-menu (new menu%
>  (label "")
>  (parent menu-bar)))
>
> (new menu-item%
>  (label "Foo")
>  (parent file-menu)
>  (callback (lambda (x y) x)))
>
> ;(send menu-bar enable #t)
> (send frame show #t)
>
> --
> 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] Adding terms to Scribble table of contents

2017-07-07 Thread Philip McGrath
I am trying to use Scribble to document some things that are not Racket
bindings. I can get the linking and typesetting behavior I want by building
on top of elemtag and elemref, but I would also like the defining instances
to be added to the table of contents in the same way as bindings defined
using defproc and friends. Is there a mechanism to do this?

Thanks,
Philip

-- 
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] Pixelated results from pict->bitmap

2017-07-13 Thread Philip McGrath
Bitmaps created using pict->bitmap look pixelated to me on screen (on Mac
OS in "Retina" mode, which I suspect might be relevant). I initially
discovered this when using picts as labels for message% instances like this:

#lang racket/gui

(require pict)

(define f
  (new frame%
   [label "Example"]))

(new message%
 [parent f]
 [label (pict->bitmap (disk 100))])


(new canvas%
 [parent f]
 [style '(transparent)]
 [min-width 100]
 [min-height 100]
 [paint-callback (λ (c dc)
   (draw-pict (colorize (disk 100) "green")
  dc
  0
  0))])
(send f show #t)


The black disk in the above is pixelated for me, while the green one drawn
on a canvas looks normal.

I also noticed as I was writing this that evaluating (pict->bitmap (disk
100)) in the DrRacket REPL produces a pixelated result compared to
evaluating (disk 100).

Is there either a way to avoid this in general, or else a recommended way
to do the equivalent of using picts for message% labels in particular? (I
suppose I could subclass canvas% …)

Thanks,
Philip

-- 
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] Scribble PDF output breaks when using include-section with scribble/lp2

2017-07-14 Thread Philip McGrath
I have a document written in #lang scribble/manual that used
include-section to include a section written in #lang scribble/lp2. It
renders perfectly to HTML, and I can render both the literate program and
the main document, with the inclusion of the literate program commented
out, to PDF individually.

However, when the include-section is present, generating PDF output fails
with an error "run-pdflatex: got error exit code" (or "run-xelatex: got
error exit code", or "run-dvipdf-latex: got error exit code"). From
skimming the extremely long output to STDERR, it is not immediately obvious
what is going wrong: the line above the Racket error message reads "output
written on guidelines.pdf (17 pages)."

Especially oddly, running scribble with --latex and then manually making
the PDF works, except that the table of contents is blank.

Any thoughts on how to debug this?

Thanks,
Philip

-- 
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] ?

2017-07-16 Thread Philip McGrath
Could you share the code that is producing the error? The following, for
example, defines a struct with two fields:

(struct point (x y))

-Philip

On Sun, Jul 16, 2017 at 7:23 AM, Masto Fine 
wrote:

> i have a problem , i want to define a structure white many fields in the
> definition screen and the computer say me : "excpected nothing after the
> field name but found one extra part",cannot i program a function whit more
> than one part?
> bonjour , j'ai un probleme avec la creation de definitions , j'essaye de
> probgramme une strucure a plusieur champs ( une serie de lignes ) et le
> logiciel me repond toujours expected nothing after the field name but found
> one extra part , quel est le probleme ?
>
> --
> 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] Replacing multiple characters in a string?

2017-07-08 Thread Philip McGrath
This works, for instance (and I would much prefer case to hash-ref):

#lang typed/racket

(regexp-replace* #rx"[ABC]"
 "ABCABC"
 (λ ([c : String] . _)
   (case c
 [("A") "AC"]
 [("B") "BA"]
 [("C") "CCA"]
 [else (error 'bad-match c)])))

-Philip

On Sat, Jul 8, 2017 at 8:14 AM, Alasdair McAndrew  wrote:

> Many thanks - that works fine!  And it makes sense, to use regexp-replace*
> with a hash table.  (All these things I'm still finding out...)  Is it
> possible to do this - or something similar - in Typed Racket?
>
> On Saturday, 8 July 2017 22:45:04 UTC+10, Neil Van Dyke  wrote:
> > This is one OK way that people are likely to do:
> >
> >
> > #lang racket/base
> >
> > (define (foo str)
> >(regexp-replace* #rx"[ABC]"
> > str
> >(lambda (s)
> >  (hash-ref #hash(("A" . "AC")
> >  ("B" . "BA")
> >  ("C" . "CCA"))
> >s
> >
> > (module+ test
> >(require rackunit)
> >(check-equal? (foo "") "")
> >(check-equal? (foo "ABCABC")   "ACBACCAACBACCA")
> >(check-equal? (foo "ABCDABCD") "ACBACCADACBACCAD"))
> >
> >
> > It's not necessarily the most maintainable (note the duplicated info
> > between the regexp and the map) nor most efficient, but it's OK, IMHO.
>
> --
> 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] Contracts in interrelated signatures

2017-07-08 Thread Philip McGrath
Working through the chapter on units in the Racket guide, it shows how to
translate the comment-specified contracts on toy-factory^ to enforced
contracts:

(define-signature contracted-toy-factory^
  ((contracted
[build-toys (-> integer? (listof toy?))]
[repaint(-> toy? symbol? toy?)]
[toy?   (-> any/c boolean?)]
[toy-color  (-> toy? symbol?)])))


I am trying to figure out how you would create an analogous
contracted-toy-store^ from the example toy-store^:

(define-signature toy-store^
  (store-color ; (-> symbol?)
   stock!  ; (integer? -> void?)
   get-inventory)) ; (-> (listof toy?))


The complication here is that the contract for get-inventory needs to have
a binding for toy?, which implicitly comes from the toy-factory^ signature.

Ultimately what I'm trying to do is to create mutually dependent units
along the lines of store-specific-factory@ from the linking example, but
where the factory could rely on the results of get-inventory being toys
according to its notion of toy?, as created by build-toys.

I have the sense that open or extends might be part of the answer, but, if
they are what I need to use, I haven't figured out how to use them properly
yet.

Thanks,
Philip

-- 
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] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
I'm confused about why the following program is blaming the server for the
client's misuse of an applicable struct instance. More generally, I've
tried doing this in several different ways, and I can't figure out how to
make applicable structs that are still protected by contracts after
deserialization and blame the client module for misusing them.

Thanks,
Philip

#lang racket

(module server racket
  (require racket/serialize)
  (provide (contract-out
[adder (-> natural-number/c (-> natural-number/c
natural-number/c))]))
  (struct adder (base)
#:property prop:procedure
(λ (this x)
  (+ (adder-base this) x))
#:property prop:serializable
(make-serialize-info (λ (this) (vector (adder-base this)))
 #'deserialize-info:adder-v0
 #f
 (or (current-load-relative-directory)
 (current-directory
  (define/contract make-adder
(-> natural-number/c (-> natural-number/c
 natural-number/c))
adder)
  (define deserialize-info:adder-v0
(make-deserialize-info make-adder
   (λ () (error 'adder
"can't have cycles"
  (module+ deserialize-info
(provide deserialize-info:adder-v0)))


(require 'server racket/serialize)

((deserialize (serialize (adder 5))) 'not-a-number)

-- 
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] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
Aha — so it isn't really an issue with serialization at all. If I (now)
understand this correctly, when a function produces a contracted
higher-order result, it is the responsibility of the caller of the original
function to ensure that the result function is always applied to
appropriate arguments. That would explain why this version
blames intermediary:

#lang racket

(module server racket
  (provide (contract-out
[adder (-> natural-number/c (-> natural-number/c
natural-number/c))]))
  (struct adder (base)
#:property prop:procedure
(λ (this x)
  (+ (adder-base this) x
(module intermediary racket
  (require (submod ".." server))
  (provide add5)
  (define add5
(adder 5)))
(require 'intermediary)
(add5 'not-a-number)


I had previously intuited that the obligation would be on the caller of the
result function, whoever that might be.

When serialization is in the mix, is there a correct way for server to
protect itself from instances of adder being abused after they are
deserialized?


-Philip

On Sun, Jul 23, 2017 at 8:16 PM, Matthias Felleisen <matth...@ccs.neu.edu>
wrote:

>
> On Jul 23, 2017, at 8:54 PM, Philip McGrath <philip.mcgr...@gmail.com>
> wrote:
>
> I'm confused about why the following program is blaming the server for the
> client's misuse of an applicable struct instance. More generally, I've
> tried doing this in several different ways, and I can't figure out how to
> make applicable structs that are still protected by contracts after
> deserialization and blame the client module for misusing them.
>
> Thanks,
> Philip
>
> #lang racket
>
> (module server racket
>   (require racket/serialize)
>   (provide (contract-out
> [adder (-> natural-number/c (-> natural-number/c
> natural-number/c))]))
>   (struct adder (base)
> #:property prop:procedure
> (λ (this x)
>   (+ (adder-base this) x))
> #:property prop:serializable
> (make-serialize-info (λ (this) (vector (adder-base this)))
>  #'deserialize-info:adder-v0
>  #f
>  (or (current-load-relative-directory)
>  (current-directory
>   (define/contract make-adder
> (-> natural-number/c (-> natural-number/c
>  natural-number/c))
> adder)
>
>
>
>
> You defined make-adder with a contract. As far as it is concerned, its
> contract is with the surrounding module, which is server. Hence if it is
> misapplied, the server broke the contract of always protecting its entry
> channels (with a natural-number/c test).
>
>
>
>
>
>   (define deserialize-info:adder-v0
> (make-deserialize-info make-adder
>(λ () (error 'adder
> "can't have cycles"
>   (module+ deserialize-info
> (provide deserialize-info:adder-v0)))
>
>
> (require 'server racket/serialize)
>
> ((deserialize (serialize (adder 5))) 'not-a-number)
>
> --
> 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] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
Here is the problem with serialization, without my attempts to mitigate it:

#lang racket

(module server racket
  (require racket/serialize)
  (provide (contract-out
[adder (-> natural-number/c (-> natural-number/c
natural-number/c))]))
  (serializable-struct adder (base)
#:property prop:procedure
(λ (this x)
  (+ (adder-base this) x
(require 'server racket/serialize)

;; would report a contract violation in terms of adder
;; and blame this module
;((adder 5) 'not-a-number)

;; reports a contract violation in terms of +
((deserialize (serialize (adder 5))) 'not-a-number)

-Philip

On Sun, Jul 23, 2017 at 9:02 PM, Matthias Felleisen 
wrote:

> [replying to myself]
>
>
> > On Jul 23, 2017, at 9:58 PM, Matthias Felleisen 
> wrote:
> >
> >
> > At some point I wrote all this up for the contract doc (as the opening
> paragraphs). I can’t see it right now.
>
>
> Still there:
>
>http://docs.racket-lang.org/guide/contract-boundaries.html
>
>
>
>

-- 
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] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
If I'm following correctly, I think that's what I was trying to do, but I'm
unclear how to give `make-deserialize-info` a variant of `make-adder` that
has a contract. The initial example with `define/contract` was the closest
I've come: it at least reported violations in terms of `make-adder` rather
than `+`, but (as I now understand) it blamed the `server` module for all
violations.

-Philip

On Sun, Jul 23, 2017 at 9:27 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> The original example had an explicit deserializer:
>
> At Sun, 23 Jul 2017 19:54:43 -0500, Philip McGrath wrote:
> >   (define deserialize-info:adder-v0
> > (make-deserialize-info make-adder
> >(λ () (error 'adder
> > "can't have cycles"
>
> You're constructing the deserializer with `make-adder` --- the variant
> from inside the `server` module, so it doesn't have a contract.
>
> I think this is where you want to draw a new boundary by giving
> `make-deserialize-info` a variant of `make-adder` that has a contract.
>
> --
> 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] Blame for contracts on applicable serializable structs

2017-07-24 Thread Philip McGrath
That is precisely the contract violation I'd like to see reported, but,
without the shadowing of serialize and deserialize, the error is reported
in terms of `+`. (And, if it wasn't clear, I do intend to actually read and
write the serialized instance.)

I (think) I understand why deserialization strips the contract from the
instance: the contract is added at the module boundary using the
chaperone/impersonator infrastructure, and deserialization uses the
unprotected form of `adder` passed to `make-deserialize-info` within the
server module.

What I don't understand is how to give `make-deserialize-info` a function
that (1) has a contract where (2) fulfilling the range part of the contract
becomes the deserializing module's obligation — if such a thing is
possible. Aside from attempts with `define/contract` (which as I now
understand achieved point 1 but not point 2), I've also tried putting the
definition of `deserialize-info:adder-v0` in a different module, so that
its version of `adder` has a contract, but then the binding isn't seen by
`make-serialize-info`.

-Philip

On Mon, Jul 24, 2017 at 7:30 AM, Matthias Felleisen <matth...@ccs.neu.edu>
wrote:

>
> On Jul 23, 2017, at 10:50 PM, Philip McGrath <phi...@philipmcgrath.com>
> wrote:
>
> If I'm following correctly, I think that's what I was trying to do, but
> I'm unclear how to give `make-deserialize-info` a variant of `make-adder`
> that has a contract. The initial example with `define/contract` was the
> closest I've come: it at least reported violations in terms of `make-adder`
> rather than `+`, but (as I now understand) it blamed the `server` module
> for all violations.
>
> -Philip
>
> On Sun, Jul 23, 2017 at 9:27 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
>
>> The original example had an explicit deserializer:
>>
>> At Sun, 23 Jul 2017 19:54:43 -0500, Philip McGrath wrote:
>> >   (define deserialize-info:adder-v0
>> > (make-deserialize-info make-adder
>> >(λ () (error 'adder
>> > "can't have cycles"
>>
>> You're constructing the deserializer with `make-adder` --- the variant
>> from inside the `server` module, so it doesn't have a contract.
>>
>> I think this is where you want to draw a new boundary by giving
>> `make-deserialize-info` a variant of `make-adder` that has a contract.
>
>
>
>
> Don’t you just want this:
>
> #lang racket
>
> (module server racket
>   (require racket/serialize)
>
>   (provide (contract-out
> [adder (-> natural-number/c (-> natural-number/c
> natural-number/c))]))
>
>   (struct adder (base)
> #:property prop:procedure
> (λ (this x) (+ (adder-base this) x))
> #:property prop:serializable
> (make-serialize-info (λ (this) (vector (adder-base this)))
>  #'deserialize-info:adder-v0
>  #f
>  (or (current-load-relative-directory)
>  (current-directory
>
>   (define deserialize-info:adder-v0
> (make-deserialize-info adder (λ () (error 'adder "can't have
> cycles"
>
>   (module+ deserialize-info
> (provide deserialize-info:adder-v0)))
>
> (require (submod "." server) racket/serialize)
>
> (local ((define serialize values)
> (define deserialize values))
>   (define x (serialize (adder 5)))
>   (define f (deserialize x))
>   (f 'not-a-number))
>
>
>

-- 
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] [ANN] MessagePack implementation for Racke

2017-07-24 Thread Philip McGrath
You probably want `integer-in` for the contract on `ext`.

Have you read about the special treatment of test submodules?
https://docs.racket-lang.org/guide/Module_Syntax.html#%28part._main-and-test%29

That is the idiomatic Racket way to write tests that run automatically when
you want them and don't get in the way when you don't. If you have
particularly extensive tests, it can also make sense to have a file where
the program consists of nothing but the test submodule.

-Philip

On Mon, Jul 24, 2017 at 5:50 PM, Alejandro Sanchez 
wrote:

>
> > On 24 Jul 2017, at 22:40, Jay McCarthy  wrote:
> >
> > On Mon, Jul 24, 2017 at 3:18 PM, Alejandro Sanchez
> >  wrote:
> >>> - I'm curious of the performance. In particular, I would expect that a
> >>> computed jump in unpack could do you good. Did you try that?
> >> I haven’t investigated performance yet. As I said, I am new to Racket,
> this is my first time doing anything useful in it, my only previous Scheme
> knowledge was from doing the exercises in SICP and dabbling in Guile a bit.
> What is a computed jump?
> >
> > Rather than having a big `cond`, you could look up the function that
> > does the work in a vector and then call it. IMHO, msgpack was designed
> > with that in mind, because tags that aren't immediate values are all
> > nicely ordered. So you'd check the size, subtract a constant, and grab
> > the appropriate procedure from a constant vector.
> OK, that’s the sort of thing I would have done in C where the tag would be
> an index into an array of function pointers. Can you please point me to
> where in the manual it explains how to profile a single function?
>
> >>> - Your package collection is 'multi, which is fine, but normally you
> >>> just do that when you're defining something like data/heap or
> >>> net/turkeyrpc, where you are extending some existing collection. In
> >>> particular, you define msgpack and then you also define the test/pack
> >>> collection (where you might expect it to be tests/msgpack/pack). I
> >>> recommend having your collection be "msgpack" and putting your tests
> >>> inside a tests sub-directory.
> >> Just to make sure I understood correctly: ‘msgpack’ is the umbrella
> module that users import, ‘msgpack/test/pack’ (and ‘unpack’) are the test
> modules that will be run for testing only. How about the directory
> structure? I like to keep all source files in a source directory (my
> original reason for doing ‘multi), can I still do something like this?
> >>
> >>|-README
> >>|-LICENSE
> >>|-info.rkt
> >>|-source
> >>  |-msgpack.rkt
> >>  |-pack.rkt
> >>  |-unpack.rkt
> >>|-test
> >>  |-pack.rkt
> >>  |-pack
> >>|- ...
> >>  |-unpack.rkt
> >>  |-unpack
> >>|- …
> >>
> >> It doesn’t have to be exactly this structure, but the idea is that all
> project-realted files are in the root, all the source files in the source
> directory and all the test files in the test directory.
> >
> > You can do that, but you'd have to have an additional `main.rkt` file
> > at the top-level that would require the things in `source` then
> > re-export them. It is not really Racket style to do what you're
> > talking about, however. If you did do that, then you could call the
> > `source` directory, `private` and then it would have a Racket-y name,
> > but your project isn't really large enough to warrant it and those
> > files aren't actually provide.
> >
> > Furthermore, your test/pack.rkt and test/unpack.rkt modules aren't
> > necessary, because you should be testing with `raco test -c msgpack`,
> > which will just go find everything. There's no need to build such
> > things yourself. (Although, FWIW, I also wouldn't have separate those
> > tests into such small files with just one or two, because they are,
> > again, so small.)
> I guess I’m weird that way, but I think of a project like a box. When you
> buy a thing and open the box you want all the contents to be neatly
> separated: here is the manual, here is the warranty card, here are the
> parts, all wrapped nicely in a bag. You wouldn’t want the contents to be
> loose and spill all over the floor. That’s why I like to separate the
> project
> into directories by functionality (documentation, source, tests, manuals,
> …). Oh well, if that is the Racket style I’ll do it your way.
>
>
> >>> - On a style level, I think you should remove your lets and turn your
> >>> if/begin blocks into conds, for example:
> >> Good point.
> >>
> >>>
> >>> On Mon, Jul 24, 2017 at 9:17 AM, Alejandro Sanchez
> >>>  wrote:
>  Hello dear Racketeers,
> 
>  I have been writing an implementation of the MessagePack protocol for
> Racket
>  and I think the library is ready to be showcased now:
> 
>  https://gitlab.com/HiPhish/MsgPack.rkt
> 
> 
>  ### What is MessagePack? ###
> 
>  MessagePack is a binary data 

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Philip McGrath
Eliminating the optional argument and using match-define to avoid any
redundant checking on first and rest gets me a significant speedup:

#lang racket

(collect-garbage)
(collect-garbage)
(collect-garbage)

(define as (build-list 100 (λ (n) (random 100
(define bs (build-list 100 (λ (n) (random 100

(define (f as bs [acc 0])
  (if (or (null? as) (null? bs))
  acc
  (f (rest as) (rest bs) (+ acc (* (first as) (first bs))

(time (f as bs))

(collect-garbage)
(collect-garbage)
(collect-garbage)

(define (g as bs)
  (let g ([as as]
  [bs bs]
  [acc 0])
  (cond
[(or (null? as) (null? bs))
 acc]
[else
 (match-define (cons this-a more-as)
   as)
 (match-define (cons this-b more-bs)
   bs)
 (g more-as more-bs (+ acc this-a this-b))])))

(time (g as bs))

; timed in DrRacket w/ debugging
;cpu time: 326 real time: 326 gc time: 0
;2451374037
;cpu time: 68 real time: 69 gc time: 0
;98991285

-Philip

On Thu, Jul 27, 2017 at 8:08 PM, Gustavo Massaccesi 
wrote:

> Functions with optional arguments are slow. They are expanded to a
> case-lambda and an if. This version with an auxiliary function is
> faster:
>
>
> #lang racket
>
> (define as (build-list 100 (λ (n) (random 100
> (define bs (build-list 100 (λ (n) (random 100
>
>
> (define (f/opt as bs [acc 0])
>   (if (or (null? as) (null? bs))
>   acc
>   (f/opt (rest as) (rest bs) (+ acc (* (first as) (first bs))
>
> (collect-garbage)
> (collect-garbage)
> (collect-garbage)
> (time (f/opt as bs))
>
>
> (define (f/acc as bs acc)
>   (if (or (null? as) (null? bs))
>   acc
>   (f/acc (rest as) (rest bs) (+ acc (* (first as) (first bs))
>
> (define (f/no-acc as bs acc)
>   (f/acc as bs 0))
>
> (collect-garbage)
> (collect-garbage)
> (collect-garbage)
> (time (f/no-acc as bs 0))
>
> ;cpu time: 281 real time: 268 gc time: 0
> ;2447735069
> ;cpu time: 94 real time: 93 gc time: 0
> ;2447735069
>
> Gustavo
>
> On Thu, Jul 27, 2017 at 10:07 PM, Jon Zeppieri  wrote:
> > You can get better performance out of the recursive function by using
> > car/cdr instead of first/rest; first/rest require their arguments to
> > be lists, whereas car/cdr require theirs to be pairs, which is a lot
> > cheaper to check. Also, using an optional argument (in a loop,
> > especially) makes a difference.
> >
> > Even so, for/sum wins, because it uses ops like unsafe-car and
> > unsafe-cdr, which it can do safely, since it first establishes that
> > it's working with a list (and then doesn't have to check again).
> >
> > - Jon
> >
> > On Thu, Jul 27, 2017 at 8:55 PM, Daniel Prager
> >  wrote:
> >> Revised to collect garbage before each timing shows the recursive
> function
> >> isn't too bad (but not great):
> >>
> >> cpu time: 405 real time: 404 gc time: 0
> >> 2452578471
> >>
> >> cpu time: 368 real time: 368 gc time: 0
> >> 2452578471
> >>
> >> cpu time: 50 real time: 50 gc time: 0
> >> 2452578471
> >>
> >> cpu time: 194 real time: 195 gc time: 75
> >> 2452578471
> >>
> >>
> >> Dan
> >>
> >> --
> >> 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.


Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Philip McGrath
*Slightly too significant, since I wrote g incorrectly. This is right:

#lang racket

(collect-garbage)
(collect-garbage)
(collect-garbage)

(define as (build-list 100 (λ (n) (random 100
(define bs (build-list 100 (λ (n) (random 100

(define (f as bs [acc 0])
  (if (or (null? as) (null? bs))
  acc
  (f (rest as) (rest bs) (+ acc (* (first as) (first bs))

(time (f as bs))

(collect-garbage)
(collect-garbage)
(collect-garbage)

(define (g as bs)
  (let g ([as as]
  [bs bs]
  [acc 0])
  (cond
[(or (null? as) (null? bs))
 acc]
[else
 (match-define (cons this-a more-as)
   as)
 (match-define (cons this-b more-bs)
   bs)
 (g more-as more-bs (+ acc (* this-a this-b)))])))

(time (g as bs))

;; timed in DrRacket w/ debugging
;cpu time: 386 real time: 385 gc time: 45
;2448129646
;cpu time: 122 real time: 121 gc time: 0
;2448129646

-Philip

On Thu, Jul 27, 2017 at 8:13 PM, Philip McGrath <phi...@philipmcgrath.com>
wrote:

> Eliminating the optional argument and using match-define to avoid any
> redundant checking on first and rest gets me a significant speedup:
>
> #lang racket
>
> (collect-garbage)
> (collect-garbage)
> (collect-garbage)
>
> (define as (build-list 100 (λ (n) (random 100
> (define bs (build-list 100 (λ (n) (random 100
>
> (define (f as bs [acc 0])
>   (if (or (null? as) (null? bs))
>   acc
>   (f (rest as) (rest bs) (+ acc (* (first as) (first bs))
>
> (time (f as bs))
>
> (collect-garbage)
> (collect-garbage)
> (collect-garbage)
>
> (define (g as bs)
>   (let g ([as as]
>   [bs bs]
>   [acc 0])
>   (cond
> [(or (null? as) (null? bs))
>  acc]
> [else
>  (match-define (cons this-a more-as)
>as)
>  (match-define (cons this-b more-bs)
>bs)
>  (g more-as more-bs (+ acc this-a this-b))])))
>
> (time (g as bs))
>
> ; timed in DrRacket w/ debugging
> ;cpu time: 326 real time: 326 gc time: 0
> ;2451374037
> ;cpu time: 68 real time: 69 gc time: 0
> ;98991285
>
> -Philip
>
> On Thu, Jul 27, 2017 at 8:08 PM, Gustavo Massaccesi <gust...@oma.org.ar>
> wrote:
>
>> Functions with optional arguments are slow. They are expanded to a
>> case-lambda and an if. This version with an auxiliary function is
>> faster:
>>
>>
>> #lang racket
>>
>> (define as (build-list 100 (λ (n) (random 100
>> (define bs (build-list 100 (λ (n) (random 100
>>
>>
>> (define (f/opt as bs [acc 0])
>>   (if (or (null? as) (null? bs))
>>   acc
>>   (f/opt (rest as) (rest bs) (+ acc (* (first as) (first bs))
>>
>> (collect-garbage)
>> (collect-garbage)
>> (collect-garbage)
>> (time (f/opt as bs))
>>
>>
>> (define (f/acc as bs acc)
>>   (if (or (null? as) (null? bs))
>>   acc
>>   (f/acc (rest as) (rest bs) (+ acc (* (first as) (first bs))
>>
>> (define (f/no-acc as bs acc)
>>   (f/acc as bs 0))
>>
>> (collect-garbage)
>> (collect-garbage)
>> (collect-garbage)
>> (time (f/no-acc as bs 0))
>>
>> ;cpu time: 281 real time: 268 gc time: 0
>> ;2447735069
>> ;cpu time: 94 real time: 93 gc time: 0
>> ;2447735069
>>
>> Gustavo
>>
>> On Thu, Jul 27, 2017 at 10:07 PM, Jon Zeppieri <zeppi...@gmail.com>
>> wrote:
>> > You can get better performance out of the recursive function by using
>> > car/cdr instead of first/rest; first/rest require their arguments to
>> > be lists, whereas car/cdr require theirs to be pairs, which is a lot
>> > cheaper to check. Also, using an optional argument (in a loop,
>> > especially) makes a difference.
>> >
>> > Even so, for/sum wins, because it uses ops like unsafe-car and
>> > unsafe-cdr, which it can do safely, since it first establishes that
>> > it's working with a list (and then doesn't have to check again).
>> >
>> > - Jon
>> >
>> > On Thu, Jul 27, 2017 at 8:55 PM, Daniel Prager
>> > <daniel.a.pra...@gmail.com> wrote:
>> >> Revised to collect garbage before each timing shows the recursive
>> function
>> >> isn't too bad (but not great):
>> >>
>> >> cpu time: 405 real time: 404 gc time: 0
>> >> 2452578471
>> >>
>> >> cpu time: 368 real time: 368 gc time: 0
>> >> 2452578471
>> >>
>> >> cpu time: 50 real time: 50 gc time: 0
>> >> 2452578471
>> >>
>> >> cpu time: 194 real time: 195 gc time: 75
>> >>

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Philip McGrath
`match-define` seems to be the real source of the speedup for me:

#lang racket

(define (as)
  (build-list 100 (λ (n) (random 100
(define (bs)
  (build-list 100 (λ (n) (random 100

(define (f as bs [acc 0])
  (if (or (null? as) (null? bs))
  acc
  (f (rest as) (rest bs) (+ acc (* (first as) (first bs))

(let ([as (as)]
  [bs (bs)])
  (collect-garbage)
  (collect-garbage)
  (collect-garbage)
  (time (f as bs)))



(define (g as bs)
  (let g ([as as]
  [bs bs]
  [acc 0])
(cond
  [(or (null? as) (null? bs))
   acc]
  [else
   (match-define (cons this-a more-as)
 as)
   (match-define (cons this-b more-bs)
 bs)
   (g more-as more-bs (+ acc (* this-a this-b)))])))


(let ([as (as)]
  [bs (bs)])
  (collect-garbage)
  (collect-garbage)
  (collect-garbage)
  (time (g as bs)))

(collect-garbage)
(collect-garbage)
(collect-garbage)

(define (z as bs [acc 0])
  (cond
[(or (null? as) (null? bs))
 acc]
[else
 (match-define (cons this-a more-as)
   as)
 (match-define (cons this-b more-bs)
   bs)
 (z more-as more-bs (+ acc (* this-a this-b)))]))

(let ([as (as)]
  [bs (bs)])
  (collect-garbage)
  (collect-garbage)
  (collect-garbage)
  (time (z as bs)))

; timed at the command line
;cpu time: 242 real time: 241 gc time: 0
;2452993452
;cpu time: 21 real time: 21 gc time: 0
;2450414634
;cpu time: 22 real time: 22 gc time: 0
;2450010495

-Philip

On Thu, Jul 27, 2017 at 8:22 PM, Matthias Felleisen 
wrote:

>
> On Jul 27, 2017, at 9:18 PM, Matthew Flatt  wrote:
>
> I don't think optional arguments are all that slow.
>
>
>
> This isn’t just Matthew’s opinion. Vincent’s feature-specific profiler
> could not detect a significant impact of optional or keyword arguments.
> (See Compiler Construction paper, London 2014 I think)
>
> --
> 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] Re: Decision Tree in Racket - Performance

2017-07-26 Thread Philip McGrath
Re multiple return values, you can write (call-with-values (λ () (values 1
2 3)) list)

Because this problem bugs me, I've also written a package adjutor that
includes values->list, list->values, and for/fold/define:
http://docs.racket-lang.org/adjutor/index.html

-Philip

On Wed, Jul 26, 2017 at 3:00 AM, Daniel Prager 
wrote:

> Actually, I only use multiple values because that's what for/fold returns.
>
> Is there a way to convert from values to a list without going through
> define-values or similar?
>
> Dan
>
>
> On 26 Jul. 2017 09:40, "Zelphir Kaltstahl" 
> wrote:
>
> I've come to the conclusion, that not assuming binary classification makes
> no sense, since every n-class classification problem can be split into n
> binary classification problems.
>
> When assuming classes 0 and 1, the performance increases and I get to:
>
> cpu time: 608 real time: 605 gc time: 68
>
> For finding the best split.
>
> Daniel's solution makes use of multiple return values, which were new to
> me. I am using a struct for this, which might be unnecessary and later
> removed in favor of returning multiple values like in Daniel's solution.
>
> --
> 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.


Re: [racket-users] Custom reader that's a strict subset of racket

2017-06-29 Thread Philip McGrath
I think you might be able to leave the reader as-is and just re-define
#%datum to reject whatever kinds of literal data you don't want to allow.

-Philip

On Thu, Jun 29, 2017 at 9:44 PM, Sam Waxman  wrote:

> Hello,
>
> I'm building a #lang, and I don't want it to have a few things like
> complex numbers, or vectors. Other than the things I don't want, the reader
> would be identical to racket's. Is there an easy way to "turn off" the
> things I don't want, so to speak, and take Racket's reader and delete the
> things I don't need? The alternative, of course, would be to write my own
> reader from scratch. Just seems a bit silly when there's a perfectly good
> one already written that has everything I need.
>
> Many 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.
> 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] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Philip McGrath
I'm working on a Racket web application for which I need to proxy certain
requests to a non-Racket service over HTTP. I've built a very basic proxy
on top of http-sendrecv/url that works quite well for the most part.

For POST requests, I pass the request-post-data/raw of the original request
as the #:data argument of http-sendrecv/url.

However, I've discovered that certain POST requests (specifically involving
file uploads) are not working as expected. On these requests, Chrome
reports that it is performing a request with a header
Content-Type:multipart/form-data;
boundary=WebKitFormBoundaryAJOgATwBujJhhtbY and a payload as follows:

--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="tool"
corpus.CorpusCreator
--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="palette"
default
--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="textarea-1014-inputEl"
Type in one or more URLs on separate lines or paste in a full text.
--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="upload"; filename="tmp-file.txt"
Content-Type: text/plain
--WebKitFormBoundaryAJOgATwBujJhhtbY--


However, at the Racket level, request-post-data/raw returns #f for these
requests — but, adding to my confusion, the bindings still show up
in request-bindings/raw.

Why doesn't this content show up in request-post-data/raw? Is there a way
to access the raw, original data for these requests, or do I need to
somehow reconstruct it from the bindings?

Thanks very much,
Philip

-- 
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] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Philip McGrath
Thanks for your comments.

The only legal files to upload in this case are plain text, so I'm not too
worried about size. I'm relying on the web-server libraries to deal with
any malicious attempts to send overwhelmingly large files (if that's a bad
idea, I'd definitely appreciate hearing it!). Other parts of the
application are implemented in #lang web-server, including some access
control logic surrounding the requests that are proxied to the external
service.

With other requests, the  post-data/raw field of the request struct has
been #f only when the method field is #"GET": with POST requests, it has
otherwise (and I thought it always would) contained the raw POST data e.g. #
"corpus=austen=corpus.CorpusMetadata". I thought the bindings from
the bindings/raw-promise field were simply an abstraction over the
post-data/raw (and/or query part of the uri field), which is why I'm
confused that this POST request has bindings, but has #f for its
post-data/raw.

-Philip

On Thu, Jun 29, 2017 at 9:44 PM, Neil Van Dyke  wrote:

> I don't know the answer to your particular questions with `web-server`
> (I've made my own implementations of this in the past), and these comments
> might not apply to your particular application, but I'll mention here for
> whomever is interested...
>
> It sounds like you're using this, which might preempt your question:
>
> post-data/raw : (or/c false/c bytes?)
>>
>
> Does your application permit a large file upload (an uploaded DVD-ROM
> ".iso" file, like for a Linux distro install disc 1, is typically a few
> gigabytes, and video files can also get huge), and is your program
> (including libraries it uses) going to try to allocate gigabytes at a time
> just for one HTTP request?
>
> If the `POST` data is potentially huge, you might want to think about
> doing stream reading of it (i.e., not sucking it all into memory before you
> do something with it), and sending blocks out your proxy approximately as
> soon as they come in (without buffering too much).  That can make your
> program more robust, lower latency, and maybe even improve overall speed.
>
> Or, if you want to keep getting a convenient byte string out of the MIME
> parser, and you plan to reject huge `POST` data before it
> accidentally/intentionally DoS's your server, that will probably happen
> either as the HTTP request is being read, or in the MIME multipart parser
> (when the request is in MIME multipart, which `POST` isn't always, and if
> the HTTP code hands off a pretty raw input port to multipart parsing code,
> which it should).  This is because you can't assume that HTTP or part
> headers will tell you the content size before you read the content --
> sometimes you have to read to find the EOF or the MIME boundary string
> kludge.
>
> I think streaming algorithms are usually the way to go for potentially
> huge data.  (Well, until you then get into what I'll call "poetic license"
> situations, in which you know how to do it in streaming, and you know why
> you don't have to stream in this case.)
>
> --
> 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] Missing request-post-data/raw (from web-server/http)

2017-06-30 Thread Philip McGrath
Thanks, Jay. It is definitely POST, and there is a Content-Length header,
so it seems like the problem is indeed #3. I was expecting the raw data to
be there even if it had been parsed — I believe the POST data of #
"corpus=austen=corpus.CorpusMetadata" was also parsed into bindings
(though not from multipart, obviously).

So it sounds like what I'll need to do is detect when this situation is
happening — I guess that would be when the method is POST, the
request-post-data/raw
is #f, and there are some bindings — and convert the bindings back into
multipart form data to give to http-sendrecv/url.

-Philip

On Fri, Jun 30, 2017 at 8:20 AM, Jay McCarthy <jay.mccar...@gmail.com>
wrote:

> Hi Philip,
>
> I don't necessarily know the answer and it's possible that it is an
> error. I'll explain what it is doing and maybe that will help us move
> forward.
>
> 1) The request-bindings/raw is just an abstraction over
> request-post-data/raw (and the URI)
> 2) The request-post-data/raw is always #f for GETs, are you sure they are
> POSTs?
> 3) POSTs with multipart form data are converted into a
> request-bindings and the raw data is not made available, un-parsed.
> 4) If there's no Content-Length header, then even if there is data,
> then it is not exposed.
>
> I think that your problem may be (3). It sounds like you expect to see
> a copy of the raw data of the request all the time even if it has been
> parsed. (The logic of the current behavior is that at the
> "application" level there is no POST data, but there is only form
> data, but because of "transport" level constraints on the length of
> URIs it had to be sent in the data part of the transport layer.)
>
> Jay
>
>
> On Thu, Jun 29, 2017 at 9:08 PM, Philip McGrath
> <phi...@philipmcgrath.com> wrote:
> > I'm working on a Racket web application for which I need to proxy certain
> > requests to a non-Racket service over HTTP. I've built a very basic
> proxy on
> > top of http-sendrecv/url that works quite well for the most part.
> >
> > For POST requests, I pass the request-post-data/raw of the original
> request
> > as the #:data argument of http-sendrecv/url.
> >
> > However, I've discovered that certain POST requests (specifically
> involving
> > file uploads) are not working as expected. On these requests, Chrome
> reports
> > that it is performing a request with a header
> > Content-Type:multipart/form-data;
> > boundary=WebKitFormBoundaryAJOgATwBujJhhtbY and a payload as
> follows:
> >
> > --WebKitFormBoundaryAJOgATwBujJhhtbY
> > Content-Disposition: form-data; name="tool"
> > corpus.CorpusCreator
> > --WebKitFormBoundaryAJOgATwBujJhhtbY
> > Content-Disposition: form-data; name="palette"
> > default
> > --WebKitFormBoundaryAJOgATwBujJhhtbY
> > Content-Disposition: form-data; name="textarea-1014-inputEl"
> > Type in one or more URLs on separate lines or paste in a full text.
> > --WebKitFormBoundaryAJOgATwBujJhhtbY
> > Content-Disposition: form-data; name="upload"; filename="tmp-file.txt"
> > Content-Type: text/plain
> > --WebKitFormBoundaryAJOgATwBujJhhtbY--
> >
> >
> > However, at the Racket level, request-post-data/raw returns #f for these
> > requests — but, adding to my confusion, the bindings still show up in
> > request-bindings/raw.
> >
> > Why doesn't this content show up in request-post-data/raw? Is there a
> way to
> > access the raw, original data for these requests, or do I need to somehow
> > reconstruct it from the bindings?
> >
> > Thanks very much,
> > Philip
> >
> > --
> > 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.
>
>
>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-
>

-- 
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] can `impersonate-hash` really filter out hash keys?

2017-06-30 Thread Philip McGrath
If it doesn't absolutely have to be a hash, you can definitely
make dict-ref and dict-iterate-key etc. work differently.

-Philip

On Fri, Jun 30, 2017 at 12:15 PM, Matthew Butterick  wrote:

>
> > On Jun 30, 2017, at 10:07 AM, Robby Findler 
> wrote:
> >
> > Maybe you could make the impersonator (it would be a chaperone, really
> > in what I'm suggesting) signal an error if it gets one of the private
> > keys and then hand out only the hashes with the impersonator around
> > it, keeping the "raw" one around for code that is allowed to access
> > the private keys?
>
> I still want the private keys to be directly accessible. Maybe this is the
> best bet, where I include a #f/#f entry in the table, and then I can use
> #:when to do the filtering easily:
>
> (define ih (impersonate-hash (make-hash (list (cons #f #f)))
>  (λ (h k) (values k (λ (h k v) v)))
>  (λ (h k v) (values k v))
>  (λ (h k) k)
>  (λ (h k) (and (eq? k 'foo) k
> (hash-set! ih 'foo 42)
> (hash-set! ih 'bar 21)
> (hash-set! ih 'zam 7)
> (for/list ([(k v) (in-hash ih)]
>  #:when k)
>  (cons k v)) ; '((foo . 42))
> (hash-ref ih 'foo) ; 42
> (hash-ref ih 'bar) ; 21
> (hash-ref ih 'zam) ; 7
>
> --
> 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] Defining new exception types with guards and default messages

2017-06-29 Thread Philip McGrath
Note, though, (having tried this) that putting a contract on the guard will
give you undesirable blame behavior unless you use any/c for all the domain
contracts as Matthias did. The guard must be able to accept all arguments,
so the server module will be blamed if a client calls the constructor with
values that violate the domain portion of the contract.

-Philip

On Thu, Jun 29, 2017 at 10:18 AM, David Storrs 
wrote:

>
>
> On Thu, Jun 29, 2017 at 9:50 AM, Matthias Felleisen 
> wrote:
>
>>
>> > On Jun 29, 2017, at 9:21 AM, David Storrs 
>> wrote:
>> >
>> > I'd like to create a new exception type, 'exn:fail:insufficient-space',
>> something like this:
>> >
>> > (struct exn:fail:insufficient-space exn:fail (requested available
>> source))
>> >
>> > I would like to do two things:
>> >
>> > 1) Make the exn-message field be standardized so that the person
>> throwing the exception doesn't need to (or, ideally, cannot) set it.
>> >
>> > 2) Apply a contract so that only valid arguments can be supplied.
>> >
>> > I could do both of these with a 'guard' statement and an external
>> function definition:
>> >
>> > (define/contract (zot msg ccm req avail src type)
>> >   (values "Insufficient space" ccm req avail src))
>> > (struct exn:fail:insufficient-space exn:fail (requested available
>> source)
>> > #:guard zot)
>> >
>> > ...but this gives me a top-level definition that I don't want and need
>> to remember to not export.
>>
>>
>> I really think we should explicitly export bindings not implicitly.
>> (all-defined-out) is a kludge.
>>
>>
>> > I've been through the sections on contracts and local bindings and I
>> don't see a way to apply one to a raw lamdba -- is there one?
>>
>>
>> (struct exn:fail:insufficient-space exn:fail (requested available source)
>>   #:guard
>>   (local ((define/contract (zot msg   ccm   req   avail src   type)
>> (-> any/c any/c any/c any/c any/c any/c (values string? any/c
>> any/c any/c any/c))
>> (values "Insufficient space" ccm req avail src)))
>> zot))
>>
>>
>>
> Brilliant.  Thanks, Matthias.
>
> --
> 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] Catching syntax errors

2017-06-30 Thread Philip McGrath
If testing with parenthetical syntax is sufficient, you might want
something like this:

#lang racket

(with-handlers ([exn:fail:syntax? values])
  (eval `(module bad racket (define foo (define bar 1)))
(make-base-namespace)))

which returns:

(exn:fail:syntax
 "define: not allowed in an expression context"
 #
 '(.#))







-Philip

On Fri, Jun 30, 2017 at 3:47 PM, Sam Waxman  wrote:

> Hello,
>
> I'm trying to test whether or not certain programs result in syntax
> errors. For example the program
>
> #lang racket
> a
>
> will result in an unbound identifier error, even before runtime (you'll
> see the little error message at the bottom because it errored in phase 1).
>
> I know how to catch runtime errors, but I haven't been able to catch these
> expansion time errors as of yet. I've tried doing roughly the same thing as
> catching runtime errors, but with begin-for-syntax, but it hasn't been
> working out for me.
>
> Ideally, I want a macro like
>
> (return-syntax-error stuff-to-expand ...)
>
> that will run stuff-to-expand, and if runs into a syntax error, for it to
> be caught and returned (as the error struct # #).
>
> Any tips?
>
> Many 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.
> 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] Best way to write run-once-and-cache functions?

2017-04-25 Thread Philip McGrath
In this very simple case, I would probably not define a function at all,
just something like

(define conf
  (with-input-from-file "db.conf"
read-json))


You may also find yourself wanting define-runtime-path from
racket/runtime-path.

On Tue, Apr 25, 2017 at 11:12 PM, David Storrs 
wrote:

> Reading configuration files is a good example of a run-once function.
> It's effectively self-memoizing -- it should run once, cache its result,
> and on future calls just return the cached value.  I could pull in
> https://docs.racket-lang.org/memoize/index.html or
> http://docs.racket-lang.org/mischief@mischief/memoize.html to do that,
> but adding an extra module to the project just for one or two functions
> feels pretty heavy. (Also, memoizing is overkill if the functions are
> thunks.)  Is there a simple way to do this in pure Racket?
>
> In Perl I would do something like this (for simplicity I'm ignoring
> encoding and assuming that the config file is JSON):
>
> use JSON;
> sub read_conf {
>   state $conf = do {
> local $/;
> open my $fh, "<", "db.conf" or die "failed to open config: $!";
> from_json( <$fh> )
>   };
>   $conf
> }
>
>
> I could do this in Racket using set!, but that's not very Rackety:
>
> (require json)
> (define conf #f)
> (define (read-conf)
>(or conf
>  (begin
>(set! conf (with-input-from-file "db.conf" (thunk (read-json
>conf)))
>
>
> I could do it with a parameter but that's only sweeping the above ugliness
> under the rug:
>
> (define conf (make-parameter #f))
> (define (read-conf)
>(or (conf)
>  (begin
>(conf (with-input-from-file "db.conf" (thunk (read-json
>(conf
>
> What is the right way?
>
> --
> 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] Lexical context for all-defined-out

2017-04-26 Thread Philip McGrath
I'm working on a #%module-begin variant that provides all module-level
bindings, and I'm having trouble finding the right way to give lexical
context to all-defined-out.

The issue (IIUC) is that all-defined-out only exports identifiers "that
have the same lexical context as the (all-defined-out) form"; however, I
want to have #%module-begin introduce all-defined-out, but have it export
the identifiers defined by the programmer in the body of the module.

Currently what I'm doing is essentially this:

#lang racket

(module lang racket
  (provide (except-out (all-from-out racket)
   #%module-begin
   provide
   ;all-defined-out ;can't omit this
   )
   (rename-out [providing-module-begin
#%module-begin]))
  (require (for-syntax syntax/parse))
  (define-syntax (providing-module-begin stx)
(syntax-parse stx
  [(_ body:expr ...)
   #`(#%module-begin
  (provide #,(datum->syntax stx '(all-defined-out)))
  body ...)])))

(module demo (submod ".." lang)
  (define something
"a value"))

(require (submod "." demo))

something


This almost works — the providing happens correctly — but it requires that
the lang module provide all-defined-out, which I don't actually want to be
otherwise available.

Is there a way to give all-defined-out the lexical context I'm looking for?

-- 
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] Lexical context for all-defined-out

2017-04-26 Thread Philip McGrath
Thanks, that does the trick!

-Philip

On Wed, Apr 26, 2017 at 6:27 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> The `all-defined-out` macro supports a trick that several non-hygienic
> macros use: it uses the scopes on the parentheses around
> `all-defined-out` non-hygienically, instead of the scopes on the
> identifier.
>
> So, in place of
>
>  (datum->syntax stx '(all-defined-out)))
>
> you can use
>
>  (datum->syntax stx `(,#'all-defined-out)))
>
> and then you don't have to export `all-defined-out`.
>
> At Wed, 26 Apr 2017 18:01:00 -0500, Philip McGrath wrote:
> > I'm working on a #%module-begin variant that provides all module-level
> > bindings, and I'm having trouble finding the right way to give lexical
> > context to all-defined-out.
> >
> > The issue (IIUC) is that all-defined-out only exports identifiers "that
> > have the same lexical context as the (all-defined-out) form"; however, I
> > want to have #%module-begin introduce all-defined-out, but have it export
> > the identifiers defined by the programmer in the body of the module.
> >
> > Currently what I'm doing is essentially this:
> >
> > #lang racket
> >
> > (module lang racket
> >   (provide (except-out (all-from-out racket)
> >#%module-begin
> >provide
> >;all-defined-out ;can't omit this
> >)
> >(rename-out [providing-module-begin
> > #%module-begin]))
> >   (require (for-syntax syntax/parse))
> >   (define-syntax (providing-module-begin stx)
> > (syntax-parse stx
> >   [(_ body:expr ...)
> >#`(#%module-begin
> >   (provide #,(datum->syntax stx '(all-defined-out)))
> >   body ...)])))
> >
> > (module demo (submod ".." lang)
> >   (define something
> > "a value"))
> >
> > (require (submod "." demo))
> >
> > something
> >
> >
> > This almost works — the providing happens correctly — but it requires
> that
> > the lang module provide all-defined-out, which I don't actually want to
> be
> > otherwise available.
> >
> > Is there a way to give all-defined-out the lexical context I'm looking
> for?
> >
> > --
> > 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.


Re: [racket-users] Setting parameters between files does not work as expected

2017-04-25 Thread Philip McGrath
   1. Yes, that was supposed to be (current-database-handle)
   2. A struct would definitely be a reasonable choice for the spec, but
   you might just want to add a failure result to the hash-ref calls inside
   initialize: in that case default-database-spec could just be #hasheq(), and
   you wouldn't have to explicitly specify a port, for example, to specify a
   different password. You're right though that the example should really have
   used checks for hash-has-key? in database-spec/c, as well, since it assumed
   those keys were present. In practice I would probably also require that the
   hash be immutable, though mostly for ease of reasoning.


-Philip

On Tue, Apr 25, 2017 at 12:48 PM, David Storrs <david.sto...@gmail.com>
wrote:

>
>
> On Mon, Apr 24, 2017 at 9:46 PM, Philip McGrath <phi...@philipmcgrath.com>
> wrote:
>
>> Another thing that might be relevant:
>>>
>>> In contrast, direct assignment to a parameter (by calling the parameter
>>> procedure with a value) changes the value in a thread cell, and therefore
>>> changes the setting only for the current thread. http://docs.racket-lan
>>> g.org/reference/parameters.html
>>
>>
>> Also, do you want multiple underlying connections of the same virtual
>> connection to potentially use different values for the
>> user/database/password/port?
>>
>
> Nope, a given dbh should only be connected to one DB.
>
>
>
>>
>> If not, the most recent way I've dealt with this sort of thing is to come
>> up with some type of "database connection spec" — for a quick example, I'll
>> use a hash table — and then do some things with parameter guards, opaque
>> structures, and a tiny macro to keep the details away from higher-level
>> code.
>>
>> I think code might be clearer than a description, so here's a minimal
>> sketch:
>>
>>
> I admit that I had to stare at this for a few minutes and look up some
> details (e.g. how hash/dc works), but when it clicked my reaction was
> "Racket. Is. Epic."
>
> Thank you for this; it's exactly what I needed and I'll definitely use
> it.  Two questions:
>
> 1) This line was intended to reference (current-database-handle), not
> (current-database), right?
> [_ (force (database-handle-promise (current-database)))]))
>
> 2) We're already using hashes for data passing in a lot of areas because
> (a) they are really convenient and (b) my co-founder and I both come from
> Perl backgrounds.  In this particular case, though, it seems like maybe I
> should define a struct for the database spec instead of a hash, as hash/dc
> validates the keys and values that happen to exist in the hash, as opposed
> to validating that the hash has a given set of keys/values.  Does this make
> sense or am I overcomplicating things?
>
> Dave
>
> NB:  I'm glad you used hashes for the demo, though, as it was much easier
> to follow and introduced me to the hash/dc contract.
>
>
> #lang racket
>>
>> (require db
>>  )
>>
>> (struct database-handle (promise))
>>
>> (define database-spec/c
>>   (or/c database-handle?
>> (hash/dc [k (or/c 'user 'database 'password 'port)]
>>  [v (k)
>> (case k
>>   [(user database password)
>>string?]
>>   [(port)
>>natural-number/c]
>>   [else none/c])])))
>>
>> (define default-database-spec
>>   #hasheq([user . "postgres"]
>>   [database . "test-db"]
>>   [password . "mellon"]
>>   [port . 5433]))
>>
>>
>> (define/contract current-database-handle
>>   (parameter/c database-spec/c database-handle?)
>>   (let ([initialize
>>  (λ (spec)
>>(if (database-handle? spec)
>>spec
>>(let ([u (hash-ref spec 'user)]
>>  [d (hash-ref spec 'database)]
>>  [p (hash-ref spec 'password)]
>>  [prt (hash-ref spec 'port)])
>>  (database-handle
>>   (delay (virtual-connection
>>   (connection-pool
>>(λ ()
>>  (postgresql-connect
>>   #:user u
>>   #:database d
>>   #:password p
>>   #:port prt
>>   )])
>> (make

Re: [racket-users] Speeding up graphics / moving away from 2htdp/image

2017-04-29 Thread Philip McGrath
I think that would be because "the *draw* is called during the dynamic
extent of the call to dc

as part of the contract checking."

-Philip

On Sat, Apr 29, 2017 at 2:58 AM, Daniel Prager 
wrote:

> Thanks for all the suggestions.
>
> I was able to get pict down to "direct to dc"-like performance by making a
> custom pict that calls my direct-to-dc code ...
>
> (define (pict:render block)
>   (pict:dc (λ (dc dx dy)
> (define old-brush (send dc get-brush))
> (define old-pen (send dc get-pen))
> (dc:draw dc block dx dy)
> (send dc set-brush old-brush)
> (send dc set-pen old-pen))
> (* *size* *n*) (* *size* *n*)))
>
>
> My only remaining question is why pict calls the custom code on
> construction, as well as on rendering.
>
> (displayln "Render, then convert to bitmap%...")
> (define pict:c1 (time (pict:render b1)))
> (define p1 (time (pict->bitmap% pict:c1)))
>
>
> Dan
>
>
> Revised timings ...
>
>
> SQUARES
> ===
>
> 2htdp/image
> ---
> Render, then convert to bitmap%...
> cpu time: 134 real time: 136 gc time: 46
> cpu time: 344 real time: 355 gc time: 60
>
> pict
> 
> Render, then convert to bitmap%...
> cpu time: 80 real time: 87 gc time: 0
> cpu time: 83 real time: 84 gc time: 13
>
> direct to dc
> 
> Render direct to bitmap%...
> cpu time: 67 real time: 68 gc time: 0
>
>
> TRIANGLES
> =
>
> 2htdp/image
> ---
> Method 1 - Render, then convert to bitmap%...
> cpu time: 542 real time: 559 gc time: 76
> cpu time: 606 real time: 622 gc time: 63
>
> Method 2 - Render, then convert to bitmap%...
> cpu time: 332 real time: 337 gc time: 51
> cpu time: 539 real time: 550 gc time: 62
>
> Method 3 - Render, then convert to bitmap%...
> cpu time: 223 real time: 230 gc time: 37
> cpu time: 276 real time: 279 gc time: 25
>
>
> pict
> 
> Render, then convert to bitmap%...
> cpu time: 176 real time: 173 gc time: 22
> cpu time: 188 real time: 188 gc time: 9
>
> direct to dc
> 
> Render direct to bitmap%...
> cpu time: 193 real time: 194 gc time: 16
>
> --
> 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] DrRacket preferences error

2017-04-29 Thread Philip McGrath
After upgrading to 6.9, I'm getting the following "DrRacket Internal Error"
when I try to open the preferences menu on MacOS:

preferences:get: tried to get a preference but no default set for
'scribble-reindent-paragraph-width
  context...:
   /Applications/Racket
v6.9/share/pkgs/gui-lib/framework/preferences.rkt:93:0: preferences:get
   /Applications/Racket
v6.9/collects/racket/contract/private/arrow-val-first.rkt:357:18
   /Applications/Racket
v6.9/share/pkgs/gui-lib/scribble/private/indentation.rkt:15:1
   /Applications/Racket
v6.9/collects/racket/contract/private/arrow-higher-order.rkt:342:33
   /Applications/Racket
v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:390:5
   /Applications/Racket
v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:289:14:
build-ppanel-tree
   /Applications/Racket
v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:261:2:
make-preferences-dialog
   /Applications/Racket
v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:243:2: show-dialog
   /Applications/Racket v6.9/share/pkgs/gui-lib/mred/private/app.rkt:67:21
   /Applications/Racket
v6.9/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:454:6
   /Applications/Racket
v6.9/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:505:32
   /Applications/Racket
v6.9/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:653:3

Is this a problem with my setup, or with DrRacket?

-- 
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] DrRacket preferences error

2017-04-29 Thread Philip McGrath
I don't remember what I did last time (it's very possible I'd opened some
at-exp file), but I tried this now, and it works fine for me.

-Philip

On Sat, Apr 29, 2017 at 3:31 PM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> When you started DrRacket, had you opened a file that uses either one
> of the #lang scribble variants or an at-exp before opening the
> preferences dialog?
>
> I believe that if you don't do that before opening the preferences
> dialog the first time, you can work around this error.
>
> Robby
>
>
> On Sat, Apr 29, 2017 at 1:36 PM, Philip McGrath
> <phi...@philipmcgrath.com> wrote:
> > After upgrading to 6.9, I'm getting the following "DrRacket Internal
> Error"
> > when I try to open the preferences menu on MacOS:
> >
> > preferences:get: tried to get a preference but no default set for
> > 'scribble-reindent-paragraph-width
> >   context...:
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/framework/preferences.rkt:93:0: preferences:get
> >/Applications/Racket
> > v6.9/collects/racket/contract/private/arrow-val-first.rkt:357:18
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/scribble/private/indentation.rkt:15:1
> >/Applications/Racket
> > v6.9/collects/racket/contract/private/arrow-higher-order.rkt:342:33
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:390:5
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:289:14:
> > build-ppanel-tree
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:261:2:
> > make-preferences-dialog
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/framework/private/preferences.rkt:243:2:
> show-dialog
> >/Applications/Racket v6.9/share/pkgs/gui-lib/mred/
> private/app.rkt:67:21
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:454:6
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:505:32
> >/Applications/Racket
> > v6.9/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:653:3
> >
> > Is this a problem with my setup, or with DrRacket?
> >
> > --
> > 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.


Re: [racket-users] Re: table lookup shorthands?

2017-08-07 Thread Philip McGrath
Others have given good reasons to take alternate approaches, but if I were
writing your define-lookup-function macro, I would avoid using a dictionary
type and have the macro expand to `case`, like this:
(define-syntax define-lookup-function
  (syntax-parser
[(_ name:id
[lhs:expr rhs:expr] ...)
 #'(define (name arg)
 (case arg
   [(lhs) rhs] ...
   [else (error 'name (format "no matching clause for ~e"
arg))]))]))

For a pre-made solution, I'd look at match-lambda.

I'm interested to see what you're doing with this code! (I'm a musicology
student when I'm not playing with Racket.)

-Philip

On Mon, Aug 7, 2017 at 1:01 PM, Luis Sanjuán 
wrote:

> On Monday, August 7, 2017 at 6:39:58 PM UTC+2, Luis Sanjuán wrote:
> > EDIT.
> >
> > In the description of the 'Interval' data type, replace 'notes'  with
> 'pitch-classes'
> >
> > In the signature of the function `interval`, replace 'Nat' with
> 'Interval'
>
> Another one:
>
> In the signature of `fifths-from-to` replace the returned type `Nat` with
> `Integer`
>
> --
> 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] Generate function defintions at compile time

2017-08-22 Thread Philip McGrath
I guess my first question would be where does the hash table in
nvim/api/specification.rkt come from, where else is it used, and is it
necessary for the format to be what it currently is. For example, the first
thing that jumped out at me is that you're using strings for all the hash
keys rather than symbols, which prevents you from using a (faster) hasheq.
Also, it is strange to me that functions is a vector and not a list. But it
would probably make even more sense to use structs for many of these
things, unless it needs to be `read`-able or convertible to json or
something.

-Philip

On Tue, Aug 22, 2017 at 5:06 PM, Neil Van Dyke  wrote:

> hiph...@openmailbox.org wrote on 08/22/2017 05:29 PM:
>
>> So far it looks good, but I am stuck on macros. There is a hash table
>> which serves as a specification for which functions to generate, it is
>> stored in the file 'nvim/api/specification.rkt'. This table has the key"
>> functions" which contains a vector of more hash tables.
>>
>
> You *can* go from hashes at syntax expansion time to syntax, but, in this
> case, I think there are ways that are more idiomatic and (once you're
> comfortable with syntax extension) easier...
>
> If you define a kind of domain-specific language (DSL) syntax extension in
> Racket for your Neovim API, your specification might then look like this
> (with the "..." filled in):
>
> (define-and-provide-neovim-api
>   (version ...)
>   (error-types ...)
>   (types ...)
>   (functions ...)
>   (ui-events ...))
>
> Or:
>
> (define-and-provide-neovim-api
>   #:version ...
>   #:error-types ...
>   #:types ...)
>   #:functions ...
>   #:ui-events ...)
>
> Then you implement your `define-and-provide-neovim-api` syntax
> transformer using `syntax-case` or `syntax-parse`.  (When you're
> implementing this, it sometimes (not always) helps to type an example use
> of your syntax, then type an example of what syntax you would like that to
> expand to, and then rework those two examples into your `syntax-case` or
> `syntax-parse` form.)
>
> Or, a somewhat different way is to have separate definition forms in
> Racket for each element of the API, such as:
>
> (define neovim-foo (neovim-api-lambda ...))
> (provide neovim-foo)
>
> Or:
>
> (define-and-provide-neovim-procedure neovim-foo ...)
>
> BTW, consider making the `require` name be simply `neovim` or `nvim`, not
> `neovim/api` or `nvim/api`.  Or call the package `neovim-api`.
>
> Also BTW, consider including the string "neovim" or "nvim" in the names of
> all provided identifiers of your API package, such as `neovim-command`
> instead of `command`.  (For example, I included "roomba" in every name in "
> http://www.neilvandyke.org/racket/roomba/;.)  This is not a rule, just
> something to consider.  Personally, I would probably make it
> `neovim-command` in the API library that can be used from `#lang racket`,
> and then, someday, I have the option of making a `#lang neovim` that (among
> doing other things) provides that procedure simply as `command` rather than
> `neovim-command`.
>
>
> --
> 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] surprising [to me and students] printer behavior with #:transparent

2017-05-16 Thread Philip McGrath
The printer tries to produce an expression that you could copy, paste, and
evaluate. Transparent structs aren't quotable but do support
constructor-style printing, so the printer uses constructor-style printing
for values that contain transparent structs. (Apparently you can configure
this in DrRacket to use e.g. quasiquotation if you prefer:
https://docs.racket-lang.org/drracket/output-syntax.html) Since opaque
structs don't support any nice printing behavior by default, the printer
gives up and uses the more concise quoted form with the non-expression
printed form of the opaque value.

The docs for prop:custom-print-quotable and gen:custom-write and the
Reference section on The Printer
 have more technical
details.

On Tue, May 16, 2017 at 9:21 AM, Dan Grossman  wrote:

>
> Hi all,
>
> In my course here on campus, I have students use #lang racket and we put
> #:transparent on our struct definitions for easier REPL interactions.  A
> student was confused by the different printer-behavior between a and b in
> the attached screenshot, and I can't think of a reason for the different
> behavior for b compared to a and c either.  Curious if there /is/ a decent
> reason or if this is just one of those glitches.
>
> "No big deal" but worth asking...
>
> [image: Inline image 1]
>
> --
> 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] Naive question on how to capitalize only the first word of a string

2017-06-19 Thread Philip McGrath
I don't think there's a library function that does what you want, so you'd
need to define your own. Here's one way to do it:

(define (capitalize-first-letter str)
  (cond
[(non-empty-string? str)
 (define first-letter-str
   (substring str 0 1))
 (define rest-str
   (substring str 1 (string-length str)))
 (string-append (string-upcase first-letter-str)
rest-str)]
[else
 ""]))

-Philip

On Mon, Jun 19, 2017 at 5:12 PM, Glenn Hoetker  wrote:

> I'm quite new to Racket/LISP, so I hope this isn't breathtakingly
> obvious.  Can someone please tell me the best way to capitalize just the
> first word in a multiword string.  So, given the string "it was a dark and
> stormy night", I would like to get "It was a dark and stormy night". I see
> functions for turning everything lower case, everything uppercase or
> capitalizing each word, but nothing in line with what I hope to do.
>
> > (define it "cat dog")
> > (string-titlecase it)
> "Dog Cat"  ; So close, but not quite "Dog cat" as I want.
>
> Many thanks.
>
>
> --
> 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] Controlling the installation-specific "Racket Documentation" page

2017-06-21 Thread Philip McGrath
Hi everyone,

I'm looking for information on how to customize the top-level "Racket
Documentation" page generated by Scribble for a particular Racket
installation.

Specifically, I am working with a group that has now accumulated a few
internal Racket packages with documentation, as well as some documents of a
similar nature to which our developers need to refer. (Many, though not
all, of these documents are written in Scribble, and some of the developers
involved are not Racketeers.) I would like to customize the
installation-specific "Racket Documentation" page on our server — for
example, to put the documentation for our group's packages at the very top
of the list. Then I could simply serve that directory over HTTPS and give
our team, including the non-Racketeers, a convenient way to view these
documents in a central location.

(I could, of course, roll my own web page that simply linked to the
documents, but it would be nice to cooperate with Scribble's "top" link
etc., and I definitely want to avoid adding anything to our Racket package
documentation that would make them *only* work in the context of our
server.)

Is there a mechanism for doing this sort of customization?

Thanks,
Philip

-- 
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] Consulting parameters in #lang web-server servlets

2017-06-22 Thread Philip McGrath
I'm encountering some strange behavior when using parameters with my
(stateless) web servlets.

I want to check the value of a cookie every time a request is made to my
server and make a Racket value derived from the cookie's value available
for use within the servlet code. Since this value shouldn't be stored in
the continuation — it should be generated fresh for every request — it
seemed like writing a dispatcher (in the sense of serve/launch/wait, not of
dispatch-rules) was the right place to do this. Since the servlet code
itself does not need to (and indeed should not) modify the value, I thought
I could use a standard parameter to store the value. Essentially I have a
function shaped like this:

(define ((wrap-dispatcher inner) connection request)
  (parameterize ([my-param ...])
(inner connection request)))

where inner is a dispatcher produced by dispatch/servlet.

All of the work being done by wrap-dispatcher seems to be happening
correctly (e.g. setting and reading the cookie), but within the servlet
itself, the parameter seems to get "stuck" on the first value installed by
wrap-dispatcher after the server is launched (which is not the default
value for the parameter).

I'm not sure why this is happening. I understand that plain parameters
cannot be set within stateless servlets for serialization reasons (hence
the existence of web-parameters), but I didn't think that impacted code
that merely accesses the value of a parameter.

More urgently, I'm not sure how to fix it. Would making my-param a web
parameter solve the problem (without storing the value in the
continuation)? Or is there some other method that should be used for this
sort of per-request work?

Thanks,
Philip

-- 
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] Consulting parameters in #lang web-server servlets

2017-06-22 Thread Philip McGrath
Ok, I think I've got it, but just to make sure I'm not missing any
subtleties, or else for the benefit of posterity, here's the version with
thread cells.


In "common.rkt":

#lang racket

(provide my-val
 call-with-my-val)

(define cell:my-val
  (make-thread-cell #f #t))

(define (my-val)
  (thread-cell-ref cell:my-val))

(define (call-with-my-val new thunk)
  (let ([old (my-val)])
(dynamic-wind (λ () (thread-cell-set! cell:my-val new))
  thunk
  (λ () (thread-cell-set! cell:my-val old)


In "servlet.rkt":

#lang web-server

(require "common.rkt")

(provide start)

(define (start req)
  (response/xexpr
   `(html (head (title "Example"))
  (body (p ,(format "~v" (my-val)))


In "run.rkt":

#lang racket

(require "common.rkt"
 "servlet.rkt"
 web-server/http
 web-server/servlet-dispatch)

(define ((wrap-dispatcher inner) connection request)
  (call-with-my-val (request-uri request)
(λ () (inner connection request

(serve/launch/wait (λ (quit-sema)
 (wrap-dispatcher
  (dispatch/servlet start
#:stateless? #t)))
   #:banner? #t)


Thanks so much!

Philip


-Philip

On Thu, Jun 22, 2017 at 9:31 AM, Jay McCarthy <jay.mccar...@gmail.com>
wrote:

> On Thu, Jun 22, 2017 at 10:21 AM, Philip McGrath
> <phi...@philipmcgrath.com> wrote:
> > I've come up with a (relatively) minimal example.
> >
> > In "common.rkt":
> >>
> >> #lang racket
> >> (provide my-param)
> >> (define my-param
> >>   (make-parameter #f))
> >
> >
> > In "servlet.rkt":
> >>
> >> #lang web-server
> >> (require "common.rkt")
> >> (provide start)
> >> (define (start req)
> >>   (response/xexpr
> >>`(html (head (title "Example"))
> >>   (body (p ,(format "~v" (my-param)))
> >
> >
> > In "run.rkt":
> >>
> >> #lang racket
> >> (require "common.rkt"
> >>  "servlet.rkt"
> >>  web-server/http
> >>  web-server/servlet-dispatch)
> >> (define ((wrap-dispatcher inner) connection request)
> >>   (parameterize ([my-param (request-uri request)])
> >> (inner connection request)))
> >> (serve/launch/wait (λ (quit-sema)
> >>  (wrap-dispatcher
> >>   (dispatch/servlet start
> >> #:stateless? #t)))
> >>#:banner? #t)
> >
> >
> > If you visit a bunch of different URLs, the page will always show the
> first
> > URL you visited.
> >
> > From what you said, I'm guessing the problem is that "the stateless Web
> > language guarantees that the parameters will have values they had when
> the
> > servlet was initialized", which I was not aware of.
>
> Yup
>
> > I haven't worked with thread cells before, if that is indeed where I
> want to
> > store this data. One difference that immediately occurs to me is that the
> > value would not be propagated to any new child threads, right?
>
> If you want it propagated, then create the cell with #t for preserved?
>
> http://docs.racket-lang.org/reference/threadcells.html?q=
> thread-cell#%28def._%28%28quote._~23~25kernel%29._make-thread-cell%29%29
>
> > Thanks,
> > Philip
> >
> > -Philip
> >
> > On Thu, Jun 22, 2017 at 8:39 AM, Jay McCarthy <jay.mccar...@gmail.com>
> > wrote:
> >>
> >> Hi Philip,
> >>
> >> I think I'd have to see more code to really tell what the problem is,
> >> but here are some thoughts:
> >>
> >> - A continuation captures the values of parameters at the time it is
> >> captured. So, if your parameterize is outside of the dispatcher that
> >> calls the continuation, then the code inside the continuation will not
> >> see the parameter change. That's a pretty important feature of
> >> continuations.
> >>
> >> - Web parameters would work the same way as normal parameters and not
> help
> >> you.
> >>
> >> - The stateless Web language guarantees that the parameters will have
> >> values they had when the servlet was initialized.
> >>
> >> - I think that you may want to use a thread-cell as the storage place.
> >>
> >> Jay
> >>
> >>
> >&

[racket-users] DrRacket becomes unresponsive when confronted with a long line

2017-06-26 Thread Philip McGrath
When I open the attached file (which contains a very long line) in DrRacket
and attempt to type a closing parenthesis (either ")" or "]") on line 4
(i.e. to close the define form), DrRacket becomes unresponsive until
forcibly killed (at least for several minutes, and even the caret stops
blinking). Interestingly, if I paste a closing parenthesis at that
position, I can continue editing as normal.

I don't know if this is relevant, but when I attached
drracket-problem-file.rkt, I noticed it somehow wound up in the WXME
format: drracket-problem-plain.rkt is a plain-text version and appears to
exhibit the same issue.

Thanks,
Philip

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


drracket-problem-file.rkt
Description: Binary data


drracket-problem-plain.rkt
Description: Binary data


[racket-users] Re: DrRacket becomes unresponsive when confronted with a long line

2017-06-26 Thread Philip McGrath
I spoke too soon about continuing to edit as normal: actually, I can paste
text and use backspace after the long line, but attempting to type anything
further on in the file renders DrRacket unresponsive. Sometimes, when I
"Force Quit" DrRacket (Mac OS), a DrRacket error window flickers onto the
screen, but it's gone before I can read it.

file->value for me, for now.

-Philip

On Mon, Jun 26, 2017 at 10:22 PM, Philip McGrath <phi...@philipmcgrath.com>
wrote:

> When I open the attached file (which contains a very long line) in
> DrRacket and attempt to type a closing parenthesis (either ")" or "]") on
> line 4 (i.e. to close the define form), DrRacket becomes unresponsive until
> forcibly killed (at least for several minutes, and even the caret stops
> blinking). Interestingly, if I paste a closing parenthesis at that
> position, I can continue editing as normal.
>
> I don't know if this is relevant, but when I attached
> drracket-problem-file.rkt, I noticed it somehow wound up in the WXME
> format: drracket-problem-plain.rkt is a plain-text version and appears to
> exhibit the same issue.
>
> Thanks,
> Philip
>

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


Fwd: [racket-users] Racket APIs doesn't strip Byte Order Mark (BOM) when reading strings from UTF-8 files

2017-06-24 Thread Philip McGrath
I'm grateful to have seen this post so that I had some idea what was going
on when read-xml just gave me the exception:
>
> read-xml: parse-error: expected root element - received "\uFEFF"

on a file that had been validated by libxml.

I confess that this is a bit low-level for my expertise, but I wonder if
perhaps higher-level reading functions like read-xml should take care of
this detail automatically.

-Philip

On Thu, Jun 22, 2017 at 5:33 PM, Matthew Flatt  wrote:

> At Thu, 22 Jun 2017 14:59:35 -0700 (PDT), kay wrote:
> > There're files that starts with BOM. When reading from those files, it
> seems
> > all of Racket's I/O API don't know to strip the BOM, making them
> extremely
> > difficult to work with.
>
> I think that's the normal choice for UTF-8 readers. (Just to make sure
> I typed "UTF-8 BOM " for a few s and got the same
> answer each time.) Apparently, there's some question of what the
> standard recommends for readers, although it clearly recommends against
> a useless BOM for UTF-8 writers.
>
> Some languages/libraries provide an encoding to strip a BOM from UTF-8,
> and selecting that encoding is analogous to using `reencode-input-port`
> in Racket. There's not a convenient encoding for that purpose in
> `iconv`, though, which is what `reencode-input-port` uses.
>
> So, instead of changing the port's encoding, I recommend just
> discarding a BOM match at the start of the port:
>
>  (define (discard-bom p)
>(void (regexp-try-match #rx"^\uFEFF" p)))
>
> Used like this:
>
>   (define port (open-input-file #:mode 'text "test.txt"))
>   (discard-bom p)
>   (define line (read-line port))
>
> --
> 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.


  1   2   3   4   >