Re: [racket] syntax/parse ellipses question

2010-06-11 Thread Ryan Culpepper

Eric Dobson wrote:

I'm trying to use the syntax/parse library, and am running into a
weird problem when using ~or. It works without ellipses, but with
ellipses it complains about a duplicated attribute. I would assume
that the attributes with the same name in an ~or pattern were the same
attribute that could just match in different ways. A simplified
version is below, the first 4 examples work, and the fifth does not.
Is there a restriction that I am missing for why this does not work?


There are three variants of ~or: single-term ~or, head ~or, and 
ellipsis-head ~or. Ellipsis-head ~or has different rules for attributes, 
which the docs seem not to explain. I'll update the docs.



(syntax-parse #'(1 2 3)
 [((~or x:number) ...) (syntax->datum #'(x ...))])

(syntax-parse #'(a b c)
 [((~or x:id) ...) (syntax->datum #'(x ...))])


Both of the above are ellipsis-head ~or, not that it matters.


(syntax-parse #'(1)
 [((~or x:id x:number)) (syntax->datum #'(x))])

(syntax-parse #'(a)
 [((~or x:id x:number)) (syntax->datum #'(x))])


These are both single-term ~or.


#;
(syntax-parse #'(a 1 b)
 [((~or x:id x:number) ...) (syntax->datum #'(x ...))])


This is ellipsis-head ~or. The difference is that ellipsis-head ~or 
accumulates different alternatives' attributes independently. The 
different alternatives must have disjoint attributes. (For now, anyway; 
I'm considering relaxing that restriction.) For example,


(syntax-parse #'(a b #:c d e #:f g)
  [((~or x:id (~seq k:keyword kx:id)) ...)
   #'((x ...) ((k kx) ...))])
=> #

You can turn the ~or back into a single-term ~or by putting another 
pattern form between it and the ellipses. For example,


(syntax-parse #'(a 1 b)
  [((~and (~or x:id x:number)) ...) ___])

Hope that helps!

Ryan

_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Y-combinator perfomance

2010-06-25 Thread Ryan Culpepper
On 06/25/2010 12:59 PM, Groshev Dmitry wrote:
> Is there any way to avoid this overhead? I'm really interested in
> combinator style, but if it makes programs 8 times slower, it is
> useless. Maybe some compiler/macro optimizations is possible?

You might find this version interesting:

(define-syntax define/rec
  (syntax-rules ()
[(define/rec (name arg ...) body)
 (define name
   (let ([actual
  (λ (self arg ...)
(let-syntax ([name
  (syntax-rules ()
[(name name-arg (... ...))
 (self self name-arg (... ...))])])
  body))])
 (lambda (arg ...) (actual actual arg ...]))

The (... ...) escapes the ellipses, so they are interpreted as ellipses
for the local 'name' macro, not the 'define/rec' macro.

(define/rec (rec-sum l t)
  (if (empty? l) t (rec-sum (cdr l) (+ t (car l)

Ryan


> 25.06.10, 22:50, "Matthew Flatt" :
> 
>> If you're interested in specially the overhead of combinator style,
>>  then your example still understates the overhead compared to relatively
>>  cheap operations.
>>  
>>  In addition to Matthias's change to get rid of `apply', I've revised
>>  your program (see below) to replace `first' and `rest' with `car' and
>>  `cdr' (which don't have to check that they're given lists) and to lift
>>  out the list creation (which becomes significant). With those changes,
>>  I get
>>  
>>   cpu time: 1655 real time: 1668 gc time: 1546 ; list creation
>>   cpu time: 422 real time: 426 gc time: 41
>>   1000
>>   cpu time: 60 real time: 60 gc time: 0
>>   1000
>>  
>>  The direct version is faster because the compiler can see the loop, so
>>  it can produce code with fewer jumps and less allocation of
>>  intermediate closures. I suppose that the general rule is that the
>>  compiler is more effective when you can use constructs that say more
>>  directly what you want.
>>  
>>  Compilers can't easily see through a Y combinator, and a factor of 8 or
>>  so difference is probably typical for Lisp compilers. (I tried Ikarus
>>  and Gambit to double check, and performance was about the same as with
>>  Racket.)
>>  
>>  
>>  
>>  #lang racket
>>  (define-syntax U
>>(syntax-rules ()
>>  [(_ f) (f f)]))
>>  (define-syntax define/comb
>>(syntax-rules ()
>>  [(_ comb name (arg . args) f)
>>   (define name 
>> (comb (λ (name) (λ (arg . args) f]))
>>  
>>  (define (Z f)
>>(U (λ (g) (λ (x y)
>>((f (U g)) x y)
>>  
>>  (define/comb Z comb-sum (l t) 
>>(if (null? l) t (comb-sum (cdr l) (+ t (car l)
>>  
>>  (define (sum l t)
>>(if (null? l) t (sum (cdr l) (+ t (car l)
>>  
>>  (define l (time (make-list 1000 1)))
>>  (time (comb-sum l 0))
>>  (time (sum l 0))
>>  
>>  
>>  
> _
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] CoreMIDI bindings

2010-07-21 Thread Ryan Culpepper
On 07/21/2010 12:51 PM, Evan Hanson wrote:
> In an effort to learn scheme, I ported some bindings for a subset of
> the OS X CoreMIDI API from a Ruby project of mine to scheme/foreign.
> I'm posting them (a) in case anyone wants to use them, but more
> because (b) I'm hoping for some feedback. I'm sure there are places
> where I could have done things better, more idiomatically, etc. Any
> advice is appreciated (but file this one under "non-emergency").

A couple thoughts:

1) Use provide/contract for your library's entry points. Besides making
your library safer to use, they act as a basic kind of documentation.
Also, using contracts in this program will be a little lesson in name
management: ffi/unsafe and racket/contract have different bindings for
->, so you'll need to prefix or rename one of them. E.g.,
  (require (rename-in racket/contract [-> c->]))

2) Consider using tagged pointers instead of just _pointer. For example,
you could turn this:

  (define midi-get-destination
(ffi-load "MIDIGetDestination"
  (_fun _item-count; returns a
-> _pointer))) ; MIDIEndPointRef *

into this:

  (define-cpointer-type _midi-end-point-ref)
  ...
  (define midi-get-destination
(ffi-load "MIDIGetDestination"
  (_fun _item-count -> _midi-end-point-ref)))

(That is, if I remember how tagged pointers work correctly.)

And then by all means put it up on planet.racket-lang.org!

Ryan


> Also, is this the kind of thing that should be namespaced? In
> contrast to other languages where namespacing is used heavily
> (sometimes even to a fault), it seems that many scheme libraries are
> quite flat. Is this simply left up to the user to manage, or does the
> module system take care of this, or is there something else I'm
> missing altogether? Forgive the naïveté if this should be clear to
> me.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] CoreMIDI bindings

2010-07-21 Thread Ryan Culpepper
On 07/21/2010 02:43 PM, Evan Hanson wrote:
> Makes sense. That's nice flexibility for module users.
> 
> Out of curiosity, how dynamic are module names? Can they be
> manipulated? Say you had two modules that each provide a function
> "connect". You would load them as mod1:connect and mod2:connect using
> prefix-in -- how might one design a form that would associate a call
> to connect inside a passed expression to a given module?
> 
> (define (within-module module-name fun)
>   (module-associate module-name fun) ... )
> 
> (within-module mod1:
>   (lambda (...)
> (connect arg arg arg) ... )) ; --> equates to (mod1:connect ...)
> 
> This is miles from how it would work, I'm sure, but is it possible?

To a first approximation, module linkage is static, and programs don't
manipulate modules dynamically. (That's not entirely true, of course.
Racket has reflection, but your example doesn't sound like a good use
for it.)

There are a couple idioms that might be what you want, depending on who
does the choosing and how much code the choice affects.

1) Create a "dispatcher" procedure that decides which one to call based
on its arguments:

  (require (prefix-in mod1: "mod1.rkt")
   (prefix-in mod2: "mod2.rkt"))

  (define (connect which arg1 arg2)
(cond [(eq? which 'mod1) (mod1:connect arg1 arg2)]
  [(eq? which 'mod2) (mod2:connect arg1 arg2)]
  [else (error 'connect "huh?")]))

2) Use a "parameter":

  (define current-connect (make-parameter mod1:connect))
  (define (connect arg) ((current-connect) arg))

  ;; out here, connect uses mod1:connect
  ...
  (parameterize ((current-connect mod2:connect))
;; in here, connect uses mod2:connect
...)

3) Use units (dynamically linkable components) to parameterize large
amounts of code over a single choice of implementation.

Ryan


> On Wed, Jul 21, 2010 at 2:45 PM, Todd O'Bryan  wrote:
>>> On Jul 21, 2010, at 2:51 PM, Evan Hanson wrote:
>>>
>>> Also, is this the kind of thing that should be namespaced? In
>>> contrast to other languages where namespacing is used heavily
>>> (sometimes even to a fault), it seems that many scheme libraries
>>> are quite flat. Is this simply left up to the user to manage, or does
>>> the module system take care of this, or is there something else
>>> I'm missing altogether? Forgive the naïveté if this should be clear to
>>
>> One way that name collisions get avoided is the
>>
>> (require (prefix-in pre: "imported-module.rkt"))
>>
>> form. Every name in the module is prefixed with pre: when you use it
>> in your module, so if you have any name collisions or want to remind
>> yourself where something came from, you just give the module an
>> appropriate prefix when you import it in.
>>
>> Todd
>>
> _
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Newbie question - Drscheme hangs on directory-exists?

2010-07-21 Thread Ryan Culpepper

John Sampson wrote:

Hello -

If I enter "(directory-exists? "C:\iconsource")" into DrRacket
I would expect it to answer with "#t" or "'#f" but in fact the
cursor goes to the next line, leaving an indent.
I am running this on Windows 7.

As a newbie I do not understand this behaviour.


You need to escape the backslash in your string:

  (directory-exists? "C:\\iconsource")

DrRacket colors the bad string red to indicate that there's a problem 
with it. If you insert the extra backslash, it turns green.


Wouldn't it be nice for DrRacket to signal an error when you hit enter 
instead? Yes, but it strikes me as a subtle problem. (We do, after all, 
want to permit multi-line repl entries.) I'll let someone who's thought 
about it more address that part.


Ryan

_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket-users] Why do single-form modules behave differently?

2021-01-03 Thread Ryan Culpepper
It's the consequence of two design goals:

1. The `module` form is separate from the `#%module-begin` syntax hook so
that the module's initial language can pick the hook macro that controls
the entire module body.

2. Racket's primitive syntax is designed so that it can be re-expanded.
(The `expand` operation should be idempotent.) Some of Racket's tools (for
example, debugging support) work by expanding code, instrumenting it, and
then re-expanding, compiling, and running the result. But a
`#%module-begin` hook macro can transform the module body in non-idempotent
ways, so that hook macro should only be called once. So the answer to "have
I already run the module's `#%module-begin` hook?" must be reflected in the
fully-expanded syntax of the module.

Ryan


On Sun, Jan 3, 2021 at 8:40 AM Michael MacLeod 
wrote:

> Oops, sorry about interpreting your question wrong. Unfortunately I don't
> know the answer to your actual question.
>
> On Sat, Jan 2, 2021, 10:24 PM Sage Gerard  wrote:
>
>> I know about that. I asked why it was designed that way.
>>
>>
>> Sent from ProtonMail mobile
>>
>>
>>
>>  Original Message 
>> On Jan 3, 2021, 12:18 AM, Michael MacLeod < michaelmmacl...@gmail.com>
>> wrote:
>>
>>
>> There's an edge case of 'module' when only one form is provided which
>> results in that form being partially expanded to determine if such
>> expansion would lead to a #%plain-module-begin form. Otherwise (more than
>> one form provided) they are wrapped in #%module-begin with no partial
>> expansion occurring.
>>
>> I think this might be causing the discrepancy you witnessed.
>>
>> From the docs (https://docs.racket-lang.org/reference/module.html):
>>
>> If a single form is provided, then it is partially expanded in a
>> module-begin context. If the expansion leads to #%plain-module-begin, then
>> the body of the #%plain-module-begin is the body of the module. If partial
>> expansion leads to any other primitive form, then the form is wrapped with
>> #%module-begin using the lexical context of the module body; this
>> identifier must be bound by the initial module-path import, and its
>> expansion must produce a #%plain-module-begin to supply the module body.
>> Finally, if multiple forms are provided, they are wrapped with
>> #%module-begin, as in the case where a single form does not expand to
>> #%plain-module-begin.
>>
>> (This response was adapted from one of my earlier replies to the mailing
>> list. Search racket-users for "perplexed by macro-expansion behavior near
>> #%module-begin" for more context).
>>
>> Best,
>> Michael
>>
>> On Sat, Jan 2, 2021 at 8:26 PM Sage Gerard  wrote:
>>
>>> Why does Racket handle modules with exactly one form differently?
>>>
>>> I ran into a bug where modules in my module language won't expand if the
>>> modules have exactly one form, so I'm just curious.
>>>
>>> (Wild guess: It's Racket's way of checking for a shortcut to end
>>> expansion earlier)
>>>
>>> *~slg*
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to racket-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/racket-users/OVvZ0OK4_PfyvXCWfuvzDWBM5-ellmDvNmWchVmsCwAJb_rbSZkCkyraakcGsEMSCl2BsLsWtMXFhQcXY75IKhYiYYGQQEI7lVXLgGBbTCc%3D%40sagegerard.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CACehHmBvs5KK4vQmwio93D1NZ9hTOoSv-Qkm8XOjF%2B4JWDOiHg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qmm57T3jFZW_saSQ_g%3Der5BNRdARuAjtSJ%2BsMsaQnQo%3DA%40mail.gmail.com.


[racket-users] synchronization with ffi/unsafe/os-thread

2021-01-26 Thread Ryan Culpepper
I'm trying to figure out how to use ffi/unsafe/os-thread to call a
long-running foreign function in an OS thread to avoid blocking other
Racket threads. I want to communicate the result of the foreign call to the
original Racket thread and have it wake up when the call completes.
Normally I could use a channel, but OS threads are not allowed to use
Racket synchronization primitives (channels, semaphores, etc). I can't use
a spinlock, because the docs for call-in-os-thread say that mutations are
allowed but their visibility is unspecified except as synchronized by
os-semaphores. The docs for os-semaphore-wait say that if it is called by a
Racket thread (ie, not a restricted OS thread), then waiting blocks all
Racket threads, which I want to avoid.

Places already have to solve the problem of bridging OS threads and Racket
synchronization. So here's my best idea so far: use a variable (or box)
protected by an os-semaphore for communicating the result, but use a place
channel for the synchronization. The code looks like this:

(define result #f)
(define os-sema (make-os-semaphore))
(define-values (c1 c2) (place-channel))
(call-in-os-thread
 (lambda ()
   (set! result (...))
   (os-semaphore-post os-sema)
   (place-channel-put c1 'ready)))
(void (sync c2))
(os-semaphore-wait os-sema)
result

This "works", but is it reliably safe to use place-channel-put from an OS
thread? Or is there a better way to do this?

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qnFo1hYcasdNm%2BN29bW3HbqtuYG8X-cCkgoZpJw%3DqKDWw%40mail.gmail.com.


Re: [racket-users] synchronization with ffi/unsafe/os-thread

2021-01-26 Thread Ryan Culpepper
On Tue, Jan 26, 2021 at 1:23 PM Matthew Flatt  wrote:

> At Tue, 26 Jan 2021 10:25:42 +0100, Ryan Culpepper wrote:
> > This "works", but is it reliably safe to use place-channel-put from an OS
> > thread?
>
> No. It's not intended to work from an arbitrary OS thread, and because
> `place-channel-put` touches the thread scheduler to enter atomic mode,
> I can imagine that it might go wrong either now or with some small
> future change.
>
> > Or is there a better way to do this?
>
> Probably the only way currently is to use `unsafe-poller`. See
> "rktrl.rkt" in "readline" for an example. It would make sense to make
> that part of `ffi/unsafe/thread` or a new `ffi/unsafe` library. (It
> would also be good to add `unsafe-make-signal-received` to
> `ffi/unsafe/schedule`.)
>

Thanks for the pointer! Those sound useful, but in the spirit of maximum
caution, is there a guarantee that the write to the box from the new OS
thread will be visible to the original Racket OS thread when the poller
tries to read it? Is `box-cas!` or one of the memory-order operations
needed?

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qm9Fu%3DxPWSG%2BPRoG9Pbfddo0FJQLnb_CWr8isvCmGNSfQ%40mail.gmail.com.


Re: [racket-users] synchronization with ffi/unsafe/os-thread

2021-01-26 Thread Ryan Culpepper
On Tue, Jan 26, 2021 at 3:06 PM Matthew Flatt  wrote:

> At Tue, 26 Jan 2021 14:49:22 +0100, Ryan Culpepper wrote:
> > Thanks for the pointer! Those sound useful, but in the spirit of maximum
> > caution, is there a guarantee that the write to the box from the new OS
> > thread will be visible to the original Racket OS thread when the poller
> > tries to read it? Is `box-cas!` or one of the memory-order operations
> > needed?
>
> I think enough synchronization is implied by `(signal-received)` and
> the way it interacts with the scheduler. That is, there's no guarantee
> that the waiting thread sees a box change right away, but signaling the
> waiting thread will imply a barrier on both the signaling side and
> waiting side, so that the next poll iteration after receiving the
> signal will definitely see the update at the latest. If that sounds
> right, we could make that a guarantee for signaling and polling.
>

That sounds reasonable. Thanks!

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33q%3DETxYur_5VNFmdROjqg69u_gRWgqwmNq%3DW5cFQKnEOPQ%40mail.gmail.com.


Re: [racket-users] Parenthesizing infix expressions in Redex renderings?

2021-02-24 Thread Ryan Culpepper
The `binary-rw` function from unstable/gui/redex library has some support
for optionally parenthesizing its arguments.

Ryan


On Wed, Feb 24, 2021 at 11:07 AM David Thrane Christiansen <
da...@davidchristiansen.dk> wrote:

> Hello all,
>
> I'm working on coding up a little language model in Redex, and I'd like to
> get it to render things in the form that my colleagues are used to. This
> means some infix operators as well as dealing with parenthesizing based on
> operator precedence.
>
> Here's a boiled-down sample of what I'm up to:
>
> #lang racket
>
> (require redex pict)
>
> (define-language L
>   (C success (then C C) (or C C)))
>
> (with-compound-rewriters
>   (['or (match-lambda [(list _ _ x y _) (list "" x " or " y "")])]
>['then (match-lambda [(list _ _ x y _) (list "" x " then " y "")])])
>   (vl-append
>20
>(render-language L)
>(render-term L (then (or success success) success
>
> I've attached the result. The resulting rendering of L looks appropriate,
> but the nesting of then and or in the rendered term does not indicate the
> nesting. I'd like to be able to specify precedence and associativity and
> have parentheses inserted appropriately; failing that, a reasonable backup
> would be parenthesizing sub-expressions that are not atomic.
>
> Can anyone point me at the right resource to use to figure out how to do
> this?
>
> Thank you!
>
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CAF_itEtHuJP6i%3DR3_ggKTn1%3DRDmswZfCiFMYJqBwcHqpXB7fpw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qmAv_KzhBj_%2B3NezyXgt6vAzL_M6dF0J9S%3DRZkQyA1HSQ%40mail.gmail.com.


Re: [racket-users] Re: Do I need to explicitly enable readline support for the REPL?

2021-03-13 Thread Ryan Culpepper
Yes, since version 6.7 Racket automatically loads xrepl, which
automatically loads readline support (or libedit support, if readline-gpl
is not installed).

Ryan


On Sat, Mar 13, 2021 at 8:39 AM Tim Lee  wrote:

> Is it possible that the documentation is outdated?
>
> According to
> https://docs.racket-lang.org/readline/index.html#%28part._.Normal_.Use_of_.Readline%29
> :
>
> > You can also put (require readline) in your "~/.racketrc", so that Racket
> > automatically loads Readline support in interactive mode.
>
> Is this unnecessary now?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/20210313073934.blz7pstpqv7wvraq%40home-guest
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qkLRtZLDMoG8ODJV%3DMTZ90OE%3DH0bAE_wtwDaDOB1L4o8Q%40mail.gmail.com.


Re: [racket-users] How do I, a client, get a copy of an untrusted server certificate?

2021-04-12 Thread Ryan Culpepper
Racket does not provide a way to do that.

You can use `openssl s_client -showcerts -connect host:port < /dev/null` to
get the server's certificate chain in PEM form (with other logs around it).
Of course, an attacker could intercept the connection and send you their CA
certificate instead. It would be safer if example.com published their
certificate in a (standardly) trusted location.

If you do something like this, consider mitigating the danger by having the
user add the certificate to a separate location managed by your application
rather than the OS trust store. You can extend the
`ssl-default-verify-sources` parameter to point to a file containing
additional root certificates.

Ryan


On Mon, Apr 12, 2021 at 3:20 PM Sage Gerard  wrote:

> When ssl-connect fails due to an untrusted certificate, this error is
> raised:
>
> ssl-connect: connect failed (error:1416F086:SSL
> routines:tls_process_server_certificate:certificate verify failed)
>
> I'd like to give the user a more helpful error, like this:
>
> Could not connect due to an untrusted certificate. In many cases, it is
> not advisable to proceed. However, if you trust the server at
> example.com, add /tmp/example.com.cert to your trusted certificates
> using this guide: 
>
> How can I get a copy of the offending certificate so that I can do this?
>
> --
> ~slg
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/8a55256d-71ed-b47f-5b92-c958438c5659%40sagegerard.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qnnqy9HFW3UyOZ%3DiqO_Xz%3DSuVJ%2BZ%2Bv_paOFSKD7M%3Dgqpw%40mail.gmail.com.


Re: [racket-users] How do I, a client, get a copy of an untrusted server certificate?

2021-04-12 Thread Ryan Culpepper
Yes, that's right.

Ryan


On Mon, Apr 12, 2021 at 4:23 PM Sage Gerard  wrote:

> Understood, thank you. By "trusted location," do you mean a server with a
> certificate that operating systems already trust?
> On 4/12/21 10:15 AM, Ryan Culpepper wrote:
>
> Racket does not provide a way to do that.
>
> You can use `openssl s_client -showcerts -connect host:port < /dev/null`
> to get the server's certificate chain in PEM form (with other logs around
> it). Of course, an attacker could intercept the connection and send you
> their CA certificate instead. It would be safer if example.com published
> their certificate in a (standardly) trusted location.
>
> If you do something like this, consider mitigating the danger by having
> the user add the certificate to a separate location managed by your
> application rather than the OS trust store. You can extend the
> `ssl-default-verify-sources` parameter to point to a file containing
> additional root certificates.
>
> Ryan
>
>
> On Mon, Apr 12, 2021 at 3:20 PM Sage Gerard  wrote:
>
>> When ssl-connect fails due to an untrusted certificate, this error is
>> raised:
>>
>> ssl-connect: connect failed (error:1416F086:SSL
>> routines:tls_process_server_certificate:certificate verify failed)
>>
>> I'd like to give the user a more helpful error, like this:
>>
>> Could not connect due to an untrusted certificate. In many cases, it is
>> not advisable to proceed. However, if you trust the server at
>> example.com, add /tmp/example.com.cert to your trusted certificates
>> using this guide: 
>>
>> How can I get a copy of the offending certificate so that I can do this?
>>
>> --
>> ~slg
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/8a55256d-71ed-b47f-5b92-c958438c5659%40sagegerard.com
>> .
>>
> --
> ~slg
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/8edbd1fd-715d-a730-5659-3731518c5fba%40sagegerard.com
> <https://groups.google.com/d/msgid/racket-users/8edbd1fd-715d-a730-5659-3731518c5fba%40sagegerard.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qm0ZGX4MviFJZVq9x8Ax7Cx7yW9nNTZbWu2ha2r72LPRg%40mail.gmail.com.


Re: [racket-users] Tell require where to find C libraries ?

2021-05-07 Thread Ryan Culpepper
It looks like there are two issues. One is the shared library's directory,
but the other is that the Racket library is looking for "libtag_c.so.0",
and you have "libtag_c.so.3.0". That is, it's looking for a version suffix
of "0", not "3.0" (see
https://github.com/takikawa/taglib-racket/blob/master/taglib/taglib.rkt#L83
).

One fix would be to change the Racket code to try "3.0" also. Maybe
conditioned on the OS, since on Ubuntu I also get the library with suffix
"0".

An alternative would be to copy or link /usr/local/lib/libtag_c.so.3.0 to
Racket's lib directory with the file name the Racket code is trying to load:

  ln -s /usr/local/lib/libtag_c.so.3.0
~/.local/share/racket/7.9/lib/libtag_c.so.0

Note: that assumes that the library versions are actually compatible;
otherwise, the Racket code is likely to misbehave, even if it loads the
library. Loading the shared library might still fail if the shared library
itself has dependencies that are not in the default OS search path. (In
that case, Nate's point about LD_LIBRARY_PATH might help.)

Ryan


On Fri, May 7, 2021 at 3:12 PM krs...@gmail.com  wrote:

> I know it sees my custom dir, I ran this in racket:
> > (require setup/dirs)
> > (get-lib-search-dirs)
> '(#
>   #
>   #)
>
>
> On Friday, May 7, 2021 at 8:08:26 AM UTC-4 krs...@gmail.com wrote:
>
>> I'm so close :)
>>
>> I installed taglib locally to /home/wise/root/lib, so I *have* the file
>> exactly as racket is complaining about:
>> /home/wise/root/lib/libtag_c.so.0
>>
>> I used your config example to edit (as root) /etc/racket/config.rktd
>> I added the "lib-search-dirs" line, so it looks like:
>> ;; generated by unixstyle-install
>> #hash(
>>   (doc-dir . "/usr/local/share/doc/racket")
>>   (lib-dir . "/usr/local/lib/racket")
>>   (share-dir . "/usr/local/share/racket")
>>   (include-dir . "/usr/local/include/racket")
>>   (bin-dir . "/usr/local/bin")
>>   (apps-dir . "/usr/local/share/applications")
>>   (man-dir . "/usr/local/man")
>>   (absolute-installation? . #t)
>>   (build-stamp . "")
>>   (doc-search-url . "
>> https://download.racket-lang.org/releases/7.9/doc/local-redirect/index.html
>> ")
>>   (catalogs . ("
>> https://download.racket-lang.org/releases/7.9/catalog/";))
>>   (lib-search-dirs . (#f "/home/wise/root/lib"))
>> )
>>
>> I still get the error:
>> Welcome to Racket v7.9 [cs].
>>
>> > (require taglib)
>> ; ffi-lib: could not load foreign library
>> ;   path: libtag_c.so.0
>> ;   system error: File not found
>> ; [,bt for context]
>>
>> I'm still poking at it, thanks again for the help.
>>
>> On Thursday, May 6, 2021 at 11:41:03 PM UTC-4 krs...@gmail.com wrote:
>>
>>> Thanks for the help!
>>> I was sure that was going to be it but it's not :(
>>>
>>> This is what is on my system:
>>> /usr/local/lib/libtag_c.so.3.0
>>>
>>> racket is looking for libtag_c.so.0
>>>
>>> So i'm not sure what to do next.
>>>
>>> On Thursday, May 6, 2021 at 7:21:10 PM UTC-4 johnbclements wrote:
>>>
 It looks to me like you probably need to edit your “config.rktd” file:


 https://docs.racket-lang.org/raco/config-file.html?q=config.rktd#%28idx._%28gentag._67._%28lib._scribblings%2Fraco%2Fraco..scrbl%29%29%29

 On my machine (macOS using macports), for instance I have do do this
 for every new installation of drracket:

 - edit /config.rktd to contain
 (lib-search-dirs . (#f "/opt/local/lib”))

 Let me know if I misunderstood your situation!

 John Clements


 > On May 6, 2021, at 3:54 AM, krs...@gmail.com 
 wrote:
 >
 >
 > Hi!,
 >
 > I am doing: (require taglib) and I get:
 > > (require taglib)
 > ; ffi-lib: could not load foreign library
 > ; path: libtag_c.so.0
 > ; system error: File not found
 > ; [,bt for context]
 >
 > I am on OpenBSD and that file is at:
 > /usr/local/lib/libtag_c.so.3.0
 >
 > How can I change my search path for C libs to be /usr/local ?
 >
 > --
 > You received this message because you are subscribed to the Google
 Groups "Racket Users" group.
 > To unsubscribe from this group and stop receiving emails from it,
 send an email to racket-users...@googlegroups.com.
 > To view this discussion on the web visit
 https://groups.google.com/d/msgid/racket-users/b8425f0a-6d45-4954-9e32-df51aa5151cbn%40googlegroups.com.


 --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/59a44f94-5931-46cd-ba3b-039c02a47076n%40googlegroups.com
> 
> .
>

-- 
You received this mess

Re: [racket-users] Tell require where to find C libraries ?

2021-05-07 Thread Ryan Culpepper
Sorry, I did miss those emails.

What do you see if you try (require taglib) after starting Racket with
logging for "ffi-lib"? For example:

  $ PLTSTDERR="debug@ffi-lib" racket
   unrelated logging 
  > (require taglib)
  ???

If it lists the file you pointed to in your email and says "(exists)", then
the problem is probably that loading fails because libtag_c.so.0 depends on
another shared library, and the dependency couldn't be found. On Linux, I
would inspect shared library dependencies with the ldd command, but I don't
know what to use on OpenBSD.

---

I see that setting LD_LIBRARY_PATH worked for you. The difference between
Racket's search path (reported by get-lib-search-dirs) and the OS search
path (which LD_LIBRARY_PATH extends) is that Racket's search path only
applies to shared libraries loaded directly from Racket using ffi-lib; it
doesn't apply to any other shared libraries that they depend on.

Ryan


On Fri, May 7, 2021 at 5:03 PM krs...@gmail.com  wrote:

> Thanks for your help all!
> I think you didn't see my last 2 replies.
>
> I compiled taglib locally and set the library include path as seen in the
> racket REPL output.
> I shouldn't need to do the symlink because my version is now the exact
> same file name as the REPL says cant be found.
> (I it anyway, and it says same error file doesnt exist)
>
> Also I ran:
> (get-lib-search-dirs)
> '(#
>   #
>   #)  <-- LOOK AT THE DIR
>
> The actaul file name that it says it cannot find is in that directory.
> wise@dug:/home/wise$ ls -1 /home/wise/root/lib/   <--
> THIS IS IN MY "lib-search-dirs"
>
>
> libtag.a
> libtag.so.1
> libtag.so.1.18.0
> libtag_c.a
> libtag_c.so.0   <-- THIS IS THE FILE IT SAYS CANNOT BE FOUND
> libtag_c.so.0.0.0
> pkgconfig
>
>
> > (require taglib)
> ; ffi-lib: could not load foreign library
> ;   path: libtag_c.so.0   <-- SAYS IT CANNOT FIND THIS FILE
> ;   system error: File not found
>
>
>
> On Friday, May 7, 2021 at 10:29:21 AM UTC-4 rmculp...@gmail.com wrote:
>
>> It looks like there are two issues. One is the shared library's
>> directory, but the other is that the Racket library is looking for
>> "libtag_c.so.0", and you have "libtag_c.so.3.0". That is, it's looking for
>> a version suffix of "0", not "3.0" (see
>> https://github.com/takikawa/taglib-racket/blob/master/taglib/taglib.rkt#L83
>> ).
>>
>> One fix would be to change the Racket code to try "3.0" also. Maybe
>> conditioned on the OS, since on Ubuntu I also get the library with suffix
>> "0".
>>
>> An alternative would be to copy or link /usr/local/lib/libtag_c.so.3.0 to
>> Racket's lib directory with the file name the Racket code is trying to load:
>>
>>   ln -s /usr/local/lib/libtag_c.so.3.0
>> ~/.local/share/racket/7.9/lib/libtag_c.so.0
>>
>> Note: that assumes that the library versions are actually compatible;
>> otherwise, the Racket code is likely to misbehave, even if it loads the
>> library. Loading the shared library might still fail if the shared library
>> itself has dependencies that are not in the default OS search path. (In
>> that case, Nate's point about LD_LIBRARY_PATH might help.)
>>
>> Ryan
>>
>>
>> On Fri, May 7, 2021 at 3:12 PM krs...@gmail.com  wrote:
>>
>>> I know it sees my custom dir, I ran this in racket:
>>> > (require setup/dirs)
>>> > (get-lib-search-dirs)
>>> '(#
>>>   #
>>>   #)
>>>
>>>
>>> On Friday, May 7, 2021 at 8:08:26 AM UTC-4 krs...@gmail.com wrote:
>>>
 I'm so close :)

 I installed taglib locally to /home/wise/root/lib, so I *have* the file
 exactly as racket is complaining about:
 /home/wise/root/lib/libtag_c.so.0

 I used your config example to edit (as root) /etc/racket/config.rktd
 I added the "lib-search-dirs" line, so it looks like:
 ;; generated by unixstyle-install
 #hash(
   (doc-dir . "/usr/local/share/doc/racket")
   (lib-dir . "/usr/local/lib/racket")
   (share-dir . "/usr/local/share/racket")
   (include-dir . "/usr/local/include/racket")
   (bin-dir . "/usr/local/bin")
   (apps-dir . "/usr/local/share/applications")
   (man-dir . "/usr/local/man")
   (absolute-installation? . #t)
   (build-stamp . "")
   (doc-search-url . "
 https://download.racket-lang.org/releases/7.9/doc/local-redirect/index.html
 ")
   (catalogs . ("
 https://download.racket-lang.org/releases/7.9/catalog/";))
   (lib-search-dirs . (#f "/home/wise/root/lib"))
 )

 I still get the error:
 Welcome to Racket v7.9 [cs].

 > (require taglib)
 ; ffi-lib: could not load foreign library
 ;   path: libtag_c.so.0
 ;   system error: File not found
 ; [,bt for context]

 I'm still poking at it, thanks again for the help.

 On Thursday, May 6, 2021 at 11:41:03 PM UTC-4 krs...@gmail.com wrote:

> Thanks for the help!
> I was sure that was going to be it but it's not :(
>
> This is what is on my sys

Re: [racket-users] macros in Racket repository

2021-05-09 Thread Ryan Culpepper
Here are the three most convenient ways I know of to find that information
(which is "$RACKET/collects/racket/private/qq-and-or.rkt" in this specific
case):

If you use DrRacket, then open a file that uses `and`, right-click on an
occurrence of `and`, and choose "Open Defining File" (which changes to
"Jump to Definition (in Other File)" once DrRacket opens the file.

If you use Emacs with racket-mode, go to an occurrence of `and` and hit
"M-." (that is, hold down Meta/Alt and press the period key). You can also
use "M-x racket-visit-definition". That opens the defining module and jumps
to the definition.

If you have the `whereis` package installed, run the command `raco whereis
-b racket/base and` and it will print the path of the defining file.

Ryan


On Sun, May 9, 2021 at 3:26 PM Tim Meehan  wrote:

> Where in the repository are macros like "and" and "or" defined?
> I tried searching for "and" and "or" ... but you probably know how that
> worked out.
>
> Thanks folks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CACgrOxK6S8EOAGk_rPbE%2B_wMLJiSbpwMhVd4AeRL8C9%2BDW3mgg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33q%3DsLEH-ooUJxTay6pG1GNcRLZDUotNJ23L1HRTC1XqHwA%40mail.gmail.com.


Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-09 Thread Ryan Culpepper
I'm not clear on what constraints you're working under with respect to
modules, but hopefully you can adapt this to your needs.

One option is to use a combination of `define-module-boundary-contract` (or
`define/contract`) and `define-match-expander` to bind a name that can be
used as a contracted constructor and as a match pattern. (If you want to
extend the struct type, though, you still need to use the real one.)

Another option would be to "forge" a new compile-time struct-info based on
the original struct-info but replacing the constructor.

Minimally tested sample implementations attached.

Ryan


On Mon, May 10, 2021 at 12:23 AM Sage Gerard  wrote:

> I have a project with 57 prefab structure types. I need to construct
> instances using a *local* contract (module level contracts do not fit my
> needs here). Since I cannot define guards, the solution is easy enough.
> (struct foo (num) #:prefab)
> (define/contract make-foo (-> real? foo?) foo)
>
> Problem: I already have a few hundred constructor calls without contracts.
> I could either A) rewrite them all to use contracted constructors, or B)
> attach local contracts in a sweet spot so that I don't have to rewrite
> anything else.
>
> I prefer option B, but it doesn't look like I can attach a local contract
> to a constructor with `struct` alone, or even with an impersonator. When I
> hack around to rebind or hide the constructor's identifier, I break
> compatibility with `match` and `defstruct*`.
>
> If you were in my position, what would you do?
> --
>
> ~slg
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/0a16cfbe-4789-a939-796e-5f6f9da21626%40sagegerard.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33qmngGoVoAok6%2BR885jkh8MroMqYHpOd6XtjCSH7iiESQA%40mail.gmail.com.


prefab-contract.rkt
Description: Binary data


Re: [racket-users] Obtaining the path of the application program?

2021-08-26 Thread Ryan Culpepper
Usually, if you want to refer to data files etc relative to the current
module's file, a good solution is to use `define-runtime-path`. It uses
`#%variable-reference` as the basis for its implementation, but adds other
features like cooperation with `raco exe` (see docs for
`define-runtime-path` near "an executable creator").

Ryan


On Thu, Aug 26, 2021 at 4:51 PM Jeff Henrikson  wrote:

> Racket users,
>
> Many software applications use their location in the filesystem to
> establish filesystem relationships between their executable file, their
> configuration and their data.  For this purpose, C provides the first
> element of the string array provided to main, python provides __file__,
> bash provides ${BASH_SOURCE[0]}, etc.
>
> Racket strips said value before current-command-line-arguments receives
> the subsequent command-line arguments from the operating system.
>
> A related value can be pulled from syntax-source as follows:
>
> (define-syntax (get-current-source stx)
>   (datum->syntax
>(quote-syntax here)
>(syntax-source stx)
>stx))
>
> Macro get-current-source works as intended if called at program startup
> and the program is compiled on the fly with:
>
> racket program.rkt
>
> However get-current-source has the unintended property of memorizing the
> original source location if the program is compiled with raco exe (and then
> moved).
> Is there a way in racket to obtain the path of the application program?
>
>
> Jeff Henrikson
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/a076dfa2-d1a5-3cda-72ae-a30cdb91dc31%40gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33q%3D-suP4a_GKtBeBYWUS6P%3D-WNvDo5mFa1cAgFWUi6bEYQ%40mail.gmail.com.


Re: [racket-users] How to set up rackunit tests to test the REPL?

2021-09-09 Thread Ryan Culpepper
This is one of the few (IMO) legitimate uses of `eval`.

Your test suite should create a namespace, set it up by requiring your
language's module, and then eval interactions expressed as quoted
S-expressions or syntax objects. Here's a basic example for testing `match`:

#lang racket/base
(require syntax/strip-context rackunit)

(define test-ns (make-base-empty-namespace))
(parameterize ((current-namespace test-ns))
  (namespace-require 'racket/base)
  (namespace-require 'racket/match))

;; test-eval : (U Syntax S-expr) -> Any
(define (test-eval expr)
  (parameterize ((current-namespace test-ns))
(eval `(#%top-interaction
. ,(cond [(syntax? expr)
  (namespace-syntax-introduce
   (strip-context expr))]
 [else expr])

(check-equal? (test-eval
   '(match (list 1 2 3)
  [(cons x ys) x]
  [_ #f]))
  1)

(void (test-eval '(define null? zero?))) ;; !!!

(check-equal? (test-eval
   #'(match 0
   [(? null?) 'ok]
   [_ 'no]))
  'ok)

The call to `strip-syntax` is necessary in the second test to make `null?`
refer to the redefinition in the testing namespace instead of the normal
binding visible to the testing module.

Ryan


On Thu, Sep 9, 2021 at 3:31 AM Kuang-Chen Lu 
wrote:

> Hi,
>
> What are the recommended ways to create unit tests that test *both* run
> *and* REPL (#%top-interaction)?
>
> *Background:* I created a custom language and have some unit tests. My
> updated language passed all unit tests. After delivery, a client ran into a
> bug that only happens in REPL. I could have found the bug if the REPL was
> also tested.
>
> Thanks,
>
> KC
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/e768fbf6-81db-4bb9-9195-6e3ce74a2d55n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CANy33q%3D-exnqEROJ1SDngO54T4erg7NUMTSZWagG-KdYO67HzA%40mail.gmail.com.


Re: [racket] Parsing a string into a quoted expr

2011-09-12 Thread Ryan Culpepper

Use read and open-input-string:

> (read (open-input-string "(+ 1 2)"))
'(+ 1 2)

You can use eval to evaluate that datum, but first read this section of 
the guide carefully: http://docs.racket-lang.org/guide/reflection.html


Ryan


On 09/12/2011 05:20 PM, Jeremy Kun wrote:

I want to take a string which contains an expression and parse it as a
quoted expression, which I can then potentially evaluate or manipulate.

I noticed that the load function has this capability built into it, and
I know at some point racket has to take strings and parse them into
expressions. Is there a single function I can call to do this? If not,
would it be trivial to write a reader extension to do this? As in, just
read all characters in and quote the result.

Or I might just be better off writing a function that matches
parens...but it seems like reinventing the wheel when I don't have to.

Thanks for the advice!

Jeremy



_
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users

_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] invoke macro stepper from command line

2011-09-14 Thread Ryan Culpepper
Not directly, but you can build a script that uses 'expand/step' or 
'expand-module/step' from macro-debugger/stepper. You will need to set 
the current namespace to something suitable for what you're expanding.


Ryan


On 09/14/2011 02:17 PM, Jon Rafkind wrote:

Is there a way to invoke the gui macro stepper from the command line?
_
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] a syntax-case question

2011-09-27 Thread Ryan Culpepper

On 09/27/2011 08:15 PM, Jon Stenerson wrote:


I'm trying to understand what this is supposed to do:

(define (parse stx)
   (syntax-case stx ()
 [(_ p ...) #'(p ...)]))

(display (parse #'(1 2 3)))

If I run this in DrRacket with first line #lang racket
I get a syntax object containing a list: #

If I run with #!r6rs instead I get a list of syntax objects:
{ #  #  }


Is this a legitimate difference between two languages? Or is one of them
right and the other wrong?


Both languages are behaving according to their specifications, so I 
suppose you could call that a legitimate difference. I think the Racket 
rules about representing syntax are superior to the R6RS rules, though, 
so Racket is right and R6RS is somewhat less right.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Question about round

2011-09-29 Thread Ryan Culpepper

On 09/29/2011 03:11 PM, Mark Engelberg wrote:

I'm a bit baffled by this behavior:

 > (exact? (round (sin 30)))
#f
 > (integer? (round (sin 30)))
#t
 >

How is it possible to have an inexact integer?


> (inexact? 1.0)
#t

The interpretation of "inexact" is subtle and contentious. But to a 
first approximation, "inexact" just means "floating-point".


To a second approximation, I interpret

  (integer? 1.0) = #t
  (inexact? 1.0) = #t

as "the representation is definitely an integer, but it may not exactly 
represent the quantity you really wanted to talk about". But I haven't 
studied this carefully, and it is possible that my interpretation is 
horribly wrong according to someone.


The pragmatic answer is you generally have to write

  (inexact->exact (round x))

which is annoying, but no one has yet bothered to add a standard library 
function for this, as far as I know.


Note also that round does not necessarily return an integer:

> (round +inf.0)
+inf.0

Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] processor-count

2011-10-05 Thread Ryan Culpepper
Racket *threads* are not truly parallel. So Racket only uses a single 
core, unless you use *futures* and/or *places*.


Ryan


On 10/05/2011 11:05 PM, Ivanyi Peter wrote:

Hi All,
Is there any reason why the (processor-count) function is only available
in the futures module?
For example if I want to start number of threads that is equal to the
number of cores,
I also need to require the futures module. Is there any way around it?
Should there be any other way? :-)
Thanks,
Peter Ivanyi



_
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Making a contract between a function and "the world in general"

2011-10-08 Thread Ryan Culpepper

On 10/08/2011 10:12 AM, Matthias Felleisen wrote:

[...]

(2) I object to

  provide-with-whatever-contract-you-already-have

because I think programmers should explicitly state what
they want (if they want something logical).

We can already do this

  (define primes-to-primes (->  (listof prime?) (listof prime?)))

  (provide/contract
[f primes-to-primes]
[primes-to-primes contract?])

So in some client module we can write

  (provide/contract
[f primes-to-primes])

again.


I don't understand the benefit to your approach. I'd like to write 
something like the following this:


  (provide (re-contract-out f))

I believe your objection is that the contract for f is not manifest in 
this module: we have to chase down the source of f to find its contract. 
Perhaps you would say that re-contract-out is bad the way type inference 
for top-level functions is bad, and explicit contracts are better the 
way that explicit type declarations are better.


But in your alternative,

  (provide (contract-out [f contract-of-f]))

the contract of f is *still* not manifest in the module. Instead of 
chasing down f, we have to chase down contract-of-f. We've also 
duplicated code/knowledge (the association between f and contract-of-f) 
with all the problems that entails. Also, we've cluttered up the 
namespace with these contract-of-* bindings.


Of course, duplicating the contract expression would make it manifest, 
but it would aggravate the ill effects from code duplication. My 
experience: partly because of its lazy-require tricks, the db library 
has some duplication of contracts, and I hate it. I've also eliminated 
internal contracts to avoid having to repeat them in the 
externally-visible modules.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] parser tools - defining tokens

2011-10-08 Thread Ryan Culpepper

On 10/04/2011 01:21 PM, George Neuner wrote:

Hi all,

I am playing with the parser tools in Racket. I would like to be able
pass a separately defined list of symbols to define-empty-tokens (which
is a syntax macro defined in parser-tools/private-lex/token.rkt).
Unfortunately passing a list to define-empty-tokens doesn't work because
the macro is expecting to find the token symbols coded in-line.

My lexer uses a hash table to distinguish the reserved words in my
language from other identifiers. The object is to initialize the parser
and the hash table from the same list of symbols ... I don't want to
have to maintain 2 identical lists.

Currently I'm doing the following:

=

(define *reserved-words* '(word1 word2 ...))

(define *reserved-word-hash*
(for/hash ((sym *reserved-words*))
(values (string-downcase (symbol->string sym)) sym)
))

(eval `(define-empty-tokens RESERVED ,*reserved-words*))

=

This works, but using eval seems like a hack and the code fails syntax
checking in DrRacket (the parser generator code complains that the
RESERVED token group is undefined).


I probably could modify the macro to return the symbols passed into it
(I'm sure I don't know how to make it accept a separate list). But I'm
not sure it is a good idea to mess with the macro anyway ... there is
enough black magic in the yacc/lex implementation already.


No need to modify any existing macros; just create your own. It's far 
easier to move data from compile time to run time than vice versa. That 
is, instead of generating the define-empty-tokens form from 
*reserved-words*, generate both from a single macro:


(define-syntax-rule
  (define-empty-tokens+list tokens-name list-name (token ...))
  (begin (define-empty-tokens tokens-name (token ...))
 (define list-name '(token ...

(define-empty-tokens+list RESERVED *reserved-words* (word1 word2 ...))

Then you can define *reserved-words-hash* the same way.

Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Which match macro is correct?

2011-10-11 Thread Ryan Culpepper

On 10/11/2011 09:23 PM, Niitsuma Hirotaka wrote:

on Gauche

work

(use srfi-1)
(use util.match)
(match '(0 (1 2) (3 4 5))
   [(a (b c) (d e f))
(list a b c d e f)]) ;;note this case

(match '(0 (1 2) (3 4 5))
  [`(,a (,b ,c) (,d ,e ,f))
(list a b c d e f)])


on Racket

Err

#lang scheme
  (require racket/match)
(match '(0 (1 2) (3 4 5))
   [(a (b c) (d e f))
(list a b c d e f)])
;=>  match: syntax error in pattern in: (a (b c) (d e f)) ;;compare to gouche



If you want to use that syntax for patterns, use the mzlib/match legacy 
library instead of racket/match. But if you're writing new Racket code, 
racket/match is preferred.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Reliably disable/redirect console output

2011-10-17 Thread Ryan Culpepper
It's possible that the output happens when the main module's requires 
are executed. Or another module might be capturing the initial output or 
error port.


Try creating a new module that sets the ports and then dynamic-requires 
your main program:


#lang racket/base
(require racket/port)
(current-output-port (open-output-nowhere))
(dynamic-require "your-main-module.rkt" #f)

A trick for hunting down the source of the output is to create a custom 
port (see make-output-port) that always raises an error on write. The 
stack trace might help you narrow down the source of the outputs. Simply 
closing the initial output port might have the same effect; I haven't 
tried it.


Ryan


On 10/17/2011 01:21 PM, Erich Rast wrote:


Is it possible to reliably disable/supress or redirect the console error
and the ordinary output in a GRacket application?

I tried:

(let ((out (open-output-string))
 (err (open-output-string)))
 (parameterize ((current-output-port out)
(current-error-port err))
   ...))

at the topmost place that opens the first window but it doesn't work, at
least not in each and every case (why not?)

I have an application that on windows outputs one or two #t whose origin
are a bit hard to track down in all the source modules, which means that
a console window shows up on Windows every time.


_
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users

_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Copying objects

2011-10-19 Thread Ryan Culpepper

On 10/19/2011 08:39 PM, Eduardo Bellani wrote:

Hello list.

This should be obvious, but due probably to my ignorance I am finding
more difficult than expected to find a function that copies an object.

I did found struct-copy, but I don't think it deals with classical
objects. Am I wrong?


There's no built-in way to copy objects. You'll have to add and 
implement a method that does it for the classes you want to be copyable.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] [typed racket] typing monads

2011-10-20 Thread Ryan Culpepper

On 10/20/2011 01:27 PM, Jay McCarthy wrote:

On Thu, Oct 20, 2011 at 12:52 PM, Eric Tanter  wrote:

Thanks Sam,

Actually, that's not what we're after.

In untyped Racket, we have a struct monad:

(struct monad
  (;; A ->  M A
   return
   ;; A ->  (A ->  M B) ->  M B
   bind))

Then we have several instantiations (exception, state, what-have-you):
(define my-fancy-monad (monad (lambda ...) (lambda ...)))


How do you protect against combing the Maybe monad's bind with the
State monad's bind? Monads are more like objects where the methods
have to take the same kind of thing, not just some higher level monad
class.


I expect that's what the M type constructor is for.

It looks like Eric's monad struct is just a reification of the Haskell 
type class dictionary for a monad instance (type).


Eric, is your question whether Typed Racket can parameterize a typed 
structure of a type constructor rather than a type?


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] irritating output format (shared ((-3- (list 3))) ...

2011-10-22 Thread Ryan Culpepper

On 10/19/2011 01:31 PM, Sancho wrote:

I try the following piece of code:

(define (insertions e list)
   (if (null? list)
   (cons (cons e list) list)
   (cons (cons e list)
 (map (lambda (tail) (cons (car list) tail))
  (insertions e (cdr list))

(insertions 1 (list 2 3))


and the output I get is:

(shared ((-3- (list 3))) (list (cons 1 (cons 2 -3-)) (cons 2 (cons 1 -3-)) (list
2 3 1)))


Is there a way to turn off this format? I prefer to get the output simply as:

(list (list 1 2 3) (list 2 1 3) (list 2 3 1))


So far I've been unable to find such an option in the Preferences or advice on
the internet.


I assume you're using the Advanced Student language in DrRacket? If so, 
go to the "Languages menu", then select "Choose Language ...". At the 
bottom of the dialog, click "Show Details", and at the bottom of the 
"Output Syntax" group on the right, uncheck the box labeled "Show 
sharing in values".


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Ryanc db.plt, Postgres and bytea []

2011-10-28 Thread Ryan Culpepper

On 10/28/2011 06:21 AM, Curtis Dutton wrote:

I've been using db.plt package and it has been working well for me.

Thanks to Ryan for making it.


You're welcome!

BTW, the db package will be included in the next release as a standard 
Racket library.



I would like to store and retrieve some binary data in my postgres
databases. Unfortunatly db.plt says it doesn't support bytea types yet.

How likely or doable would it be to get support for byta[] in the db.plt
library. I'm willing to add or help out in any way to get this
working... Even some pointers on where to start or what the solution
should look like would be greatly appreciated.


The type "bytea" should work fine. If it doesn't work for you, could you 
send me a short program that illustrates the problem?


Here's a query that returns bytea:

> (query-value c "select cast('abc' as bytea)")
#"abc"

What doesn't work is PostgreSQL's general array types, like "int[]" or 
"bytea[]". Is that what you have? If so, I can look into adding support 
this weekend. If you want to look around yourself, the relevant code 
(reading and writing) is in db/private/postgresql/dbsystem.rkt, but 
you'll also need information from the postgresql source for the array 
binary format and the pg_type system table for the array type OIDs.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] I'd use an object for this in PHP, how do I handle it in racket?

2011-11-04 Thread Ryan Culpepper
You could put all the context information in a struct and pass that 
around instead. But sometimes objects are just neater. Here's some code 
I wrote for the oauth2 protocol:


  https://github.com/rmculpepper/webapi/blob/master/oauth2.rkt

I like the objects version more than the first version I wrote.

Ryan


On 11/04/2011 10:28 AM, Jordan Schatz wrote:

I'm making an API wrapper for the WebDriver wire protocol:
http://code.google.com/p/selenium/wiki/JsonWireProtocol#Command_Detail

In general all of the API calls require me to pass back to the server a
token (:sessionId in the spec) that is unique to the current instance. In
PHP or some "other" language I would create the wrapper as an object, and
store the token in a private property. I know racket has full support for
classes and objects, but using an object here doesn't feel like racket's
style.

How do I write it without using an object? What is best practice?

If it matters I'm likely to have 10-100 instances / threads of this
running in parallel at a time... as many as I can fit on a machine.

Shalom,
Jordan
_
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Doubt about ryanc/db unreadable values

2011-11-10 Thread Ryan Culpepper
It looks like main.the_procedure is returning either defined composite 
types or some ad hoc ROW type, neither of which is fully supported by 
db. (And I didn't realize I left partial support turned on.)


As a workaround, you can extract the components of the ROW value so 
they're separate fields in the query result.


The underlying problem is that the db library requests binary format for 
most data types---except datetime types and decimals, which it requests 
as text. So mixing the two kinds of data in a single ROW means that the 
parts normally received as text can't be read. The solution will be to 
add binary readers for the remaining types.


Ryan


On 11/10/2011 04:52 AM, Eduardo Bellani wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello list.

I am somewhat stuck with a mysterious return from my postgresql DB. I
have a stored procedure that behaves like this:

my_test_db=# select main.the_procedure();
  the_procedure
- 
  (1,1,16642,3,"2011-11-10 10:41:58.574135")
  (4,1,16642,3,"2011-11-10 10:42:11.916132")
(2 rows)

While on racket world:

(require (planet ryanc/db:1:5))

(for/vector ([x
   (in-query (get-db-connection) ;; returns a DB connection
 "select main.the_procedure")])
 (displayln x))


=>

#(1 1 16642 3 unreadable)
#(4 1 16642 3 unreadable)


Did anyone stumbled on this behavior before? Any hints?
Thanks all.

- --
Eduardo Bellani

omnia mutantur, nihil interit.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk67yQUACgkQSbLl0kCTjGkAPgCeILJdycRFSFQhiZCSGoe/GuGR
UkoAoIM20iAE2LXM2xdojMSjVi3JvkUb
=xTRj
-END PGP SIGNATURE-
_
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] reconstructing syntax objects

2011-11-17 Thread Ryan Culpepper

On 11/17/2011 12:28 PM, Jon Rafkind wrote:

I have some code that deconstructs and reconstructs a syntax object. I'm
pretty sure this code is at fault for not adding the proper lexical
context back on so I get an error about 'no #%app bound'.

(syntax-parse form
  [(form ...)
   (with-syntax ([(form* ...) (map honu->racket (syntax->list #'(form ...)))])
 (datum->syntax forms
#'(form* ...)
forms
forms))]

I had hoped that datum->syntax would add the original lexical context
back on, is it not doing what I hoped?


No, the datum->syntax there is a no-op, because #'(form* ...) is already 
a syntax object, and datum->syntax stops when it hits something that's 
already a syntax object.


You should do something like this instead:

  (datum->syntax forms
 (map honu->racket (syntax->list #'(form ...)))
 forms
 forms)

Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Got some trouble the the mysql-connect

2011-11-18 Thread Ryan Culpepper

On 11/18/2011 12:23 AM, MingQian Zhang wrote:

Hi all:

I got some errors when using new (require db) module.
Here are the two errors:
1. io:read-null-terminated-bytes: internal error: communication problem
(unexpected EOF)
2. parse-packet: internal error: communication problem (expected
authentication ok packet)

The whole thing is like this:
1. write my code like this:
(require db)
(define sql-exp
(mysql-connect #:server "my sql server ip"
#:port 3306
#:database "name"
#:user "user"
#:password "password"))

2. when I run this code , I met my problems:
I have two mysql servers to connect, they are in different ips.

when use the code to connect 1 , I got Error 1:
io:read-null-terminated-bytes: internal error: communication problem
(unexpected EOF)

Then I tried to connect server 2, I got another error:
parse-packet: internal error: communication problem (expected
authentication ok packet)

3. other tries
After got the errors, I tried to connect a localhost server,
Like this :
(define test
(mysql-connect #:server "localhost"
#:port 3306
#:database "test"
#:user "root"))

It's OK and no error happens.

Then I tried this in a virtual machine like this
(define test
(mysql-connect #:server "10.0.2.2"
#:port 3306
#:database "test"
#:user "root"))
It's OK , too.

Also I tried postgresql, it's OK , too.

Can you help me to figure out what's wrong when connecting my mysql server ?
Thanks very much!


I'll look into this. What version of MySQL is each of the servers 
running? In particular, does it succeed with one version and fail with 
another? And are any of the servers configured to reject non-SSL 
connections?


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] DB library - postgres and user defined errors...

2011-11-18 Thread Ryan Culpepper

On 11/18/2011 12:41 PM, Curtis Dutton wrote:

What is a good way to get user defined exceptions, written inside of
postrges function to be reflected to the end user?

Say I have an item table in a database and it has a unique 'name' column.

When I call my 'create_item' function in the postgres database, and the
name given conflicts with an existing row in that table, I would like
the exception returned to be 'that name already exists' and then pass
that message through my web interface down to the user.

Of course other types of exceptions, that I didn't anticipate, don't
ultimately get sent to my client and they just see an "OOPS!" message.


If you use RAISE (as described here: 
http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html) 
it should get translated to an exn:fail:sql exception, which preserves 
all of the error properties present (MESSAGE, HINT, etc) in an 
association list. The exn:fail:sql struct isn't currently exported, but 
I'll fix that.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] shortest paths, resource allocation/scheduling

2011-12-05 Thread Ryan Culpepper

On 12/05/2011 08:40 AM, Sam Tobin-Hochstadt wrote:

On Mon, Dec 5, 2011 at 10:00 AM, Geoffrey S. Knauth  wrote:

I'm wondering if there is something in the now very rich set of Racket 
libraries that already does this.  Let's say I have 5 points {A,B,C,D,E}.  I 
want to interconnect all of them:

{AB,AC,AD,AE,AF,BC,BD,BE,BF,CD,CE,CF,DE,DF,EF}

That's 15 edges rather than the 5x5=25 that a dumb interconnect
would do.  To start, I just need to track and sort the edge
weights, and AB is the same as BA.


Here's the start of an answer (sadly quadratic, but for N=121 I don't
think that will matter much):

#lang racket
(require unstable/sequence)
(define (subsets-of-size-2 l)
   (for*/lists (r) ([i l] [j l]
#:unless (eq? i j)
#:unless (member (cons j i) r))
 (cons i j)))

(for ([(p q) (in-pairs (subsets-of-size-2 '(A B C D E F)))])
   (printf "~a<->  ~a\n" p q))



That looks quartic in the length of l, because of the member check.

Here's a quadratic version:

(require srfi/1)
(define (subsets-of-size-2 l)
  (for*/list ([ne-sublist (pair-fold-right cons null l)]
  [b (in-list (cdr ne-sublist))])
(cons (car ne-sublist) b)))

Note: (pair-fold-right cons null l) produces a list of the non-empty 
sublists of l.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] shortest paths, resource allocation/scheduling

2011-12-05 Thread Ryan Culpepper

On 12/05/2011 09:20 AM, Maurizio Giordano GMAIL wrote:

On Mon, 2011-12-05 at 09:00 -0700, Ryan Culpepper wrote:

On 12/05/2011 08:40 AM, Sam Tobin-Hochstadt wrote:

On Mon, Dec 5, 2011 at 10:00 AM, Geoffrey S. Knauth   wrote:

I'm wondering if there is something in the now very rich set of Racket 
libraries that already does this.  Let's say I have 5 points {A,B,C,D,E}.  I 
want to interconnect all of them:

{AB,AC,AD,AE,AF,BC,BD,BE,BF,CD,CE,CF,DE,DF,EF}

That's 15 edges rather than the 5x5=25 that a dumb interconnect
would do.  To start, I just need to track and sort the edge
weights, and AB is the same as BA.


Here's the start of an answer (sadly quadratic, but for N=121 I don't
think that will matter much):

#lang racket
(require unstable/sequence)
(define (subsets-of-size-2 l)
(for*/lists (r) ([i l] [j l]
 #:unless (eq? i j)
 #:unless (member (cons j i) r))
  (cons i j)))

(for ([(p q) (in-pairs (subsets-of-size-2 '(A B C D E F)))])
(printf "~a<->   ~a\n" p q))



That looks quartic in the length of l, because of the member check.

Here's a quadratic version:

(require srfi/1)
(define (subsets-of-size-2 l)
(for*/list ([ne-sublist (pair-fold-right cons null l)]
[b (in-list (cdr ne-sublist))])
  (cons (car ne-sublist) b)))

Note: (pair-fold-right cons null l) produces a list of the non-empty
sublists of l.


Hi Ryan,
some time ago I was looking for an efficient algorithm in Racket to
extract k-sized combinations of elements from a list l... Could you
provide a generalisation of your code, I mean "subset-of-size-k"
where k<  (lenght l) ?


Here's the basic idea:

;; subsets-of-size : nat list -> (listof list)
(define (subsets-of-size n l)
  (cond [(zero? n) (list null)]
[else
 (for*/list ([ne-list (pair-fold-right cons null l)]
 [subsetN-1
  (in-list (subsets-of-size (sub1 n)
(cdr ne-list)))])
   (cons (car ne-list) subsetN-1))]))

This has bad complexity, I believe, although I haven't calculated it. If 
you add in memoization, though, you should get good (optimal?) 
complexity and optimal tail-sharing.


Ryan
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] info.rkt planet-version variable?

2012-01-04 Thread Ryan Culpepper
It sounds like a bad idea to me. Calling it 'planet-version' makes it 
sound like it answers the question "who am I?", but the planet/version 
library already provides a way to do that that avoids the obligation of 
manually updating the definition after (or is it before?) every release 
to PLaneT. If the intent is instead "who am I meant to be?", say as a 
hint to a link manager, the name should reflect that.


Ryan


On 01/04/2012 01:48 AM, Neil Van Dyke wrote:

Would it be a good idea to officially add to "info.rkt" a
"planet-version" variable, which indicates that the directory tree
corresponds to a particular PLaneT package and version?

For example:

(define planet-version 'joebob/soundex:1:=2)

The "=" in this example is optional.

I currently use an unofficial variable like this (called
"mcfly-planet"), in generating PLaneT package documentation, and for
managing development links. I plan to also use this variable for making
uploads to PLaneT with some safety checks.

Perhaps other tools would also like to use this information. And perhaps
they'd prefer to use an official variable, not an ad-hoc variable that's
named specific to my documentation tool.

If there's going to be an official "planet-version" variable, I'd like
to start using it. Or I can keep using "mcfly-planet" or something
unofficial-looking like that.




 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Documentations in PDF/PS format

2012-01-04 Thread Ryan Culpepper
You could also use scribble to render a manual as a single HTML page 
(plus CSS files and images). Then you can use a program like Calibre to 
convert the HTML to ePub.


Here's the command I used to render the Racket Guide:

raco scribble \
  --html \
  --dest /tmp/guide/ \
  ++xref-in setup/xref load-collections-xref \
  --redirect-main http://docs.racket-lang.org/ \
  collects/scribblings/guide/guide.scrbl

And here are instructions for Calibre:
  http://osxdaily.com/2010/08/12/convert-to-epub/

When I tried it, the ePub version looked reasonable in the Calibre 
viewer, although there were some spacing problems with typeset code. The 
HTML->Mobi version was unusable on my actual Kindle (left margin way too 
big), but HTML->ePub->Mobi looks okay.


You might have to replace some of the CSS files to hide unnecessary 
parts, fix the formatting, etc. See the scribble manual for 
changing/adding CSS. If you (or anyone else!) would like to contribute 
ebook-friendly CSS for scribble, I'm sure we can find a place for it.


Ryan

On 01/04/2012 08:20 AM, nitralime wrote:

Thank you!

For reading on an eBook Reader an overall larger font  (e.g. at 14pt)
would be more pleasant! "Times" is terrible for sizes smaller than 12pt!

I would generate a pdf version with a font size at 14pt
using Palatino/Consolas, if I could do it myself.
(An ePub format, if possible at all, would be even better.)

Regards
Nik

PS: By the way, how did you get to http://pre.racket-lang.org/
 from Racket's main site?


On 01/04/2012 03:07 PM, Matthias Felleisen wrote:


It exists in PDF, e.g., http://pre.racket-lang.org/docs/pdf/guide.pdf


On Jan 4, 2012, at 9:00 AM, nitralime wrote:


Hello folks!

Is there a (simple) way to convert Racket documentations (e.g. Racket
Guide) into PDF/PS format?

Regards
Nik



 Racket Users list:
http://lists.racket-lang.org/users







   Racket Users list:
   http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] XML library: representing CDATA

2012-01-04 Thread Ryan Culpepper

On 01/03/2012 08:47 PM, John Clements wrote:


On Jan 3, 2012, at 3:09 PM, Neil Van Dyke wrote:


I don't know what the *stock* XML parsing does, but I have used
Oleg Kiselyov's SSAX parser a lot in Racket-based production apps,
and it does handle CDATA.

Oleg spent a lot of time on XML, including learning things about it
that its designers might not have known, and the SSAX parser has
handled every case of valid XML that I've thrown at it so far.

You can read about SSAX, and the SXML format it uses, at:
http://okmij.org/ftp/Scheme/xml.html

You can use this PLaneT package to get SSAX, but see the above URL for 
documentation:
http://planet.racket-lang.org/display.ss?package=ssax.plt&owner=lizorkin


No! Don't use this one.  We forked this code and cleaned it up a bit, to get:

http://planet.racket-lang.org/display.ss?package=sxml2.plt&owner=clements

1) It doesn't have the insane require chain, so it installs fast,
2) it contains both the SSAX and the SXML,
3) It's PLT-ized in a few other ways.

Ryan worked on the code a bit as well, and coincidentally I just
pushed this out as a new planet package today.


I've got a bunch more unpushed commits, and I'll send you another pull 
request once I go back and find where and how severely I broke backwards 
compatibility.


IIRC, there's some extremely useful functional update code (much nicer 
than pre-post-order) that isn't documented at all in the current package.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] scribble -> ePub/mobi?

2012-01-04 Thread Ryan Culpepper

On 01/04/2012 09:51 PM, John Clements wrote:

Has anyone taken a look at generating ePub or mobi documents directly
from scribble?

As the owner of a Kindle, I can see that pdf/dvi/ps is terrible for
these kind of on-the-fly reformatting systems. HTML is better, but
trying to convert the existing HTML for HtDP 2e (I haven't tried
removing the left contents bar) produces not-great output. I took a
look for systems that generate ePub and/or mobi from TeX, and didn't
get a lot of useful hits, which I'm guessing is due to the fact that
TeX--like pdf etc--is fundamentally about providing control over the
structure of a page, and not about producing reflow-able output. Has
anyone taken a look at the cost and/or advantages of generating ePub
or mobi documents directly from scribble?


Did you see my email on this earlier today? (The thread was 
"Documentation in PDF/PS format".)


I think the most reasonable path is to use "scribble --html" with custom 
CSS files that make the formatting friendlier for book readers, then to 
pass it through Calibre's ebook-convert utility. It would probably make 
sense to add some minor hooks to the scribble html renderer so it can 
mark the table of contents and chapter breaks appropriately, but that's 
all that comes to mind.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Formatted output of floating-point numbers?

2012-01-12 Thread Ryan Culpepper

On 01/12/2012 03:53 AM, Dmitry Pavlov wrote:

Hello all,

I have been looking for a way to do in Racket
something you can easily do in C:

printf("%10.5lf\n", 12.345678);

so it properly cuts the fractional part to 5 digits
and adds padding to get 10 characters in total,
producing "  12.34568" as a result.


This is supported by SRFI 48: Intermediate Format Strings, which is 
already provided with Racket.


> (require (prefix-in srfi: srfi/48)) ;; avoid shadowing racket's format
> (srfi:format "~10,5F" 12.345678901)
"  12.34568"

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] freeze and bounding boxes

2012-01-18 Thread Ryan Culpepper
In the docs from the last release (here: 
http://docs.racket-lang.org/teachpack/2htdpimage.html#%28part._nitty-gritty%29) 
the grid is missing the right edge and the bottom edge. So perhaps this 
issue was recently fixed?


Ryan


On 01/18/2012 07:05 PM, Robby Findler wrote:

On Wed, Jan 18, 2012 at 5:22 PM, David Van Horn  wrote:

On 1/18/12 6:04 PM, Robby Findler wrote:


Yes, that's the right behavior. See the end of the 2htdp/image docs
about pixels and whatnot.



OK, it seems at odds with the note that freeze can "mpirove performance
without changing how the image draws," but I get that a square draws larger
than its bounding box so it gets cropped when frozen (or saved to a file).


I've clarified that in the docs.


By the way, I think you can see this phenomenon in the rendering of the
2htdp/image docs.  So for example, the section you referred me to has this
example:

   (let* ([s (rectangle 20 20 "outline" "black")]
  [r (beside s s s s s s)])
   (above r r r r r r))

which when run in DrRacket produces a grid, but in the docs crops the right
and bottom lines.  That makes the discussion about cropping very confusing.
  Also: it seems you cannot in general have Scribble examples that involve
outlined shapes such that they look like they really appear in DrRacket.


I see the attached in the docs. Do you see differently?




   Racket Users list:
   http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] class variables in racket

2012-01-19 Thread Ryan Culpepper
The Racket class system doesn't have such a thing because it doesn't 
need it. The idiomatic Racket alternative to "class variables" or 
"static members" is to define the variable/constant/function at the 
top-level of the enclosing module.


This scope-based solution also eliminates what in other OOPLs is a 
distinct class of errors: attempting to refer from static members to 
instance members, which syntactically appear to be in scope. In Racket, 
it's obvious that the instance members aren't in scope. To properly 
implement a form like 'class-variable' in Racket, one would have to 
implement error-checks for "in scope but not accessible" references (a 
naive implementation would give misleading "unbound identifier" errors). 
Or perhaps restrict the initialization expressions to immediate values.


I'm not sure that helps you with your goal, but perhaps it explains why 
Racket doesn't have what you're looking for.


Ryan

On 01/19/2012 12:41 PM, Christian Wagenknecht wrote:

I expected to find some special-form, like 'class-variable' or something
like that.

For pedagogical reasons I'd prefer to implement two syntactically
different programs representing the oop thinking style quite obvious:
the first one makes absolutely no use of the bindings provided by the
'class' library that comes with Racket whereas the second one is mainly
limited to take them. The first one helps the students to understand
lots behind the scene of how oop works and why. The second one abstracts
of that and really allows for oo programming.

What I mean is that the terms describing the basic concepts of object
oriented programming should be mapped to related code. Using 'let' to
get the right variable scope causes to mix both levels of thinking /
abstraction. Thats exactly what I like to avoid.

Am 19.01.2012 18:09, schrieb Matthias Felleisen:


On Jan 19, 2012, at 11:57 AM, Christian Wagenknecht wrote:


How class variables/methods (instead of instance variables/methods)
can be implemented be means of Racket's class definition expressions?
An unsatisfying way I found is by using a let expression enclosing
the whole definition of the class.


What's unsatisfying about it?


Racket Users list:
http://lists.racket-lang.org/users


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Browser module for OAuth use?

2012-01-23 Thread Ryan Culpepper
I have some code that does this for OAuth2 (but so far only the subset 
that Google implements, which is probably different from the subset 
Facebook uses). You can see the code here:


  https://github.com/rmculpepper/webapi

The part that implements the web-browser interaction is in 
private/oauth2-web.rkt. It starts a little web-server that catches the 
OAuth2 server's redirect to localhost.


I plan to make that a PLaneT package eventually, but not soon, so feel 
free to borrow the code.


Ryan


On 01/18/2012 05:29 PM, Jonathan Schuster wrote:

I'm starting to write some Racket bindings for the Facebook API, and I'm
trying to get the authentication up and running. They use an OAuth
system that, for desktop clients, requires that your app open a browser
window to allow the user to login. Once they've done that, your app is
supposed to detect a navigation within the browser and extract the
access token out of the new URL so that it can be used in all subsequent
Facebook API calls.

Does anyone know if there's some sort of browser module in Racket that
would fulfill my needs? Specifically, it should send some sort of
signal/event to my program every time it navigates to a new page, and
should provide the URL on each navigation. I found the launch-browser
project on PLaneT
(http://planet.plt-scheme.org/display.ss?package=launch-browser.plt&owner=oesterholt
),
but that only takes care of starting a browser, not tracking it. Thoughts?

Jonathan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Delivering / distributing an application that uses places

2012-01-24 Thread Ryan Culpepper

On 01/24/2012 11:42 AM, Brian Mastenbrook wrote:

On 11/15/2011 08:22 PM, Matthew Flatt wrote:

On 11/04/2011 11:40 AM, Brian Mastenbrook wrote:

I can't figure out how to distribute an application that uses places.


I've pushed a repair for the current development version.
(Unfortunately, I see no workaround that would make v5.2 and earlier
work.)



This has been working fine for me for applications that use the `place'
form, but applications using `db' and the #:use-place argument to
`sqlite3-connect' still do not work out of the box:

standard-module-name-resolver: collection not found:
"db/private/generic" in any of: ()

=== context ===
standard-module-name-resolver

I take it this is a result of the use of `dynamic-place' instead of
`place'? In any event, I can work around this by adding (require
db/private/generic/place-server) to my module.


Thanks for the report. The problem was indeed due to my using 
dynamic-place; I've added a use of define-runtime-module-path-index so 
the compiler knows about the dependency.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Delivering / distributing an application that uses places

2012-01-27 Thread Ryan Culpepper

On 01/25/2012 08:14 AM, Brian Mastenbrook wrote:

On 01/24/2012 05:24 PM, Ryan Culpepper wrote:

Thanks for the report. The problem was indeed due to my using
dynamic-place; I've added a use of define-runtime-module-path-index so
the compiler knows about the dependency.


Thanks Ryan. Will this be in the 5.2.1 release? I'm sure other people
will be interested in the change. (I didn't see any mention of Matthew's
fix or yours in the release note drafts on devel.)


Yes, it will. (Most bug fixes are not included in the release announcement.)

Ryan



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] macros in local namespaces?...

2012-02-01 Thread Ryan Culpepper

On 02/01/2012 09:45 AM, Rüdiger Asche wrote:

Hi there,

I'm trying to get a grip on macros. Here is a very simple Racket expression  
(1):

(letrec [(a 2)
 (b 3)
 (afn (lambda (x) (+ x a)))
 (bfn (lambda (x) (+ x b)))]
   (afn (bfn 2)))

Now I need a syntactic abstraction for afn and bfn. The following will do in 
first approximation (2):

(define-syntax-rule (absfn varname) (lambda (x) (+ x varname)))

(letrec [(a 2)
 (b 3)
 (afn (absfn a))
 (bfn (absfn b))]
   (afn (bfn 2)))


However, it will fail due to scoping rules in the following example (3):

(define-syntax-rule (absfn varname) (lambda (x) (+ (+ x localc) varname)))

(letrec [(a 2)
 (b 3)
 (localc 4)
 (afn (absfn a))
 (bfn (absfn b))]
   (afn (bfn 2)))

In other words, my syntactic extension absfn needs to be embedded in the namespace of the 
sorrounding expression (or as a "dumb" macro which simply does lexical 
replacement without considering scoping, but needless to say such a macro would be 
unhygienic).
I suspect that letrec-syntax was meant for that purpose, but I can't figure out 
how the parameters to define-syntax-rule would translate to those of 
letrec-syntax.

Does anyone have sample code for how to get (3) above to work?

Thanks!


The easiest way is to use internal definitions instead:

(let ()
  (define a 2)
  (define b 3)
  (define localc 4)
  (define-syntax-rule (absfn varname)
(lambda (x) (+ (+ x localc) varname)))
  (define afn (absfn a))
  (define bfn (absfn b))
  (afn (bfn 2)))

Another way is to use letrec-syntaxes+values, as Matthias answered.

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] racket/db - query-rows: connection is permanently locked due to a terminated thread

2012-02-01 Thread Ryan Culpepper

On 02/01/2012 10:09 PM, Curtis Dutton wrote:

I'm receiving this error after my webserver is running for a few days.

Hosting a plt webserver on Ubuntu server, I'm using the racket/db
library to access a local postgres database. After a few hundred
requests, over a period of days, I eventually get this error message.
"query-rows: connection is permanently locked due to a terminated thread"

Once this error is generated all calls made to the database then fail,
and continue to fail until I restart the webserver process.

I am using the virtual connection pooling interface as well.

Has anyone seen this yet?

I submitted  bug #12530.

I have not been able to reproduce this manually. It happens after a few
days. I'm willing to instrument or hack at it to help determine the
issue but a little guidance would be very welcome.


I'll look into it. If the error has a stack trace, that would be very 
helpful.


You could also try wrapping the postgresql connection in a 
kill-safe-connection proxy. That is, change


  (postgresql-connect )

to

  (kill-safe-connection (postgresql-connect ))

and see if that makes a difference.

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] copy syntax properties

2012-02-15 Thread Ryan Culpepper

On 02/15/2012 01:28 PM, Jon Rafkind wrote:

`datum->syntax' does not copy syntax properties from the 4th
parameter to the new syntax object if the 2nd parameter is already a
syntax object. What is the reasoning for this? Lexical context and
source location are taken from the 1st and 3rd arguments so it seems
inconsistent for syntax properties not to act the same way. I don't
really have an opinion as to whether the new syntax object should
combine syntax properties from the 2nd and 4th argument or if only
the properties from the 4th should be used.


'datum->syntax' always returns the second argument unchanged if it is 
already a syntax object. The handling of properties is no different from 
the handling of lexical context or source location.



Perhaps the API for `datum->syntax' could change slightly so that a
list of syntax objects can be used to provide syntax properties.

(datum->syntax lexical original source (list a b c)) ;; would create a new 
syntax object with syntax properties from 'a', 'b', and 'c'.

This way the original syntax object can be put into the list to
retain its properties.

(datum->syntax lexical original source (list original a b c))


Have you looked at 'syntax-track-origin'? Perhaps it handles the 
situation you have.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] About DB and events

2012-02-24 Thread Ryan Culpepper
I don't think it's possible to do this strictly on the Racket side. Your 
best bet is to see if you can write a PostgreSQL procedure that 
blocks/sleeps until rows are available (or until it hits some timeout) 
and then returns them. PostgreSQL has pg_sleep, LISTEN, NOTIFY, and 
LOCK---some combination of those might be able to express what you want. 
I suggest asking on the PostgreSQL mailing list about that part. On the 
Racket side you just run the query that executes the wait-for-results 
procedure.


Ryan

On 02/24/2012 06:43 AM, Eduardo Bellani wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello list.

I am building a deamon here that pings a postgres database to send
some messages. A bit like the following code:

(let check-loop
 ([unsent-messages (get-unsent-messages)]) ;; get messages from DB
   (for-each (? (message) (do-it! message)) unsent-messages)
   (sleep *interval*)
   (check-loop (get-unsent-messages)))

I'm thinking this would be a great task for an event, but I'm having
some trouble transforming a DB call into an event. Is it possible?
Feasible? Anyone can think of alternatives? That looping and sleeping
does not sound like a nice way to code this.


Thanks.
- --
Eduardo Bellani

fear is an alarm, not a compass.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk9Hk/cACgkQSbLl0kCTjGn4HwCfTfYx7O2Svgs1fU/iozNaH1If
tp8An2BcNHjnkvXP5FlC5N/4MTzp1Jdr
=LY9m
-END PGP SIGNATURE-

   Racket Users list:
   http://lists.racket-lang.org/users


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Macro Help

2012-02-26 Thread Ryan Culpepper

On 02/26/2012 05:18 PM, Helmut Rohrbacher wrote:

I'm trying to write a macro provide a new way to define functions so that:


(define fold-left
   (function
_ i '() -> i
f i (cons x xs) -> (fold-left f (f i x) xs)))


Would be valid syntax that would expand to:

(define fold-left
   (match-lambda*
 [(list _ i '()) i]
 [(list f i (cons x xs)) (fold-left f (f i x) xs)]))

So far I have been able to get there half-way by wrapping each /args
.../ -> /body/ pattern in parens, which makes the above declaration look
like this:

(define fold-left
   (function
[_ i '() -> i]
[f i (cons x xs) -> (fold-left f (f i x) xs)]))

By using this macro:

(define-syntax function
   (syntax-rules (->)
 [(_ (args ... -> body) ...)
  (match-lambda*
[(list args ...) body]
...)]))


What macro voodoo do I need to harness in order to be able to implement
the first definition syntax where the /args ... -> body/ segments need
not be wrapped in parens?


IIUC, the syntax you want for 'function' could be described as follows:

  (function clause ...)
  where clause = arg-pattern ... -> body-expr
arg-pattern is any match-pattern other than a literal '->'

You can express nonterminals like 'clause' using syntax-parse's splicing 
syntax classes:


(require (for-syntax syntax/parse))

(begin-for-syntax

  ;; clause = arg-pattern ... -> body-expr
  (define-splicing-syntax-class clause
(pattern (~seq arg:argument-pattern ... (~literal ->) body:expr)))

  ;; arg-pattern is any match-pattern other than a literal '->'
  ;; just accept any term other than '->'
  (define-syntax-class argument-pattern
(pattern (~not (~literal ->)

The '~seq' means "several terms in sequence but not parenthesized".

Given those definitions, you can write the macro as follows:

(define-syntax (function stx)
  (syntax-parse stx
[(_ f:clause ...)
 #'(match-lambda*
 [(list f.arg ...) f.body]
 ...)]))

The pattern variable 'f' is declared to have the (splicing) syntax class 
'clause', so you can use the attributes of 'clause' (which are 'arg' and 
'body') by writing 'f.arg' and 'f.body'. See the syntax-parse docs for 
more details.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] "private" modules to make an opaque struct type

2012-02-28 Thread Ryan Culpepper

On 02/28/2012 10:22 PM, David T. Pierson wrote:

Hi all,

Many racket collections define some modules in a subdirectory named
"private".  Presumably these modules are for definitions that are used
by other modules in the same collection but are not meant to be used
from outside the collection.  As far as I can tell, this is just a
convention and is not enforced in any way.  Are there any guidelines for
such "private" modules?  I couldn't find anything searching the
documentation and the list archives.


As you say, it's a convention, but access control isn't enforced.

Guidelines: Avoid using other libraries' private modules. Don't 
encourage other libraries to use your private modules (eg, put things 
that need to be public in public modules). Try not to refer to private 
module names in interface documentation, error messages, etc.



I'm considering such a private module to define a custom struct type.
The struct's fields would be used by multiple modules in my collection,
and instances of the struct would be used outside the collection, but I
want the struct to be opaque to code outside my collection.  In other
words I'd reexport only the type predicate procedure from the main
module.  Is this a typical use of "private" modules?


Yes, it's common to have a public module that selectively exports 
bindings from one or more private modules. It's often a good idea to put 
contracts on the public module's exports, although for simple predicates 
it isn't that important.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] okay to assemble datum->syntax #f … in stages?

2012-03-14 Thread Ryan Culpepper

On 03/14/2012 06:07 PM, John Clements wrote:

Forgot to send this earlier, question still stands:

Based on my reading of the docs, the two expressions

(datum->syntax
  #f
  (cons a b))

(datum->syntax
  #f
  (cons (datum->syntax #f a)
(datum->syntax #f b)))

…compute equivalent values.  They're not "equal?", but I conjecture
that they're interchangeable.


Technically they are distinguishable. But practically they are 
interchangeable.


Search for "syntax pair" in the docs for a hint about the difference. 
The two expressions above are as equivalent as the results of reading (a 
b c) and (a . (b c)).



I'm asking this because I want to wrap the 'require's inserted by
run-teaching-program.rkt with stepper hints (Eli, don't read this!),
and I can't do that until they're syntax objects.


Sounds like it should be fine.

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] using a binding for-syntax in a module, and also providing it from that module

2012-03-20 Thread Ryan Culpepper

If you have a fairly recent version of Racket, you can use *submodules*.

Here's library.rkt:

  #lang racket/base
  (require (for-syntax racket/base))

  ;; An auxiliary submodule for the parts to be used at
  ;; multiple phases:
  (module helper racket/base
(require (for-template racket/base))
(define (my-syntax-util stx)
  (quasisyntax/loc stx
(cons 'my-syntax-util-was-here #,stx)))
(provide my-syntax-util))

  ;; Require the submodule at the two different phases:
  (require (submod "." helper)
   (for-syntax (submod "." helper)))

  (define-syntax (my-own-syntax stx)
(syntax-case stx ()
  ((_ CONDITION VAL)
   (quasisyntax/loc stx
 (if CONDITION
 #,(my-syntax-util (syntax VAL))
 VAL)

  (provide my-own-syntax
   my-syntax-util)

Ryan


On 03/20/2012 11:08 AM, Neil Van Dyke wrote:

In the below example, can file "library.rkt" be changed (without
splitting it up into two files), so that file "program.rkt" works
without change? Is using "racket/load" the only way to keep
"library.rkt" to one file like this?


 FILE library.rkt
#lang racket/base

(require (for-syntax racket/base))

(define-for-syntax (my-syntax-util stx)
;; Pretend that "my-syntax-util" performs some big complicated processing,
;; which is useful both in the implementation of "my-own-syntax" and
;; also directly by users of this library.
(quasisyntax/loc stx
(cons 'my-syntax-util-was-here #,stx)))

(define-syntax (my-own-syntax stx)
(syntax-case stx ()
((_ CONDITION VAL)
(quasisyntax/loc stx
(if CONDITION
#,(my-syntax-util (syntax VAL))
VAL)

(provide my-own-syntax
my-syntax-util)


 FILE program.rkt
#lang racket/base

(require "library.rkt")

(my-own-syntax (equal? "a" "a") 42)

(my-syntax-util #'id)




 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] problem with module language

2012-03-22 Thread Ryan Culpepper

On 03/22/2012 01:54 PM, Joop Ringelberg wrote:

Hello all,

I try to write a small module language (named: biglooModuleSyntax.scm)
in order to be able to run some files with a bigloo module statement in
Racket. However, I run into a problem I do not understand at all.

The (Bigloo) code loads a library ssax-sxml. In Racket, this must be
replaced by: (require (planet "sxml.ss" ("lizorkin" "sxml.plt" 2 1))).
The Bigloo code also needs some extra functions not provided by sxml.ss,
so I require an additional small module (in missing-ssax-functions.scm).
To this end, biglooModuleSyntax.scm contains the following macro:

(define-syntax library
  (syntax-rules ()
[(library ssax-sxml)
 (begin
   (require (planet "sxml.ss" ("lizorkin" "sxml.plt" 2 1)))
   (require "missing-ssax-functions.scm")
   )
 ]
))


The problem is that 'require' is an unhygienic binding form. It 
introduces the imported names with the lexical context of (IIRC) the 
module path. That means that the names are imported, but they can only 
be accessed by references that have the hygiene mark from that expansion 
of the 'library' macro. You can see this if you put something like 
'(display SRV:send-reply)' at the end of the 'begin' in the macro 
definition above; it'll work (if you remove the other syntax errors from 
the rest of the module), but (unmarked) references to 'SRV:send-reply' 
in the module's body will still fail.



This, however, does not produce the desired results, as shown below. Now
there is another macro in biglooModuleSyntax.scm that handles (some)
import forms::

(define-syntax import
  (syntax-rules ()
  [(import (moduleName path))
   (require path)]
))


and that works just fine. [...]


Right, because the module path comes from the macro argument, so it 
doesn't have a mark, so the names that 'require' binds don't have a mark.


Here's one way to fix your macro:

(define-syntax (library stx)
  (syntax-case stx ()
[(library)
 (with-syntax ([(mod ...)
(syntax-local-introduce
 #'((planet "sxml.ss" ("lizorkin" "sxml.plt" 2 1))
"missing-ssax-functions.scm"))])
   #'(require mod ...))]))

'syntax-local-introduce' cancels the mark for the currently executing 
macro, so in the expansion of 'library' the module paths passed to 
'require' will be unmarked.


There are other solutions, too. The general problem is "hygienic macros 
that expand into unhygienic macros/forms".


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


[racket] Scribble your blogs!

2012-04-02 Thread Ryan Culpepper

I've just released Scriblogify, a tool that lets you write blog
posts in Scribble and automatically upload them to Blogger-hosted
blogs (such as The Racket Blog).

More details in the blog post, naturally:

  http://blog.racket-lang.org/2012/04/scribble-your-blogs.html

As you can see in the post, I've updated Racket blog's CSS to
support Scribble output. That means there's no longer any reason
not to post everything from tutorials down to little code
examples to the Racket blog.

Or use Scriblogify with your own blog and tell the list about
it. Here's mine: macrologist.blogspot.com.

Happy Scribbling,
Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] db not in collects

2012-04-10 Thread Ryan Culpepper

On 04/09/2012 03:13 PM, J G Cho wrote:

Hello,

I just compiled racket-textual-5.2.1-src-unix.tgz on Ubuntu and
discovered that db module is not in collects directory.

Not clear why so. I used db in Servlet without DrRacket before.
Anyhow, how can I get it after the installation.


It looks like the db collection was not listed as part of the textual 
distribution. (It should be in the full distribution, though.) Unless 
anyone objects, I'll change it to be part of the textual distribution 
for the next release, 5.3, due later this month.


To add the db collection to your build, go to the Racket root directory 
(the one that contains the "collects" directory) and run


  git archive --remote=git://git.racket-lang.org/plt.git v5.2.1 \
-- collects/db | tar x

That will fetch version 5.2.1 of the db library. Then run

  ./bin/raco setup

to compile it and build the documentation.

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] reading pixels from a file...

2012-04-11 Thread Ryan Culpepper

On 04/11/2012 02:49 PM, geb a wrote:

Some students are trying to do a pixel by pixel operation on a 640x480
size picture and my student's code is operating very slowly. I've heard
that Racket can process images quickly but apparently we are doing
something very wrong. There are a few parts to this problem. This is the
first one: Reading the image into a representation. I'm not sure how to
make this more efficient. Is there something I'm missing?

We have very new computers running the latest stable version of Racket.
Operating system is Fedora Core 14 (64 bit version).


#lang racket
(require mred)
(define bmdc (make-object bitmap% "apple.jpg"))
(define-struct rect (x y w h))



(define pw (send bmdc get-width))
(define ph (send bmdc get-height))

;get-my-colors: num num num num -> byte-string
(define (get-mycolors x y w h)
  (let* (
 (pixels (make-bytes (* w h 4) 0))
 (myrectangle (send bmdc get-argb-pixels x y w h pixels false)))
pixels))
(get-mycolors 0 0 pw ph)


I just tried this in DrRacket. Getting the pixels is very fast; printing 
the huge bytevector in the interactions window is very slow.

That might be the problem.

Try changing the last line to either

  (define pixels (get-mycolors 0 0 pw ph))

or, to also see how long it takes,

  (define pixels (time (get-mycolors 0 0 pw ph)))

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] My toy web app's performance: Racket vs Perl vs Ruby

2012-04-12 Thread Ryan Culpepper

On 04/11/2012 03:03 PM, jos...@anwu.org wrote:


Racketeers,

I'm new to the language, and loving it.  I'm having trouble getting
good performance out of my little toy web app, however.

I wrote this fake billing app to play with some new languages (like
Racket) and some other webdev ideas I've had (like client-side
templating with jQuery and mustache).  As such, I have the same JSON
api written in Perl, Ruby, and Racket (working on node.js and
Haskell).  Perl runs under Dancer and Starman, ruby under Sinatra and
Unicorn, and Racket under nohup and its own included webserver. All
are running on the same machine.  Each connects to a postgres db,
executes some queries from a config file, and returns JSON to the
client.

I've been running apache bench against all three, and the performance
of Racket vs Perl and Ruby has been... disheartening.  I compiled the
racket code with 'raco exe' before running it, but Perl and Ruby both
blow it away.  The racket executable also seems to grab and hold a
lot of memory, even though I told it to be stateless.  It also tends
to have failures.


You don't need to use 'raco exe'; it's for ease of distribution, not 
performance.


The stateless option doesn't really apply here, since you aren't using 
send/suspend (or any of the variants thereof).



ab -c 20 -n 1 


What URL(s?) are you testing? It's hard to analyze the numbers below 
without knowing what they're measuring.



Perl:

Concurrency Level:  20
Time taken for tests:   86.100 seconds
Complete requests:  1
Failed requests:0
Write errors:   0
Total transferred:  8815 bytes
HTML transferred:   8630 bytes
Requests per second:116.14 [#/sec] (mean)
Time per request:   172.199 [ms] (mean)
Time per request:   8.610 [ms] (mean, across all concurrent requests)
Transfer rate:  999.82 [Kbytes/sec] received


Ruby:

Concurrency Level:  20
Time taken for tests:   102.914 seconds
Complete requests:  1
Failed requests:0
Write errors:   0
Total transferred:  8848 bytes
HTML transferred:   8605 bytes
Requests per second:97.17 [#/sec] (mean)
Time per request:   205.827 [ms] (mean)
Time per request:   10.291 [ms] (mean, across all concurrent requests)
Transfer rate:  839.60 [Kbytes/sec] received


Racket:

Concurrency Level:  20
Time taken for tests:   139.059 seconds
Complete requests:  1
Failed requests:687
(Connect: 0, Receive: 0, Length: 687, Exceptions: 0)
Write errors:   0
Total transferred:  9421469 bytes
HTML transferred:   7100095 bytes
Requests per second:71.91 [#/sec] (mean)
Time per request:   278.119 [ms] (mean)
Time per request:   13.906 [ms] (mean, across all concurrent requests)
Transfer rate:  66.16 [Kbytes/sec] received


Are you sure the "Failed requests" are really failures? A Stackoverflow 
answer suggests that these might be the result of a nondeterministic 
response length. (See http://stackoverflow.com/questions/579450.)


It's odd that the total transferred for the Racket benchmark is almost 
an order of magnitude less than the totals for Perl and Ruby. It would 
help to see the actual URLs used in the tests to make sure this isn't an 
apples-to-oranges comparison.


It would also be useful to run the benchmarks with "-c 1" to measure the 
pure sequential performance. I'm not familiar with the frameworks in 
question, but a brief scan suggests that Starman and Unicorn might be 
forking multiple OS-level workers, which would lead to more parallelism 
on multicore systems. Your Racket setup is limited to a single core.



I'm hoping it's just inexperience on my part - maybe my Racket code
just sucks.  Or maybe it's that I'm trying to stay functional and
avoid mutation, which I don't bother with in the other two. Anyone
interested in looking at the code and telling me what I'm doing
wrong, or could do better?  I would love to use Racket for more
serious projects.

https://github.com/TurtleKitty/CalicoBill


A few of your functions (eg, customer-invoices) look like they suffer 
from the "N+1 problem" (basically, executing a query within a loop 
instead of executing a single query with a join), but I presume you're 
doing the same thing in Perl and Ruby, so that doesn't have anything to 
do with the performance *difference*.


I would have written 'sql-ts->string' using 'format' instead, and I 
would probably use 'for/list' and 'for/hash' instead of 'map' and 
'make-immutable-hash'. But overall your Racket code looks fine to me.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Pulling BLOB from SQL DB

2012-04-13 Thread Ryan Culpepper

On 04/12/2012 01:02 PM, J G Cho wrote:

While reading a BLOB from MySQL, DrRacket (5.2.1 on Win7) crashes
every time. (SQL was like 'select blobcol from table LIMIT 1')

Ran the same code via command line on Ubuntu. Racket seems to run out
of memory due to the size of BLOB.


How big was the blob? I have have some fixes pending for blobs that 
don't fit within a single MySQL "packet", but that limit is pretty low.



Questions:

How can I give more memory to /usr/local/bin/racket?


Just the standard "ulimit" command.


Or more importantly,
Is there a way to pipe PORTs (in from MySQL and out to file) such that
Racket can handle 'very large' BLOBs?


No, that's not possible. But you can try retrieving the blob in separate 
chunks (eg use the SUBSTR function with varying offsets).


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] PLaneTs crypto lib usage question?...

2012-04-18 Thread Ryan Culpepper

On 04/18/2012 07:05 AM, Rüdiger Asche wrote:

I'm doodling around with vyzo's crypto lib from PLaneT, doing some very
rudimentary crypting and encrypting. I'm undoubtedly doing something
wrong, I just don't know what...

Here's my code (running from a directory that contains the crypto files):

(require srfi/78
"main.ss"
(only-in "util.ss" hex))

(require file/sha1)

(define devicekey (list->bytes '(#x12 #x34 #x56 #x78 #x87 #x65 #x43 #x26
#x12 #x34 #x56 #x78 #x87 #x65 #x43 #x26))) ; must be length 16!!!

(define nonce (list->bytes '(#x12 #x34 #x56 #x78 #x87 #x65 #x43 #x26
#x12 #x34 #x56 #x78 #x87 #x65 #x43 #x27))) ; must be length 16!!!

(define devicekey1 (list->bytes '(#x12 #x34 #x56 #x88 #x87 #x65 #x43
#x26 #x12 #x34 #x56 #x78 #x87 #x65 #x43 #x26))) ; must be length 16!!!

(define nonce1 (list->bytes '(#x12 #x34 #x56 #x78 #x87 #x66 #x43 #x26
#x12 #x34 #x56 #x78 #x87 #x65 #x43 #x27))) ; must be length 16!!!

(define dummy (encrypt cipher:aes-128 devicekey nonce #"1234567887654321"))

(bytes->hex-string dummy)

(decrypt cipher:aes-128 devicekey nonce dummy)

(decrypt cipher:aes-128 devicekey1 nonce dummy)

(decrypt cipher:aes-128 devicekey nonce1 dummy)

In effect, I hardcode two distinct AES keys, 2 initialization vectors
(wich I call nonce) and one piece of plain text to encrypt and decrypt.

Here are the results of the last three lines when executed in Racket:

(decrypt cipher:aes-128 devicekey nonce dummy)
#"1234567887654321" <== 1



(decrypt cipher:aes-128 devicekey1 nonce dummy)
EVP_CipherFinal_ex: libcrypto error: bad decrypt [digital envelope
routines:EVP_
DecryptFinal_ex:101077092] <== 2



(decrypt cipher:aes-128 devicekey nonce1 dummy)
#"1234557887654321" <== 3

So the first decryption (with the correct key and iv) yields the
expected result. Everything fine here.


Note that the ciphertext is 32 bytes, whereas the plaintext is 16 bytes. 
I think this is because the 'encrypt' function is automatically doing 
PKCS padding to the plaintext to bring it to a full number of blocks. 
Since it starts out as a single block, the padding brings it to two 
blocks. (If you delete the last byte of the plaintext, the plaintext 
will be be padded to a single full block and the corresponding 
ciphertext will also be a single block---16 bytes.)


See also http://www.openssl.org/docs/crypto/EVP_EncryptInit.html#NOTES


When I decrypt with the correct iv but a wrong key, the OpenSSL Crypto
Lib raises an error. I think that is wrong; it should simply return
garbled output?


I think the error is because it tries to reverse the PKCS padding on the 
garbled decrypted output, and it fails there.



And when I decrypt with the correct key but an invalid init vector, I
would expect the decryption result to be radically different from the
original; instead, there is only one byte varying as if the iv only does
some weak manipulation on the input before doing the encryption? Is that
the way AES-128 works?


That's the way the cipher-block chaining (CBC) encryption mode works, 
and according to the docs for (planet vyzo/crypto), that's the mode used 
by ciphers that don't include a mode in their name (like cipher:aes-128).


The IV isn't responsible for the secrecy of the message; that's the 
key's job. The IV is there to prevent identical blocks in the plaintext 
from appearing as identical blocks in the ciphertext. (Where "plaintext" 
and "ciphertext" comprise all multiple communications conducted with the 
same key.)


BTW, I recommend "Practical Cryptography" by Niels Ferguson and Bruce 
Schneier as a good overview of modern cryptography and a guide to what 
to worry about when implementing cryptographic systems.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] low level question: why begin0?

2012-04-29 Thread Ryan Culpepper
I think the point of 'begin0' is that it handles multiple values 
efficiently (ie, more so than a heap-allocated list). The expansion of 
'begin0' would have to be something like


(call-with-values (lambda () e1)
  (lambda result (begin e2 (apply values result

since in general the number of values produced by e1 is not known at 
expansion time.


Ryan


On 04/29/2012 03:54 PM, Sam Tobin-Hochstadt wrote:

Presumably we could remove it from fully-expanded code and then the
compiler could re-transform this:

(let ([x e]) e0 ... x)

into some bytecode that uses begin0, which would simplify the job of
tools that process expanded code without changing performance.

On Sun, Apr 29, 2012 at 5:07 PM, Robby Findler
  wrote:

We debated this long ago and I think the conclusion was that we could
get a little more performance by including it at the bytecode level
that seemed worth having (the precise details (like if we had a
program where that mattered) escape me).

Robby

On Sun, Apr 29, 2012 at 1:03 PM, Danny Yoo  wrote:

One question that I had stowed away a long time ago: why is begin0
part of the language?  It seems redundant in the face of having 'let'
to capture a value that we want to return at the end of some sequence.

  Racket Users list:
  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users







 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Constructors for sequences

2012-04-29 Thread Ryan Culpepper

On 04/29/2012 04:33 PM, Matthias Felleisen wrote:


On Apr 29, 2012, at 6:29 PM, Asumu Takikawa wrote:


On 2012-04-29 12:43:48 -0400, Matthias Felleisen wrote:

What you're really saying is that sequence-map uses the wrong kind of type. 
Specifically, it should be polymorphic in the sequence constructor instead of 
mapping everything to the top of the class hierarchy (sequence).


I don't think this is just a type issue. The sequence that is returned
by `sequence-map` is lazy, even if the original sequence was not. That's
why you can't get the original type.

Cheers,
Asumu



Why is it lazy?

Can we add a strict one that is polymorphic (I apologize to the
defenders of proper type terminology here for the applying this word
to a dynamic aspect of Racket programs) in the sequence type-tag?


Another problem is that not all sequence types are polymorphic. For 
example, strings are sequences, but strings can contain only characters. 
So what would


  (sequence-map char->integer "abc")

return? Custom sequence types can add arbitrary additional constraints.

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] module system overview

2012-05-07 Thread Ryan Culpepper

The Guide has been updated for submodules:

  http://pre.racket-lang.org/docs/html/guide/Module_Syntax.html

Perhaps you were looking at the 5.2.1 release docs?

Ryan


On 05/07/2012 03:16 PM, Matthias Felleisen wrote:


It looks like the Module Guide needs a serious update for the submodule
addition. Any volunteers? -- Matthias




On May 7, 2012, at 5:10 PM, Danny Yoo wrote:


, but,
is there anything out there that explains the rationale and problems
that it is trying to solve -


Modules let us box code up for reuse. If you have some helper
functions, you can put them in a module. A module can reuse the
exports of other modules.

Have you seen the Racket Guide? It talks about modules here:

http://docs.racket-lang.org/guide/modules.html

Please feel free to ask questions here. Good luck!


Racket Users list:
http://lists.racket-lang.org/users





   Racket Users list:
   http://lists.racket-lang.org/users


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Delimited continuations and parameters

2012-05-14 Thread Ryan Culpepper

On 05/14/2012 04:26 PM, Asumu Takikawa wrote:

Hi all,

Here is a code snippet that uses both delimited continuations and
parameters (translated from the paper "Delimited Dynamic Binding"[1]):

   #lang racket

   (require racket/control)

   (define p (make-parameter 0))
   (define r (make-parameter 0))

   ((λ (f)
  (parameterize ([p 2])
(parameterize ([r 20])
  (f 0
(parameterize ([p 1])
  (reset
(parameterize ([r 10])
  ((λ (x) (+ (p) (r)))
   (shift f f))

If you run this, it produces 11. The authors of [1] argue that it should
return 12, namely because it follows the principle that "the dynamic
bindings in scope are those in the context".

That makes some sense, considering that when you eventually get to the
call (f 0) in the first lambda, your context looks like

   (parameterize ([p 2])
 (parameterize ([r 20])
   (f 0)))

   where f = (λ (y)
   (parameterize ([r 10])
 ((λ (x) (+ (p) (r)))
  y)))

according to shift/reset semantics. From this context, p = 2, r = 10
could make sense.

That said, I don't really have an intuition for what semantics for
dynamic binding&  delimited control is useful. Is there a pragmatic
reason for why Racket's parameters and delimited control interact in
this fashion?


Racket contexts don't store individual parameter values, they store 
entire *parameterizations* (which effectively contain the values of all 
parameters). So f captures the parameterization {p=1, r=10}. When f is 
called, it restores the entire parameterization, overriding the existing 
mapping {p=2, r=20} at the call site.


Jay's "mark parameter" library (at unstable/markparam) provides 
semantics that are probably closer to what you expect. (Except, IIRC, 
not inherited across threads as parameters are.)


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Macro stepper expansion

2012-05-22 Thread Ryan Culpepper

On 05/21/2012 08:13 PM, Harry Spier wrote:

I've entered the following example from the Racket Guide into DrRacket

#lang racket
(define-syntax-rule (swap X Y)
   (let ([tmp X])
 (set! X Y)
 (set! Y tmp)))

(let ([tmp 5] [other 6])
   (swap tmp other)
   (list tmp other))

It gives me the correct result:

'(6 5)


But  when I stepped through it with the macro expander I got:

  [Macro transformation]

(module anonymous-module racket
   (#%module-begin
(define-syntax-rule
 (swap X Y)
 (let ([tmp X]) (set! X Y) (set! Y tmp)))
(let ([tmp 5] [other 6])
  (let ([tmp tmp]) (set! tmp other) (set! other tmp))
  (list tmp other

I was expecting to see something like the Racket Guide description in
section 16.1 I.e:
"Racket doesn’t produce the naive expansion for the above use of swap.
Instead, it produces
(let ([tmp 5]
   [other 6])
   (let ([tmp_1 tmp])
 (set! tmp other)
 (set! other tmp_1))
   (list tmp other))"


The Guide should really say that it produces something *equivalent* to 
the code above. It doesn't actually change the names; the information is 
stored "out of band" as Mark and Rename wraps attached to the syntax 
object. The macro stepper renders Marks using colors: some of the 'tmp's 
should be red (or some other color besides black).


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] module browser

2012-05-23 Thread Ryan Culpepper

On 05/23/2012 11:13 AM, Neil Van Dyke wrote:

In the Module Browser, has anyone tried annotating the graph edges with
imported symbols that are actually referenced by the importing module?
Maybe further annotate those symbols with phases?


You can get this information (in text form) from the check-requires 
utility. You may find the code in macro-debugger/analysis/check-requires 
(and its dependencies) useful if you want to add this information to the 
module browser. Getting the set of references is actually somewhat 
tricky, and I think my code does as good a job as possible.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] module browser

2012-05-23 Thread Ryan Culpepper

On 05/23/2012 11:34 AM, Matthias Felleisen wrote:


It is amazing how often this request comes up and we give the same answer again 
.. a text-based tool.


FWIW, check-requires was inspired by DrRacket's Check Syntax tool. 
However, because Check Syntax has to map its results back onto the 
original program, it sometimes loses information. For example, sometimes 
it can't connect required modules with the syntax that requires them.


Ryan



On May 23, 2012, at 2:28 PM, Ryan Culpepper wrote:


On 05/23/2012 11:13 AM, Neil Van Dyke wrote:

In the Module Browser, has anyone tried annotating the graph edges with
imported symbols that are actually referenced by the importing module?
Maybe further annotate those symbols with phases?


You can get this information (in text form) from the check-requires utility. 
You may find the code in macro-debugger/analysis/check-requires (and its 
dependencies) useful if you want to add this information to the module browser. 
Getting the set of references is actually somewhat tricky, and I think my code 
does as good a job as possible.

Ryan

Racket Users list:
http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] module browser

2012-05-23 Thread Ryan Culpepper

On 05/23/2012 12:31 PM, Neil Van Dyke wrote:

Thanks, Ryan, that info is helpful, although it's missing most of the
reasons I've had to partition one library into several modules (macro
transformers).

As people have mentioned before, there seems to be a theoretical brick
wall preventing these tools from seeing references that likely will be
used in the results of macro transformations. I don't understand that in
all cases. For one example, the transformers often have templates that
should know many of the symbols and exactly where they're coming from.
(Is this information from templates lost too soon? Is the information
from templates not as precise as I assumed?)


IIRC, 'check-requires' does in fact inspect syntax templates. The 
problem is that it's not possible to predict in what phase(s) the 
identifiers in a syntax template will be interpreted.


For example, consider this module:

(module AMB racket
  (require (for-template (rename-in racket/base [- shifty]))
   (only-in racket/base [+ shifty]))
  (define shifty-stx #'(shifty 1 2))
  (provide shifty-stx))

Does the occurrence of 'shifty' in the syntax template refer to '+' or 
'-'? It might be both.


If it's used in a macro, 'shifty' means '-':

  (require (for-syntax 'AMB))
  (define-syntax m (lambda _ shifty-stx))
  (m)
  ;; => -1

but if it's evaluated with 'eval', 'shifty' means '+':

  (require 'AMB)
  (eval shifty-stx (make-base-namespace))

(Exercise: add (require (for-meta 2 (rename-in racket/base [+ shifty]))) 
to AMB. See if you can construct a program that interprets 'shifty' as '*'.)


--

But I'd estimate that 90% of the time, an identifier in a syntax 
template is interpreted at the phase one less than the phase the syntax 
template occurs in. And 90% of the remaining cases it's interpreted in 
the same phase as the syntax template. So that's what 'check-requires' 
assumes (see 'analyze/quote-syntax' in 
macro-debugger/analysis/private/get-references).


If 'check-requires' isn't seeing dependencies from syntax templates, can 
you send me an example?


> For another example (or

possibly the same thing), these tools seem to be missing references in
the code of "syntax-parse" productions that is outside templates and
that I'd think is unambiguous.


I don't understand what you mean. Can you give an example?

Ryan



BTW, a student who is bored over the summer could do worse than to
enhance the Module Browser in some other ways. First low-hanging fruit
step might be to put the information from "check-requires" into tooltips
on the arrows. Then there's a lot one could do with graph drawing. And,
as a small graphics tweak, you can make it skip redundant repaints
queued up when dragging. (Summer is good for this. More than a little
sun exposure will just age your skin prematurely and give you melanoma,
anyway.)

Neil V.

Ryan Culpepper wrote at 05/23/2012 02:28 PM:

On 05/23/2012 11:13 AM, Neil Van Dyke wrote:

In the Module Browser, has anyone tried annotating the graph edges with
imported symbols that are actually referenced by the importing module?
Maybe further annotate those symbols with phases?


You can get this information (in text form) from the check-requires
utility. You may find the code in
macro-debugger/analysis/check-requires (and its dependencies) useful
if you want to add this information to the module browser. Getting the
set of references is actually somewhat tricky, and I think my code
does as good a job as possible.

Ryan




 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] module browser

2012-05-23 Thread Ryan Culpepper

On 05/23/2012 01:04 PM, Ryan Culpepper wrote:


[...]
(Exercise: add (require (for-meta 2 (rename-in racket/base [+ shifty])))
to AMB. See if you can construct a program that interprets 'shifty' as
'*'.)


Whoops, that '+' should be a '*'.

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] use of `raco setup -l ...`

2012-05-23 Thread Ryan Culpepper

On 05/23/2012 02:04 PM, Danny Heap wrote:

I want to restrict to setting up just the collection I'm developing.
I've created a development link `raco planet link dsheap vis-eval 1 0
`, and now I'd like to generate documentation (or
at least see just the errors generated when I do), so I try

 raco setup -l dsheap/vis-eval:1:0

...but this generates an error, as does

raco setup -l


You need to use "planet -P" instead:

  raco setup -P dsheap vis-eval 1 0

Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Flatten syntax and runtime phases?

2012-06-15 Thread Ryan Culpepper

On 06/15/2012 10:41 PM, Nick Sivo wrote:

Hi,

I have the following code:

#lang racket
(require mzlib/defmacro)

(defmacro w/uniq (name . body)
   `(let ([,name (gensym)])
  ,@body))

(defmacro in (x . choices)
   (w/uniq g
  `(let ([,g ,x])
 (or ,@(map (lambda (c) `(eqv? ,g ,c)) choices)

Naturally, it fails:

expand: unbound identifier in module (in phase 1, transformer environment) in: g

Additionally defining w/uniq for-syntax fixes it:

#lang racket
(require mzlib/defmacro
  (for-syntax racket
  mzlib/defmacro))

(begin-for-syntax
   (defmacro w/uniq (name . body)
 `(let ([,name (gensym)])
,@body)))

(defmacro w/uniq (name . body)
 `(let ([,name (gensym)])
,@body))

(defmacro in (x . choices)
   (w/uniq g
  `(let ([,g ,x])
 (or ,@(map (lambda (c) `(eqv? ,g ,c)) choices)

I know this is Racket's phase separation working as intended.  Now, I
appreciate why Racket separates phases as well as the advantages of
hygienic macros, but I'm not writing new code.  I'm trying to enable
existing code* to run natively in Racket and take advantage of its
great JIT and some module optimizations (like inlining).

Is there any way to hack the first version to work? One option is to
build a deeper nest of duplicate macro definitions each time I
encounter a new one.  It seems possible, and it might even work, but
it sounds awful.  I've already written a custom reader and have an
extensive library of language syntax/parse macros, so I'm open to
anything.


I don't know of a way of doing this within Racket other than running 
each definition at every phase that it might be used at. That might not 
require duplicating code, though.


If you could rely on let*-like scoping for Arc module bodies, then you 
could do it entirely with submodules (new feature since 5.2.1; see 
http://blog.racket-lang.org/2012/06/submodules.html for an introduction).


The idea would be to use the arc language's #%module-begin macro to 
transform


(module M arc
  defn1
  defn2
  defn3))

into

(module M arc
 (#%plain-module-begin

  (module S0 arc)

  (module S1 arc
(require (submod ".." S0)
 (for-syntax (submod ".." S0)))
defn1
(provide (all-from-out (submod ".." S0))
 (all-defined-out)))

  (module S2 arc
(require (submod ".." S1)
 (for-syntax (submod ".." S1)))
defn2
(provide (all-from-out (submod ".." S1))
 (all-defined-out)))

  (module S3 arc
(require (submod ".." S2)
 (for-syntax (submod ".." S2)))
defn3
(provide (all-from-out (submod ".." S2))
 (all-defined-out)))

  (require (submod "." S3))
  (provide (all-from-out (submod "." S3)

Each S submodule provides (at phase 0 only) the names defined by all 
definitions defn1 through defn. (For S0, that means zero definitions.)


Each S submodule requires S at phases 0 and 1, thus it gets all 
definitions defn1 though defn for both run time and compile-time.


That's if you have strict let*-like scoping. If you want to support 
mutually recursive modules, you could try to group contiguous run-time 
definitions together by head-expanding (ie, calling 'local-expand' with 
a stop list) and accumulating forms as long as they produce 
'define-values' forms. I don't see any way to support mutually recursive 
functions that have macro definitions between them, though.


I also don't see any way to support references from a macro body to 
functions defined later in the module.


This will break 'set!', because variables imported from another module 
cannot be mutated. But you can fix that by defining auxiliary setter 
procedures and providing proxy set-transformer macros in place of the 
variables.


Mutating a variable (or data structure) in one phase still cannot change 
the value in other phases, no matter what you do. In fact, compile-time 
mutation won't work very well at all, since each definition is compiled 
in a new submodule, which should get its own fresh compile-time state.


If you have 'let-syntax' or its equivalent (eg, local 'define-syntax'), 
then phases 0 and 1 might not be enough, since you can have expressions 
at phase 2 (and higher):


  (let-syntax ([m0
(let-syntax ([m1 ]) )])
)

If you want to be really *really* crafty, you could try defining your 
own version of 'let-syntax', 'define-syntax', etc to create requires for 
higher phases on demand by calling 'syntax-local-lift-require'. That is,


  (arc-define-syntax id expr)

  == expands to the result of calling ==>

  (syntax-local-lift-require
   #`(for-meta #,(add1 (syntax-local-phase-level)) S)
   #'(racket-define-syntax id expr))

I hope that helps. (I haven't tried any of this, so there are surely 
bugs that need ironing out.)


Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Error trying to use "Snooze: Object Relational Mapping of PLT Structures"

2012-07-10 Thread Ryan Culpepper

I'm not sure what the status of Snooze is. It might no longer be maintained.

The library that it depends on (cce/scheme) also is not really 
maintained any longer, and I don't know of a version that works cleanly 
with the current contract system.


If you need database access but don't need an ORM, you can use the db 
library, which is part of Racket. The docs are here:


  http://docs.racket-lang.org/db/

Ryan


On 07/07/2012 01:58 AM, 刘 伦 wrote:

Dears,

I want to write a little web server using PostgreSQL as database. I found an OR-mapping 
library on PLaneT which is called "Snooze". I follow its doc on:

http://planet.racket-lang.org/package-source/untyped/snooze.plt/2/9/planet-docs/snooze/quick.html#(part._.Start_using_.Snooze)

and write below code:

#lang scheme/base

(require (planet untyped/snooze:2)
  (planet untyped/snooze:2/postgresql8/postgresql8))

(define-snooze-interface
   (make-snooze (make-database
#:server "localhost"
#:port 5432
#:database "testdb"
#:username "test"
#:password "te5t"
#:ssl 'no)))

(provide (all-from-out (planet untyped/snooze:2))
  (snooze-interface-out))

Then I click the "Check Syntax" button inDrRacket, after a while it pops error 
below:

. 
../../../Library/Racket/planet/300/5.2.1/cache/cce/scheme.plt/6/3/contract.ss:319:30:
 expand: unbound identifier in module in: proj-get

I found the file "contract.ss" but I really do not know how to correct this.
Could someone help me?



   Racket Users list:
   http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] How to tell if identifier is bound in racket/load?

2012-07-16 Thread Ryan Culpepper

On 07/16/2012 03:35 AM, Nick Sivo wrote:

Hi,

I've been using the following awesome snippet to detect when
identifiers are already bound:

; From Danny Yoo's arctangent
; https://github.com/dyoo/arctangent/blob/master/language.rkt
; Returns true if stx is an identifier that is lexically bound.
(define-for-syntax (lexically-bound? stx)
   (let ([expanded (local-expand stx (syntax-local-context) #f)])
 (cond
   [(and (identifier? expanded)
 (eq? #f (identifier-binding expanded)))
#f]
   [else
#t])))

Then I created a helper so I could call it at runtime:

(define-syntax (arc-bound stx)
   (syntax-parse
stx
[(_ var:id)
 (if (lexically-bound? #'var) #'#t #'#f)]))

That still worked great.  Then I tried using racket/load:

Welcome to DrRacket, version 5.2.1 [3m].
Language: racket/load; memory limit: 128 MB.

(arc-bound a)

#f

(define a 5)
(arc-bound a)

#f




:(  I've read through the docs on namespaces and the racket/load
language source in an attempt to fully understand why racket/load is
different, but I'm missing something.  I've noticed that I can see 'a
in (namespace-mapped-symbols), and have tried using that, but ran into
(I think) phase issues.  If there's a quick solution to this that I've
missed, that's brilliant.


It works in DrRacket using #lang racket because the interactions occur 
in a module namespace, but with #lang racket/load all interactions 
happen in an ordinary namespace. That accounts for the differences in 
the results of identifier-binding.



Otherwise, my motivation to start making use of racket/load (really
arc/load in my case), is to get access to global variables.  If
ark.rkt declares something at the module level, I need to be able to
see it - the same copy of it - from other modules that require
ark.rkt.  What I'm trying now is to have ark.rkt be a real module
written in arc, and then require it and load the rest of the arc files
using the arc/load language so they all share the same module registry
and the same ark.rkt.  If there's some other, better way to do this,
pointers will be quite warmly received.


I can't tell how the behavior you described differs from just providing 
the variable from ark.rkt and requiring ark.rkt normally. Can you elaborate?


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Some struct questions

2012-07-16 Thread Ryan Culpepper

On 07/16/2012 12:39 PM, Harry Spier wrote:

I should have been a little clearer with my question.  I understand
that its not a good idea to expose the setters and getters of a struct
unnecessarily.  What I meant was:
(provide struct-id)  exposes the struct constructor
(provide (struct-out struct-id)) exposes the constructor and the field
getters and setters
I'm not clear the use of the first form.  I.e. of what use is having
access to the constructor without access to the field getters and
setters.  So thats why I asked if there are any cases where (provide
struct-id) would be of use.  If the answer is no, then why not just
have (provide struct-id) expose the constructor and the field getters
and setters.


(provide id) always just provides 'id'. We've chosen to use other 
subforms, like struct-out, for other behavior. Making struct-name 
identifiers work specially in provide forms would be more complicated 
and (IMO) less readable.


Ryan



Another question about provide provide-specs, since almost all
provide-specs allow multiple provide-specs as arguments where would
the form (provide (combine-all x x x x)) be useful.

Thanks,
Harry Spier


About question 2, in general you don't want to expose the details of
your structures. For example, when defining a queue like:

(struct queue ([front #:mutable] [rear #:mutable]))

you don't want users to set/get the fields directly; instead you
probably want them to use the `enqueue'/`dequeue' functions, which
maintain the abstraction invariants, assuring the queue is consistent
no matter what the users do. In general, I believe it is better not to
provide the setters (unless it really makes sense, of course).

PS: Sorry for the duplicate Harry, I forgot to put
users@racket-lang.org in CC in my original response.

2012/7/15 Harry Spier:

1) In section 8 of the Racket reference there is this example:
---
Examples:
(define-struct tree (val left right))


(match (make-tree 0 (make-tree 1 #f #f) #f)

 [(tree a (tree b  _ _) _) (list a b)])

'(0 1)
--

but I wasn't able to find any reference in the documentation to a
constructor form make-struct-id .  I'm assuming that in the above example
(match (make-tree 0 (make-tree 1 #f #f) #f)
  is equivalent to
(match (tree 0 (tree 1 #f #f) #f)

Is that correct? Is make-struct-id  a deprecated form of the constructor
procedure struct-id?

2) In a module which contains a structure, lets call it  "structure-a" I can
have the statement:
(provide (struct-out structure-a))
which provides the constructor procedure and the getters and setters to
structure-a
but I can also have the statement
(provide structure-a)
which only provides the constructor function.
Are there any cases where you would want to have (provide structure-a)
rather than (provide (struct-out structure-a)) ?


Thanks,
Harry Spier


   Racket Users list:
   http://lists.racket-lang.org/users



   Racket Users list:
   http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] How to tell if identifier is bound in racket/load?

2012-07-17 Thread Ryan Culpepper

On 07/16/2012 08:23 PM, Nick Sivo wrote:

I can't tell how the behavior you described differs from just providing the
variable from ark.rkt and requiring ark.rkt normally. Can you elaborate?


Wow. I'm not sure what misconceptions I was working under, but that
works completely fine.  And it looks like I can use something like
defm from http://permalink.gmane.org/gmane.comp.lang.racket.user/13119
to hide the getters and setters.

Thanks!

That said, I'd still like to be able to enable the equivalent of the
following in arc:

#lang racket/load

(define (test1)
   (displayln "a"))

(define (test2)
   (test1))

(test2)

(define (test1)
   (displayln "b"))

(test2)

Welcome to DrRacket, version 5.2.1 [3m].
Language: racket/load [custom]; memory limit: 128 MB.
a
b

My current macro to handle top level assignment doesn't work in racket/load:

#lang racket/load

(require (for-syntax syntax/parse))

; From Danny Yoo's arctangent
; https://github.com/dyoo/arctangent/blob/master/language.rkt
; Returns true if stx is an identifier that is lexically bound.
(define-for-syntax (lexically-bound? stx)
   (let ([expanded (local-expand stx (syntax-local-context) #f)])
 (cond
   [(and (identifier? expanded)
 (eq? #f (identifier-binding expanded)))
#f]
   [else #t])))

(define-syntax (assign1 stx)
   (define-splicing-syntax-class binding-pair
 #:description "binding pair"
 (pattern (~seq var:id rhs:expr)))
   (syntax-parse
stx
[(_ p:binding-pair)
 (if (lexically-bound? #'p.var)
 #'(begin (set! p.var p.rhs)
  p.var)
 #'(begin (define p.var #f)
  (assign1 p.var p.rhs)))]))

(assign1 a 5)

When run, it never completes because lexically-bound? always returns
false and recursion never terminates.

If instead the assignment is in the body of a function, or in a
module, it all works fine:

(define (test)
   (assign a 5)
   a)

Do these examples make my intent more clear?  I'm not sure how to
describe what I want correctly.


I'm not sure how robust this solution is, but you could change the 
evaluation namespace to an empty module namespace. (Instead of an empty 
ordinary namespace, which is what #lang racket/load creates.)


In your example above, insert the following three lines right after the 
#lang line:


  (require racket/enter)
  (module scratch racket)
  (enter! 'scratch)

Then you could create your own language (arc/load?) that adds those 
lines (or something similar) automatically.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] db library and cursors

2012-07-25 Thread Ryan Culpepper

On 07/25/2012 06:13 PM, Neil Van Dyke wrote:

Any thoughts on whether the "db" library will support cursors? Or
thoughts on handling large query results in the "db" library?

Reason I ask: I'm experimentally reimplementing an older PostgreSQL
library to use the Racket "db" library. Some applications using this
library use cursors for large query results. In the Racket 5.2.1 source
code, it looks like even "in-query" sucks all the query result rows into
a non-lazy list. I can make a "cursor" object that simply wraps a
non-lazy list of results, but this could be a problem for large query
results.


Basic cursor support has been in db for a couple months (and will be in 
5.3). There's no cursor object per se. Instead, if you call 'in-query' 
with a finite value for the #:fetch argument, it fetches only that many 
rows at a time. See


http://pre.racket-lang.org/docs/html/db/query-api.html#%28def._%28%28lib._db/base..rkt%29._in-query%29%29

PostrgreSQL also has a SQL-level cursor interface, if you need the 
additional operations. See the DECLARE CURSOR statement.


Ryan

 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Formating Printing of Real Number

2012-07-27 Thread Ryan Culpepper

There's also SRFI-48 and SRFI-54.

There's also catn in unstable/cat, which was my attempt to make numeric 
formatting friendlier and more Rackety. But it is, of course, unstable.


Ryan


On 07/27/2012 03:17 PM, Ray Racine wrote:

Other than being functionally comprehensive and through in
documentation, it'll do.  : )

Probably should be a standard Racket Collection library.

Ray

On Fri, Jul 27, 2012 at 2:54 PM, Ray Racine mailto:ray.rac...@gmail.com>> wrote:

Think I found it.  Thanks.


http://planet.racket-lang.org/display.ss?package=planet-fmt.plt&owner=joskoot




On Fri, Jul 27, 2012 at 2:33 PM, Matthias Felleisen
mailto:matth...@ccs.neu.edu>> wrote:


Jos Koot has a formatting library that deals with fp numbers.
But I couldn't find it on planet.


On Jul 27, 2012, at 2:27 PM, Ray Racine wrote:

 > Unable to locate a means to control the output formatting of
Real/Floats/what-have-you either via current formatting
facilities (format procedure etc) or via some parameter.  Is
there anything available?
 >
 > ;; stipulate in some manner
 > > (asin 1.0+5.0i)
 > 0.1938+2.3310i
 >
 > vs.
 >
 > > (asin 1.0+5.0i)
 > 0.1937931365549321+2.3309746530493123i
 >
 > 
 >  Racket Users list:
 > http://lists.racket-lang.org/users






   Racket Users list:
   http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] obtaining name of module-level binding

2012-08-07 Thread Ryan Culpepper
BTW, there's almost never a need to refer to '#%datum'. Just use 'quote' 
instead.


Ryan


On 08/07/2012 04:58 PM, Danny Yoo wrote:

;; Question to others: how can this be simplified?
(splicing-let-syntax ([get-literal-metadata
   (lambda (stx)
 #`(#%datum . #,(format "~s"



I did a slight simplification of the code.  I'm putting up the revised
version here:

 https://gist.github.com/3289283

Hope this helps!



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] [bug?] Racklog cut differs from Prolog cut

2012-08-13 Thread Ryan Culpepper
As I understand it, cuts are delimited by the relations they appear in. 
So it would go something more like this (using a notation I just made up):


a(X)
>
b(X) ; c(X)
>
[delimit b(1) ; b(2) ] ; c(X)
>
[delimit X=1, ! ; b(2) ] ; c(X)
>
X=1 ; c(X)
>
X=1 ; c(2)
>
X=1 ; X=2

I've omitted the delimit brackets for a and c because they don't 
interact with any cuts.


Ryan


On 08/13/2012 02:15 PM, Jay McCarthy wrote:

Can you help me understand this example and why x should be 2? My
understanding of cut and prolog is that this should happen:

a(X)[X = _ ]
>
b(X) ; c(X)   [ X = _ ]
>
b(1) ; b(2); c(X) [ X = _ ]
>
X = 1; ! ; b(2) ; c(X)[ X = _ ]
>
! ; b(2) ; c(X)  [ X = 1 ]

! evaluates to succeed and then we get the X = 1 solution.

But because we cut, the change to the X logic variable won't be
undone, so when we try we get to...

b(2) ; c(X)
->
1 = 2 ; c(X)
>
fail ; c(X)
>
c(X)
>
c(2)
->
1 = 2
>
fail

and never see that X = 2

I must be wrong because you show that prologs actually give 2, but
could you help me see why?

Jay

On Sat, Aug 11, 2012 at 11:32 PM, Erik Dominikus
 wrote:

Racket version:

5.2.

Output of 'uname -a':

Linux kire 2.6.32-41-generic #91-Ubuntu SMP Wed Jun 13 11:43:55 UTC 2012
x86_64 GNU/Linux

Symptom:

In SWI Prolog (or any Prolog interpreter I think), querying a(X) gives
X=1 and X=2. Racklog only gives x=1.

How to reproduce:

Download 'a.pl' (attached).
Run 'prolog -f a.pl' (if using SWI Prolog).
Enter 'a(X).'.
Press ';' (semicolon) key until it prints false.

Download 'a.rkt' (attached).
Run 'racket a.rkt'.

Expectation:

Racklog gives x=1 and x=2.


Thank you.


   Racket Users list:
   http://lists.racket-lang.org/users








 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] [bug?] Racklog cut differs from Prolog cut

2012-08-13 Thread Ryan Culpepper

On 08/13/2012 04:41 PM, Marco Alberti wrote:

Erik,

On Sun, 12 Aug 2012 12:32:53 +0700, Erik Dominikus wrote:



(define %a
   (%rel (x)
 ((x) (%b x) !)
 ((x) (%c x)) ))


the cut in the first clause is not there in the Prolog version; hence the
different behaviour.


The problem exists even if you remove this cut. The other cut (in %b) is 
still behaving incorrectly.


(I assume that's what Matthias meant in his recent response.)

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] db connection-pool tip

2012-08-22 Thread Ryan Culpepper

On 08/22/2012 07:18 AM, Neil Van Dyke wrote:

A sentence or two documenting the custodian behavior for connection
pools might be useful.

The behavior is what you'd expect if you considered it, but, at least in
my anecdote, I took a while to consider it.


I've added notes to both 'connection-pool' and 'virtual-connection' 
about how they interact with custodians.


Your initial experience sounds like a bug, though; it sounds like the 
connection didn't know it had been disconnected. What was the underlying 
kind of connection?



BTW, I am really liking the "db" collection.


Thanks!

Ryan


Matthias Felleisen wrote at 08/21/2012 07:09 PM:

Are you saying that Ryan should add an appropriate warning to the
documentation? -- Matthias



On Aug 21, 2012, at 6:33 PM, Neil Van Dyke wrote:


When using the "db" collection's "connection-pool" procedure,
important safety tip: it uses the "current-custodian" from the
context in which "connection-pool" is applied.

[...]



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] thanks for the db library

2012-08-27 Thread Ryan Culpepper

Thanks, I'm glad to hear it's working well for you.

Ryan


On 08/26/2012 11:20 PM, Neil Van Dyke wrote:

Thank you to Ryan Culpepper, et al., for the "db" library.

It's been working rock-solid in my Web app stress-testing so far.

"db/postgresql" performance is good, and having it be pure-Racket
(rather than calling out to a C library) is very convenient when you
want multiple Racket threads in the same process talking to the database
at the same time.

Avoiding extra C libraries in one's process is also good for quality
assurance.  Memory-related oopses in C code are still commonplace, even
in prominent open source server software.

Neil V.


  Racket Users list:
  http://lists.racket-lang.org/users



 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] rackunit not in textual?

2012-08-30 Thread Ryan Culpepper

On 08/30/2012 04:53 PM, J G Cho wrote:

I am greeted by

... collection not found
collection: "rackuint"

in my v5.3 (textual).

Is it because rackunit relies/depends on some graphics/window?

Is there an alternative?


FWIW, rackunit (the non-gui parts) will be included in the textual 
distribution of the next release.


Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Unquote symbol outside quasiquote

2012-09-04 Thread Ryan Culpepper

On 09/04/2012 03:30 PM, André Matheus wrote:

Hi everyone,

I want to create a macro to get fields of an object specified by a list
of symbols. Like

 (get-fields '(x y) obj) -> (list (get-field x obj) (get-field y obj))

Now, my macro will receive (quote x) and (quote y), for example. What I
want to know
is, what is the right way to unquote it? Using eval as in

 (datum->syntax #'lex `(get-field ,(eval (second (syntax->datum
#'(get-fields 'y xx xx) #'srcloc)

removes the quote but I don't think it's the right way to do it.


It's possible to do what you described, but it's "un-Rackety". It would 
be more idiomatic to design the syntax so that 'get-fields' takes a 
parenthesized sequence of identifiers (*not* an expression), like this:


;; eg  (get-fields (x y) obj)
(define-syntax-rule (get-fields (field-id ...) obj-expr)
  (let ([v obj-expr])
(list (get-field field-id v) ...)))

On the other hand, that means that if you want to compute the list of 
fields, you have to do that through another macro that expands into a 
use of 'get-fields'. For example:


(define-syntax-rule (get-fields-plus-x-and-y (field-id ...) obj-expr)
  (get-fields (field-id ... x y) obj-expr))

If you do really want the macro to accept the fields as a *compile-time 
expression*, use 'syntax-local-eval' to evaluate the expression:


(require (for-syntax racket/syntax))

(define-syntax (get-fields stx)
  (syntax-case stx ()
[(get-fields fields-ct-expr obj-expr)
 (with-syntax ([(field-id ...)
(syntax-local-eval #'fields-ct-expr)])
   #'(let ([v obj-expr])
   (list (get-field field-id v) ...)))]))

Using 'eval' would evaluate the expression in the wrong environment, 
although for simple expressions it can be hard to tell. Here's a test 
case that shows the difference:


(define a%
  (class object%
(super-new)
(init-field x y z)))
(define a (new a% (x 1) (y 2) (z 3)))

(require racket/stxparam)
(define-syntax-parameter the-fields '(x))

(require rackunit)
(check-equal?
 (get-fields (syntax-parameter-value #'the-fields) a)
 '(1))
(check-equal?
 (syntax-parameterize ((the-fields '(y z)))
   (get-fields (syntax-parameter-value #'the-fields) a))
 '(2 3))

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] "fra" status?

2012-09-06 Thread Ryan Culpepper

On 09/06/2012 04:09 PM, John Clements wrote:


On Sep 6, 2012, at 1:06 PM, Michael Wilber wrote:


CSV files? Do you mean importing a CSV file into a table?

Take a look at http://dev.mysql.com/doc/refman/5.1/en/load-data.html,
the "LOAD DATA INFILE" command, which (iirc) takes a CSV file and
imports it into a table, one shot.


Well, that's half of what I want; really, I'd like a way to use the csv as the 
backing store for the table, so that I can always paw through the CSV if need 
be.


You might be able to find an ODBC driver that provides a database 
front-end for CSV files. (I believe Windows comes with one, but I don't 
know about other platforms.) Google "ODBC CSV" and see if any of the 
hits are useful.


Ryan



John Clements  writes:

On Sep 6, 2012, at 11:08 AM, Jay McCarthy wrote:


On Thu, Sep 6, 2012 at 11:42 AM, John Clements
 wrote:

I was looking today for a way to make relational algebra queries on lists, and your 
"fra" package was close enough to try out. I have a number of questions, though:

1) Is this package superseded by any of your more recent stuff? It looks like 
m8b and grade-samurai use something file-system based instead?


I don't use it for anything. The idea was to write a functional
database so that I could use it from FrTime and get "live" updating
queries where when the database time-varying value changes the answers
to old queries are automatically updated to. It was mainly just a demo
to get that demo working. I never used it anything real.


…nd, bam! I ran into the limits. It looks like joins on relations with 
thousands of tuples don't take advantage of the possible orderings of keys, so 
I appear to be getting n^2 explosion when doing joins.

Ryan, is there some way to use your db engine with files that are CSVs or 
s-expressions? I took a quick look at the db docs, and it looks like what I'm 
really asking is whether MySQL or PostgresQL have good support for using CSV 
files. Any advice from database people?

John


  Racket Users list:
  http://lists.racket-lang.org/users





 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] scriblogify/module+ quirk?

2012-09-16 Thread Ryan Culpepper

On 09/15/2012 11:05 PM, Patrick King wrote:

Windows 7, latest 64 bit Racket, latest Scriblogify from Planet.

C:\...\Source\SlowFlight\Blog>raco scriblogify -p SlowFlight 12-09-15.scrbl
file-or-directory-modify-seconds: `read' access denied for
C:\...\Source\SlowFlight\private\test-private.rkt

The scribble file renders fine from within DrRacket, and the file
test-private.rkt is not directly referenced
in the scribble file. The only references to the file are from within
(module+ test ...) in other source files
in private.

So does scriblogify have issues with module+? why should it even be
LOOKING for test-private.rkt?


I don't see why it should have problems with module+, and I haven't been 
able to reproduce the problem. Scriblogify just runs scribble on the 
file and processes the result, though, so can you report what happens if 
you run "raco scribble" on the file? Also, does the error message come 
with any backtrace/context?


Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Problem passing a reference

2012-09-17 Thread Ryan Culpepper

On 09/17/2012 02:32 PM, Kieron Hardy wrote:

Hi all,

In the following fragment, I'm trying to create a new event, queue a
callback to some handler to process that event, and then clear the event.

 (define/private (create-message)
   ...
   (set! the-event (new some-event%))
 ...
   )

 (define/private (queue-message receiver event)
   ...
   (when can-queue-message?
 (queue-callback
   (lambda () (send the-handler handle-event the-event)))
   #t)
   ...
   (set! the-event #f)
   ...
   )

However the event value that the handler actually sees is #f, i.e. the
result after the event is cleared, and not as I want a reference to the
event to process, i.e. the object resulting from the call to new.

What is the best way to get to the handler, a reference to the event it
needs to process?


Is there actually a reason to use 'set!'? Also, it's suspicious that 
your 'queue-message' method takes an 'event' argument but then refers to 
the 'the-event' field.


Here's what I would expect:

(define/private (some-method)
  
  (let ([the-event (new some-event%)])

(queue-message receiver the-event)
))

(define/private (queue-message receiver event)
  
  (when can-queue-message?
(queue-callback
 (lambda () (send the-handler handle-event event))
 #t))
  )

If the method that creates the event doesn't directly call 
'queue-message', I would first try to have it return the event to the 
method that *does* call 'queue-message', possibly using multiple values 
if it returns other values too.


If none of that works and you really have to use 'set!', then the 
solution is to save the value to a local variable that doesn't get 
mutated and have the callback refer to that instead of the field:


(define/private (queue-message receiver )
  
  (let ([event-to-handle the-event])
(set! the-event #f)
(queue-callback
 (lambda () (send the-handler handle-event event-to-handle))
 #t))
  )

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Problem passing a reference

2012-09-17 Thread Ryan Culpepper

On 09/17/2012 03:35 PM, Kieron Hardy wrote:


Is there actually a reason to use 'set!'?


There is a period of time between creating the message and actually
processing the message. Other events may cause the message to be
abandoned. Therefore I think the set! is required, but maybe there's a
better solution.


That sounds like a reasonable use of set!.

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] What am I doing wrong in this typed racket program?

2012-09-18 Thread Ryan Culpepper
Typed Racket should raise an error saying something like "(Setof Any) 
cannot be translated to a contract". Then elaborate in the docs where 
you discuss interaction with untyped code about what types cannot be 
converted to contracts and maybe why.


Ryan


On 09/18/2012 06:00 PM, Sam Tobin-Hochstadt wrote:

I'm saying that I don't at the moment know how to avoid giving this
error, given the current behavior of `set/c`.

On Tue, Sep 18, 2012 at 5:57 PM, Robby Findler
 wrote:

Are you saying it is reasonable that a typed racket program should
produce contract constructor errors like that?

Robby

On Tue, Sep 18, 2012 at 4:53 PM, Sam Tobin-Hochstadt  wrote:

The problem here is that `Any` is a special contract which isn't a
"chaperone contract", and `set/c` requires chaperone contracts.

It's not obvious to me if this can be detected statically, but you can
work around this by changing `Any` to some other type.

Sam

On Tue, Sep 18, 2012 at 5:44 PM, Tony Garnock-Jones  wrote:

Hi all,

What could I be doing wrong here?

 #lang typed/racket
 (provide (struct-out foo))
 (struct: foo ([bar : (Setof Any)]))

Racket 5.3.0.24 complains about it ("racket problem.rkt"):

 set/c: contract violation
   expected: chaperone-contract?
   given: #
   context...:
/Users/tonyg/src/racket-typed-matrix/problem.rkt: [running body]

The complaint vanishes if I comment out the provide, remove the bar
field, or change the bar field's type to Any/Integer/etc.

   Tony

   Racket Users list:
   http://lists.racket-lang.org/users




--
sam th
sa...@ccs.neu.edu

   Racket Users list:
   http://lists.racket-lang.org/users







 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] implementing OAuth 1.0 protocol?

2012-09-20 Thread Ryan Culpepper

On 09/20/2012 01:45 PM, John Clements wrote:

I have a student (cc:ed) that noticed that there's an OAuth 2.0
library for Racket, but no OAuth 1.0 library. Apparently, there are
some differences, so that you can't use OAuth 2.0 to implement (say)
an interaction with Twitter. Can anyone with OAuth experience confirm
this, and also the absence of an OAuth 1.0 library for Racket?


As I understand it, OAuth 1.0 is a much more complicated protocol. For 
example, I believe OAuth 1.0 tries to include request integrity 
protection in the protocol itself, requiring request canonicalization 
and digests and whatnot, whereas OAuth 2.0 says "you must use SSL" 
(roughly) and then allows you to use simple bearer tokens. OAuth 1.0 may 
not support all of the use scenarios that OAuth 2.0 is designed for (but 
I could be wrong about this part). Given that several web service 
providers (eg Google, Github) already support OAuth 2.0, I don't think 
anyone has felt a need to implement OAuth 1.0.


On the other hand, it certainly seems doable.

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Semaphore obscurities

2012-09-26 Thread Ryan Culpepper

On 09/26/2012 04:46 PM, Norman Gray wrote:


Greetings

The behaviour of call-with-semaphore doesn't appear to match the
documentation, or else I'm misunderstanding the documentation.

Consider:

(define (printit m)
   (printf "msg begin:~a~%" m))
(define try
   (let ((sema (make-semaphore 1)))
 (λ (msg)
   (call-with-semaphore sema
printit
;#f
msg
(try "second")

With #f commented out, I get (with Racket 5.3):

call-with-semaphore: procedure arity does not match extra-argument count
   procedure: #
   extra-argument count: 0




With #f uncommented, it works as expected:

Welcome to DrRacket, version 5.3 [3m].
Language: racket; memory limit: 128 MB.
msg begin:second




The documentation says:

(call-with-semaphoresema
proc
 [  try-fail-thunk] 
arg ...)→   any

However it appears that the try-fail-chunk argument is not in fact optional.


Here's what the documentation means: There must be at least two 
arguments. The first two arguments are 'sema' and 'proc'. If there are 
three or more arguments, the third argument is 'try-fail-thunk'. If 
there are four or more arguments, all arguments starting with the fourth 
argument are collected in a list for the 'args' rest argument.





Separately, it appears that CALL-WITH-SEMAPHORE returns the value
that (proc args…) returns.  However the documentation doesn't
actually say that.  Is that just an oversight, or is the return value
of CALL-WITH-SEMAPHORE undefined?


It's probably an oversight.

Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] merits of 2 different methods of interfacing Racket to a database

2012-10-01 Thread Ryan Culpepper
Using 'system' to call the sqlite3 program to run '.import' seems 
preferable to me, especially if the import happens infrequently.


Ryan

On 09/30/2012 10:31 PM, Don Green wrote:

Please comment on the merits of 2 different methods of interfacing
Racket to a database.

My use of the term ".import", is in reference to the SQLite3 database
dot command.

Is Method B preferable to Method A? If so, why?

Method A

Instead of using the Racket: connection function: (define db1
(sqlite3-connect ...

I can use Racket's 'system' function, to issue SQLite3 dot commands such
as '.import' to load a million lines of data from a file into a new
SQLite db.

I can then proceed to use Racket's SQL db access commands to insert or
select data.

OR

Method B

Use the Racket: connection function: (define db1 (sqlite3-connect ...

Racket does not implement SQLite dot commands, so either:

a) write a million Racket SQL commands such as:

(query-exec db1 "insert into table1 values ('a1', 'b2' 'c3')")

(query-exec db1 "insert into table1 values ('aaa', 'bbb' 'ccc')")

etc.

OR

b) write a function:

(query-exec db1 "insert into table1 values (list-loop)")

where:merits of 2 different methods of interfacing Racket to a database

(list-loop) is a function that loops through each of the million lines
in a data file that are intended for the database: db1.

THANKS.

Filter settings



   Racket Users list:
   http://lists.racket-lang.org/users




 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Experience using Scrabble evaluators to other languages

2012-10-05 Thread Ryan Culpepper

On 10/05/2012 02:28 PM, Grant Rettke wrote:

Hi,

My goal is to use Scribble to document some code and evaluated code
using the Scribble eval environments, but I want to do "external
evaluation" for example against a R6RS Scheme and something totally
separate like Clojure for example.

Has anyone done this before?

What are some clues or pointers where I might start?


I guess you can make a sandbox evaluator that "evaluates" by sending 
terms to an external process and then reading the results. There are 
evaluation hooks provided by the racket/sandbox library; there's also 
the current-eval parameter, which also affects sandbox evaluation. I'm 
not sure which is better suited to what you want.


Another issue, though, is that you may wish to distribute your 
documentation sources for other people to build even if they don't have 
all of the external programs you want to call. I have a similar 
situation with the 'db' library. You can use 'make-log-based-eval' from 
'unstable/sandbox' to record the interactions on your development 
machine and then check in the logs so that anyone can build the docs 
without the external dependencies. It probably won't compose cleanly 
with the other eval hooks you'll need to install, so you may have to 
adapt the code yourself. If you work out a clean way of composing it 
with your code, let me know.


Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] Internal definition contexts for phase 1?

2012-10-16 Thread Ryan Culpepper

On 10/16/2012 03:54 PM, J. Ian Johnson wrote:

I'm doing a bit of macrobatics where I'm creating a series of definitions, 
during which I want to also do define-for-syntax for some syntax transformers 
that are used in a produced syntax-parameterize form.

In a top level call to this macro, things would be fine. However, I set up some 
syntax parameters first with splicing-syntax-parameterize.

Now I get an error of the form

begin-for-syntax: not in a definition context
   in: (begin-for-syntax (define-values (foo) foo-def))
   context...:
backtrace


From a quick glance at the implementation, this looks like a bug in 
'splicing-syntax-parameterize'. I'll fix it.



This boils down to the fact that

(let () (define-for-syntax (foo x) x) 0)

is not legal, because the internal definition context set up is only for phase 
0.
How can I get around this? Is this an intended limitation?


Yes. (Ish. For now, anyway.)


There is more odd behavior to this. Consider the following interaction:

Welcome to Racket v5.3.0.24.

(let () (define-syntax foo (λ (stx) (syntax-case stx () [(_ e) #'e]))) (foo 0))

0

(let ()

 (define-for-syntax foo-def (λ (stx) (syntax-case stx () [(_ e) #'e])))
 (define-syntax foo foo-def)
 (foo 0))
foo-def: undefined;
  cannot reference undefined identifier
   context...:
/home/ianj/plt/pltgit/collects/racket/private/misc.rkt:87:7

(let () (define-for-syntax foo-def (λ (stx) (syntax-case stx () [(_ e) #'e]))) 
0)

begin-for-syntax: not in a definition context
   in: (begin-for-syntax (define-values (foo-def) (λ (stx) (syntax-case stx () 
((_ e) (syntax e))
   context...:
/home/ianj/plt/pltgit/collects/racket/private/misc.rkt:87:7

If the define-for-syntax is just not allowed, then shouldn't I get an error the 
form of the latter instead of the former?


Yes, although I'm not sure it's possible to reliably detect that 
situation. (I believe that checking syntax-local-context might cause a 
macro to raise an error if it's used within a splicing form, even if the 
splicing form is itself at module level. But I haven't tried it.)


Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] three-n-plus-one

2012-10-24 Thread Ryan Culpepper

On 10/24/2012 04:03 PM, Danny Yoo wrote:


Perhaps you should consider putting these on the Racket Blog?



I uploaded a draft with Ryan Culpepper's awesome Scriblogify software
(http://blog.racket-lang.org/2012/04/scribble-your-blogs.html).
However, the formatting on some of the output looks a bit bad.  The
verbatim stuff I've been using, in particular, is double-spaced for
some reason.  Suggestions?


I've updated the Racket blog's CSS to fix the excessive spacing. 
Actually, the appropriate rule was already there; I just had to add an 
"!important" for it to take effect.


Ryan


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket-users] a syntax-class that can get the var-id it was used with?

2015-04-04 Thread Ryan Culpepper

On 04/04/2015 01:42 PM, Alexander D. Knauth wrote:

Is there a way to define a syntax-class so that for example in:
(syntax-parse stx
   [(_ a:stxcls) ….])
It would be able to know that it was used with a, instead of for instance b in 
b:stxcls?

Is that possible?

If not, would it be a good idea to add?

The reason I ask is that then it might be possible to define a `lit` 
syntax-class that would do this:
(syntax-parse stx
   [+:lit #’+])
And have it check that stx matched the literal +, but also bound + as a pattern 
variable.


No, but since 6.1.1 or so, syntax-parse has allowed declared literals to 
be used with pattern variables like syntax classes. For example:


  > (syntax-parse #'(* 1 2)
  #:literals (+ *)
  [(op:+ e ...) (list 'plus #'op)]
  [(op:* e ...) (list 'times #'op)])
  '(times #)

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.


  1   2   3   4   5   >