Re: [racket-users] Is there a way to return no value?

2015-12-11 Thread David Storrs
On Fri, Dec 11, 2015 at 2:32 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

> On Fri, Dec 11, 2015 at 5:27 PM, David Storrs <david.sto...@gmail.com>
> wrote:
> >
> >
> > On Fri, Dec 11, 2015 at 1:53 PM, Matthew Butterick <chronf...@gmail.com>
> > wrote:
> >>
> >> PS. I'm assuming that you're using `eq?` here in deliberate preference
> to
> >> `equal?`. Because `eq?` is not reliable for string comparisons.
> >
> >
> > Ah.  No, I did not realize that.  I thought that Racket worked on a
> > flyweight pattern where all strings of the same characters were eq?  --
> > isn't that what interned symbols are about?
>
>
> Yes, but strings aren't interned symbols (or symbols, at all, in fact).
> Many (most?) uses of strings don't benefit from interning.
>

Aha.  Good to know, thank you guys.  That would have made for some
difficult-to-find bugs in the future.



>
> -Jon
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Is there a way to return no value?

2015-12-11 Thread David Storrs
On Fri, Dec 11, 2015 at 1:53 PM, Matthew Butterick 
wrote:

> PS. I'm assuming that you're using `eq?` here in deliberate preference to
> `equal?`. Because `eq?` is not reliable for string comparisons.
>

Ah.  No, I did not realize that.  I thought that Racket worked on a
flyweight pattern where all strings of the same characters were eq?  --
isn't that what interned symbols are about?


>
> > > #lang racket
> > > (require rackunit)
> > > (define (foo-3 x) (if (eq? x "foo") (list #t) empty))
> > > (check-equal? (append-map foo-3 '(a b "foo" "bar")) '(#t))
> >
> >
> > That was exactly what I wanted!  Thank you very much.  Also, I hadn't
> yet discovered "append-map", so that's another thank you.
>
>

-- 
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] HTTPS problem with net/url

2016-01-06 Thread David Storrs
Wow.  You're fantastic Matthew, thank you.

> Thanks for delaying this question until the first day that I know the
answer!

No problem.  I'm nice like that. ;>

On Wed, Jan 6, 2016 at 2:15 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> Racket is using the too-old version of "libssl.dylib" that is provided
> by the OS. The too-old version doesn't work with some servers.
>
> For that server, I get the same error in v6.3. It works for me with the
> development version of Racket --- but only because I've been working on
> this problem (and related issues) for the past day. The next Racket
> snapshot will include its own copy of "libssl.1.0.0dylib" to solve the
> problem.
>
> To fix a v6.3 installation, you can download
>
>
> https://racket-packages.s3-us-west-2.amazonaws.com/pkgs/cfaf0f27a375dbdac2e6f68d3863328b64b84eb2/racket-x86_64-macosx-2.zip
>
> and copy the two ".dylib" files from the "racket" folder into
>
>  /Applications/Racket_v6.3/lib/
>
> Thanks for delaying this question until the first day that I know the
> answer!
>
> At Wed, 6 Jan 2016 13:50:51 -0800, David Storrs wrote:
> > Hi folks,
> >
> > tl;dr:  How do I make HTTPS calls from within Racket?
> >
> > Background:
> >
> > I co-write a play-by-post RPG (
> >
> https://forums.sufficientvelocity.com/threads/marked-for-death-a-rational-narut
> > o-quest.24481/
> > -- stop by if you're curious; the barrier to entry is low).   The players
> > all vote to control a single character, so being able to easily tally the
> > votes is a big thing.  As part of my "learning Racket" efforts, I'm
> writing
> > a web spider that will crawl the forum starting from a given location and
> > tally up votes.
> >
> > In this I have the following method:
> >
> > (define (web/call url-string #:method [:method get-pure-port] )
> >   (string->xexp
> >(call/input-url (string->url url-string)
> >(curry :method #:redirections 5)
> >port->string)))
> >
> > (NB:  That originally hardcoded get-pure-port; I put the keyword in just
> as
> > an exercise, but it wouldn't actually work if you gave it an impure port.
> > Will fix when tuits are available.)
> >
> > When I do this:
> >
> > (define u "
> >
> https://forums.sufficientvelocity.com/threads/marked-for-death-a-rational-narut
> > o-qu\
> > est.24481/page-6")
> >
> > (web/call u)
> >
> > I get this:
> >
> > [dstorrs@MacBook-Pro:~/personal/study/scheme/sv_vote_tally:]$
> > racket tallyho.rkt
> > racket tallyho.rkt
> > ssl-connect: connect failed (error:14077410:SSL
> > routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure)
> >   context...:
> >/Applications/Racket_v6.3/collects/openssl/mzssl.rkt:1401:8: loop
> >/Applications/Racket_v6.3/collects/openssl/..:261:28
> >/Applications/Racket_v6.3/collects/openssl/..:259:25
> >/Applications/Racket_v6.3/collects/net/http-client.rkt:224:0
> >
> >
> /Applications/Racket_v6.3/collects/racket/contract/private/arrow-val-first.rkt:
> > 324:3
> >/Applications/Racket_v6.3/collects/net/url.rkt:77:0:
> > http://getpost-impure-port
> >/Applications/Racket_v6.3/collects/net/url.rkt:179:2: redirection-loop
> >/Applications/Racket_v6.3/collects/net/url.rkt:143:0:
> getpost-pure-port
> >/Applications/Racket_v6.3/collects/net/url.rkt:245:4: call/input-url
> >/Users/dstorrs/personal/study/scheme/spider/spider.rkt:204:0:
> web/call19
> >/Users/dstorrs/personal/study/scheme/sv_vote_tally/tallyho.rkt:
> [running
> > body]
> >
> > I've just spent a whole lot of time Googling around.  There are a lot of
> > tutorials about how to write a web *server* in Racket, and some of those
> > touch on SSL and/or HTTPS.  There's not so much for web *clients* though,
> > and the actual web-client module doesn't seem to handle HTTPS.
> >
> > When I read the docs for net/url I saw this bit:
> >
> > Beware: By default, "https" scheme handling does not verify a server’s
> > certificate (i.e., it’s equivalent of clicking through a browser’s
> > warnings), so communication is safe, but the identity of the server is
> not
> > verified. To validate the server’s certificate, set
> current-https-protocol
> > <
> http://docs.racket-lang.org/net/url.html#%28def._%28%28lib._net%2Furl-connect
> .
> > .rkt%29._current-https-protocol%29%29>
> > to a context created with ssl-make-client-context
>

Re: [racket-users] html parsing library does not handle 'article' tags -- any solutions?

2016-01-07 Thread David Storrs
So, I'm now doing this:

(require (planet neil/html-parsing:3:0) (planet neil/xexp:2:0))

Those loaded just fine right off, although I needed to figure out raco pkg
install sxml was necessary, but I got that.

During the install, I got the following:

[dstorrs@MacBook-Pro:~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:]$
raco pkg install sxml
<...ginormous amounts of stuff...>
raco setup: 4 skipping: /xrepl-doc/xrepl/xrepl.scrbl
raco setup: docs failure: query-exec: unable to open the database file
  error code: 14
  SQL: "ATTACH $1 AS other"
  database: #
  mode: 'read-only
  file permissions: (write read)
raco setup: --- installing collections ---
raco setup: --- post-installing collections ---
raco pkg install: packages installed, although setup reported errors
[dstorrs@MacBook-Pro:~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:]$


I do have sqlite3 installed on my machine, so that's not the problem.  Why
is it failing and what do I need to do to fix it?

Dave


On Thu, Jan 7, 2016 at 1:22 PM, Neil Van Dyke  wrote:

>
> BTW, people should *not* get `html-parsing` from the new package system.
> It has an old version that someone else put there unofficially, and it's
> missing a significant change.  I'm still maintaining the official version
> of `html-parsing` in PLaneT (until I get time to change my doc
> tools):
>
> (require (planet neil/html-parsing:3:0))
>
> http://www.neilvandyke.org/racket-html-parsing/
>
> Neil V.
>
>

-- 
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] html parsing library does not handle 'article' tags -- any solutions?

2016-01-07 Thread David Storrs
On Thu, Jan 7, 2016 at 3:25 PM, John Clements <cleme...@brinckerhoff.org>
wrote:

>
> > On Jan 7, 2016, at 2:57 PM, David Storrs <david.sto...@gmail.com> wrote:
> >
> > So, I'm now doing this:
> >
> > (require (planet neil/html-parsing:3:0) (planet neil/xexp:2:0))
> >
> > Those loaded just fine right off, although I needed to figure out raco
> pkg install sxml was necessary, but I got that.
> >
> > During the install, I got the following:
> >
> > [dstorrs@MacBook-Pro:~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:<dev*>]$
> raco pkg install sxml
> > <...ginormous amounts of stuff...>
> > raco setup: 4 skipping: /xrepl-doc/xrepl/xrepl.scrbl
> > raco setup: docs failure: query-exec: unable to open the database file
> >   error code: 14
> >   SQL: "ATTACH $1 AS other"
> >   database: #
> >   mode: 'read-only
> >   file permissions: (write read)
> > raco setup: --- installing collections ---
> > raco setup: --- post-installing collections ---
> > raco pkg install: packages installed, although setup reported errors
> > [dstorrs@MacBook-Pro
> :~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:<dev*>]$
> >
> > I do have sqlite3 installed on my machine, so that's not the problem.
> Why is it failing and what do I need to do to fix it?
>
> Wow!
>
> As quasi-maintainer of the sxml package… i don’t think this has anything
> to do with the sxml package :).
>
> Does the referenced file (docindex.sqlite) exist?
>

Yep.  And it's readable / writable by me, too:

  -rw-r--r--   1 dstorrs  staff  518144 Jan  7 14:48 docindex.sqlite


>
> More generally, I would expect that this doc build failure would not
> affect the operability of the sxml library.
>
>
Doesn't seem to have, no.  I was just wondering what would cause it.


> John
>
>
>
>

On Thu, Jan 7, 2016 at 3:35 PM, Neil Van Dyke <n...@neilvandyke.org> wrote:

> David Storrs wrote on 01/07/2016 05:57 PM:
>
>>
>> (require (planet neil/html-parsing:3:0) (planet neil/xexp:2:0))
>>
>> Those loaded just fine right off, although I needed to figure out raco
>> pkg install sxml was necessary, but I got that.
>>
>
> You shouldn't need to require `(planet neil/xexp:2:0)` explicitly -- just
> consider it to be starting-point documentation on SXML, for now.
>

Ah, thank you.  Removed.


>
> For other SXML tools, I get them (Oleg's SSAX and SXPath, and Jim Bender's
> `sxml-match`) all from PLaneT.  (I recall John C. put some or all of these
> into a mega `sxml` package in the new package system, but I haven't tried
> it.)
>

I've installed the sxml package and will let you know how it goes.


>
>
>> [dstorrs@MacBook-Pro:~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:<dev*>]$
>> raco pkg install sxml
>> <...ginormous amounts of stuff...>
>> raco setup: 4 skipping: /xrepl-doc/xrepl/xrepl.scrbl
>> raco setup: docs failure: query-exec: unable to open the database file
>>   error code: 14
>>   SQL: "ATTACH $1 AS other"
>>   database: #
>>   mode: 'read-only
>>   file permissions: (write read)
>>
>
> I don't know whether this error is related to the packages themselves, or
> just a coincidence.
>

It doesn't seem to be causing issues right now, so I'm just going to roll
by it.



>
> Neil V.
>
>

-- 
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] html parsing library does not handle 'article' tags -- any solutions?

2016-01-07 Thread David Storrs
On Thu, Jan 7, 2016 at 3:53 PM, Jay McCarthy <jay.mccar...@gmail.com> wrote:

> If you use the `html-parsing` package on the package server, you will
> not have these problems. Also, I will merge the upstream patches
> shortly.
>

When I tried to do:  "raco pkg install html-parsing" racket crashed.  Text
dump attached for reference.

Dave


> Jay
>
> On Thu, Jan 7, 2016 at 6:41 PM, David Storrs <david.sto...@gmail.com>
> wrote:
> >
> >
> > On Thu, Jan 7, 2016 at 3:25 PM, John Clements <cleme...@brinckerhoff.org
> >
> > wrote:
> >>
> >>
> >> > On Jan 7, 2016, at 2:57 PM, David Storrs <david.sto...@gmail.com>
> wrote:
> >> >
> >> > So, I'm now doing this:
> >> >
> >> > (require (planet neil/html-parsing:3:0) (planet neil/xexp:2:0))
> >> >
> >> > Those loaded just fine right off, although I needed to figure out raco
> >> > pkg install sxml was necessary, but I got that.
> >> >
> >> > During the install, I got the following:
> >> >
> >> >
> >> > [dstorrs@MacBook-Pro
> :~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:<dev*>]$
> >> > raco pkg install sxml
> >> > <...ginormous amounts of stuff...>
> >> > raco setup: 4 skipping: /xrepl-doc/xrepl/xrepl.scrbl
> >> > raco setup: docs failure: query-exec: unable to open the database file
> >> >   error code: 14
> >> >   SQL: "ATTACH $1 AS other"
> >> >   database:
> >> > #
> >> >   mode: 'read-only
> >> >   file permissions: (write read)
> >> > raco setup: --- installing collections ---
> >> > raco setup: --- post-installing collections ---
> >> > raco pkg install: packages installed, although setup reported errors
> >> >
> >> > [dstorrs@MacBook-Pro
> :~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:<dev*>]$
> >> >
> >> > I do have sqlite3 installed on my machine, so that's not the problem.
> >> > Why is it failing and what do I need to do to fix it?
> >>
> >> Wow!
> >>
> >> As quasi-maintainer of the sxml package… i don’t think this has anything
> >> to do with the sxml package :).
> >>
> >> Does the referenced file (docindex.sqlite) exist?
> >
> >
> > Yep.  And it's readable / writable by me, too:
> >
> >   -rw-r--r--   1 dstorrs  staff  518144 Jan  7 14:48 docindex.sqlite
> >
> >>
> >>
> >> More generally, I would expect that this doc build failure would not
> >> affect the operability of the sxml library.
> >>
> >
> > Doesn't seem to have, no.  I was just wondering what would cause it.
> >
> >>
> >> John
> >>
> >>
> >>
> >
> >
> > On Thu, Jan 7, 2016 at 3:35 PM, Neil Van Dyke <n...@neilvandyke.org>
> wrote:
> >>
> >> David Storrs wrote on 01/07/2016 05:57 PM:
> >>>
> >>>
> >>> (require (planet neil/html-parsing:3:0) (planet neil/xexp:2:0))
> >>>
> >>> Those loaded just fine right off, although I needed to figure out raco
> >>> pkg install sxml was necessary, but I got that.
> >>
> >>
> >> You shouldn't need to require `(planet neil/xexp:2:0)` explicitly --
> just
> >> consider it to be starting-point documentation on SXML, for now.
> >
> >
> > Ah, thank you.  Removed.
> >
> >>
> >>
> >> For other SXML tools, I get them (Oleg's SSAX and SXPath, and Jim
> Bender's
> >> `sxml-match`) all from PLaneT.  (I recall John C. put some or all of
> these
> >> into a mega `sxml` package in the new package system, but I haven't
> tried
> >> it.)
> >
> >
> > I've installed the sxml package and will let you know how it goes.
> >
> >>
> >>
> >>>
> >>>
> >>> [dstorrs@MacBook-Pro
> :~/Dropbox/dstorrs/personal/study/scheme/HTML-TreeBuilder:<dev*>]$
> >>> raco pkg install sxml
> >>> <...ginormous amounts of stuff...>
> >>> raco setup: 4 skipping: /xrepl-doc/xrepl/xrepl.scrbl
> >>> raco setup: docs failure: query-exec: unable to open the database file
> >>>   error code: 14
> >>>   SQL: "ATTACH $1 AS other"
> >>>   database:
> #
> >>>   mode: 'read-only
> >>>   file permissions: (write read)
> >>
&

Re: [racket-users] html parsing library does not handle 'article' tags -- any solutions?

2016-01-07 Thread David Storrs
On Thu, Jan 7, 2016 at 12:28 PM, Neil Van Dyke  wrote:

> I just checked that there wasn't a new bug in my old `html-parsing`
> package, in case that's which package you meant.
>

Sorry, I should have been clearer.  I'm talking about these:  (require html
xml), not yours.


`html-parsing` correctly handles your example for me under Racket 6.3, so
> that package might be a backup option for you (but beware that it uses SXML
> representation, rather than the Racket `xml` representation).
>

 Yeah, I've been looking at it since sending the message.  It parses it
correctly, which is great.  I was just hoping not to have to rewrite
everything for a new representation.

Ah, well.  It's a learning project, so this is just more learning.

Dave



> #lang racket/base
>
> (require (planet neil/html-parsing:3:0))
>
> (html->xexp
>  (string-append
>   "\n"
>   "\n"
>   "\n"
>   "\n"
>   "Message text here \n"
>   "\n"
>   "\n"
>   "\n"))
>
> ;; ==>
> ;; (*TOP*
> ;;  (div (@ (class "messageInfo primaryContent"))
> ;;   "\n"
> ;;   (div (@ (class "messageContent"))
> ;;"\n"
> ;;(article "\n"
> ;; (blockquote (@ (class "messageText
> SelectQuoteContainer ugc baseHtml"))
> ;; "\n"
> ;; "Message text here "
> ;; (br)
> ;; "\n")
> ;; "\n")
> ;;"\n")
> ;;   "\n"))
>
> http://www.neilvandyke.org/racket-html-parsing/
>
> Neil V.
>
>

-- 
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] html parsing library does not handle 'article' tags -- any solutions?

2016-01-07 Thread David Storrs
Hi folks,

I'm using the html and xml libraries to parse a page that includes the
following HTML:





Message text here 




When I parse this, the 'article' tag simply isn't parsed -- it lists the
contents of the messageContent div as just a series of PCDATA statements
containing "\n"

Is there a way to extend the library, or do I need to switch to a different
parser?

Dave

-- 
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] HTTPS problem with net/url

2016-01-06 Thread David Storrs
Hi folks,

tl;dr:  How do I make HTTPS calls from within Racket?

Background:

I co-write a play-by-post RPG (
https://forums.sufficientvelocity.com/threads/marked-for-death-a-rational-naruto-quest.24481/
-- stop by if you're curious; the barrier to entry is low).   The players
all vote to control a single character, so being able to easily tally the
votes is a big thing.  As part of my "learning Racket" efforts, I'm writing
a web spider that will crawl the forum starting from a given location and
tally up votes.

In this I have the following method:

(define (web/call url-string #:method [:method get-pure-port] )
  (string->xexp
   (call/input-url (string->url url-string)
   (curry :method #:redirections 5)
   port->string)))

(NB:  That originally hardcoded get-pure-port; I put the keyword in just as
an exercise, but it wouldn't actually work if you gave it an impure port.
Will fix when tuits are available.)

When I do this:

(define u "
https://forums.sufficientvelocity.com/threads/marked-for-death-a-rational-naruto-qu\
est.24481/page-6")

(web/call u)

I get this:

[dstorrs@MacBook-Pro:~/personal/study/scheme/sv_vote_tally:]$
racket tallyho.rkt
racket tallyho.rkt
ssl-connect: connect failed (error:14077410:SSL
routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure)
  context...:
   /Applications/Racket_v6.3/collects/openssl/mzssl.rkt:1401:8: loop
   /Applications/Racket_v6.3/collects/openssl/..:261:28
   /Applications/Racket_v6.3/collects/openssl/..:259:25
   /Applications/Racket_v6.3/collects/net/http-client.rkt:224:0

/Applications/Racket_v6.3/collects/racket/contract/private/arrow-val-first.rkt:324:3
   /Applications/Racket_v6.3/collects/net/url.rkt:77:0:
http://getpost-impure-port
   /Applications/Racket_v6.3/collects/net/url.rkt:179:2: redirection-loop
   /Applications/Racket_v6.3/collects/net/url.rkt:143:0: getpost-pure-port
   /Applications/Racket_v6.3/collects/net/url.rkt:245:4: call/input-url
   /Users/dstorrs/personal/study/scheme/spider/spider.rkt:204:0: web/call19
   /Users/dstorrs/personal/study/scheme/sv_vote_tally/tallyho.rkt: [running
body]

I've just spent a whole lot of time Googling around.  There are a lot of
tutorials about how to write a web *server* in Racket, and some of those
touch on SSL and/or HTTPS.  There's not so much for web *clients* though,
and the actual web-client module doesn't seem to handle HTTPS.

When I read the docs for net/url I saw this bit:

Beware: By default, "https" scheme handling does not verify a server’s
certificate (i.e., it’s equivalent of clicking through a browser’s
warnings), so communication is safe, but the identity of the server is not
verified. To validate the server’s certificate, set current-https-protocol

to a context created with ssl-make-client-context
,
and enable certificate validation in the context with ssl-set-verify!

.

When I look at 'current-https-protocol' I see this:

Changed in version 6.1 of package base: Added 'tls11 and 'tls12. Changed in
version 6.1.1.3: Default to new 'auto and disabled SSL 2.0 and 3.0 by
default.

So it should be attempting to negotiate the protocol on its own.

Help me, wisdom of crowds.  What is it that I don't know?

Dave

-- 
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] Simple regex question. How to match this: "[X] foo"

2016-01-08 Thread David Storrs
I'm having some trouble with the syntax for regexen, and the docs are a bit
opaque on this point.

Given this:

(regex-match*
#px"\[[xX\d]\]"
"[1] foo \n [2] bar \n [x] baz \n [X] baz \n"")

I'm expecting it to return:

( "[1]" "[2]" "[x]" "[X]")

Instead it complains about undefined identifiers.

For that matter, I can't even get it to use a simple \d class.

-> (regexp-match (pregexp "\\d") "2349803")  ;; try with two \\ because
it's a string
(regexp-match (pregexp "\\d") "2349803")
")\n(regexp-match (pregexp "
; |\d|: undefined;
;  cannot reference undefined identifier
; [,bt for context]
") "
2349803
-> (regexp-match (pregexp "\d") "2349803")  ;; try with one \
(regexp-match (pregexp "\d") "2349803")
")\n(regexp-match (pregexp "
; d: undefined;
;  cannot reference undefined identifier
; [,bt for context]
") "
2349803
-> (regexp-match #px"\d" "2349803")   ;; try with a literal, one \
(regexp-match #px"\d" "2349803")
")\n(regexp-match #px"
; d: undefined;
;  cannot reference undefined identifier
; [,bt for context]
" "
2349803
-> (regexp-match #px"\\d" "2349803")  ;; try with a literal, two \\
(regexp-match #px"\\d" "2349803")
")\n(regexp-match #px"
; |\d|: undefined;
;  cannot reference undefined identifier
; [,bt for context]
" "
2349803

What is the correct syntax here?

Related question:  Perl has a capacity to change your delimiters on regexen
in order to avoid having to backwhack everything.  For example, these all
work:

Matching:
m/foo/
m!foo!
m{foo}

Substituting:
s/foo/bar/
s!foo!bar!
s

Is there a way to get Racket to do the same thing?

Thanks for your help, folks; I can't believe I'm having to ask about this,
but I've been hammering on it with no success.

-- 
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] Simple regex question. How to match this: "[X] foo"

2016-01-08 Thread David Storrs
On Fri, Jan 8, 2016 at 10:56 PM, Neil Van Dyke <n...@neilvandyke.org> wrote:

> David Storrs wrote on 01/09/2016 01:38 AM:
>
>>
>> (regex-match*
>> #px"\[[xX\d]\]"
>> "[1] foo \n [2] bar \n [x] baz \n [X] baz \n"")
>>
>
> (regexp-match*
>  #px"\\[[xX\\d]\\]"
>  "[1] foo \n [2] bar \n [x] baz \n [X] baz \n")
> ;;==> ("[1]" "[2]" "[x]" "[X]")
>
> Looks like maybe a typo in the procedure name, and the backslashes needed
> to be escaped for the string literal.
>

Drat.  I kept looking for issues with the escape code, I missed the fact
that the problem was with the 'regexP' function.  Thanks.



>
> Related question:  Perl has a capacity to change your delimiters on
>> regexen in order to avoid having to backwhack everything.
>>
>
> You could make a Racket reader that did this.  Or you can find some of the
> interesting s-expression regular expression languages (I think Olin Shivers
> did one).  Or just not use regexps so much ("
> http://regex.info/blog/2006-09-15/247;).
>

Before I even clicked that link, I knew what it was going to be.  I've
heard that expression a lot and never quite understood it, because it seems
so unilateral. Serious question, not being snarky:  what would you suggest
using for simple text processing if not regular expressions?  For example,
my project right now is to take this chunk of text:

===QUOTE
[X] Escape with Inoue-sensei
*No. of votes: 10*
Usernames <http://forums.sufficientvelocity.com/posts/5096365/>
Ridiculously Average Guy
<http://forums.sufficientvelocity.com/posts/5101835/>
Brain_Caster <http://forums.sufficientvelocity.com/posts/5102509/>
Xyzarach <http://forums.sufficientvelocity.com/posts/5103894/>
gbear605 <http://forums.sufficientvelocity.com/posts/5104609/>
fictionfan <http://forums.sufficientvelocity.com/posts/5105921/>
Chronic <http://forums.sufficientvelocity.com/posts/5106381/>
_brightwing <http://forums.sufficientvelocity.com/posts/5106611/>
Rihaku <http://forums.sufficientvelocity.com/posts/5108015/>
Sigil <http://forums.sufficientvelocity.com/posts/5108375/>

[X] Forget all these disloyal options and stick with Shikigami-sensei's plan
===/QUOTE

...and extract the following strings:

"[X] Escape with Inoue-sensei"
"[X] Forget all these disloyal options and stick with Shikigami-sensei's
plan"

What method would you suggest for that?


Thanks again for the help with the syntax stuff.

Dave



> Neil V.
>
>

-- 
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] Problems with 'provide'

2015-12-23 Thread David Storrs
Hi folks,

I have a file, "util.rkt", the complete text of which is:

== QUOTE
#lang racket

(require racket/pretty)

(define (print-prettier s)
  (parameterize ([pretty-print-columns 1])
(pretty-print s)))

(define (hash-key-is? h k v)
  (and (hash-has-key? h k)
   (equal? (hash-ref h k) v)))

(provide (all-defined-out))
 /QUOTE

(Without the ===QUOTE stuff, obviously)

>From the same directory, I do this:

[dstorrs@localhost:~/scheme:<>]$ racket
racket
Welcome to Racket v6.3.
-> (require "./util.rkt")
(require "./util.rkt")
-> hash-key-is?
hash-key-is?
; hash-key-is?: undefined;
;  cannot reference undefined identifier
; [,bt for context]
-> (require "util.rkt")
(require "util.rkt")
-> hash-key-is?
hash-key-is?
; hash-key-is?: undefined;
;  cannot reference undefined identifier
; [,bt for context]


I've also tried changing the provide like to:  (provide print-prettier
hash-key-is?) but that changed nothing.

I've got another module which ends with a (provide (all-defined-out)) and
that one makes its functions available just fine.

What's going on?

-- 
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] Re: Problems with 'provide'

2015-12-23 Thread David Storrs
Nope, only one. And I checked to make sure I was in the right directory.

On Wednesday, December 23, 2015, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> Is it possible you have two util.rkt files and you are in the wrong
> directory?
>
> Robby
>
> On Wednesday, December 23, 2015, David Storrs <david.sto...@gmail.com
> <javascript:_e(%7B%7D,'cvml','david.sto...@gmail.com');>> wrote:
>
>> Hi folks,
>>
>> I have a file, "util.rkt", the complete text of which is:
>>
>> == QUOTE
>> #lang racket
>>
>> (require racket/pretty)
>>
>> (define (print-prettier s)
>>   (parameterize ([pretty-print-columns 1])
>> (pretty-print s)))
>>
>> (define (hash-key-is? h k v)
>>   (and (hash-has-key? h k)
>>(equal? (hash-ref h k) v)))
>>
>> (provide (all-defined-out))
>>  /QUOTE
>>
>> (Without the ===QUOTE stuff, obviously)
>>
>> From the same directory, I do this:
>>
>> [dstorrs@localhost:~/scheme:<>]$ racket
>> racket
>> Welcome to Racket v6.3.
>> -> (require "./util.rkt")
>> (require "./util.rkt")
>> -> hash-key-is?
>> hash-key-is?
>> ; hash-key-is?: undefined;
>> ;  cannot reference undefined identifier
>> ; [,bt for context]
>> -> (require "util.rkt")
>> (require "util.rkt")
>> -> hash-key-is?
>> hash-key-is?
>> ; hash-key-is?: undefined;
>> ;  cannot reference undefined identifier
>> ; [,bt for context]
>>
>>
>> I've also tried changing the provide like to:  (provide print-prettier
>> hash-key-is?) but that changed nothing.
>>
>> I've got another module which ends with a (provide (all-defined-out)) and
>> that one makes its functions available just fine.
>>
>> What's going on?
>>
>>
>>
>>
>>
>> --
>> 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] Code critique request: data/fetch, proc for walking hashes/lists

2016-01-10 Thread David Storrs
I feel like I'm starting to be somewhat functional with Racket, but I'd
like to get more idiomatic.  I'd appreciate it if people would critique the
following code:


(define (data/fetch s key-list)
  (if (or (empty? s)
  (nor (list? s)
   (hash? s)))
  s
  (let* ([key (car key-list)]
 [val (if (hash? s)
  (hash-ref s key)
  (key s))])
(data/fetch val (cdr key-list)

The intent is to take a nested data structure (hashes and lists only) and
walk down through it without needing a whole series of (hash-ref (car
(hash-ref...

Example:

-> d
'#hash(("foo" . "bar")
   (blag . #hash(("foo" . "bar")))
   (quux . (foo bar))
   (baz . 7))

-> (data/fetch d (list 'blag "foo"))
"bar"

-> (data/fetch d (list "no-such-key"))
; hash-ref: no value found for key
;   key: "no-such-key"
; [,bt for context]

-> L
'("foo" 7 (x y))

-> (data/fetch l (list first second))
"foo"

-> (data/fetch l (list third second))
'y

Thoughts?

-- 
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] Using Racket server in production?

2016-01-23 Thread David Storrs
Is anyone here using the Racket web server in production? If so, what's
your experience with it?  Specifically:

Have you had any difficulty integrating it with outside systems? (e.g.
Varnish, Redis, load balancer ooling, etc)  Most of this I wouldn't expect
to be an issue, but I figured I'd ask for unknown unknowns.

What sort of load testing have you done and how has it held up?

What has your general experience been as regards deployment speed, etc?

Can you update the system on the fly without interrupting current users, or
does it require bouncing the server?

I'm doing my due diligence on a tech startup concept and would like to use
Racket, but I want to make sure the tools are appropriate. For reference,
the concept is crowdfunding for artists with a focus on campaign growth
instead of enablement.

Dave

-- 
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] Using Racket server in production?

2016-01-24 Thread David Storrs
Thank you so much, Marc.  I really appreciate the detailed answer and the
numbers.  I'll feel much better about using Racket for production now.

Dave

On Sun, Jan 24, 2016 at 10:27 AM, Marc Burns <m4bu...@uwaterloo.ca> wrote:

> Hi David,
>
> I use the Racket web server in production to serve authentication and
> misc. requests that don't play nicely with our main web framework.
>
> There's been no difficulty integrating with outside systems. We use nginx
> in front of Racket for SSL termination and some light request processing;
> nothing unusual was required. Stephen Chang's redis client library works
> well. There were once some issues with file descriptor cleanup in the web
> server, but I haven't encountered any leaks for a couple of years.
>
> Load testing:
>
> 
> m4burns@m4burns:~$ ab -n 1 -c 10 http://192.168.1.1:12345/auth/whoami
> This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
> Licensed to The Apache Software Foundation, http://www.apache.org/
>
> Benchmarking 192.168.1.1 (be patient)
> Completed 1000 requests
> Completed 2000 requests
> Completed 3000 requests
> Completed 4000 requests
> Completed 5000 requests
> Completed 6000 requests
> Completed 7000 requests
> Completed 8000 requests
> Completed 9000 requests
> Completed 1 requests
> Finished 1 requests
>
>
> Server Software:Racket
> Server Hostname:192.168.1.1
> Server Port:12345
>
> Document Path:  /auth/whoami
> Document Length:28 bytes
>
> Concurrency Level:  10
> Time taken for tests:   7.261 seconds
> Complete requests:  1
> Failed requests:0
> Non-2xx responses:  1
> Total transferred:  227 bytes
> HTML transferred:   28 bytes
> Requests per second:1377.15 [#/sec] (mean)
> Time per request:   7.261 [ms] (mean)
> Time per request:   0.726 [ms] (mean, across all concurrent requests)
> Transfer rate:  305.29 [Kbytes/sec] received
>
> Connection Times (ms)
>   min  mean[+/-sd] median   max
> Connect:00   0.0  0   0
> Processing: 17   8.3  6 194
> Waiting:16   7.7  5 193
> Total:  17   8.3  6 194
>
> Percentage of the requests served within a certain time (ms)
>   50%  6
>   66%  7
>   75%  7
>   80%  8
>   90% 10
>   95% 15
>   98% 18
>   99% 20
>  100%194 (longest request)
> 
>
> So, it does just fine under heavy load. This service has been left running
> for a couple months at a time and nothing weird has happened.
>
> Regarding deployment speed, Typed Racket is a bit slow to compile right
> now. You can get around this by structuring your program (possibly using
> units) to allow greater build parallelism. Untyped Racket builds quickly.
>
> Unless you go out of your way to implement reloadable components (possibly
> using https://github.com/tonyg/racket-reloadable ), updating the system
> will require bouncing the server. If your server doesn't maintain internal
> state between requests, you can bounce it without any interruption. For
> example, you could set up nginx to use a backup upstream server on an
> alternate port. When you want to upgrade, start the new server on the
> alternate port before you kill the old one. After the old one has died, you
> can move back to the primary port.
>
> The continuation-based framework for managing state is very convenient. If
> you choose to keep state on the server, some care must be taken to limit
> memory use and properly evict unneeded continuations. Keeping state on the
> client works brilliantly.
>
> Using the Racket webserver has always been a breeze for me. It's easy to
> do stuff that requires mucking with HTTP and it's easy to build complete,
> reliable apps. This kind of flexibility really makes my day.
>
> Good luck in your endeavor.
>
> Cheers,
> Marc Burns
>
>
> On 2016-01-23 5:23 PM, David Storrs wrote:
>
> Is anyone here using the Racket web server in production? If so, what's
> your experience with it?  Specifically:
>
> Have you had any difficulty integrating it with outside systems? (e.g.
> Varnish, Redis, load balancer ooling, etc)  Most of this I wouldn't expect
> to be an issue, but I figured I'd ask for unknown unknowns.
>
> What sort of load testing have you done and how has it held up?
>
> What has your general experience been as regards deployment speed, etc?
>
> Can you update the system on the fly without interrupting current
> users, or does it require bouncing the server?
>

Re: [racket-users] What do you use macros for?

2016-04-07 Thread David Storrs
That makes sense.  Thank you, Rickard.

On Wed, Apr 6, 2016 at 11:13 PM, Rickard Andersson <
rickard.m.anders...@gmail.com> wrote:

> > What have you used them for?
>
> While it's certainly not the most impactful macro in the world, I was
> pretty pleased with being able to do this:
>
> https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt
>
> It's a macro that allows me to bundle expected inputs with expected
> outputs for those inputs together with a contract definition, meaning
> I have a tighter coupling of test-cases together with definitions of
> functions without a bunch of `(module+ test ...)`.
>
> > What do they do that a function couldn't?
>
> In this case we're actually generating the `(module+ test ...)` entries
> based on the lists inside the macro, but then simply appending these to
> our generated code, meaning they won't be defined in a function (which
> they can't), but rather added as if we were doing it manually.
>
> The manual variant for the first example in this file would look as
> follows:
>
> (define/contract (square x)
>   (integer? . -> . integer?)
>   (expt x 2))
>
> (module+ test
>   (check-equal? (square 2) 4)
>   (check-equal? (square 3) 9)
>   (check-equal? (square 5) 25))
>
> We're skipping straight to defining inputs and outputs, only because we
> are using macros.
>
> > What are good times to use them
>
> In this case I wanted to succinctly define test cases for functions and
> for this to be tighter coupled to function definitions, but you can't
> call `module+` while inside a function, so the only real solution is to
> lift that content outside the function definition.
>
> > ... what are their drawbacks?
>
> The obvious drawback here is that this macro is next to useless for
> anyone else when they stumble upon it. When you have an actually useful
> macro (I hesitate to call this one universally useful, though I like it
> myself), this is solved by great documentation facilities, like
> Scribble, as well as good macro constructs that will help you guide your
> user through proper usage.
>
> On Wed, Apr 06, 2016 at 05:19:05PM -0700, David Storrs wrote:
> > Hi folks,
> >
> > Macros are one of the biggest features that people list as the advantages
> > of LISP / Scheme, and I don't really understand them.  I get the basics
> --
> > they can create new code structures -- but not the implications  What
> have
> > you used them for, and what do they do that a function couldn't?  What
> are
> > good times to use them, and what are their drawbacks?
> >
> > Dave
> >
> > --
> > 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] What do you use macros for?

2016-04-07 Thread David Storrs
That's very cool, Dan.  Thanks for the example.  (Although, shouldn't -4^2
+ 4^2 = 32, not 31?)

If/when you do the 'further challenges' section, could you post the result
here?  It looks like it would be useful.

Dave


On Thu, Apr 7, 2016 at 1:53 PM, Daniel Prager 
wrote:

> On Thu, Apr 7, 2016 at 4:13 PM, Rickard Andersson <
> rickard.m.anders...@gmail.com> wrote:
>
>> > What have you used them for?
>>
>> https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt
>>
>> It's a macro that allows me to bundle expected inputs with expected
>> outputs for those inputs together with a contract definition, meaning
>> I have a tighter coupling of test-cases together with definitions of
>> functions without a bunch of `(module+ test ...)`.
>>
>
> That's a neat example, both as motivation for those asking "why macros?"
> and folks like me who want to get better at writing them.
>
> For a bit of learning-by-doing I was able to easily change Rickard's macro
> to get a different surface syntax that correctly processes:
>
> (define/cti (square2 x y)
>   contract:
>   (integer? integer? . -> . integer?)
>
>   tests:
>   [2 3 -> 13]
>   [1 2 -> 5]
>   [-4 4 -> 31]
>
>   implementation:
>   (+ (expt x 2) (expt y 2)))
>
> Further challenges:
>
>- allow the "contract:" and "tests:" sections to be blank, but print a
>warning
>- add handling for default, keyword and rest parameters
>
> 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.


[racket-users] What do you use macros for?

2016-04-06 Thread David Storrs
Hi folks,

Macros are one of the biggest features that people list as the advantages
of LISP / Scheme, and I don't really understand them.  I get the basics --
they can create new code structures -- but not the implications  What have
you used them for, and what do they do that a function couldn't?  What are
good times to use them, and what are their drawbacks?

Dave

-- 
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] What do you use macros for?

2016-04-06 Thread David Storrs
Nice.  Thank you, Asumu.  That helps.

On Wed, Apr 6, 2016 at 5:39 PM, Asumu Takikawa <as...@ccs.neu.edu> wrote:

> Hi David,
>
> On 2016-04-06 17:19:05 -0700, David Storrs wrote:
> >Macros are one of the biggest features that people list as the
> advantages
> >of LISP / Scheme, and I don't really understand them.  I get the
> basics --
> >they can create new code structures -- but not the implications  What
> have
> >you used them for, and what do they do that a function couldn't?
> What are
> >good times to use them, and what are their drawbacks?
>
> There are three "canonical" uses of macros that people often talk about.
> The
> main reference for this idea is an e-mail by Matthias on the LL1 list:
>
>
> http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg01539.html
>
> (quoted below)
>
> At Sat, 25 May 2002 11:03:02 -0400 (EDT), Matthias Felleisen wrote:
> >  I'd like to propose that there are three disciplined uses of macros:
> >
> >  1. data sublanguages: I can write simple looking expressions and
> >  create complex nested lists/arrays/tables with quote, unquote etc
> >  neatly dressed up with macros.
> >
> >  2. binding constructs: I can introduce new binding constructs with
> >  macros. That helps me get rid of lambda's and with placing things
> >  closer together that belong together. For example, one of our teachpacks
> >  contains a form
> >(web-query ([last-name
> >  (string-append "Hello " first-name " what's your last
> name?"])
> >  ... last-name ... first-name ...)
> >  with the obvious interaction between a program and a Web consumer
> implied.
> >[Note: In ML you could write
> >   web-query(fn last-name => ...)string_append(...)
> > but by golly that's a pain and an unnecessary pattern.]
> >
> >
> >  3. evaluation reordering: I can introduce constructs that delay/postpone
> >  the evaluation of expressions as needed. Think of loops, new
> conditionals,
> >  delay/force, etc.
> >[Note: In Haskell, you don't need that one.]
> >
> >  I understand that Lispers use macros for other reasons. In all honesty,
> I
> >  believe that this is partly due to compiler deficiencies, and partly
> due to
> >  "semantic" irregularities in the target language.
> >
> >  I challenge people to address all three issues when they say language X
> >  can do what macros can do.
>
> I think Modern Racket may have additional uses for macros that don't quite
> fit
> into these. For example, the use of macros that expand into submodules in
> order
> to provide metadata for other programs/tools.
>
> Cheers,
> Asumu
>

-- 
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] Re: How to differentiate between files and directories?

2016-07-21 Thread David Storrs
Hi Stephen,

Yep, I saw file-exists?, thanks. Like I said, I don't want to check the
disk twice (once when getting the list of paths with (in-directory), then
again with file-exists?). I don't care if the file actually exists on disk,
I care if this path is describing a file or a directory. I'm hoping to be
able to do something like, e.g., use (fold-files) or (find-files)
to process just files or just directories.

On Thursday, July 21, 2016, Stephen De Gabrielle <spdegabrie...@gmail.com>
wrote:

>
> http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28quote._~23~25kernel%29._file-exists~3f%29%29
>
> in http://docs.racket-lang.org/reference/Filesystem.html
>
>
>
> (file-exists?
> <http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28quote._~23~25kernel%29._file-exists~3f%29%29>
>  path) → boolean?
> <http://docs.racket-lang.org/reference/booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29>
> (link-exists?
> <http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28quote._~23~25kernel%29._link-exists~3f%29%29>
>  path) → boolean?
> <http://docs.racket-lang.org/reference/booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29>
>
> (directory-exists?
> <http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28quote._~23~25kernel%29._directory-exists~3f%29%29>
>  path) → boolean?
> <http://docs.racket-lang.org/reference/booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29>
>
>   path : path-string?
> <http://docs.racket-lang.org/reference/Manipulating_Paths.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-string~3f%29%29>
>
> Returns #t if path refers to a directory, #f otherwise.
>
>
> On Thu, Jul 21, 2016 at 7:44 PM, David Storrs <david.sto...@gmail.com
> <javascript:_e(%7B%7D,'cvml','david.sto...@gmail.com');>> wrote:
>
>> Silly question: given a <#path>, how do I tell if it's to a file,
>> directory, link, etc?  I'd like to know this in general, although the
>> proximate issue is that I would like to use (in-directory) to process
>> all the files in a directory, but I need a way to ignore everything
>> that isn't a file.
>>
>> I saw 'file-exists?' but I don't want to check the disk twice, I just
>> want to know what type it is.  That information should have been
>> available when the path was constructed.
>>
>>
>> In a related question, is there a way to introspect a struct to find
>> out what its fields are?
>>
>>
>> Dave
>>
>> --
>> 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
>> <javascript:_e(%7B%7D,'cvml','racket-users%2bunsubscr...@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] Re: How to differentiate between files and directories?

2016-07-21 Thread David Storrs
So there's no way to query the interface of a struct?

On Thursday, July 21, 2016, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> On Thu, Jul 21, 2016 at 2:44 PM, David Storrs <david.sto...@gmail.com
> <javascript:_e(%7B%7D,'cvml','david.sto...@gmail.com');>> wrote:
>>
>>
>>
>> In a related question, is there a way to introspect a struct to find
>> out what its fields are?
>>
>>
> If you mean the field values: yes, but only if the struct is transparent
> or prefab or if you have the proper inspector, which you probably do not.
> You can generally try struct->vector and see if you get anything useful.
>
> If you mean the field names: I don't think so; I don't think they exist at
> runtime.
>
> - Jon
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How to differentiate between files and directories?

2016-07-21 Thread David Storrs
Silly question: given a <#path>, how do I tell if it's to a file,
directory, link, etc?  I'd like to know this in general, although the
proximate issue is that I would like to use (in-directory) to process
all the files in a directory, but I need a way to ignore everything
that isn't a file.

I saw 'file-exists?' but I don't want to check the disk twice, I just
want to know what type it is.  That information should have been
available when the path was constructed.


In a related question, is there a way to introspect a struct to find
out what its fields are?


Dave

-- 
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] Re: How to differentiate between files and directories?

2016-07-21 Thread David Storrs
Okay. Thanks for the help, all.

On Thursday, July 21, 2016, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> On Thu, Jul 21, 2016 at 3:59 PM, David Storrs <david.sto...@gmail.com
> <javascript:_e(%7B%7D,'cvml','david.sto...@gmail.com');>> wrote:
>
>> So there's no way to query the interface of a struct?
>>
>>
>>
> Not in general, no. -J
>
>
>

-- 
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] Is my model of (values) accurate?

2016-07-22 Thread David Storrs
*sigh*  Just when I was feeling clever, I discover I missed the obvious.  ;>


Thanks, everyone.

On Fri, Jul 22, 2016 at 8:05 PM, Ryan Culpepper <ry...@ccs.neu.edu> wrote:

> On 07/22/2016 07:58 PM, David Storrs wrote:
>
>> Thanks Jon, I appreciate the clear explanation.
>>
>> I'm using call-with-values in database code in order to turn a list into
>> an acceptable set of bind parameters.  Here's an example:
>>
>> (query-exec conn "insert into foo (bar, baz) values ($1, $2)" (some-func))
>>
>> some-func returns a list, '("bob", "george").  query-exec throws an
>> exception because it wants to see two elements for the bind parameters,
>> not a list.  The solution I found was this:
>>
>> (call-with-values
>>  (lambda () (apply values the-list))
>>  (curry query-exec conn stmt))
>>
>
> You can also write that as just
>
>   (apply query-exec conn stmt the-list)
>
> so your example above would be
>
>   (apply query-exec
>
>  conn
>  "insert into foo (bar, baz) values ($1, $2)"
>  (some-func))
>
> Ryan
>
>

-- 
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] Is my model of (values) accurate?

2016-07-22 Thread David Storrs
I think I don't understand (values) very well. I expected the
following to return '(1 2 3):

-> (list (apply values '(1 2 3)))

(list (apply values '(1 2 3)))
; result arity mismatch;
;  expected number of values not received
;   expected: 1
;   received: 3
; [,bt for context]

This, on the other hand, does:

-> (call-with-values  (lambda () (apply values '(1 2 3)) list)
'(1 2 3)

The best mental model I've been able to come up with is that (values)
returns its results vertically but most functions expect to get them
horizontally and will die if there are parallel lines of uncollected
values. Under this model (call-with-values) collects values from the Y
axis and pivots them back onto the X axis for consumption by regular
functions. This feels like a fragile analogy though.  Would someone
please fill me in on how it actually works?

Dave

-- 
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] Is my model of (values) accurate?

2016-07-22 Thread David Storrs
Thanks Jon, I appreciate the clear explanation.

I'm using call-with-values in database code in order to turn a list into an
acceptable set of bind parameters.  Here's an example:

(query-exec conn "insert into foo (bar, baz) values ($1, $2)" (some-func))

some-func returns a list, '("bob", "george").  query-exec throws an
exception because it wants to see two elements for the bind parameters, not
a list.  The solution I found was this:

(call-with-values
(lambda () (apply values the-list))
(curry query-exec conn stmt))

I know that I could have dug the parameters out with (car) and (cadr), but
this seemed like it would be a common enough pattern that it was worth
coming up with a standard answer that would work for any number of params.

This is what got me thinking about how exactly (values) worked.


On Fri, Jul 22, 2016 at 7:28 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> On Fri, Jul 22, 2016 at 6:30 PM, David Storrs <david.sto...@gmail.com>
> wrote:
>
>>
>> The best mental model I've been able to come up with is that (values)
>> returns its results vertically but most functions expect to get them
>> horizontally and will die if there are parallel lines of uncollected
>> values. Under this model (call-with-values) collects values from the Y
>> axis and pivots them back onto the X axis for consumption by regular
>> functions. This feels like a fragile analogy though.  Would someone
>> please fill me in on how it actually works?
>>
>>
>
> When you do:
>
>(values ...)
>
> in a DrRacket window, it does list the values vertically, but that's
> probably not a very useful way to think about what `values` is.  You can
> think of `values` as a constructor of a second-class tuple. The fact that
> the resultant tuple is "second-class" is very important here. You can't
> give a name to this tuple. For example,
>
>(define foo (values 1 2 3))
>
> is illegal.  You can't pass it as an argument to a procedure:
>
>(list (values 1 2 3))
>
> is likewise illegal. There is, in fact, very little you can do with this
> tuple other than let `call-with-values` unpack it.
>
> `call-with-values` is special (like call-with-continuation is special).
> Its first argument, a zero-arity procedure, produces a values which are
> then passed *as separate arguments* -- not as a second-class tuple -- to
> its second argument. That's what `call-with-values` does: it translates
> this second-class tuple into separate procedure arguments.
>
> `call-with-values` is rarely used directly. It's far more common to use
> `define-values` or `let-values` (or one of its variants). For example,
> although you can't do:
>
>(define foo (values 1 2 3))
>
> You can do:
>
>(define-values (a b c) (values 1 2 3))
>
> There is one special case to keep in mind: a unary use of `values`, e.g.:
>
>(values 1)
>
> is exactly equivalent to its argument. That is, (values 1) *is exactly* 1.
> That's not true for any other arity of `values`. (This is also how
> *first*-class tuples in ML behave.)
>
> For my own part, I'm not a big fan of `values` and `call-with-values`.
> Their use is for returning multiple values from a procedure -- which you
> can also do by returning a first-class, composite piece of data, like a
> vector or a list. The one advantage of second-class tuples is that, because
> there's so little you can do
> with them, they're easier to give optimized representations.
>
> - Jon
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-10 Thread David Storrs
Yes.  Yes, that exactly solves my problem.  *sheepish look*   Thanks.

On Tue, Aug 9, 2016 at 8:47 PM, Matthew Butterick <m...@mbtype.com> wrote:

>
> On Aug 9, 2016, at 7:52 PM, David Storrs <david.sto...@gmail.com> wrote:
>
> > This solves the problem of creating top-level bindings at run time (more
> or less run time, anyway), but it doesn't handle the lexical closure part.
> Is there a way to do that?
>
> The code generated by a macro automatically adopts the lexical context at
> the macro-definition site. So is this not analogous to your Perl code?
>
> ;;;
>
> #lang racket
>
> (define z 1)
>
> (define-syntax-rule (makefuns name ...)
>   (begin
> (define (name)
>   (displayln (format "~a: ~a" 'name z))
>   (set! z (+ z 1))) ...))
>
> (makefuns foo bar baz)
>
> (foo) ; prints "foo: 1"
> (bar) ; prints "bar: 2"
> (baz) ; prints "baz: 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.


Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread David Storrs
On Tue, Aug 9, 2016 at 2:35 PM, Ben Greenman <benjaminlgreen...@gmail.com>
wrote:

> Here's something in the ballpark.
>
> #lang racket
>
> (define-namespace-anchor nsa)
> (define ns (namespace-anchor->namespace nsa))
>
> (let ((xyz 1))
>   (for ((name '(x y z)))
> (namespace-set-variable-value! name (lambda () (displayln (format
> "~a: ~a" name xyz)) (set! xyz (add1 xyz))) #f ns)))
>
> (eval '(x) ns)
>
>
This doesn't actually create a top-level binding, though.  I can't say (x)
and have it work.

(Incidentally, is 'top-level binding' the right term here?)


> On Tue, Aug 9, 2016 at 5:20 PM, 'John Clements' via Racket Users <
> racket-users@googlegroups.com> wrote:
>
>>
>> > On Aug 9, 2016, at 4:46 PM, David Storrs <david.sto...@gmail.com>
>> wrote:
>> >
>> > In Perl it's possible to generate main-namespace functions like so:
>> >
>> > perl -E 'my $z = 1; for (qw/foo bar baz/) {my $x = $_; *$_ = sub{ say
>> "$x: ", $z++ }};  foo(); bar(); baz();'
>> >
>> > This outputs:
>> > foo: 1
>> > bar: 2
>> > baz: 3
>> >
>> >
>> > Note that it is generating top-level subroutines that can be called
>> from elsewhere in the program (including other modules) and that those
>> subroutines close over existing lexical variables.
>> >
>> >
>> > I tried to do this in Racket and haven't been able to figure it out:
>> >
>> > First attempt, only partial solution:
>> > $ racket
>> > -> (for ((name '(x y z))) (define name (lambda () (displayln "foo"
>> >
>> > ; /Applications/Racket_v6.3/collects/racket/private/for.rkt:1487:62:
>> begin
>> > ;   (possibly implicit): no expression after a sequence of internal
>> definitions
>> > ;   in: (begin (define name (lambda () (displayln "foo"
>> > ; [,bt for context]
>> >
>> >
>> > I found 'eval', but that doesn't close over lexical variables (
>> https://docs.racket-lang.org/guide/eval.html: "The eval function cannot
>> see local bindings"):
>> >
>> > $ racket
>> > Welcome to Racket v6.3.
>> > -> (let ((xyz 1)) (for ((name '(x y z))) (eval `(define ,name (lambda
>> () (displayln (format "~a: ~a" ,name ,xyz) (set! xyz (add1 xyz
>> >
>> > -> (x)
>> > (x)
>> > ; xyz: undefined;
>> > ;  cannot reference undefined identifier
>> > ; [,bt for context]
>> >
>> >
>> > What have I not found?
>>
>> Racket is essentially a lexically scoped language. That is: it should be
>> possible to look at a piece of code and figure out where the binding for a
>> given variable is. It does have a dynamic binding mechanism, but the names
>> that are bound dynamically … can be determined lexically.
>>
>> This might seem to prevent the kind of code that you’re talking about,
>> but Racket compensates for this with an extraordinarily flexible macro
>> system, and a very permissive notion of what exactly constitutes
>> “compile-time.” It’s certainly possible to dynamically generate a piece of
>> code using macros. Once generated, though, this piece of code is going to
>> behave dependably.
>>
>> How does this affect your particular example? Well, it’s extremely easy
>> to write a macro that does what you describe:
>>
>> #lang racket
>>
>> (define-syntax makefuns
>>   (syntax-rules ()
>> [(_ name ...)
>>  (begin (define name (lambda () (displayln "foo")))
>> ...)]))
>>
>> (makefuns x y z)
>>
>> (x)
>>
>> (y)
>>
>> (z)
>>
>>
>>
>> Does this solve your problem? If not, why not? It’s going to depend a lot
>> on what exactly you want to do.
>>
>>
>> Hope this helps, apologies for telling you anything that you already knew.
>>
>> 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] Iterating through a list more than one at a time

2016-08-10 Thread David Storrs
On Wed, Aug 10, 2016 at 5:50 AM, Greg Hendershott  wrote:

> > I feel like there should be a simpler way to do this, but I haven't found
> > one despite much Googling and reading of docs about "for" and its
> siblings.
> > Can someone point me the right way?
> >
> > I'd like to be able to iterate over a list N elements at a time -- e.g.,
> > grab elements 1 and 2, do something with them, grab 3 and 4, etc.
> >
> > This will do the job, but I suspect there's a more built-in way:
> >
> > (define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")))
>
> racket/sequence provides an `in-slice` sequence to use with `for` forms:
>
> https://docs.racket-lang.org/reference/sequences.html#%
> 28def._%28%28lib._racket%2Fsequence..rkt%29._in-slice%29%29
>

in-slice produces lists of N elements, so I guess if I wanted to iterate
over every 2nd element I would use something like this?:

(define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")))
(for ((x (~>  data
in-list
(in-slice _ 2)
(map car
...do something...)

-- 
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 dynamically generate top-level procedures?

2016-08-09 Thread David Storrs
On Tue, Aug 9, 2016 at 2:20 PM, John Clements 
wrote:

>
> Racket is essentially a lexically scoped language. That is: it should be
> possible to look at a piece of code and figure out where the binding for a
> given variable is. It does have a dynamic binding mechanism, but the names
> that are bound dynamically … can be determined lexically.
>
> This might seem to prevent the kind of code that you’re talking about, but
> Racket compensates for this with an extraordinarily flexible macro system,
> and a very permissive notion of what exactly constitutes “compile-time.”
> It’s certainly possible to dynamically generate a piece of code using
> macros. Once generated, though, this piece of code is going to behave
> dependably.
>
> How does this affect your particular example? Well, it’s extremely easy to
> write a macro that does what you describe:
>
> #lang racket
>
> (define-syntax makefuns
>   (syntax-rules ()
> [(_ name ...)
>  (begin (define name (lambda () (displayln "foo")))
> ...)]))
>
> (makefuns x y z)
>
> (x)
>
> (y)
>
> (z)
>
>

This solves the problem of creating top-level bindings at run time (more or
less run time, anyway), but it doesn't handle the lexical closure part.  Is
there a way to do that?



> Hope this helps, apologies for telling you anything that you already knew.
>

I actually knew none of that, so I appreciate the telling. :>

Dave


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


Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
I see.  Okay, thanks for clarifying.

On Sat, Jul 16, 2016 at 8:05 PM, Alex Knauth <alexan...@knauth.org> wrote:
>
>> On Jul 16, 2016, at 7:18 PM, David Storrs <david.sto...@gmail.com> wrote:
>>
>> Wow, that is a lot of problems.  Thanks for taking the time to
>> comment; this was in large part an effort to learn macros, so it's
>> helpful to get this kind of feedback.
>
>> On Sat, Jul 16, 2016 at 2:48 PM, Alex Knauth <alexan...@knauth.org> wrote:
>
>>> A few problems with this.
>>>
>>> One, you shouldn't put extra (lambda () ...)s around the #:when conditions. 
>>> A lambda is a truthy value, since it's not false, so those #:when checks 
>>> weren't checking anything at all.
>>
>> I thought the #:when ran the predicate that it was given and reacted
>> based on the truth value of the response?
>
> The #:when takes a boolean. It works like the #:when clause in match, if 
> you've used that. Or like the condition of an if expression where the 
> then-branch keeps going in the same clause and the else-branch makes it go to 
> the next clause.
>
>> Would (string? pred)  have worked there instead?
>
> I'm not sure what you mean.
>
> #lang racket
> ;; no, I don't want a for-syntax, I'm using it at run-time, as a match-like 
> form
> (require syntax/parse)
> (syntax-parse (syntax ignored)
>   [_
>#:when (string? "hello")
>'string])
>
> This tests whether "hello" is a string. But for a pattern-variable like pred 
> it almost can work like that, but not quite.
>
> (syntax-parse (syntax (foo "hello"))
>   [(foo a)
>#:when (string? a)
>'string])
>
> This gives the error `a: pattern variable cannot be used outside of a 
> template`. A template means something like the syntax form. However even with 
> that fixed this doesn't work as expected:
>
> (syntax-parse (syntax (foo "hello"))
>   [(foo a)
>#:when (string? (syntax a)) ; writing (string? #'a) would mean the same 
> thing
>'string])
>
> The string? predicate returns false, so this fails as well. The problem is 
> that (syntax a) returns a syntax object, but you want the contents inside the 
> syntax object, because that's where the string (or otherwise) will be. To do 
> that you can use syntax-e (one-level-down) or syntax->datum (pure 
> s-expression with no syntax-object sub-expressions).
>
> (syntax-parse (syntax (foo "hello"))
>   [(foo a)
>#:when (string? (syntax-e (syntax a)))
>'string])
>
> This succeeds, producing 'string. Using syntax->datum will also work here:
>
> (syntax-parse (syntax (foo "hello"))
>   [(foo a)
>#:when (string? (syntax->datum (syntax a)))
>'string])
>
>>> Two, once you remove those lambdas, (procedure? #'pred) will always fail 
>>> because #'pred isn't the actual predicate, it's an expression, which might 
>>> eventually evaluate to predicate, or it might evaluate something else. At 
>>> compile-time, you just don't know yet. What you could do is check that it's 
>>> an identifier, with (identifier? #'pred).
>>
>> Would (procedure? (syntax->datum #'pred)) have worked there?  pred
>> either is or is not a procedure, and that should be known at compile
>> time.
>
> For simple literal data like strings, (string? (syntax->datum #'pred)) will 
> work, since literal data is known at compile-time.
>
> However procedures, although they are values, they only become values at 
> run-time. At compile-time, this pred is only an expression, so (procedure? 
> (syntax->datum #'pred)) will return false.
>
> A procedure given to you by a user in something like
> (throws (boom) exn:fail? "should trigger the proc form")
> Will not be known at compile time. (syntax pred) is an identifier, and 
> (syntax->datum (syntax pred)) will return a symbol, not a procedure.
>
> At compile-time that's all you know. It could be an identifier that happens 
> to be bound to a procedure, or it could be an identifier bound to a number, 
> or it could have no definition at all.
>
> So, for simple literal data like strings, it is known at compile-time, but 
> for more complicated things like procedures, it usually isn't.
>
> 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] Macros that use with-handlers

2016-07-16 Thread David Storrs
On Sat, Jul 16, 2016 at 2:48 PM, William J. Bowman
 wrote:

> To address the immediate problem, this `procedure?` test will always return 
> `#f`, since `#'pred` is a
> syntax object and not a procedure. You need to do `(procedure? (syntax->datum 
> #'pred))`. Similarly
> reasoning applies to the `string?` test.
>

Oh, of course; I should have realized.  I was thinking of #' as the
"get the value of the syntax object" expression, but that is exactly
backwards.  It's just the shortcut for (syntax ).   Thanks!

Dave

-- 
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] Macros that use with-handlers

2016-07-16 Thread David Storrs
Wow, that is a lot of problems.  Thanks for taking the time to
comment; this was in large part an effort to learn macros, so it's
helpful to get this kind of feedback.


On Sat, Jul 16, 2016 at 2:48 PM, Alex Knauth <alexan...@knauth.org> wrote:
>
>> On Jul 16, 2016, at 2:16 PM, David Storrs <david.sto...@gmail.com> wrote:
>>
>> I'm trying to write a macro to test expected exceptions.  I'd like it
>> to have the following forms:
>>
>> (throws exception-generator-function proc msg)
>> (throws exception-generator-function string msg)
>>
>> Where 'proc' would be something like exn:fail? and 'string' would be
>> matched against the message inside the exception.
>>
>> I got all the pieces of this working but not playing nice together.
>> There's three elements in the pattern for both versions, so the only
>> way to distinguish which to use is by the types of the arguments.  I
>> looked at syntax classes but made no headway on grokking that.  I saw
>> the #:when keyword for patterns and thought that would do what I
>> needed.  The following code seems like it should work, but it doesn't.
>> What am I missing?
>>
>>
>> (define-syntax (throws stx)
>>  (syntax-parse stx
>>[(_ boom pred msg)
>> #:when (lambda () (procedure? #'pred))
>> #'(with-handlers
>>([(lambda (x) #t) ;; already checked it's a proc
>>  (lambda (xcpt)
>>(println "procedure form"))])
>>boom)]
>>
>>[(_ boom pred msg)
>> #:when (lambda () (string? #'pred))
>> #'(with-handlers
>>([(lambda (x) #t) ;; already checked it's a string
>>  (println "string form")])
>>boom)]))
>>
>> (define (boom) (raise-argument-error 'boom "PEBKAC" 18)) ;; random choices
>> (throws (boom) exn:fail? "should trigger the proc form")
>> (throws (boom) "PEBKAC"  "should trigger the string form")
>
> A few problems with this.
>
> One, you shouldn't put extra (lambda () ...)s around the #:when conditions. A 
> lambda is a truthy value, since it's not false, so those #:when checks 
> weren't checking anything at all.
>

I thought the #:when ran the predicate that it was given and reacted
based on the truth value of the response?  Would (string? pred)  have
worked there instead?

> Two, once you remove those lambdas, (procedure? #'pred) will always fail 
> because #'pred isn't the actual predicate, it's an expression, which might 
> eventually evaluate to predicate, or it might evaluate something else. At 
> compile-time, you just don't know yet. What you could do is check that it's 
> an identifier, with (identifier? #'pred).

Would (procedure? (syntax->datum #'pred)) have worked there?  pred
either is or is not a procedure, and that should be known at compile
time.

>
> Four, in the second clause you have (println "string form") as the handler 
> function. You probably meant to put a lambda around it like you did for the 
> first clause: (lambda (xcpt) (println "string form")).

I did, yes.  Thanks.

> Five, did you mean to actually use the pred argument in the exception 
> predicates of the with-handlers forms?
> Six, did you mean to use the msg argument for anything?

The code I sent out was stripped down to be the minimum necessary to
demonstrate the problem, so it wasn't doing what it would ultimately
have done.  Once things were working as expected then the pred and msg
would have both been used, yes.


>

>
> With the first five of these addressed, the code looks like this:
>
> #lang racket
> (require (for-syntax racket/base syntax/parse))
> (define-syntax (throws stx)
>   (syntax-parse stx
> [(_ boom pred msg)
>  #:when (identifier? #'pred)
>  #'(with-handlers
>([pred
>  (lambda (xcpt)
>(println "procedure form"))])
>  boom)]
> [(_ boom pred msg)
>  #:when (string? (syntax-e #'pred))
>  #'(with-handlers
>([(lambda (x) (string-contains? (exn-message x) pred))
>  (lambda (xcpt)
>(println "string form"))])
>  boom)]))
>
> (define (boom) (raise-argument-error 'boom "PEBKAC" 18)) ;; random choices
> (throws (boom) exn:fail? "should trigger the proc form")
> (throws (boom) "PEBKAC"  "should trigger the string form")
>
> Although there is an easier, better way to check whether an argument is

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
On Sat, Jul 16, 2016 at 2:48 PM, Alexis King  wrote:
> Of course, this makes sense, given that macros operate entirely at
> compile-time. What you really want here is a function, not a macro. You
> can write a simple function that will accept a procedure or a string and
> will produce a procedure:
>[...]
>
> In fact, throws can be implemented as a function as well, [...example...]
>
> Generally, prefer functions over macros when functions will do.
> Functions are both more flexible (they can be used as values, and
> therefore can be used higher-order) and more predictable (function
> invocations have very predictable evaluation semantics, while macros
> might not).

Makes sense; thank you.

So, if one should prefer functions, what is a good place to use
macros?  When people talk about why LISP/Scheme/Racket are the most
powerful languages, they inevitably mention macros and continuations.
What is a good use case for macros?

Dave

-- 
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] Question on contracts -- check equal length of args

2016-07-15 Thread David Storrs
> On Fri, Jul 15, 2016 at various times, various people said:
>  Here, let me solve your problem


You guys are great.  Thank you very much.

Dave

On Fri, Jul 15, 2016 at 12:47 PM, Daniel Feltey <dfel...@ccs.neu.edu> wrote:
> Here's a version that uses a #:pre condition:
>
> #lang racket
>
> (define/contract (tau l m)
>   (->i ([list1 (listof (and/c exact-integer? (>/c 0)))]
> [list2 (listof (and/c exact-integer? (>/c 0)))])
>#:pre (list1 list2) (= (length list1) (length list2))
>[_ number?])
>   (begin
> (println "I was called")
> 300))
>
> (tau '(8) '(9))   ;; this succeeds
> (tau '(8) '(9.0)) ;; this doesn't satisfy the contract anymore
> (tau '(8) '(9 10)) ;; neither does this
>
> For differentiating between integers like 9 and 9.0, the predicate you want
> to use is `exact-integer?`. The `integer?` predicate accepts both exact and
> inexact integers which can be a little strange at first.
>
> Dan
>
>
>
> On Fri, Jul 15, 2016 at 11:22 AM, David Storrs <david.sto...@gmail.com>
> wrote:
>>
>> Hi folks,
>>
>> I'm writing a stats library (I'm sure there is already one out there;
>> this is a learning exercise), and I'm currently implementing Kendall's
>> Tau-a.  I've got my head wrapped part of the way around contracts, but
>> not all the way.  I'd like to be able to express the following:
>>
>> (tau l m)
>> - l is a non-empty list of numbers, all greater than 0
>> - m is a non-empty list of numbers, all greater than 0
>> - l and m are of the same length
>>
>> Here's a stub version that does the first two checks:
>>
>> (define/contract (tau l m)
>>   (-> (listof (and/c integer? (>/c 0)))
>>   (listof (and/c integer? (>/c 0)))
>>   number?)
>>   300)
>>
>> (tau '(8) '(9));; should succeed and does
>> (tau '(8) '(9.0))  ;; should fail (element is not integer) => SUCCEEDS??
>> ;;
>> ;; not implemented
>> ;; (tau '(8) '(9 10)) ;; should fail -- different length lists
>>
>>
>> I figured I'd let the 'integer?' failure go for a minute and focus on
>> the missing criteria (lists are of equal length).  First, I wanted to
>> make sure that I had understood the ->i syntax, so I did this:
>>
>> (define/contract (tau l m)
>>   (->i ([list1 (listof (and/c integer? (>/c 0)))]
>> [list2 (list1) (and/c
>> (listof (and/c integer? (>/c 0])
>>
>>[result (list1 list2) number?])
>>   300)
>>
>> Okay, good, that has the same results as the one above.  Now let's try
>> to get the 'equal length' criteria working.
>>
>> (define/contract (tau l m)
>>   (->i ([list1 (listof (and/c integer? (>/c 0)))]
>> [list2 (list1) (and/c
>> (listof (and/c integer? (>/c 0)))
>> (equal? (length list1) (length list2)))])
>>
>>[result (list1 list2) number?])
>>   (begin
>> (println "I was called")
>> 300))
>>
>> Result =>
>> t.rkt:21:79: list2: unbound identifier in module
>>   in: list2
>>
>> Nope.  Unsurprisingly, 'arg2' is not available inside its own binding.
>>
>>
>> At this point I faffed around with implementing the check as a
>> precondition or in the result function, and everything else I could
>> think of, all to no avail.
>>
>>
>> How do I do this?  It feels like it shouldn't be this hard.
>>
>>
>> On a separate question:  How do I contribute to the docs?  The
>> contract docs are nearly silent on using preconditions and
>> postconditions, Section 7.4, "A Thorough Example of Contracts" is
>> anything but thorough, and the docs could stand to include more
>> examples in general.  I'd love to help future Racket students
>> understand what's going on.
>>
>>
>> Dave
>>
>> --
>> 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] Question on contracts -- check equal length of args

2016-07-15 Thread David Storrs
Hi folks,

I'm writing a stats library (I'm sure there is already one out there;
this is a learning exercise), and I'm currently implementing Kendall's
Tau-a.  I've got my head wrapped part of the way around contracts, but
not all the way.  I'd like to be able to express the following:

(tau l m)
- l is a non-empty list of numbers, all greater than 0
- m is a non-empty list of numbers, all greater than 0
- l and m are of the same length

Here's a stub version that does the first two checks:

(define/contract (tau l m)
  (-> (listof (and/c integer? (>/c 0)))
  (listof (and/c integer? (>/c 0)))
  number?)
  300)

(tau '(8) '(9));; should succeed and does
(tau '(8) '(9.0))  ;; should fail (element is not integer) => SUCCEEDS??
;;
;; not implemented
;; (tau '(8) '(9 10)) ;; should fail -- different length lists


I figured I'd let the 'integer?' failure go for a minute and focus on
the missing criteria (lists are of equal length).  First, I wanted to
make sure that I had understood the ->i syntax, so I did this:

(define/contract (tau l m)
  (->i ([list1 (listof (and/c integer? (>/c 0)))]
[list2 (list1) (and/c
(listof (and/c integer? (>/c 0])

   [result (list1 list2) number?])
  300)

Okay, good, that has the same results as the one above.  Now let's try
to get the 'equal length' criteria working.

(define/contract (tau l m)
  (->i ([list1 (listof (and/c integer? (>/c 0)))]
[list2 (list1) (and/c
(listof (and/c integer? (>/c 0)))
(equal? (length list1) (length list2)))])

   [result (list1 list2) number?])
  (begin
(println "I was called")
300))

Result =>
t.rkt:21:79: list2: unbound identifier in module
  in: list2

Nope.  Unsurprisingly, 'arg2' is not available inside its own binding.


At this point I faffed around with implementing the check as a
precondition or in the result function, and everything else I could
think of, all to no avail.


How do I do this?  It feels like it shouldn't be this hard.


On a separate question:  How do I contribute to the docs?  The
contract docs are nearly silent on using preconditions and
postconditions, Section 7.4, "A Thorough Example of Contracts" is
anything but thorough, and the docs could stand to include more
examples in general.  I'd love to help future Racket students
understand what's going on.


Dave

-- 
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] Question on contracts -- check equal length of args

2016-07-15 Thread David Storrs
Thanks Jens!

On Fri, Jul 15, 2016 at 1:00 PM, Jens Axel Søgaard
<jensa...@soegaard.net> wrote:
> 2016-07-15 18:22 GMT+02:00 David Storrs <david.sto...@gmail.com>:
>
>>
>> On a separate question:  How do I contribute to the docs?  The
>> contract docs are nearly silent on using preconditions and
>> postconditions, Section 7.4, "A Thorough Example of Contracts" is
>> anything but thorough, and the docs could stand to include more
>> examples in general.  I'd love to help future Racket students
>> understand what's going on.
>
>
> 1. First find the file to fix:
>   Go tohttps://github.com/racket
>   then enterA Thorough Example of Contracts
>   in the search field.
>   Notice that the "Code" tab to the left now says 1.
>   Now click the Code tab and click at "first-extended-example.scrbl"
>
> 2.  Fixing a single typo is most easily done by clicking at the small
>  pencil (next to the trash can) in the (almost) upper, right corner.
>
> 3.  For more substantial edits, clone the repository and use
>  DrRacket to edit the scrbl-file. The submit a pull request.
>
> /Jens Axel
>
>
>
>
>

-- 
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] Macros that use with-handlers

2016-07-16 Thread David Storrs
I'm trying to write a macro to test expected exceptions.  I'd like it
to have the following forms:

(throws exception-generator-function proc msg)
(throws exception-generator-function string msg)

Where 'proc' would be something like exn:fail? and 'string' would be
matched against the message inside the exception.

I got all the pieces of this working but not playing nice together.
There's three elements in the pattern for both versions, so the only
way to distinguish which to use is by the types of the arguments.  I
looked at syntax classes but made no headway on grokking that.  I saw
the #:when keyword for patterns and thought that would do what I
needed.  The following code seems like it should work, but it doesn't.
What am I missing?


(define-syntax (throws stx)
  (syntax-parse stx
[(_ boom pred msg)
 #:when (lambda () (procedure? #'pred))
 #'(with-handlers
([(lambda (x) #t) ;; already checked it's a proc
  (lambda (xcpt)
(println "procedure form"))])
boom)]

[(_ boom pred msg)
 #:when (lambda () (string? #'pred))
 #'(with-handlers
([(lambda (x) #t) ;; already checked it's a string
  (println "string form")])
boom)]))

(define (boom) (raise-argument-error 'boom "PEBKAC" 18)) ;; random choices
(throws (boom) exn:fail? "should trigger the proc form")
(throws (boom) "PEBKAC"  "should trigger the string form")

-- 
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] Writing Racket for iOS / Android

2016-07-10 Thread David Storrs
I need to build an app for iPhone and (later) Android, and I'd prefer to be
able to write it in Racket but still get native interfaces.  I searched
through the list archives and found this thread
https://lists.racket-lang.org/users/archive/2015-February/065929.html
("[racket] compiling Racket to android and ios apps") from last year; I was
wondering if anything has changed on this front?

In particular, Apple is now moving to Swift as their preferred (and,
eventually, only) language for iOS development.  Is there an easy way to
generate Swift from Racket, or simply compile directly to a Swift
executable?

On that subject, I found this:
https://lists.racket-lang.org/users/archive/2014-June/062871.html
 ("[racket] SWIFT IS AWESOME!")").  That thread ended with Gregory
Woodhouse saying "One of the first things that attracted me to Racket was
the possibility of programming OS X or maybe even iOS applications in a
Lisp-like language", but I couldn't find more details on that.

Thanks for any help,

Dave

-- 
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] Iterating through a list more than one at a time

2016-08-04 Thread David Storrs
I feel like there should be a simpler way to do this, but I haven't found
one despite much Googling and reading of docs about "for" and its
siblings.  Can someone point me the right way?


I'd like to be able to iterate over a list N elements at a time -- e.g.,
grab elements 1 and 2, do something with them, grab 3 and 4, etc.

This will do the job, but I suspect there's a more built-in way:

(define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")))

(define (step-by-n func data [num 2])
  (if (null? data)
  (func '())
  (append (func (take data num))
  (step-by-n func (drop data num) num

(step-by-n (lambda (l)
 (if (null? l)
 '()
 (list (hash (car (first l))
 (car (second l))
   data)

(step-by-n (lambda (l)
 (if (null? l)
 '()
 (list (hash (car (first l))
 (list (car (second l))
   (car (third l)))
   data
   3)

OUTPUT:
'(#hash(("foo" . "bar")) #hash(("baz" . "jaz")) #hash(("quux" . "glug")))
'(#hash(("foo" . ("bar" "baz"))) #hash(("jaz" . ("quux" "glug"


(Note that the fact that it returns the results as a list was a deliberate
choice but not an essential one.)

-- 
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] Iterating through a list more than one at a time

2016-08-04 Thread David Storrs
Great, thank you.  I was thinking maybe there was some construct that could
do this built-in, the way 'map' can double as 'zip'.

I looked through sugar and it looks very convenient; I'll be using it in
future.  Note that when I installed it, I got the following:

[...snip lots of "raco setup: 0 skipping: /..." lines]
raco setup: docs failure: query-exec: unable to open the database file
  error code: 14
  SQL: "ATTACH $1 AS other"
  database: #
  mode: 'read-only
  file permissions: (write read)
raco setup: --- installing collections ---
raco setup: --- post-installing collections ---
raco pkg install: packages installed, although setup reported errors

Doesn't seem to have mattered and it might just be something weird about
permissions on my system.  I figured I'd mention it, though.

Dave


On Thu, Aug 4, 2016 at 5:04 PM, Matthew Butterick <m...@mbtype.com> wrote:

>
> On Aug 4, 2016, at 3:10 PM, David Storrs <david.sto...@gmail.com> wrote:
> > I'd like to be able to iterate over a list N elements at a time -- e.g.,
> grab elements 1 and 2, do something with them, grab 3 and 4, etc.
>
> Your technique seems fine. You could use `split-at` if you wanted to save
> a list operation, otherwise it's the standard recursion pattern:
>
> #lang racket
> (define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")))
>
> (define (step-by-n func xs [num 2])
>   (if (null? xs)
>   null
>   (let-values ([(head tail) (split-at xs num)])
> (cons (func head) (step-by-n func tail num)
>
> (step-by-n (λ (xx) (apply hash (map car xx))) data)
>
> (step-by-n (λ (xxx) (hash (caar xxx) (map car (cdr xxx data 3)
>
>
> I wrote a utility function called `slice-at` to handle this problem. [1]
>
>
> [1] http://docs.racket-lang.org/sugar/#%28def._%28%28lib._
> sugar%2Flist..rkt%29._slice-at%29%29

-- 
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: How to differentiate between files and directories?

2016-07-22 Thread David Storrs
Thanks, I'll try that.

On Fri, Jul 22, 2016 at 12:29 AM, WarGrey Gyoudmon Ju
<juzhenli...@gmail.com> wrote:
> Maybe you can work with (namespace-mapped-symbols) and
> (namespace-variable-value),
> All field accessors are procedures with name starts with "struct-name-", no
> duplicates in the entire application.
>
> On Fri, Jul 22, 2016 at 3:59 AM, David Storrs <david.sto...@gmail.com>
> wrote:
>>
>> So there's no way to query the interface of a struct?
>>
>>
>> On Thursday, July 21, 2016, Jon Zeppieri <zeppi...@gmail.com> wrote:
>>>
>>>
>>>
>>> On Thu, Jul 21, 2016 at 2:44 PM, David Storrs <david.sto...@gmail.com>
>>> wrote:
>>>>
>>>>
>>>>
>>>> In a related question, is there a way to introspect a struct to find
>>>> out what its fields are?
>>>>
>>>
>>> If you mean the field values: yes, but only if the struct is transparent
>>> or prefab or if you have the proper inspector, which you probably do not.
>>> You can generally try struct->vector and see if you get anything useful.
>>>
>>> If you mean the field names: I don't think so; I don't think they exist
>>> at runtime.
>>>
>>> - Jon
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> 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] How to dynamically generate top-level procedures?

2016-08-09 Thread David Storrs
In Perl it's possible to generate main-namespace functions like so:

perl -E 'my $z = 1; for (qw/foo bar baz/) {my $x = $_; *$_ = sub{ say "$x:
", $z++ }};  foo(); bar(); baz();'

This outputs:
foo: 1
bar: 2
baz: 3


Note that it is generating top-level subroutines that can be called from
elsewhere in the program (including other modules) and that those
subroutines close over existing lexical variables.


I tried to do this in Racket and haven't been able to figure it out:

First attempt, only partial solution:
$ racket
-> (for ((name '(x y z))) (define name (lambda () (displayln "foo"

; /Applications/Racket_v6.3/collects/racket/private/for.rkt:1487:62: begin
;   (possibly implicit): no expression after a sequence of internal
definitions
;   in: (begin (define name (lambda () (displayln "foo"
; [,bt for context]


I found 'eval', but that doesn't close over lexical variables (
https://docs.racket-lang.org/guide/eval.html: "The eval

function cannot see local bindings"):

$ racket
Welcome to Racket v6.3.
-> (let ((xyz 1)) (for ((name '(x y z))) (eval `(define ,name (lambda ()
(displayln (format "~a: ~a" ,name ,xyz) (set! xyz (add1 xyz

-> (x)
(x)
; xyz: undefined;
;  cannot reference undefined identifier
; [,bt for context]


What have I not found?

-- 
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-21 Thread David Storrs
Thanks, Dupéron, that's helpful.

On Fri, Jan 20, 2017 at 8:35 PM, Dupéron Georges
 wrote:
> Le vendredi 20 janvier 2017 19:47:11 UTC+1, David K. Storrs a écrit :
>> I see that I can get the event telling me that something changed.  As
>> far as I can tell the event contains no information about *what*
>> changed, it simply alerts that *something* changed.  Likewise, the
>> monitor is only for the directory that I point it at, not for the
>> subdirectories.
>
> There *should* be a way to know what changed, at least in Linux as inotify 
> allows this IIRC. Someone already wrote an FFI wrapper for inotify, hopefully 
> it suits your needs (if it does, it would be cool to send a Pull Request to 
> turn the repo in a Racket package, so that it can be put on 
> pkgn.racket-lang.org):
>
> https://github.com/samdphillips/racket-inotify
>
> As for monitoring subdirectories, unfortunately (and surprisingly) this is 
> not possible with inotify on Linux. From the man page:
>
> Inotify monitoring of directories is not recursive: to monitor
> subdirectories under a directory, additional watches must be created.
>
> Fortunately, this should be easy enough to do in Racket, thanks to the 
> wonderful in-directory:
>
> (define (watch-recursively d)
> (for ([subnode (in-sequences (in-value d) (in-directory d))])
>   (when (directory-exists? subnode) ;; filter out files
> (watch-the-directory subnode)))
>
> This might take a while (and use up some resources) when watching a large 
> directory :-( .
>
> --
> 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] Thread and filesystem watching

2017-01-24 Thread David Storrs
On Tue, Jan 24, 2017 at 7:26 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

> Hi David,
>
> On Tue, Jan 24, 2017 at 6:52 PM, David Storrs <david.sto...@gmail.com>
> wrote:
>
>> [snip]
>>
>> - When I create the 'monitor this' event, I will need to wrap the sync in
>>> a thread since (sync) is synchronous.
>>
>>
>>
>> If I understand you correctly, you're considering creating a separate
> thread for each directory that you monitor. You could do that, but I'd
> suggest this instead:
> - build a list of `filesystem-change-evt`s
> - create a single thread, and in it monitor all of them at once with
> `(apply sync list-of-evts)`
>
> - Jon
>
>
That would neatly solve my concern about too many threads.  Thanks, Jon.
And since Racket threads are preemptive but not parallel it doesn't
actually cost me anything.

Oh, that reminds me:  can I be confident that all events will be
delivered?  Will an event be canceled if, e.g., it isn't synced in a
certain amount of time?

-- 
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] Stickers!

2017-01-27 Thread David Storrs
On Tue, Jan 24, 2017 at 4:15 PM, Ben Greenman 
wrote:

> Hi Racket Users,
>
> I ordered a bunch of Racket stickers to celebrate the 6.8 release. Here's
> proof:
> http://www.ccs.neu.edu/home/types/resources/stickers.jpg
>
> If you send me your address, I will mail you some stickers. For free!*
>

I'd like some!  I'll email you my address directly?



>
> I'm thinking 4 stickers per request (2 rectangles, 2 circles), but if you
> live outside the US and promise to serve as a "volunteer regional sticker
> distributor" then I'll send more.**
>
> Peace, Love, and Racket,
> Ben
>
>
> * While supplies last. And if you want un-free stickers, you can make your
> own on stickermule.com or send a donation to RacketCon 2017.
>
> ** While supplies last, and subject to the internal dimensions of the
> cheapest padded envelope at my local US post office.
>
> --
> 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] Racket v6.8

2017-01-25 Thread David Storrs
Congratulations, everyone.  I am frequently surprised and always impressed
at how fast bugs are fixed and new versions released.

On Wed, Jan 25, 2017 at 10:53 AM, Konrad Hinsen 
wrote:

> Matthew Flatt  writes:
>
> > There's a `raco pkg migrate` command that should do what you want. The
> > same functionality is in DrRacket's "File" -> "Package Manager..." ->
> > "Copy from Version".
>
> Ahhh... And it works great! I saw this when scanning the output of
> "raco pkg -h" but had the impression that it was for somehow fixing
> incompatible packages.
>
> Thanks,
>   Konrad.
>
> --
> 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] Thread and filesystem watching

2017-01-25 Thread David Storrs
Thanks, Matthew.  That's reassuring.

On Wed, Jan 25, 2017 at 8:20 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> At Tue, 24 Jan 2017 18:52:43 -0500, David Storrs wrote:
> > 1) How do I determine what a safe maximum number of threads is?
>
> For a typical program, 10k or so is probably safe.
>
> The program below creates 10k threads. On my machine, it allocates
> about 200M of memory with a peak memory use of 160MB.
>
> 
>
> #lang racket/base
>
> (define s (make-semaphore))
>
> (define ts
>   (for/list ([i (in-range 1)])
> (thread
>  (lambda ()
>(semaphore-wait s)
>(semaphore-post s)
>
> 'waiting
> (semaphore-post s)
>
> (for ([t (in-list ts)])
>   (thread-wait t))
>
> 'done
>
> --
> 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] Thread and filesystem watching

2017-01-25 Thread David Storrs
On Tue, Jan 24, 2017 at 7:26 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

> Hi David,
>
> On Tue, Jan 24, 2017 at 6:52 PM, David Storrs <david.sto...@gmail.com>
> wrote:
>
>> [snip]
>>
>> - When I create the 'monitor this' event, I will need to wrap the sync in
>>> a thread since (sync) is synchronous.
>>
>>
>>
>> If I understand you correctly, you're considering creating a separate
> thread for each directory that you monitor. You could do that, but I'd
> suggest this instead:
> - build a list of `filesystem-change-evt`s
> - create a single thread, and in it monitor all of them at once with
> `(apply sync list-of-evts)`
>
> - Jon
>
>
After trying this out I see there's a problem:  if you apply sync to all of
them simultaneously there is no way to distinguish which directory it was
that changed.  By spawning a separate thread for each one I can close over
the relevant directory.  Unless I'm missing something?

I wish there were a way to encode information into the change event at
creation time.

-- 
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] Creating and publishing modules

2017-01-20 Thread David Storrs
Since I'm going to need this filesystem-watching code, I figured I
would package it up and make it available to other people as well.

I know that planet is no longer the preferred package repository.  Is
this still the correct documentation for how to publish modules?:
https://docs.racket-lang.org/planet/Developing_Packages_for_PLaneT.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.


[racket-users] Re: Creating and publishing modules

2017-01-20 Thread David Storrs
On Fri, Jan 20, 2017 at 3:01 PM, David Storrs <david.sto...@gmail.com> wrote:
> Since I'm going to need this filesystem-watching code, I figured I
> would package it up and make it available to other people as well.
>
> I know that planet is no longer the preferred package repository.  Is
> this still the correct documentation for how to publish modules?:
> https://docs.racket-lang.org/planet/Developing_Packages_for_PLaneT.html

Nope.  For future readers of this thread, the correct answers appear to be:

Basics of packages: https://docs.racket-lang.org/pkg/Package_Concepts.html
Basics of modules: https://docs.racket-lang.org/guide/module-basics.html
Overall docs on packages (creating, using, publishing):
https://docs.racket-lang.org/pkg/getting-started.html

Specifics on creating
packages:https://docs.racket-lang.org/pkg/getting-started.html#%28part._how-to-create%29

-- 
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] Thread and filesystem watching

2017-01-26 Thread David Storrs
Thanks for the help, everyone.  This works great.  I especially like
handle-evt -- I had seen it in the Reference when I was reading about
events but didn't understand what it did.  It really makes this easy.



On Wed, Jan 25, 2017 at 8:17 PM, Jon Zeppieri  wrote:

> On Wed, Jan 25, 2017 at 8:03 PM, Matthew Flatt  wrote:
> >
> > The `handle-evt` constructor does that.
> >
> > For example, this loop will print "one" or "two" pseudorandomly,
> depending on whether the first or second semaphore is chosen:
> >
> >  (let loop ()
> >(define e1
> > (handle-evt (make-semaphore 1)
> > (lambda (v)
> >   (printf "one\n")
> >   (loop
> >(define e2
> > (handle-evt (make-semaphore 1)
> > (lambda (v)
> >   (printf "two\n")
> >   (loop
> >(sync e1 e2))
>
> Oh, that's a lot more convenient than I realized. Guess I never gave
> enough thought to the value of the handler being called in tail
> position w.r.t. the sync. -J
>

-- 
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] Thread and filesystem watching

2017-01-24 Thread David Storrs
I mentioned before that I'm writing a system to watch the filesystem for
changes.  I'm finishing that up and I have a few questions about
concurrency issues.


1) How do I determine what a safe maximum number of threads is?

2) I think that (fold-files) is the best way to walk a directory tree,
since it will process the files in constant space without building a giant
list of files the way (find-files) would. Is there a better option?  For
this specific purpose all I care about is getting the subdirectories --
processing the actual files happens elsewhere -- so if there was a way to
say "

3) If you have any comments on the following they would be appreciated:

First, the spec:

- Monitor a directory tree for any changes, ensure that the DB accurately
records what's on the disk.
- The tree probably isn't more than 5-10 directories deep, but it could be
arbitrarily more.
- There are potentially (tens of) millions of files in the tree.
- Any given directory probably only has a few thousand files at most.

I monitor a directory with this:

(define change(sync (filesystem-change-evt "/foo")))
...do something with 'change'...

but that only monitors /foo, not the subdirectories of /foo.  To monitor
the rest of the tree I will need to walk down from /foo creating new
monitor events for each subdirectory.

I believe that:

- When I create the 'monitor this' event, I will need to wrap the sync in a
thread since (sync) is synchronous.

- The result of the sync will be the event itself, so I can then do
whatever it takes and then plug it back into sync to keep watching.

- It's okay to have each monitoring thread do its own DB processing as
opposed to having it instruct a different thread (probably via a channel)
to deal with it.


Thoughts?

-- 
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: get-file-list filter

2017-02-21 Thread David Storrs
You can also, as you pointed out, generate the string programmatically.  If
you do, you'll get mileage out of the string-upcase and string-downcase
functions:

(define basestr (string-join (map string-downcase '(...jpg jpeg etc)) ";")
(define str (string-append basestr ";" (string-upcase basestr)))



On Tue, Feb 21, 2017 at 1:55 AM, Alex Harsanyi 
wrote:

> On Tuesday, February 21, 2017 at 11:52:49 AM UTC+8, Lehi Toskin wrote:
> > In `get-file-list`  there is a filter argument that can be passed to the
> function such that when going through a directory it'll only list
> directories and those files in the filter (separated by a semicolon). This
> can get rather unruly when the filter is rather large. At current count, I
> have a filter of 14 different file extensions accounting for spelling or
> case (e.g. "*.jpg;*.jpeg;*.JPG;*.JPEG"). Is there a way to do this more
> programmatically? I don't mean using a procedure to create the string, but
> that instead of a string it'd be, say, a predicate.
> >
> > In various GUI programs, the selection would be simply "All Images" or
> "Any" without specifying exactly what list of file extensions it's
> filtering. I suppose that behavior itself is fine, which would mean hiding
> the file extensions from the filter choice and only showing the name of the
> filter.
>
> The documentation for get-file-list (well, actually get-file) suggests
> that it uses a platform specific dialog box.  On windows platforms, I
> suspect  that would be GetOpenFileName which accepts filter string in the
> same format as required by get-file-list.  It is likely that the filter is
> passed directly to the windows function and as such, it has to be a string.
>
> This was just a long way of saying that you cannot have a predicate for
> the filter, at least not while using the platform specific "File Open"
> dialog boxes.
>
> However, the documentation does have an example for a shorted pattern for
> JPEG files: "*.jp*g"
>
> 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] Programming paradigms

2017-02-21 Thread David Storrs
On Mon, Feb 20, 2017 at 10:18 PM, Rusi Mody  wrote:

> On Thursday, February 16, 2017 at 9:46:53 PM UTC+5:30, David K. Storrs
> wrote:
> > I find PP to be a useful tool for thinking about programming, but not
> terribly significant in everyday use -- my code will typically end up as a
> mixture of functional, declarative, procedural, and OO.  The fact that
> Racket makes it easy to mix all of these is one of its many appeals.
>
> If you had said aspects I would have agreed
> Appeal?? Not so sure
>

You are allowed to not like the things I like.

-- 
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] Re: Why is this exception giving me an arity error?

2017-02-17 Thread David Storrs
Oh.  When I change the name to exn:fail:bmtc:unknownuser  it works fine.  I
guess '-' is a disallowed character for exceptions?

-> (struct exn:fail:bmtc:unknownuser exn:fail:bmtc (username) #:transparent)

-> (exn:fail:bmtc:unknownuser "msg" (current-continuation-marks) "foo")
(exn:fail:bmtc:unknownuser "msg" # ... "foo")



Underscore also works:

-> (struct exn:fail:bmtc:unknown_user exn:fail:bmtc (username)
#:transparent)

-> (exn:fail:bmtc:unknown_user "msg" # ... "foo")
(exn:fail:bmtc:unknown_user "msg" # ... "foo")



On Fri, Feb 17, 2017 at 1:17 PM, David Storrs <david.sto...@gmail.com>
wrote:

> I have the following file:
>
>
> #lang racket
>
> (provide (all-defined-out))
>
> (struct exn:fail:bmtc exn:fail ()
> #:extra-constructor-name make-exn:fail:bmtc
> #:transparent)
>
> ;; I expect this to take all the arguments from exn (its ultimate
> superclass), plus a new argument which comes last.
> (struct exn:fail:bmtc:unknown-user exn:fail:bmtc (username)
> #:extra-constructor-name make-exn:fail:bmtc:unknown-user
> #:transparent)
>
>
> At the command line:
>
> $ racket
> -> (require "network/exceptions")
>
> -> exn:fail:bmtc:unknown-user
> #
>
> -> (exn:fail:bmtc:unknown-user "message" (current-continuation-marks)
> "bob")
> ; exn:fail:bmtc:unknown-user: arity mismatch;
> ;  the expected number of arguments does not match the given number
> ;   expected: 2
> ;   given: 3
> ; [,bt for context]
>
> -> (exn:fail:bmtc:unknown-user "msg" (current-continuation-marks))
> (exn:fail:bmtc:unknown-user "msg" #)
>
>
> Given the declaration of exn:fail:bmtc:unknown-user I was expecting it to
> take a third argument.  What am I missing?
>
>
> Note that I'm using Emacs and the command line, not 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] intensional equality and unit tests

2017-02-19 Thread David Storrs
On Sat, Feb 18, 2017 at 11:12 PM, 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

> (cc:ak)
>
> Okay, this sounds just crushingly obvious now that I say it, but honestly,
> I don’t think it’s occurred to me:
>
> One reason that equality is such a nightmare in Java and Python (which
> turns out to be JUST AS BAD), is that those of us that actually want to
> write unit test cases want *intensional* equality, not extensional
> equality—but not pointer-based equality.
>
> I just came across a nice example while working on code for first-year
> students (thanks, Aaron!).
>
> Specifically, imagine an “array” class that contains a backing array and a
> length, where the backing array might be arbitrarily longer than the length:
>
> (struct arr (vec len))
>
> So, for instance, an array with two elements in it might be represented as
> either
>
> (arr (vector “apple" “horse” #f #f #f) 2)
>
> or as
>
> (arr (vector “apple” “horse” #f) 2)
>
> —they both represent the array of length 2 that has “apple” as the first
> element, and “horse” as the second.
>
> If I’m providing this library to be used by others, I probably want
> extensional equality; I don’t want users of my library to be able to
> distinguish between the two. However, if I’m writing unit tests for my
> library, I definitely *do* want to be able to distinguish between the two,
> for instance in checking the behavior of arrays that fill up and need to be
> resized. Moreover, pointer-based equality—the == of Java, and the `is` of
> Python (IIUC)—is also largely useless for unit tests.
>
> It’s probably not terribly controversial to suggest that neither Python
> nor Java were designed with unit testing in mind. Accordingly, I shouldn’t
> be surprised to discover that they don’t provide a natural notion of
> equality that fits well with unit tests.
>
> So, I have three questions:
>
> 1) Is there an existing term for what I would call “functional extensional
> equality”—that is, Racket’s ‘equal?’ ?
> 2) Does what I wrote make sense?
> 3) Has this been written down somewhere else, as part of a larger work?
>
> Thanks, everyone!
>
> John
>

I think this relates to the concept of duck typing (
https://en.wikipedia.org/wiki/Duck_typing) -- if something is fit for
purpose then it is good enough even if it isn't precisely the same.  That's
pretty much what 'equal?' is -- "Are these two things similar enough that I
could interchange them without screwing up my code?"

I'm not aware of any papers on the subject, but I would probably check some
of the unit testing books.

I've seen the argument that unit tests actually show a weakness in a
language, that it's preferable to have declarative semantics.  This is one
place where Racket's contracts really shine.  Suppose I write this:

(define/contract (foo a b)
(-> string? number? integer?)
...
)

There are entire swaths of unit tests I don't need to write, such as "what
happens if I pass an integer in the first slot", etc.  I *know* what
happens -- it throws an exn:fail:contract of a very precisely specified
form.  I haven't looked into Typed Racket yet, but I gather it will deal
with many similar issues.


One thing that I do wish Racket had was better exception handling.  Right
now I can test if an exception is of a particular type (which tells me the
broad class of issue) but if I want to know the specifics I need to regex
on the message string.  This could be significantly helped by using more
precise exception types for various functions.  For example, in the db
module this: (query-db db-handle "jlasdjfl") throws an exn:fail:sql instead
of something like exn:fail:sql:syntax.  I've started creating more and more
specific exception types for my own code as part of 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.
>

-- 
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 do I find where a module is located?

2017-02-14 Thread David Storrs
On Tue, Feb 14, 2017 at 11:41 AM, 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

>
> > On Feb 14, 2017, at 8:36 AM, David Storrs <david.sto...@gmail.com>
> wrote:
> >
> > I have murphy/protobuf installed and I'd like to look at the source
> code.  How do I find it?
>
> I think you’re looking for the ‘collection-file-path’ function, if you
> want to do it programmatically.
>

collection-file-path accepts two arguments: the path of the file and the
path of the collection.  That doesn't help if what I'm looking for is the
path of the file.  What I'd like would be a way to decompose a 'require',
so that I could say something like:

(show-full-path murphy/protobuf)

 ...and get back the actually absolute filepath to the collection.



> Alternatively, If you just want to open up the file, I usually just type
> (require protobuf) in a buffer, and right-click to go to the collection’s
> main.rkt.
>

I prefer Emacs to Dr Racket.  Asking the user to open up a separate
application just to find a module file is irritating.

In Perl I could at least do this:  perl -E 'say for @INC' and get a list of
all the directories modules were being pulled from, all of which were
rooted at a single directory which I could then run a 'find' against.

I tried these:

(current-library-collection-paths)
'(#
  #
  #)

find /Users/dstorrs/Dropbox/dstorrs/personal/study
/Users/dstorrs/Library/Racket/6.6/collects
/Applications/Racket_v6.6/collects -name "*protobuf*"
;; no result

I tried running

raco pkg show

...stuff elided...
 planet-murphy-protobuf1  626ae27c7d28b132024c81...
catalog...urphy-protobuf1
...stuff elided...

Which at least admits that the package is installed, but doesn't answer the
question because what is probably the information I'm looking for is
truncated.


I can't believe there isn't an easy way to do this that doesn't require
DrRacket.  If there are significant functions of a programming language
that can only be accessed via an IDE then that is a major problem.







>
> John
>
>
> >
> > I tried:
> >
> > (find-system-path 'collects-dir)  ;; yields ../collects, which is useless
> > /Applications/Racket_v6.6/collects ;; nothing
> > /Library/Application Support/ ;; no directory for Racket
> > ~/Library/Application Support/ ;; no directory for Racket
> >
> > I'm looking for a way to do this programmatically so I'm not flailing
> around in the future.  Where should I be looking?
> >
> >
> >
> >
> > --
> > 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.


[racket-users] How do I find where a module is located?

2017-02-14 Thread David Storrs
I have murphy/protobuf installed and I'd like to look at the source code.
How do I find it?

I tried:

(find-system-path 'collects-dir)  ;; yields ../collects, which is useless
/Applications/Racket_v6.6/collects ;; nothing
/Library/Application Support/ ;; no directory for Racket
~/Library/Application Support/ ;; no directory for Racket

I'm looking for a way to do this programmatically so I'm not flailing
around in the future.  Where should I be looking?

-- 
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 do I find where a module is located?

2017-02-14 Thread David Storrs
On Tue, Feb 14, 2017 at 12:16 PM, David Christiansen <
da...@davidchristiansen.dk> wrote:

> On 02/14/2017 12:00 PM, David Storrs wrote:
>
>>
>> I prefer Emacs to Dr Racket
>>
>
> In that case, if you're using racket-mode, you can use
> racket-open-require-path (C-c C-x C-f by default) or M-x
> racket-find-collection to get to the source of particular import or of a
> collection. You can probably find out how to do this programmatically by
> reading the racket-mode source.
>
> Hope this is handy.
>

Perfect!  Thank you, David, that solved it.



>
> /David
>
>
> --
> 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] make-directory race condition fix?

2017-02-16 Thread David Storrs
On Thu, Feb 16, 2017 at 2:33 PM, Dan Liebgold 
wrote:

> Hi -
>
> I have a few racket process running on Windows that need to each ensure
> the same directory structure exists. I have code like this:
>
> (unless (directory-exists? dir)
>   (make-directory dir))
>
> Well, since they're running in parallel occasionally they race and try to
> make the directory after another has done so, resulting in an exception.
>
> How can I rewrite this so that it either eats the exception or is atomic?
>
> Thanks,
> Dan
>

Will this do?


(with-handlers ((exn:fail? (lambda (e) #t)))
(make-directory "bar"))

It doesn't do the 'directory-exists?' check and it will eat the exceptions.




>
> --
> 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] Safely using port->string where nothing has been written to the port

2017-01-23 Thread David Storrs
Hi Sean,

Does (byte-ready?) work for your case?

https://docs.racket-lang.org/reference/Byte_and_String_Input.html?q=peek#%28def._%28%28quote._~23~25kernel%29._byte-ready~3f%29%29

On Mon, Jan 23, 2017 at 6:05 AM, Sean Kemplay 
wrote:

> Hello,
>
> I am using the URL library to interact with a REST API.
>
> One of the Endpoints sends returns no content for a POST request with a
> status code of 204 (a little unusual however it is an external API so we
> have to cater to it).
>
> I can check the status code for 204 and only apply string->port if it
> isn't a 204 - however I was wondering if there is any check that can be
> made at the port level that no content will be written - in case we
> encounter a malformed response which does not send through a body.
>
> Currently without the checks port->string will hang on a 204 response.
>
> This would be good to know more generally when dealing with ports as well.
>
> Kind regards,
> Sean
>
> --
> 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 David Storrs
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 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 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] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread David Storrs
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 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 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.


[racket-users] How to watch the filesystem

2017-01-19 Thread David Storrs
I need to write something that will notice when a change happens in a
directory (file added, delete, modified, etc) and let me take action
based on that.  I was excited when I saw Racket's "Detecting
Filesystem Changes"
(https://docs.racket-lang.org/reference/Filesystem.html#%28part._filesystem-change%29)
section, but having read through it I am (a) confused and (b) not
sanguine about this being what I need.

I also saw this: http://benaiah.me/posts/watching-filesystem-racket/
but I'm hoping there's a way that does not involve installing extra
software on the customer's machine.

After reading through the DFC docs multiple times, this is what I
think it says; could someone please confirm this for me?


"Synchronizable event" is another name for "event".  The word
"synchronizable" is redundant.

An event is an object.

Some events are purpose built objects that exist only to be events
while some events are things that have other uses.  Example: a port is
always an event but it has functionality beyond its event-ness.

The purpose of events is to let threads work together without stepping
on each other.  In essence, an event is a message that one thread
sends to another.

Events are not used for inter-process communication, only inter-thread
communication.

An event is ultimately a notification about something -- the
filesystem changed, the user moved the mouse, etc.  When a thread
receives an event and acts upon it that is called "synchronizing" the
event.

Synchronizing an event always yields a result, logically enough called
the 'synchronization result'.  This result is often the event itself
but does not have to be.

Events are mutable.  Synchronizing may affect their state.

Events are typically generated either manually (e.g. ,
which produces an event object for later use) or semi-manually (e.g.
calling thread-send which sends the specified value as an event).



Hopefully all of the above is correct.  If so, I have an understanding
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?

-- 
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 David Storrs
On Thu, Jan 19, 2017 at 6:45 PM, Robby Findler
<ro...@eecs.northwestern.edu> 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

I think so, yes.  What is current-directory set to for the DrRacket repl?

On a related topic, Dr Racket does not seem to properly inherit the
environment from the shell.  (getenv "PATH") from the repl does not
return the same value as "echo $PATH" from the shell.  Does Dr Racket
have anything equivalent to a .bashrc file?

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

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

2017-01-20 Thread David Storrs
On Fri, Jan 20, 2017 at 10:02 AM, Robby Findler
<ro...@eecs.northwestern.edu> wrote:
> On Thu, Jan 19, 2017 at 7:29 PM, David Storrs <david.sto...@gmail.com> wrote:
>> On Thu, Jan 19, 2017 at 6:45 PM, Robby Findler
>> <ro...@eecs.northwestern.edu> 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
>>
>> I think so, yes.  What is current-directory set to for the DrRacket repl?
>
> It is initialized to the directory containing the file where you hit "Run".
>
>> On a related topic, Dr Racket does not seem to properly inherit the
>> environment from the shell.  (getenv "PATH") from the repl does not
>> return the same value as "echo $PATH" from the shell.  Does Dr Racket
>> have anything equivalent to a .bashrc file?
>
> If you were to open DrRacket by running `bin/drracket` (a shell
> script) or `racket -l drracket`, it will get the environment of that
> shell. If you run it by double clicking or using "open -a DrRacket" or
> "open file.rkt" (or other similar ways) it will start the process in
> an empty (emptier) environment.
>
> Robby

Perfect, that's just what I needed.  Thanks, Robby.

>
> --
> 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-20 Thread David Storrs
[realized I sent my prior response to Neil alone.  Summary was:  Thank you!]

I see that I can get the event telling me that something changed.  As
far as I can tell the event contains no information about *what*
changed, it simply alerts that *something* changed.  Likewise, the
monitor is only for the directory that I point it at, not for the
subdirectories.  That leaves me two questions:

 - I could keep a copy of the directory state in (RAM | the DB) and
then, when I get the filesystem event, I could walk down through the
filesystem and compare against that copy to know what happened.  Is
there a better way to do this?

- Is there a way to monitor a directory and all its subdirs without
creating separate event monitors for each one?



On Thu, Jan 19, 2017 at 3:58 PM, Neil Van Dyke <n...@neilvandyke.org> 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.


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

2017-01-19 Thread David Storrs
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 https://groups.google.com/d/optout.


[racket-users] racket-mode causes .emacs file to not load

2017-02-28 Thread David Storrs
I'm sending this to the list because I suspect I'm not the only one who
will ever have this issue and the next person should now be able to google
for it.

GNU Emacs 24.5.1
Darwin MacBook-Pro.lan 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19
18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

I've been using racket-mode for a while now and enjoying it.  I'm not sure
what changed, but suddenly it is causing my .emacs to not load.  These are
the first two lines in my .emacs:

(add-to-list 'load-path "~/.emacs.d/elpa/racket-mode-20161101.1859/")
(require 'racket-mode)

I don't recall how I installed racket-mode -- whether it was elpa, directly
download, etc.


When Emacs starts it throws up an error buffer saying:
---
Warning (initialization): An error occurred while loading
`/Users/dstorrs/.emacs':

File error: Cannot open load file, No such file or directory, s

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.
---

I've commented out everything else in the .emacs file so I know it's racket
mode that is causing the issue.  The error happens on the require line.
I've attached the full output of the debug-init dump.

I never shut Emacs down, so it's possible that I had this issue sometime
long ago, resolved it for the current session, and then didn't see it again
until today I decided that I would procrastinate by debugging this.


Removing the (add-to-list 'load-path
"~/.emacs.d/elpa/racket-mode-20161101.1859/") line and moving (require
'racket-mode) to the end of the .emacs file means that I still get the
initialization error, but all of my customization has already been
processed and everything including racket-mode is working fine.

I have no idea what is up with this.

Any thoughts on how to fix 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.
Debugger entered--Lisp error: (file-error "Cannot open load file" "No such file 
or directory" "s")
  require(s)
  byte-code("\300\301!\210\300\302!\210\300\303!\207" [require racket-custom rx 
s] 2)
  require(racket-util)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\207" [require 
racket-custom racket-keywords-and-builtins racket-util cl-lib] 2)
  require(racket-font-lock)
  
byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\300\307!\207"
 [require cl-lib thingatpt racket-custom racket-keywords-and-builtins 
racket-font-lock racket-indent racket-util] 2)
  require(racket-common)
  
byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\300\307!\207"
 [require cl-lib cl-macs racket-custom racket-common racket-complete 
racket-util hideshow] 2)
  require(racket-edit)
  
byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\300\307!\210\300\310!\207"
 [require racket-edit racket-imenu racket-profile racket-repl racket-collection 
racket-bug-report racket-util easymenu] 2)
  require(racket-mode)
  eval-buffer(# nil "/Users/dstorrs/.emacs" nil t)  ; Reading 
at buffer position 93
  load-with-code-conversion("/Users/dstorrs/.emacs" "/Users/dstorrs/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262   \306=\203\307\310Q\202; 
\311=\204\307\312Q\202;\313\307\314\315#\203*\316\202;\313\307\314\317#\203:\320\nB\321\202;\316\322\323\322\211#\210\322=\203a\324\325\326\307\327Q!\"\323\322\211#\210\322=\203`\210\203\243\330!\331\232\203\243\332!\211\333P\334!\203}\211\202\210\334!\203\207\202\210\314\262\203\241\335\"\203\237\336\337#\210\340\341!\210\266\f?\205\260\314\323\342\322\211#)\262\207"
 [init-file-user system-type delayed-warnings-list user-init-file 
inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt 
"/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" 
"^_emacs\\(\\.elc?\\)?$" (initialization "`_emacs' init file is deprecated, 
please use `.emacs'") "~/_emacs" t load expand-file-name "init" 
file-name-as-directory "/.emacs.d" file-name-extension "elc" 
file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message 
"Warning: %s is newer than %s" sit-for 1 "default"] 7 "\n\n(fn)"]()
  command-line()
  normal-top-level()


Re: [racket-users] Re: racket-mode causes .emacs file to not load

2017-02-28 Thread David Storrs
*blink*

It did not even occur to me that someone would give their library a
one-character name -- I'd been assuming that it was mis-parsing the name of
whatever it was trying to load.  I should have checked that before asking.
Thanks.

On Tue, Feb 28, 2017 at 5:17 PM, Alex Harsanyi 
wrote:

> On Wednesday, March 1, 2017 at 5:30:06 AM UTC+8, David K. Storrs wrote:
> > I'm sending this to the list because I suspect I'm not the only one who
> will ever have this issue and the next person should now be able to google
> for it.
> >
> > GNU Emacs 24.5.1
> > Darwin MacBook-Pro.lan 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19
> 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
> >
> > I've been using racket-mode for a while now and enjoying it.  I'm not
> sure what changed, but suddenly it is causing my .emacs to not load.  These
> are the first two lines in my .emacs:
> >
> > (add-to-list 'load-path "~/.emacs.d/elpa/racket-mode-20161101.1859/")
> > (require 'racket-mode)
> >
> >
> > I don't recall how I installed racket-mode -- whether it was elpa,
> directly download, etc.
> >
> >
> >
> >
> > When Emacs starts it throws up an error buffer saying:
> > ---
> > Warning (initialization): An error occurred while loading
> `/Users/dstorrs/.emacs':
> >
> > File error: Cannot open load file, No such file or directory, s
> >
> > To ensure normal operation, you should investigate and remove the
> > cause of the error in your initialization file.  Start Emacs with
> > the `--debug-init' option to view a complete error backtrace.
> > ---
> >
> > I've commented out everything else in the .emacs file so I know it's
> racket mode that is causing the issue.  The error happens on the require
> line.  I've attached the full output of the debug-init dump.
> >
> >
> > I never shut Emacs down, so it's possible that I had this issue sometime
> long ago, resolved it for the current session, and then didn't see it again
> until today I decided that I would procrastinate by debugging this.
> >
> >
> >
> > Removing the (add-to-list 'load-path 
> > "~/.emacs.d/elpa/racket-mode-20161101.1859/")
> line and moving (require 'racket-mode) to the end of the .emacs file means
> that I still get the initialization error, but all of my customization has
> already been processed and everything including racket-mode is working fine.
> >
> >
> > I have no idea what is up with this.
> >
> > Any thoughts on how to fix it?
>
> racket-mode depends on a library named "s", it looks like this library is
> missing on your machine. See https://github.com/magnars/s.el, or install
> it via the emacs package manager.
>
> 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] Idiomatic way to include numbers in a map?

2017-03-02 Thread David Storrs
I'd like to be able to do something like this:

(struct foo (a b c))
(define lst-A '(a b))
(define lst-B '(d e))
(map
foo
lst-A
lst-B
(in-naturals))

I'd expected this to produce:  (foo 'a 'd 0) (foo 'b 'e 1), but instead it
throws an exception "expected list, given stream".  I could do it with a
for/list but that's much more verbose.  What would be the idiomatic way of
doing 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.


[racket-users] DrRacket says #%module-begin not a module

2016-09-03 Thread David Storrs
I typically use Emacs, but I thought I would experiment with DrRacket a
bit.  I'm on OSX 10.11 using DrRacket v6.6, freshly installed an hour ago.
I started it up, File>New, typed this:


#lang racket
(displayln "hello world")


and hit the Run button at top right.  I get the following message at bottom:

Welcome to DrRacket, version 6.6 [3m].
Language: R5RS [custom]; memory limit: 128 MB.
. #%module-begin: illegal use (not a module body) in: (#%module-begin
(displayln "hello world"))

I tried saving the file (File>Save Definitions) as "foo.rkt" and running it
again with (unsurprisingly) no change.

It runs fine from the command line using "racket foo.rkt"  'which racket'
shows that I am in fact using the v6.6 version.  (I have v5.3.1, v6.3 and
v6.6 installed)

I've googled around and found something similar
 from
2013 but there was no closure on that thread.  I threw "illegal use (not a
module body)" at the search box in the Racket docs and got nothing back.
I've skimmed through the documentation on modules and I don't see what
would be relevant there.

I'm sure this is something simple but I have no idea where to look.  Any
suggestions?

Dave

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

2016-09-03 Thread David Storrs
Spiffy, thanks.

Also, what license is your spreadsheet under?  I'm building a for-commerce
app and I don't want to step on your toes if you'd rather it not be used
that way.

Dave

On Sat, Sep 3, 2016 at 10:03 AM, Dmitry Pavlov  wrote:

> David,
>
>invalid symbol: 'hide-hscroll
>>given: '(hide-hscroll)
>>
> This is relatively new in Racket GUI. (Matthew added this option at my
> request not long ago).
> If you can update your Racket installation to the latest version, it is
> probably the easiest way to get past this error.
>
> Best regards,
>
> Dmitry
>
>

-- 
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 says #%module-begin not a module

2016-09-03 Thread David Storrs
On Sat, Sep 3, 2016 at 6:03 PM, John Clements <cleme...@brinckerhoff.org>
wrote:

>
> > On Sep 3, 2016, at 5:54 PM, David Storrs <david.sto...@gmail.com> wrote:
> >
> > The best would probably be if DrRacket's out-of-the-box language setting
> was something like "Use whatever is specified in the file; if nothing is
> specified then default to ”
>
> For the last ’n’ years, the out-of-the-box setting has been “you must
> choose a language level before continuing,” though it’s possible that in
> 6.6, the default is “the Racket language.” My guess—and keep in mind my
> guesses are usually wrong—is that you set your language level preference
> months or years ago, and that it was just lurking in a preference file.
>

Ah, that makes sense.  I don't know why I would have chosen anything other
than 'what's specified in the file', but that's probably what happened.

Regardless, it does seem like the file should be allowed to override the
IDE.  If someone went to the trouble of putting the language declaration in
the file it probably means that it's not going to work without that
language.


>
> John
>
> >
> > Dave
> >
> >
> >
> > >
> > > I tried saving the file (File>Save Definitions) as "foo.rkt" and
> running it again with (unsurprisingly) no change.
> > >
> > > It runs fine from the command line using "racket foo.rkt"  'which
> racket' shows that I am in fact using the v6.6 version.  (I have v5.3.1,
> v6.3 and v6.6 installed)
> > >
> > > I've googled around and found something similar from 2013 but there
> was no closure on that thread.  I threw "illegal use (not a module body)"
> at the search box in the Racket docs and got nothing back.  I've skimmed
> through the documentation on modules and I don't see what would be relevant
> there.
> > >
> > > I'm sure this is something simple but I have no idea where to look.
> Any suggestions?
> > >
> > > Dave
> > >
> > > --
> > > 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] Positioning GUI controls in contact with one another

2016-09-05 Thread David Storrs
How do I find the actual minimum size of a GUI control (e.g. a button)
without the space around it?


I'm on OSX 10.11.  I'm working on a spreadsheet application, and my current
plan is to have each cell be represented as a separate text control.[1]  I
need to have these controls be in contact with one another the way they are
in Excel or any other spreadsheet.  (That is, there is no empty space
between the controls.) By default Racket wants to put significant space
between controls and I've been unable to figure out how to stop this in a
clean, cross-platform way.

Here's what I've tried:

(define frame (new frame% [label "Example"]))
(define panel (new horizontal-panel% [parent frame]))
(define left-btn (new button% [parent panel] [label "Left"]))
(define right-btn (new button% [parent panel] [label "Right"]))
(define (shrinkwrap c)
  (send c horiz-margin 0)
  (send c vert-margin 0))
(void (map shrinkwrap (list left-btn right-btn panel)))
(for ((c (list panel frame)))
 (send c spacing 0))
;;These won't work because get-min-graphical-size is 84 and will trump
the requested size
(send left-btn min-width 70)
(send right-btn min-width 70)

(send frame show #t)

This shows the frame with two buttons arranged horizontally.  There is
significant space around each button and between the two buttons.  I want
there to be no space between them.


Both the left and right buttons have minimum graphical sizes of (84,32), as
shown by:
(begin
  (define-values (w h) (send left-btn get-graphical-min-size))
  (displayln
   (format "left button min w/h: ~a,~a" w h)))
;; Same for right-btn

A quick test shows that I can get the behavior I need by overriding
place-children:

(define squishable-panel%
  (class horizontal-panel%
 (define/override (place-children info w h)
   (displayln "Called place-children")
   '((0 0 70 20) (70 0 70 20)))
 (super-new)))
(define panel (new squishable-panel% [parent frame]))
;;  ...all other declarations stay the same...

The problem is that I got the above numbers by experimentation.
get-graphical-min-size returns the size *with* the spacing that I'm trying
to get rid of, which defeats the purpose.  (Also, why??  That's not the
size of the button, it's the size of the button plus some extra space.)  I
don't see a clean way to go from the GMS to the actual minimum size when
dealing with cross-platform size differences and the fact that Windows is
pixel-based and OSX is drawing-unit-based.

Any suggestions?


Dave

[1] I may need to do some optimizations later instead of representing empty
cells as controls, but that's for later.

-- 
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] Positioning GUI controls in contact with one another

2016-09-06 Thread David Storrs
On Mon, Sep 5, 2016 at 3:03 PM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> I haven't seen buttons in spreadsheet cells in excel, but maybe I'm
> taking your words too literally?
>

Ah, sorry, I phrased that poorly.  I'm thinking of things like the header
on a column, which you can click to make it sort that column.



> Have you considered using canvas% objects instead of buttons? They
> should give you the flexibility you're after.
>

I hadn't.  Thanks, that's a good idea.  I've been playing with it yesterday
and today and having better success, although still not total.

Dave


>
> Robby
>
> On Mon, Sep 5, 2016 at 4:23 PM, David Storrs <david.sto...@gmail.com>
> wrote:
> > How do I find the actual minimum size of a GUI control (e.g. a button)
> > without the space around it?
> >
> >
> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
> current
> > plan is to have each cell be represented as a separate text control.[1]
> I
> > need to have these controls be in contact with one another the way they
> are
> > in Excel or any other spreadsheet.  (That is, there is no empty space
> > between the controls.) By default Racket wants to put significant space
> > between controls and I've been unable to figure out how to stop this in a
> > clean, cross-platform way.
> >
> > Here's what I've tried:
> >
> > (define frame (new frame% [label "Example"]))
> > (define panel (new horizontal-panel% [parent frame]))
> > (define left-btn (new button% [parent panel] [label "Left"]))
> > (define right-btn (new button% [parent panel] [label "Right"]))
> > (define (shrinkwrap c)
> >   (send c horiz-margin 0)
> >   (send c vert-margin 0))
> > (void (map shrinkwrap (list left-btn right-btn panel)))
> > (for ((c (list panel frame)))
> >  (send c spacing 0))
> > ;;These won't work because get-min-graphical-size is 84 and will
> trump
> > the requested size
> > (send left-btn min-width 70)
> > (send right-btn min-width 70)
> >
> > (send frame show #t)
> >
> > This shows the frame with two buttons arranged horizontally.  There is
> > significant space around each button and between the two buttons.  I want
> > there to be no space between them.
> >
> >
> > Both the left and right buttons have minimum graphical sizes of (84,32),
> as
> > shown by:
> > (begin
> >   (define-values (w h) (send left-btn get-graphical-min-size))
> >   (displayln
> >(format "left button min w/h: ~a,~a" w h)))
> > ;; Same for right-btn
> >
> > A quick test shows that I can get the behavior I need by overriding
> > place-children:
> >
> > (define squishable-panel%
> >   (class horizontal-panel%
> >  (define/override (place-children info w h)
> >(displayln "Called place-children")
> >'((0 0 70 20) (70 0 70 20)))
> >  (super-new)))
> > (define panel (new squishable-panel% [parent frame]))
> > ;;  ...all other declarations stay the same...
> >
> > The problem is that I got the above numbers by experimentation.
> > get-graphical-min-size returns the size *with* the spacing that I'm
> trying
> > to get rid of, which defeats the purpose.  (Also, why??  That's not the
> size
> > of the button, it's the size of the button plus some extra space.)  I
> don't
> > see a clean way to go from the GMS to the actual minimum size when
> dealing
> > with cross-platform size differences and the fact that Windows is
> > pixel-based and OSX is drawing-unit-based.
> >
> > Any suggestions?
> >
> >
> > Dave
> >
> > [1] I may need to do some optimizations later instead of representing
> empty
> > cells as controls, but that's for later.
> >
> > --
> > 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] Positioning GUI controls in contact with one another

2016-09-06 Thread David Storrs
On Tue, Sep 6, 2016 at 1:15 AM, Jens Axel Søgaard <jensa...@soegaard.net>
wrote:

> Dave wrote:
> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
> current plan is to have each cell be
> > represented as a separate text control.[1]
>
> This potentially leads to many controls (even with your optimization in
> footnote [1]).
>
> Consider displaying (a section of) the spreadsheet in a canvas.
> Simply draw lines and text to get the grid with contents.
> When the user clicks at a cell, create a control to receive the input,
> then remove it afterwards.
> Or perhaps even have a single control that are shown/hidden.
>
> See an older discussion here:
> https://groups.google.com/d/msg/racket-users/xiKAHjIDmt8/m9-SGZuUVfsJ
>
> /Jens Axel
>
>
Thanks, that's helpful.



Other topic:  I feel like I ask a lot of questions on this list and it
occasionally makes me feel like a nudge.  The helpfulness of the community
is really impressive; people always come back with answers quickly, and the
answers are always helpful.  Thank you all.


Dave





>
>
> 2016-09-06 0:03 GMT+02:00 Robby Findler <ro...@eecs.northwestern.edu>:
>
>> I haven't seen buttons in spreadsheet cells in excel, but maybe I'm
>> taking your words too literally?
>>
>> Have you considered using canvas% objects instead of buttons? They
>> should give you the flexibility you're after.
>>
>> Robby
>>
>> On Mon, Sep 5, 2016 at 4:23 PM, David Storrs <david.sto...@gmail.com>
>> wrote:
>> > How do I find the actual minimum size of a GUI control (e.g. a button)
>> > without the space around it?
>> >
>> >
>> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
>> current
>> > plan is to have each cell be represented as a separate text
>> control.[1]  I
>> > need to have these controls be in contact with one another the way they
>> are
>> > in Excel or any other spreadsheet.  (That is, there is no empty space
>> > between the controls.) By default Racket wants to put significant space
>> > between controls and I've been unable to figure out how to stop this in
>> a
>> > clean, cross-platform way.
>> >
>> > Here's what I've tried:
>> >
>> > (define frame (new frame% [label "Example"]))
>> > (define panel (new horizontal-panel% [parent frame]))
>> > (define left-btn (new button% [parent panel] [label "Left"]))
>> > (define right-btn (new button% [parent panel] [label "Right"]))
>> > (define (shrinkwrap c)
>> >   (send c horiz-margin 0)
>> >   (send c vert-margin 0))
>> > (void (map shrinkwrap (list left-btn right-btn panel)))
>> > (for ((c (list panel frame)))
>> >  (send c spacing 0))
>> > ;;These won't work because get-min-graphical-size is 84 and will
>> trump
>> > the requested size
>> > (send left-btn min-width 70)
>> > (send right-btn min-width 70)
>> >
>> > (send frame show #t)
>> >
>> > This shows the frame with two buttons arranged horizontally.  There is
>> > significant space around each button and between the two buttons.  I
>> want
>> > there to be no space between them.
>> >
>> >
>> > Both the left and right buttons have minimum graphical sizes of
>> (84,32), as
>> > shown by:
>> > (begin
>> >   (define-values (w h) (send left-btn get-graphical-min-size))
>> >   (displayln
>> >(format "left button min w/h: ~a,~a" w h)))
>> > ;; Same for right-btn
>> >
>> > A quick test shows that I can get the behavior I need by overriding
>> > place-children:
>> >
>> > (define squishable-panel%
>> >   (class horizontal-panel%
>> >  (define/override (place-children info w h)
>> >(displayln "Called place-children")
>> >'((0 0 70 20) (70 0 70 20)))
>> >  (super-new)))
>> > (define panel (new squishable-panel% [parent frame]))
>> > ;;  ...all other declarations stay the same...
>> >
>> > The problem is that I got the above numbers by experimentation.
>> > get-graphical-min-size returns the size *with* the spacing that I'm
>> trying
>> > to get rid of, which defeats the purpose.  (Also, why??  That's not the
>> size
>> > of the button, it's the size of the button plus some extra space.)  I
>> don't
>> > see a clean way to go from the GMS to the actual minimum size when
>>

[racket-users] Spreadsheet widget?

2016-08-29 Thread David Storrs
Is there a spreadsheet in Racket?  I dug through the list and found a
mailing list thread
 from
2008 but nothing since then.  I also checked the  Widget Gallery
 and didn't see one.

Greg Cooper, in that thread you said
 that
you'd be interested in talking/working with someone to make this happen.
Is that still the case, and do you have time / interest?  Even if you don't
want to take it on yourself I'd sure appreciate having someone to talk it
through with so I can judge if it's something I can do.

(If anyone else has time/interest in talking it out, that would also be
great.)

Dave

-- 
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] Persisting large values for debugging long-running programs

2016-09-14 Thread David Storrs
Would a database work for you?  SQLite (
https://docs.racket-lang.org/db/connect.html#%28def._%28%28lib._db%2Fmain..rkt%29._sqlite3-connect%29%29)
is dead easy and very convenient.  Their maximum DB size is 140TB, so they
won't have an issue with a few gigs.

Dave


On Wed, Sep 14, 2016 at 12:38 PM, Jonathan Schuster 
wrote:

> I have some large (several GB worth) sets of values I'd like to persist
> across debugging runs of a program, rather than recomputing them each time.
> I'm currently doing this with the built-in "read" and "write", but is there
> a more efficient method, especially for reading the data back in?
>
> I could of course come up with some kind of custom encoding, but that's
> likely not worth the effort in my case, so I'm wondering if there's any
> general purpose method already available in Racket (or in a package).
>
> Thanks,
> Jon
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> 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] Urgent Need--Cloud Engineer---EAD or GC or Citizens only

2016-09-12 Thread David Storrs
Granted, it's annoying to get spammed by someone who thinks that sending
email blasts full of buzzword bingo≥ to inappropriate lists is a good way
to recruit.  That said, I was amused by:

A) That he's recruiting Java engineers on a Racket (aka Lisp) list

B) This line: " *3) Must be comfortable with not working with AWS and not
complaining about not working with AWS."* [emphasis mine]

Dave

On Mon, Sep 12, 2016 at 9:45 AM, Saikiran Nandrolu 
wrote:

> Hi Friends,
>
> Hope you are doing great,
>
> I have an urgent requirement from one of my esteem client, I will
> appreciate if you can have an eye on the below requirement and send me your
> consultant updated profile ASAP.
>
> *Title: Cloud Engineer*
>
> *Location: Cincinnati, OH*
>
> *Duration: 12 months + (Strong potential for extension)*
>
> *EAD or GC or Citizens only*
>
>
>
> * Top Desired Skills: Pivotal Cloud Foundry or Open Source Cloud Foundry,
> Docker experience*
>
>
>
> *Pivotal Cloud Foundry or Open Source Cloud Foundry experience.*
>
> * 2) Docker experience. **3) Must be comfortable with not working with
> AWS and not complaining about not working with AWS.*
> *4) Someone hands on, a doer versus a thinker.*
>
> *Desired Skills:*
>
> *1) **Experience with scripting and automation languages and tools
> (bash, curl, PowerShell, Chef/Puppet/Ansible, Python, Ruby, JavaScript,
> etc). *
>
> *2) **Experience with enterprise software develop integration
> patterns, frameworks and tools (Java EE, Spring Framework, Spring Cloud,
> Spring Configuration, Spring Boot, Hibernate, Spring AOP, Spring MVC, Ruby,
> JavaScript, REST, JSON, HTML). *
>
> *3) **AngularJS (SPA), SQL, Teamcity/Jenkins, GIT/Stash,
> IntellijIDEA, Eclipse, etc). *
>
>
>
>
>
> Best Regard
>
> Sai Kiran
>
> saikir...@usmsystems.com
>
> 703-880-4146
>
>
>
> --
> 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] Trying to understand racket/gui and racket/draw

2016-09-15 Thread David Storrs
How do I draw into a canvas and have the results persist past the next call
to paint-callback?


Given the code below I was expecting to see:

1) A window opens with a diagonal green line on it
2) A vertical blue line appears, crossing with the green line
3) The window goes fullscreen, still showing the green and blue lines

Instead what I get is:
1) A window appears with vertical blue line
2) The blue line disappears and is replaced by a diagonal green line
3) The window goes fullscreen.  Only the green line is shown.

I'm guessing that what's happening is that the window opens, completes
going through the script (and therefore calling the section of code that
displays the blue line), then the on-paint event is triggered and erases
the canvas's dc before calling the paint callback.

I tried removing the paint-callback on the theory that the default one
probably just told the dc to render its content.  That made no change
except that (unsurprisingly) the green line is not painted -- the blue line
is, but promptly disappears.

Assuming I'm right about what's going on, how do I draw into a dc and have
the changes persist?


#lang racket
(require racket/gui)

(define-values (w h) (get-display-size))
(displayln (format "Display size (pixels): ~a x ~a" w h))  ;; 1440 x 877
(define frame (new frame%
   (label "Example")
   (width w)
   (height h)
   ))
(define canvas
  (new canvas%
   (parent frame)
   (style '(border hscroll vscroll resize-corner))
   (paint-callback (lambda (canvas dc)
 (send dc set-pen (send the-pen-list
find-or-create-pen "green" 1 'solid))
 (send dc draw-line 0 0 1430 867)
   

(define dc (send canvas get-dc))

(send frame show #t)
(send dc set-pen (send the-pen-list find-or-create-pen "blue" 1 'solid))
(send dc draw-line 700 0 700 877)
(send frame fullscreen #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.


[racket-users] Taking hash of really big files

2016-09-24 Thread David Storrs
Is there a hashing function in Racket that will operate on a file without
reading the entire thing into memory first?

I need to verify that a file is unchanged after I break it into chunks and
then put the chunks back together again.  My plan is to take a (sha, md5,
...) hash of the file before and after.  The problem is that these are gene
expression BAM files and they could be extremely large -- 200GB or possibly
even more.  Reading in the whole file won't work, and I'm not sure where to
go next.  I could shell out to shasum or something like that, but I wanted
to check if there was a Racket method first.

-- 
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] Re: Taking hash of really big files

2016-09-24 Thread David Storrs
Aaaand, no sooner do I send this than I discover openssl/sha1.  Sorry to
have wasted your time.

On a separate topic, is it reasonable to assume that openssl/sha1 will work
on any platform that Racket will run on?  I'm specifically thinking of
Windows here.

On Sat, Sep 24, 2016 at 7:10 AM, David Storrs <david.sto...@gmail.com>
wrote:

> Is there a hashing function in Racket that will operate on a file without
> reading the entire thing into memory first?
>
> I need to verify that a file is unchanged after I break it into chunks and
> then put the chunks back together again.  My plan is to take a (sha, md5,
> ...) hash of the file before and after.  The problem is that these are gene
> expression BAM files and they could be extremely large -- 200GB or possibly
> even more.  Reading in the whole file won't work, and I'm not sure where to
> go next.  I could shell out to shasum or something like that, but I wanted
> to check if there was a Racket method first.
>

-- 
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] Twenty six low-risk ways to use Racket at work You can start right now

2016-09-29 Thread David Storrs
For the record:  I am cofounder of a biotech startup, and we're writing the
software in Racket.  I hadn't actually thought to mention it here, but this
seems like a good opportunity: we haven't launched yet, but we're looking
to line up beta testers.  The first piece we'll be releasing is a
peer-to-peer filesharing system designed to handle unlimited-size datasets
like gene expression profiles (on the order of 10TB with BAM files of
50-200GB).  In addition to moving large amounts of data it will also
provide accelerated download and backups by way of BitTorrent-esque
swarming.

Would anyone be interested in beta testing?  It'll be a few weeks before we
have a release, but it would be great to have some volunteers lined up.

On Thu, Sep 29, 2016 at 10:57 AM, Matthias Felleisen 
wrote:

>
> Do you mean to write a Racket version for this? I think that would be
> amazing!
>
>
>
> > On Sep 29, 2016, at 4:43 AM, Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
> >
> > Hi all,
> >
> > I was listening to a podcast about F# That mentioned an article like this
> > As I've used a racket at work a number of times for small job, it occurs
> to me that this might be a nice thing to pop on the wiki. Please let me
> know if you have any objections.
> >
> > Kind regards,
> >
> > Stephen
> >
> > Ref https://fsharpforfunandprofit.com/posts/low-risk-ways-to-
> use-fsharp-at-work/
> > --
> > Kind regards,
> > Stephen
> > --
> > Bigger than Scheme, cooler than Clojure & more fun than CL.(n=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.
>

-- 
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] Using schemas with the 'db' module

2016-10-06 Thread David Storrs
Is it possible to connect to a specific schema in a Postgres database, or
to set the current schema of an existing connection?

The 'postgresql-connect' function has no parameter for schema...in fact,
the only mention of schemas in the docs for db is in the Database Catalog
section (
https://docs.racket-lang.org/db/query-api.html#%28part._.Database_.Catalog_.Information%29
)

-- 
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] Using schemas with the 'db' module

2016-10-06 Thread David Storrs
That works perfectly.  Thanks, Ryan.

On Thu, Oct 6, 2016 at 6:42 PM, Ryan Culpepper <ry...@ccs.neu.edu> wrote:

> In PostgreSQL, clusters contain databases contain schemas.
>
> I think the answer is to use "SET SCHEMA" or the more general "SET
> search_path". See
>
>   https://www.postgresql.org/docs/current/static/ddl-schemas.html
>   https://www.postgresql.org/docs/current/static/sql-set.html
>
> Ryan
>
> On 10/06/2016 06:21 PM, Jon Zeppieri wrote:
>
>> Isn't the #:database parameter in postgresql-connect what you're looking
>> for?
>>
>> On Oct 6, 2016, at 6:12 PM, David Storrs <david.sto...@gmail.com
>> <mailto:david.sto...@gmail.com>> wrote:
>>
>> Is it possible to connect to a specific schema in a Postgres database,
>>> or to set the current schema of an existing connection?
>>>
>>> The 'postgresql-connect' function has no parameter for schema...in
>>> fact, the only mention of schemas in the docs for db is in the
>>> Database Catalog section
>>> (https://docs.racket-lang.org/db/query-api.html#%28part._.Da
>>> tabase_.Catalog_.Information%29)
>>>
>>> --
>>> 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
>>> <mailto: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
>> <mailto: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] Is there a predefined (define-runtime-path "this_file")?

2016-09-23 Thread David Storrs
Is there a Racket equivalent of Perl's __FILE__ token?

In Perl I can do this:


I'd like to be able to access files at runtime that have a path known in
relation to the current file.  I can do this:

(define-runtime-path this-dir ".")
(file-exists? (build-path this-dir (some-func-that-returns-a-path)))

...but that requires the define-runtime-path in any file I want to do this
in.

Is there a built-in version of (define-runtime-path this-dir ".") ?

Alternatively, is there a built-in version of Perl's __FILE__ token, which
gives me the absolute path to the source file in which it is used?

-- 
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] Is there a predefined (define-runtime-path "this_file")?

2016-09-23 Thread David Storrs
Brilliant.  Thanks, Alex.

On Fri, Sep 23, 2016 at 8:15 AM, Alex Knauth <alexan...@knauth.org> wrote:

>
> > On Sep 23, 2016, at 10:53 AM, David Storrs <david.sto...@gmail.com>
> wrote:
> >
> > Is there a Racket equivalent of Perl's __FILE__ token?
>
> Yes, it's called `quote-source-file`, in syntax/location.
> http://docs.racket-lang.org/syntax/Source_Locations.html#%
> 28form._%28%28lib._syntax%2Flocation..rkt%29._quote-source-file%29%29
>
> You can also read Greg Hendershott's blog post about writing macros like
> this:
> http://www.greghendershott.com/2014/06/-file-and-line-in-racket.html
>
> Alex Knauth
>
> > In Perl I can do this:
> >
> >
> > I'd like to be able to access files at runtime that have a path known in
> relation to the current file.  I can do this:
> >
> > (define-runtime-path this-dir ".")
> > (file-exists? (build-path this-dir (some-func-that-returns-a-path)))
> >
> > ...but that requires the define-runtime-path in any file I want to do
> this in.
> >
> > Is there a built-in version of (define-runtime-path this-dir ".") ?
> >
> > Alternatively, is there a built-in version of Perl's __FILE__ token,
> which gives me the absolute path to the source file in which it is used?
>
>

-- 
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 parse a html file into a sexpr?

2016-09-27 Thread David Storrs
Yep!

The function is:  html->xexp and it's in (require (planet
neil/html-parsing:3:0))

Note that xexp isn't *exactly* the same as sexp, but after substantial
messing with it myself I can guarantee that you will find it easier.

Dave


On Tue, Sep 27, 2016 at 11:50 AM, Lin Lee  wrote:

> I have a problem to parse a html file into a sexpr.
>
> I plan to use the 'HTML: Parsing Library' to do this.
> But it's a little complicate to parse a html file.
>
> So, I just want to know if there is a lib just parse a html file into a
> sexpr like the example in Tutorial.2:
> '(html
>  (head (title "My Blog"))
>  (body (h1 "Under construction")))
>
> Very appreciate.
>
> --
> 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] Crosscompiling executables

2016-10-26 Thread David Storrs
I'm running Mac and would like to compile my code to a Windows executable.
Is there a way to do this, or do I need to copy the code over to a Windows
installation and compile it there?

-- 
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] Re: Crosscompiling executables

2016-10-26 Thread David Storrs
I should add that I read the docs on raco exe and googled around, but the
list post that I found was from 2013 and said that at the time it was not
possible.

On Wed, Oct 26, 2016 at 10:06 AM, David Storrs <david.sto...@gmail.com>
wrote:

> I'm running Mac and would like to compile my code to a Windows
> executable.  Is there a way to do this, or do I need to copy the code over
> to a Windows installation and compile it there?
>

-- 
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] Programmatically generating keywords

2016-10-26 Thread David Storrs
Thanks, Sam.  That was exactly what I needed.

Thanks, Matthas.  The example was useful.


On Wed, Oct 26, 2016 at 2:13 PM, Sam Tobin-Hochstadt
<sa...@cs.indiana.edu> wrote:
> I think `keyword-apply` is what you want.
>
> Sam
>
> On Wed, Oct 26, 2016 at 2:11 PM, David Storrs <david.sto...@gmail.com> wrote:
>> Is it possible to generate keywords for a call?
>>
>> For example, this works:
>>
>> (with-output-to-file
>>   (buildpath "." "foo")
>>   (lambda () (displayln "f!"))
>> #:mode 'text
>> #:exists 'replace)
>>
>> But this does not:
>>
>> (with-output-to-file
>>   (buildpath "." "foo")
>>   (lambda () (displayln "f!"))
>> #:mode 'text
>> (string->keyword "exists") 'replace)
>>
>> I ask because I'm interested in automating the production of structs
>> from the murphy/protobuf library for purposes of testing.  It provides
>> reflection usage so I can determine the fields and their types, but
>> the structs are created using keywords.
>>
>> I'm guessing that this is a phase issue and I could do it with a macro
>> at compile time but not a function at runtime.  Is that right?
>>
>> --
>> 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: Crosscompiling executables

2016-10-26 Thread David Storrs
That document talks about running raco pkg, although I would have
expected raco exe.  I'm guessing, but it seems like the process for
crosscompiling a racket file target.rkt would be:

1) Download a .tgz for Windows (making sure that you choose 32-bit or
64-bit as appropriate to the target machine) and unroll it into an
arbitrary directory, call it /path/to/windows.

2) Run:  raco  racket -G /path/to/windows/etc -X
/path/to/windows/collects -l- raco exe target.rkt

  What is "-l-" ?  (That's an "ell", right?  Not a 1 / pipe /
etc.)  I would have expected a space between the -l (--lib) and the
"-".  Is it a typo?


3)  Email someone the new "target" executable which they can run on
their Windows machine.

Is this right?




On Wed, Oct 26, 2016 at 10:18 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> It's now possible. See
>
>  http://docs.racket-lang.org/raco/cross-system.html
>
>
> In contrast to the previous discussion,
>
>  https://groups.google.com/d/msg/racket-users/bYR1ZF86NGI/5pcS5FYVCgAJ
>
> we now distribute ".tgz" files containing a minimal Racket distribution
> for each platform:
>
>  http://download.racket-lang.org/releases/6.6/
>
> Also, it's more likely to work than it was back in January.
>
>
> At Wed, 26 Oct 2016 10:07:45 -0400, David Storrs wrote:
>> I should add that I read the docs on raco exe and googled around, but the
>> list post that I found was from 2013 and said that at the time it was not
>> possible.
>>
>> On Wed, Oct 26, 2016 at 10:06 AM, David Storrs <david.sto...@gmail.com>
>> wrote:
>>
>> > I'm running Mac and would like to compile my code to a Windows
>> > executable.  Is there a way to do this, or do I need to copy the code over
>> > to a Windows installation and compile it there?
>> >
>>
>> --
>> 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.


[racket-users] Programmatically generating keywords

2016-10-26 Thread David Storrs
Is it possible to generate keywords for a call?

For example, this works:

(with-output-to-file
  (buildpath "." "foo")
  (lambda () (displayln "f!"))
#:mode 'text
#:exists 'replace)

But this does not:

(with-output-to-file
  (buildpath "." "foo")
  (lambda () (displayln "f!"))
#:mode 'text
(string->keyword "exists") 'replace)

I ask because I'm interested in automating the production of structs
from the murphy/protobuf library for purposes of testing.  It provides
reflection usage so I can determine the fields and their types, but
the structs are created using keywords.

I'm guessing that this is a phase issue and I could do it with a macro
at compile time but not a function at runtime.  Is that right?

-- 
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: Crosscompiling executables

2016-10-26 Thread David Storrs
On Wed, Oct 26, 2016 at 2:30 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> At Wed, 26 Oct 2016 14:01:15 -0400, David Storrs wrote:
>> That document talks about running raco pkg, although I would have
>> expected raco exe.  I'm guessing, but it seems like the process for
>> crosscompiling a racket file target.rkt would be:
>>
>> 1) Download a .tgz for Windows (making sure that you choose 32-bit or
>> 64-bit as appropriate to the target machine) and unroll it into an
>> arbitrary directory, call it /path/to/windows.
>>
>> 2) Run:  raco  racket -G /path/to/windows/etc -X
>> /path/to/windows/collects -l- raco exe target.rkt
>
> That first "raco" is not intended, right?

Oops.  Yes, not intended.


>>   What is "-l-" ?  (That's an "ell", right?  Not a 1 / pipe /
>> etc.)  I would have expected a space between the -l (--lib) and the
>> "-".  Is it a typo?
>
> Yes, it's an "ell", and not a typo. `-l- raco` is short for `-l raco
> --`, where `--` causes any later argument that start with "-" to be
> passed on to `raco` instead of treated as a flag to `racket`.

Ah, good to know.  Is that a Racket-specific thing or a bit of
Unix-ish lore that I've not encountered?  Google is not telling me.


>> 3)  Email someone the new "target" executable which they can run on
>> their Windows machine.
>>
>> Is this right?
>
> Yes, although I bet you'll need
>
>  racket -G /path/to/windows/etc -X /path/to/windows/collects \
> -l- raco pkg install -i 
>
> to install some packages that "target.rkt" uses, since the unpacked
> ".tgz" will have only the "base" package.

Probably this would happen first, right?  Unroll the Windows tgz, then
install the packages, then do the cross-compilation?


On a separate but related note:  I would like to be able to contribute
to the docs, both of core Racket and of various packages.  Is there a
clear tutorial anywhere on that?  If so I can take the above and add
it to the docs for cross compilation.

I know that in general this consists of sending a git pull request,
but there are quite a few repositories (https://github.com/racket),
and it's not obvious at all where the docs (Guide, Reference, etc)
reside.  I've done quite a bit of fruitless exploring and finally
given up.

-- 
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] Structs vs Lists

2016-10-27 Thread David Storrs
You know, it's a very pleasant surprise to me how many messages I've
recently seen on this list that began "I'm just getting started with
Racket and"  Great to see that the Racket community is growing.

On Thu, Oct 27, 2016 at 2:42 PM, Jos Koot  wrote:
> Hi
>
> Lisp (and Racket) programmers know the value, Fortran (and assembler) 
> programmers the cost.
> Nowadays the PLTeam is working on effeciency too, I think.
> But: the most important factor for efficient programming is to select 
> efficient algorithms.
> Two very simple, but notorious examples where you can go wrong in efficiency 
> with the algorithm
> are Fibonacci numbers and binomial coefficients.
>
> Nowadays we have lots of primary memory, but long ago, with machines with 
> limited primary memory,
> there was a time that for some computations it was faster to recompute than 
> to store to and retrieve from disk.
> Much depends on the architecture of the computer, which in the old days was 
> documented very well,
> so well that you could predict how data were flowing through the processors 
> (even with virtual memory).
> Nowaday manufactures of computers give less information.
> For a good estimation of the efficiency of a program
> you have to know which busses are used, their numbers of bits and their 
> frequencies
> and how well these busses connect to each other.
> Well, a little bit of nostalgia.
>
> MHO, Jos
>
> -Original Message-
> From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com] On 
> Behalf Of Ken MacKenzie
> Sent: jueves, 27 de octubre de 2016 19:28
> To: Racket Users
> Cc: deviloc...@gmail.com
> Subject: Re: [racket-users] Structs vs Lists
>
> Thank you for the information.  Good to know.  Performance isn't the first 
> thing I am thinking about, but as I am tinkering and
> getting running with Racket I like to kind of dig into the underlying 
> structure to know the cost of certain operations.
>
> Ken
>
>> For accessing an arbitrary member, yes. A Racket vector is like, say, a C 
>> array: it's a contiguous chunk of memory, and you can
> get at any member of it in constant time.
>>
>>
>> For other purposes? Depends on the purpose. A struct is superior to a list 
>> for struct-like operations. A list is superior to a
> struct for list-like operations.
>>
>
> --
> 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: Crosscompiling executables

2016-10-27 Thread David Storrs
On Thu, Oct 27, 2016 at 9:12 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> At Wed, 26 Oct 2016 15:16:03 -0400, David Storrs wrote:
>> On Wed, Oct 26, 2016 at 2:30 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
>> > At Wed, 26 Oct 2016 14:01:15 -0400, David Storrs wrote:
>> >>   What is "-l-" ?  (That's an "ell", right?  Not a 1 / pipe /
>> >> etc.)  I would have expected a space between the -l (--lib) and the
>> >> "-".  Is it a typo?
>> >
>> > Yes, it's an "ell", and not a typo. `-l- raco` is short for `-l raco
>> > --`, where `--` causes any later argument that start with "-" to be
>> > passed on to `raco` instead of treated as a flag to `racket`.
>>
>> Ah, good to know.  Is that a Racket-specific thing or a bit of
>> Unix-ish lore that I've not encountered?  Google is not telling me.
>
> Yes, the convention of abbreviating multiple "-" flags with a single
> "-" is Unix-ish (second bullet):
>
>  https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
>

Yep, I was aware of the "combine single-letter flags" thing, I'd just
never seen it done with '--'.  Thanks!


>> On a separate but related note:  I would like to be able to contribute
>> to the docs, both of core Racket and of various packages.  Is there a
>> clear tutorial anywhere on that?  If so I can take the above and add
>> it to the docs for cross compilation.
>>
>> I know that in general this consists of sending a git pull request,
>> but there are quite a few repositories (https://github.com/racket),
>> and it's not obvious at all where the docs (Guide, Reference, etc)
>> reside.  I've done quite a bit of fruitless exploring and finally
>> given up.
>
> You're right that it's not obvious where to find the source.
>
> Clicking a section title effectively tells you the module path of the
> enclosing document's source, since it tells how to link to a section.
> For example, clicking "6.14 API for Cross-Platform Configuration" shows
>
>   @secref["cross-system" #:doc '(lib "scribblings/raco/raco.scrbl")]
>
> You could use DrRacket's "Open Require Path..." menu to open
> "scribblings/raco/raco.scrbl".
>
> Then, it's still some detective work to figure out that section "6.14"
> would be in the 6th `include-section` which is "setup.scrbl", while the
> path of the source file gives you a hint that it's in the package
> "racket-doc". Finally, "pkgs.racket-lang.org" gives the source of
> "racket-doc" as
>
>git://github.com/racket/racket/?path=pkgs/racket-doc
>
> So, it's in the "racket/racket" repo on GitHub, specifically in the
> "pkgs/racket-doc/scribblings/raco" subdirectory.
>
> In short, a pull request at https://github.com/racket/racket would be
> welcome.
>

Okay, thanks.  I'll go dig around a bit and see if I can get a better
handle on how it all works.

Dave

-- 
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] Trying to build 'routing' macro for dispatch-rules

2016-10-28 Thread David Storrs
I'm trying to build a macro that will generate routing rules for
'dispatch-rules'.

(dispatch-rules) from web-server/dispatch has this form:

(dispatch-rules
   (("announce-user") #:method post process-announce-user))
   ...more routes here...
)

This seems like it should be automatable, so I tried to write a macro
to generate these rules.  I'd like
(routing announce-user)
to expand to the line above:(("announce-user") #:method post
process-announce-user))

Here's my stab at it, which is currently failing:


;;This part works if I use it directly, ie:
;;  [("announce-file") #:method post (make-route msg-announce-file
announce-file*)]
;;
(define (make-route msg-handler pbuf-type)
  (lambda (req)
(msg-handler (req->protobuf req pbuf-type


;;Let's try to generate the entire rule using the above
(define-syntax (routing stx)
  (syntax-case
  stx ()
([_ pbuf-type]
 (with-syntax* ([type-name(format-id stx "~a*" #'pbuf-type)]
[handler-name (format-id stx "msg-~a" #'type-name)]
[route-name   (symbol->string (syntax->datum
(format-id stx "~a" (syntax->datum #'pbuf-type]
)
   #'[(route-name) #:method "post" (make-route
handler-name type-name)]
;;   #'(quote [(route-name) #:method "post"
(make-route handler-name type-name)])
   

;;(routing announce-file)  ; If I use this (i.e. outside the
dispatch-rules) in combination with the 'quote' version above, I see
the correct thing

(define-values (dispatch-request url-for)
  (dispatch-rules
   (routing announce-file)
   [("create-user") #:method post process-create-user]
   ...more routes here...
)

Error is:

racket network/routing.rkt
~/app/network/routing.rkt:194.2: dispatch-rules: bad syntax
  in: (dispatch-rules (routing announce-file) (("create-user")
#:method post process-create-user) ...
  context...:
   
/Applications/Racket_v6.6/collects/syntax/parse/private/runtime-report.rkt:698:0:
error/report
   
/Applications/Racket_v6.6/collects/syntax/parse/private/runtime-report.rkt:28:0:
call-current-failure-handler
   standard-module-name-resolver


As mentioned in the comments, it does generate (the quoted form of)
the correct thing if I:

1) inside the macro, comment in the 'quote' line and comment out the
line above it
2) comment OUT the '(routing announce-file) that is inside dispatch-rules
3) comment IN the (routing announce-user) line that is just above dispatch-rules


My suspicion is that dispatch-rules is a macro and so my macro is not
being expanded inside another macro.  That's not how I thought macros
worked, though, so now I'm really puzzled.

Can anyone clarify this for me?

-- 
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   5   6   7   8   >