Re: [racket-users] How to make unit test for error "unbound identifier"?

2017-04-25 Thread Alexis King
You can use convert-syntax-error from syntax/macro-testing to convert
the syntax error to a runtime error, which can be caught by RackUnit:

http://docs.racket-lang.org/syntax/macro-testing.html#%28form._%28%28lib._syntax%2Fmacro-testing..rkt%29._convert-syntax-error%29%29

Alexis

> On Apr 25, 2017, at 23:18, Jinzhou Zhang  wrote:
> 
> Hi there,
> 
> I am writing a simple macro `if-let` that tried to bind the condition to a 
> variable.
> 
> ```
> (define-simple-macro (if-let (~describe "binding pairs" [binding:expr 
> value:expr])
> (~describe "\"then\" clause" then:expr)
> (~describe "\"else\" clause" else:expr))
>  (let ([val value])
>(if val (match-let ([binding val]) then) else)))
> ```
> 
> I finished the macro and start to write unit tests for it. Then I realized 
> that
> the "binding" should not working in "else" statement. That means:
> 
> ```
> (if-let [it #f]
>  'true
>  it   ; <- should report "unbound identifier".
> )
> ```
> 
> However when I tried the following code:
> 
> ```
> (check-exn exn:fail?
>   (lambda ()
> (if-let [it #f]
> (fail "if-let: wrong-branch")
> it)))
> 
> ```
> 
> It gives error:
> 
> ```
> it: unbound identifier in module
> ```
> 
> So the question is how to catch the "unbound identifier" exception for unit 
> test?
> 
> Thanks!

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


[racket-users] Re: How to make unit test for error "unbound identifier"?

2017-04-25 Thread Jinzhou Zhang
Sorry for forgot to mention Racket version. It is 6.8.

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


[racket-users] How to make unit test for error "unbound identifier"?

2017-04-25 Thread Jinzhou Zhang
Hi there,

I am writing a simple macro `if-let` that tried to bind the condition to a 
variable.

```
(define-simple-macro (if-let (~describe "binding pairs" [binding:expr 
value:expr])
 (~describe "\"then\" clause" then:expr)
 (~describe "\"else\" clause" else:expr))
  (let ([val value])
(if val (match-let ([binding val]) then) else)))
```

I finished the macro and start to write unit tests for it. Then I realized that
the "binding" should not working in "else" statement. That means:

```
(if-let [it #f]
  'true
  it   ; <- should report "unbound identifier".
)
```

However when I tried the following code:

```
(check-exn exn:fail?
   (lambda ()
 (if-let [it #f]
 (fail "if-let: wrong-branch")
 it)))

```

It gives error:

```
 it: unbound identifier in module
```

So the question is how to catch the "unbound identifier" exception for unit 
test?

Thanks!

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


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

2017-04-25 Thread Vishesh Yadav
Are you repeatedly generating image for an animation inside an event loop?

Depending on the kind of program `freeze` from 2htdp/image may help if you
haven't tried already. For example this[1] program renders faster with
freeze both in RacketScript and 2htdp/image.

[1] http://rapture.twistedplane.com:8080/#example/default

--Vishesh

On Tue, Apr 25, 2017 at 9:09 PM, Daniel Prager 
wrote:

> Much as I enjoy making images using 2htdp/image it does get a tad slow as
> complexity increases.
>
> I currently have a program in which I generate images in 2htdp/image and
> translate them into bitmap%s per racket/gui and render on canvas%'s via a
> dc.
>
> Speed has become sluggish and I'm going to need to move away from
> 2htdp/image to address this.
>
> A typical image is built up out of lots of above, beside, overlay, square,
> and triangle calls.
>
> Does anyone have a "clever" way to do this programatically (rather than a
> manual re-write with lots of absolute calculations replacing heights and
> widths)?
>
> Many thanks
>
> Dan
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


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

2017-04-25 Thread Alex Harsanyi
On Wednesday, April 26, 2017 at 12:09:54 PM UTC+8, Daniel Prager wrote:
> Much as I enjoy making images using 2htdp/image it does get a tad slow as 
> complexity increases.
> 
> I currently have a program in which I generate images in 2htdp/image and 
> translate them into bitmap%s per racket/gui and render on canvas%'s via a dc.
> 
> Speed has become sluggish and I'm going to need to move away from 2htdp/image 
> to address this.
> 
> A typical image is built up out of lots of above, beside, overlay, square, 
> and triangle calls. 
> 
> Does anyone have a "clever" way to do this programatically (rather than a 
> manual re-write with lots of absolute calculations replacing heights and 
> widths)?

You could try using the pict module, as a pict can be drawn directly to a 
canvas using `draw-pict`.  This assumes that the performance degradation is 
caused by using the intermediate bitmap% object.

Alex.


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


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

2017-04-25 Thread WarGrey Gyoudmon Ju
Hi Daniel,

I have a functional bitmap library[1] as a part of my CSS engine.
This library is inspired by the official pict-lib and flomap(images-lib),
and handles bitmap% directly.
I don't think it is efficient enough since every functional operation
creates another bitmap%.

Here I recommend you to take a look at the flomap, it is written in typed
racket and represents high precision
bitmap objects with flvector, composition and transformation should
therefore efficient. You just need to convert
the flomap struct into a bitmap% instance when drawing(you might need to
take care of the backing scale).

The basic composition is simple, you can write your own version within a
day, but the performance ceiling may
relate to Racket instead of algorithms you picked(since algorithms are
already simple enough). If performance
is really a problem, you may want to write your own library with Racket
Futures.

[1]https://github.com/wargrey/css/tree/master/bitmap

On Wed, Apr 26, 2017 at 12:09 PM, Daniel Prager 
wrote:

> Much as I enjoy making images using 2htdp/image it does get a tad slow as
> complexity increases.
>
> I currently have a program in which I generate images in 2htdp/image and
> translate them into bitmap%s per racket/gui and render on canvas%'s via a
> dc.
>
> Speed has become sluggish and I'm going to need to move away from
> 2htdp/image to address this.
>
> A typical image is built up out of lots of above, beside, overlay, square,
> and triangle calls.
>
> Does anyone have a "clever" way to do this programatically (rather than a
> manual re-write with lots of absolute calculations replacing heights and
> widths)?
>
> Many thanks
>
> Dan
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[racket-users] Re: Best way to write run-once-and-cache functions?

2017-04-25 Thread Alex Harsanyi
On Wednesday, April 26, 2017 at 12:12:26 PM UTC+8, David K. Storrs wrote:

> 
> I could do it with a parameter but that's only sweeping the above ugliness 
> under the rug:
> 
> (define conf (make-parameter #f))
> 
> (define (read-conf)
>    (or (conf)
>  (begin
>    (conf (with-input-from-file "db.conf" (thunk (read-json
>    (conf

This is probably the wrong way, as the parameter will only be set in the 
current thread.  The code will read the contents of "db.conf" in every thread 
that `read-conf` is called.

Best Regards,
Alex.

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


Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-25 Thread Jon Zeppieri
I don't know that there's a right way, but if your functions are
nullary, then promises are a decent fit:

(define conf
  (delay
(with-input-from-file ...)))

Then just (force conf) whenever you want the value.



On Wed, Apr 26, 2017 at 12:12 AM, David Storrs  wrote:
> Reading configuration files is a good example of a run-once function.  It's
> effectively self-memoizing -- it should run once, cache its result, and on
> future calls just return the cached value.  I could pull in
> https://docs.racket-lang.org/memoize/index.html or
> http://docs.racket-lang.org/mischief@mischief/memoize.html to do that, but
> adding an extra module to the project just for one or two functions feels
> pretty heavy. (Also, memoizing is overkill if the functions are thunks.)  Is
> there a simple way to do this in pure Racket?
>
> In Perl I would do something like this (for simplicity I'm ignoring encoding
> and assuming that the config file is JSON):
>
> use JSON;
> sub read_conf {
>   state $conf = do {
> local $/;
> open my $fh, "<", "db.conf" or die "failed to open config: $!";
> from_json( <$fh> )
>   };
>   $conf
> }
>
>
> I could do this in Racket using set!, but that's not very Rackety:
>
> (require json)
> (define conf #f)
> (define (read-conf)
>(or conf
>  (begin
>(set! conf (with-input-from-file "db.conf" (thunk (read-json
>conf)))
>
>
> I could do it with a parameter but that's only sweeping the above ugliness
> under the rug:
>
> (define conf (make-parameter #f))
> (define (read-conf)
>(or (conf)
>  (begin
>(conf (with-input-from-file "db.conf" (thunk (read-json
>(conf
>
> What is the right way?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [racket-users] Best way to write run-once-and-cache functions?

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

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


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

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

> Reading configuration files is a good example of a run-once function.
> It's effectively self-memoizing -- it should run once, cache its result,
> and on future calls just return the cached value.  I could pull in
> https://docs.racket-lang.org/memoize/index.html or
> http://docs.racket-lang.org/mischief@mischief/memoize.html to do that,
> but adding an extra module to the project just for one or two functions
> feels pretty heavy. (Also, memoizing is overkill if the functions are
> thunks.)  Is there a simple way to do this in pure Racket?
>
> In Perl I would do something like this (for simplicity I'm ignoring
> encoding and assuming that the config file is JSON):
>
> use JSON;
> sub read_conf {
>   state $conf = do {
> local $/;
> open my $fh, "<", "db.conf" or die "failed to open config: $!";
> from_json( <$fh> )
>   };
>   $conf
> }
>
>
> I could do this in Racket using set!, but that's not very Rackety:
>
> (require json)
> (define conf #f)
> (define (read-conf)
>(or conf
>  (begin
>(set! conf (with-input-from-file "db.conf" (thunk (read-json
>conf)))
>
>
> I could do it with a parameter but that's only sweeping the above ugliness
> under the rug:
>
> (define conf (make-parameter #f))
> (define (read-conf)
>(or (conf)
>  (begin
>(conf (with-input-from-file "db.conf" (thunk (read-json
>(conf
>
> What is the right way?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[racket-users] Best way to write run-once-and-cache functions?

2017-04-25 Thread David Storrs
Reading configuration files is a good example of a run-once function.  It's
effectively self-memoizing -- it should run once, cache its result, and on
future calls just return the cached value.  I could pull in
https://docs.racket-lang.org/memoize/index.html or
http://docs.racket-lang.org/mischief@mischief/memoize.html to do that, but
adding an extra module to the project just for one or two functions feels
pretty heavy. (Also, memoizing is overkill if the functions are thunks.)
Is there a simple way to do this in pure Racket?

In Perl I would do something like this (for simplicity I'm ignoring
encoding and assuming that the config file is JSON):

use JSON;
sub read_conf {
  state $conf = do {
local $/;
open my $fh, "<", "db.conf" or die "failed to open config: $!";
from_json( <$fh> )
  };
  $conf
}


I could do this in Racket using set!, but that's not very Rackety:

(require json)
(define conf #f)
(define (read-conf)
   (or conf
 (begin
   (set! conf (with-input-from-file "db.conf" (thunk (read-json
   conf)))


I could do it with a parameter but that's only sweeping the above ugliness
under the rug:

(define conf (make-parameter #f))
(define (read-conf)
   (or (conf)
 (begin
   (conf (with-input-from-file "db.conf" (thunk (read-json
   (conf

What is the right way?

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


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

2017-04-25 Thread Daniel Prager
Much as I enjoy making images using 2htdp/image it does get a tad slow as
complexity increases.

I currently have a program in which I generate images in 2htdp/image and
translate them into bitmap%s per racket/gui and render on canvas%'s via a
dc.

Speed has become sluggish and I'm going to need to move away from
2htdp/image to address this.

A typical image is built up out of lots of above, beside, overlay, square,
and triangle calls.

Does anyone have a "clever" way to do this programatically (rather than a
manual re-write with lots of absolute calculations replacing heights and
widths)?

Many thanks

Dan

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


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

2017-04-25 Thread David Storrs
Thanks Ryan, I had forgotten that those were there.

​

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


Re: [racket-users] Re: Proper non-tail recursion?

2017-04-25 Thread Jay McCarthy
+1 to Robby's idea :P

On Tue, Apr 25, 2017 at 9:50 PM, Robby Findler
 wrote:
> "..., Hooray!" ? :)
>
> Robby
>
> On Tue, Apr 25, 2017 at 8:46 PM Jordan Johnson  wrote:
>>
>> On Apr 25, 2017, at 6:09 PM, Matthias Felleisen 
>> wrote:
>> > While I am at it, let me advocate PITCH as the slogan for Proper
>> > Implementation of Tail Calls. (Where does the H come from? I added it to
>> > make a complete word.)
>>
>> Proper Implementation of Tail Call Handling? :)
>>
>> Cheers,
>> Jordan
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

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


Re: [racket-users] Re: Proper non-tail recursion?

2017-04-25 Thread Robby Findler
"..., Hooray!" ? :)

Robby

On Tue, Apr 25, 2017 at 8:46 PM Jordan Johnson  wrote:

> On Apr 25, 2017, at 6:09 PM, Matthias Felleisen 
> wrote:
> > While I am at it, let me advocate PITCH as the slogan for Proper
> Implementation of Tail Calls. (Where does the H come from? I added it to
> make a complete word.)
>
> Proper Implementation of Tail Call Handling? :)
>
> Cheers,
> Jordan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Re: Proper non-tail recursion?

2017-04-25 Thread Jordan Johnson
On Apr 25, 2017, at 6:09 PM, Matthias Felleisen  wrote:
> While I am at it, let me advocate PITCH as the slogan for Proper 
> Implementation of Tail Calls. (Where does the H come from? I added it to make 
> a complete word.)

Proper Implementation of Tail Call Handling? :)

Cheers,
Jordan

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


Re: [racket-users] Re: Proper non-tail recursion?

2017-04-25 Thread Matthias Felleisen


Brendan, 

you’re correct in attributing the idea that the proper implementation of tail 
calls is far less important to the Scheme and Racket community. Dybvig 
expressed this idea first in a talk titled a Bag of Hacks in the early 90s. 
Matthew then at some point said that the true goal is to never run out of stack 
space (other than run out of memory period); once we have that proper tail-call 
implementation might just be of secondary value. 

As for terminology, I think I would say that a language ought to support 
‘unbounded recursion depth’. Unwieldy name. 

How is it implemented? When a call is about to exhaust the available stack 
space, grab the stack, move it into the heap, start a new one with a frame that 
links to the moved stack. If you now also want to implement 
continuation-grabing control operators (call/cc, C, F, prompt, etc) you can do 
so with one extra bit per stack frame and lazy copying of heap-moved stacks to 
the stack proper. 

While I am at it, let me advocate PITCH as the slogan for Proper Implementation 
of Tail Calls. (Where does the H come from? I added it to make a complete 
word.) What many people fail to see is that every language with function calls 
has tail positions. The syntax may obscure those with various superfluous 
keywords but that does not invalidate the idea. A tail-call position is a 
‘return’ place in a function body. Period. So when people say “we implement 
tail calls”, it’s basically nonsense because every language with function calls 
must implement tail calls. The question is whether the evaluation of arguments 
or the evaluation of function calls consumes space. And if you love OO design 
patterns — which is where Scheme comes from — you must opt into the former not 
the latter, which means you must implement tail calls properly. 

— Matthias







> On Apr 25, 2017, at 7:32 PM, brendan  wrote:
> 
> Good points: It wasn't strictly true to say that you can make non-tail calls 
> "without fear." Rather, your memory for continuation frames is shared with, 
> and just as large as, any other kind of data.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


[racket-users] Re: Proper non-tail recursion?

2017-04-25 Thread brendan
Good points: It wasn't strictly true to say that you can make non-tail calls 
"without fear." Rather, your memory for continuation frames is shared with, and 
just as large as, any other kind of data.

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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread Robby Findler
Ah, lucky you. This is not a "stack overflow". This is a "all of memory
overflow". The cool thing about racket is that there is not separate limit
on some mysterious PL-internal data structure called a "stack".

Robby

On Tue, Apr 25, 2017 at 6:13 PM Matthew Butterick  wrote:

>
> > On Apr 25, 2017, at 4:05 PM, brendan  wrote:
> >
> > Indeed; I should have clarified that I didn't mean only recursion per
> se. Not the first time I've stumbled on that misnomer.
> >
> > On Tuesday, April 25, 2017 at 6:53:59 PM UTC-4, Robby Findler wrote:
> >> I think the question is about non-tail calls and limits on them.
>
>
> FWIW you can definitely trigger a stack overflow with non-tail calls. In
> DrRacket, go to Racket → Limit Mem­ory and change the limit to 8 MB. Then
> try this:
>
> (define (sum n)
>   (if (zero? n)
>   n
>   (+ n (sum (sub1 n)
>
> (sum 1) ; boom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread Jon Zeppieri
On Tue, Apr 25, 2017 at 6:37 PM, brendan  wrote:
> Scheme implementations are required to have proper tail recursion. Racket 
> goes further and lets the programmer make recursive calls from any position 
> without fear because, to paraphrase Dr. Flatt, it's the 21st century and 
> stack overflows should not be a thing. My questions are: Is there a name for 
> this feature? And do any other major languages or implementations have it? 
> Thanks.

I don't know if there's one particular term for this. A resizable (or
growable) call stack, maybe?

It's very different from proper tail calls, though, because a non-tail
call still accumulates space, and you can still run out of space. It's
just that many language implementations use a fixed-size stack,
whereas Racket will increase the size of the stack at runtime. I'm not
sure what other language implementations do this.

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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread Matthew Butterick

> On Apr 25, 2017, at 4:05 PM, brendan  wrote:
> 
> Indeed; I should have clarified that I didn't mean only recursion per se. Not 
> the first time I've stumbled on that misnomer.
> 
> On Tuesday, April 25, 2017 at 6:53:59 PM UTC-4, Robby Findler wrote:
>> I think the question is about non-tail calls and limits on them. 


FWIW you can definitely trigger a stack overflow with non-tail calls. In 
DrRacket, go to Racket → Limit Mem­ory and change the limit to 8 MB. Then try 
this:

(define (sum n)
  (if (zero? n)
  n
  (+ n (sum (sub1 n)

(sum 1) ; boom

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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread 'John Clements' via Racket Users

> On Apr 25, 2017, at 4:05 PM, brendan  wrote:
> 
> Indeed; I should have clarified that I didn't mean only recursion per se. Not 
> the first time I've stumbled on that misnomer.

Forgive me. In that case, I’m not sure exactly what property it is you’re 
looking for a name for. 

:)

John



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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread brendan
Indeed; I should have clarified that I didn't mean only recursion per se. Not 
the first time I've stumbled on that misnomer.

On Tuesday, April 25, 2017 at 6:53:59 PM UTC-4, Robby Findler wrote:
> I think the question is about non-tail calls and limits on them. 
> 
> 
> Robby
> 
> 
> 
> On Tue, Apr 25, 2017 at 5:52 PM 'John Clements' via Racket Users 
>  wrote:
> 
> 
> > On Apr 25, 2017, at 3:37 PM, brendan  wrote:
> 
> >
> 
> > Scheme implementations are required to have proper tail recursion. Racket 
> > goes further and lets the programmer make recursive calls from any position 
> > without fear because, to paraphrase Dr. Flatt, it's the 21st century and 
> > stack overflows should not be a thing. My questions are: Is there a name 
> > for this feature? And do any other major languages or implementations have 
> > it? Thanks.
> 
> 
> 
> Sadly, there are *many* names for this feature.
> 
> 
> 
> But first, a correction! Like Racket, Scheme implementations are also 
> required to have the desired memory behavior (specifically, they must not 
> grow without bound on a class of programs that makes only tail calls). It’s 
> true that the standard uses the phrase “tail recursion,” but if you check it 
> out, you’ll see that it’s not just recursive calls that are covered.
> 
> 
> 
> In answer to your actual question, the most common name is “Tail Call 
> Optimization,” which many people correctly object to because it’s not an 
> optimization, it’s a change to the meaning of terms in the language, at least 
> if you can distinguish stack overflows from programs that run forever.
> 
> 
> 
> I once invented the name “tail-cursion” for this, which everyone hated.
> 
> 
> 
> Finally, I’m moderately fond of Dave Herman’s phrase “properly tail-calling,” 
> though I admit that it’s not as short as it could be.
> 
> 
> 
> John Clements
> 
> 
> 
> 
> 
> 
> 
> --
> 
> You received this message because you are subscribed 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.
> 
> For more options, visit https://groups.google.com/d/optout.

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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread Robby Findler
I think the question is about non-tail calls and limits on them.

Robby

On Tue, Apr 25, 2017 at 5:52 PM 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

>
> > On Apr 25, 2017, at 3:37 PM, brendan  wrote:
> >
> > Scheme implementations are required to have proper tail recursion.
> Racket goes further and lets the programmer make recursive calls from any
> position without fear because, to paraphrase Dr. Flatt, it's the 21st
> century and stack overflows should not be a thing. My questions are: Is
> there a name for this feature? And do any other major languages or
> implementations have it? Thanks.
>
> Sadly, there are *many* names for this feature.
>
> But first, a correction! Like Racket, Scheme implementations are also
> required to have the desired memory behavior (specifically, they must not
> grow without bound on a class of programs that makes only tail calls). It’s
> true that the standard uses the phrase “tail recursion,” but if you check
> it out, you’ll see that it’s not just recursive calls that are covered.
>
> In answer to your actual question, the most common name is “Tail Call
> Optimization,” which many people correctly object to because it’s not an
> optimization, it’s a change to the meaning of terms in the language, at
> least if you can distinguish stack overflows from programs that run forever.
>
> I once invented the name “tail-cursion” for this, which everyone hated.
>
> Finally, I’m moderately fond of Dave Herman’s phrase “properly
> tail-calling,” though I admit that it’s not as short as it could be.
>
> John Clements
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Proper non-tail recursion?

2017-04-25 Thread 'John Clements' via Racket Users

> On Apr 25, 2017, at 3:37 PM, brendan  wrote:
> 
> Scheme implementations are required to have proper tail recursion. Racket 
> goes further and lets the programmer make recursive calls from any position 
> without fear because, to paraphrase Dr. Flatt, it's the 21st century and 
> stack overflows should not be a thing. My questions are: Is there a name for 
> this feature? And do any other major languages or implementations have it? 
> Thanks.

Sadly, there are *many* names for this feature.

But first, a correction! Like Racket, Scheme implementations are also required 
to have the desired memory behavior (specifically, they must not grow without 
bound on a class of programs that makes only tail calls). It’s true that the 
standard uses the phrase “tail recursion,” but if you check it out, you’ll see 
that it’s not just recursive calls that are covered.

In answer to your actual question, the most common name is “Tail Call 
Optimization,” which many people correctly object to because it’s not an 
optimization, it’s a change to the meaning of terms in the language, at least 
if you can distinguish stack overflows from programs that run forever.

I once invented the name “tail-cursion” for this, which everyone hated.

Finally, I’m moderately fond of Dave Herman’s phrase “properly tail-calling,” 
though I admit that it’s not as short as it could be.

John Clements



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


[racket-users] Proper non-tail recursion?

2017-04-25 Thread brendan
Scheme implementations are required to have proper tail recursion. Racket goes 
further and lets the programmer make recursive calls from any position without 
fear because, to paraphrase Dr. Flatt, it's the 21st century and stack 
overflows should not be a thing. My questions are: Is there a name for this 
feature? And do any other major languages or implementations have it? Thanks.

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


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

2017-04-25 Thread Ryan Culpepper
You might be interested in `dsn-connect` and the `data-source` structure 
(http://docs.racket-lang.org/db/connect.html#%28part._.Data_.Source_.Names%29).


Ryan


On 4/25/17 8:18 PM, David Storrs wrote:

Great.  Thanks, Phillip!

On Tue, Apr 25, 2017 at 2:14 PM, Philip McGrath
mailto:phi...@philipmcgrath.com>> wrote:

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


-Philip

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



On Mon, Apr 24, 2017 at 9:46 PM, Philip McGrath
mailto:phi...@philipmcgrath.com>> wrote:

Another thing that might be relevant:

In contrast, direct assignment to a parameter (by
calling the parameter procedure with a value) changes
the value in a thread cell, and therefore changes the
setting only for the current
thread. http://docs.racket-lang.org/reference/parameters.html



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


Nope, a given dbh should only be connected to one DB.




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

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


I admit that I had to stare at this for a few minutes and look
up some details (e.g. how hash/dc works), but when it clicked my
reaction was "Racket. Is. Epic."

Thank you for this; it's exactly what I needed and I'll
definitely use it.  Two questions:

1) This line was intended to reference
(current-database-handle), not (current-database), right?
[_ (force (database-handle-promise (current-database)))]))

2) We're already using hashes for data passing in a lot of areas
because (a) they are really convenient and (b) my co-founder and
I both come from Perl backgrounds.  In this particular case,
though, it seems like maybe I should define a struct for the
database spec instead of a hash, as hash/dc validates the keys
and values that happen to exist in the hash, as opposed to
validating that the hash has a given set of keys/values.  Does
this make sense or am I overcomplicating things?

Dave

NB:  I'm glad you used hashes for the demo, though, as it was
much easier to follow and introduced me to the hash/dc contract.


#lang racket

(require db
 )

(struct database-handle (promise))

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

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


(define/contract current-database-handle
  (parameter/c database-spec/c database-handle?)
  (let ([initialize
 (λ (spec)
   (if (database-handle? spec)
   spec
   (let ([u (hash-ref spec 'user)]
 [d (hash-ref spec 'database)]
 [p (hash-ref spec 'password)]
 [prt (hash-ref spec 'port)])
 (database-handle
   

Re: [racket-users] Any work on demo.racket-lang.org?

2017-04-25 Thread Tim Brown
Matthew,

I’m no lawyer, but...

On Tuesday, April 25, 2017 at 4:45:29 PM UTC+1, Matthew Butterick wrote:
> PS about Rosetta Code generally. As a user, its utility is hugely
> undermined by the fact that I can't take code from the site and easily
> adapt / reuse it (at least, if I want to comply with the GFDL). 
> 
> http://www.gnu.org/licenses/fdl-1.2.html
> 
> IMO a library of sample Racket code ought to be available under the
> same license as Racket (IIRC we are heading toward MIT/Apache)
> 
> https://github.com/racket/racket/issues/1570

That’s a sticky one.


Rosetta Code examples are often structured as such:

TITLE: Bogo Sort
   -

INTRO: In computer science, bogosort
   is a highly ineffective sorting algorithm...

TASK:  Write a program to bogosort a list of 50 numbers. Print out how
   long it takes to complete.

IMPLEMENTATIONS:

   =={{header|ADA}}==
   ...
   ...

   =={{header|Racket}}==
   (define bogo-sort ...)
(time (bogo-sort ...))


The INTRO is lifted from Wikipedia, and probably properly credited since
it’s a URL. Without being under the GFDL, would that be permitted by
Wikipedia’s licence?


The TASK is written by an RC contributor. Said contributor can release
the task description under another licence (would only make sense to
make it more permissive). Or someone complying with the GFDL could copy
it.


There seems to be an incompatibility between source code and
documentation and the GPL and the GFDL. But assume for a moment that the
text of code is documentation covered by GFDL (although the same is
true of it as code covered by GPL): The IMPLEMENTATION writers can
release their implementations permissively.

Now, I wouldn’t bother asking the ADA implementor’s permission, since
I’m not interested in copying their code (maybe I am deriving from the
overall work by removing it).

I want to copy the Racket implementors’ documentation/source code. I
would need to ask the Racket implementors whether, for the benefit of
the Racket community (and therefore humanity at large) they could ensure
the code is explicitly released for (at least) that purpose.


So we could end up writing the example below. The TASK and
IMPLEMENTATION would either be uncopied/non-derivative or relicenced.
But, the INTRO is still a copy of the Wikipedia content. And even if my
previous arguments hold true WRT Rosetta Code -- this project would
/still/ have issues with GFDL.

TITLE: Bogo Sort
   -

INTRO: In computer science, bogosort
   is a highly ineffective sorting algorithm...

TASK:  [In this case not necessary after WP has described it, and in any
other case probably not appropriate to lift verbatim]

IMPLEMENTATION:
   (define bogo-sort ...)
   (time (bogo-sort ...))


Racket is permissive enough to use Scribble (scribble/lp) on a separate
site (not necessarily a Wiki).

A package could be pre-built with only the released library code and no
documentation (at least allowing folk to use the examples). Which would
pervert any idea of easy open source.

I wouldn’t know how to describe BogoSort without reference to WP (or
worse, another printed source)†. So it would be difficult in this respect
to, for example, gather together a canonical list of sorts; and
illustrate them in Racket.


Has anyone any ideas of how to navigate this minefield?

Tim

† Am I missing a resource here?



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


[racket-users] [Call for Tutorials] CUFP 2017

2017-04-25 Thread Runhang Li
  Call for Tutorials

  Commercial Users of Functional Programming (CUFP) 2017

  September 7th-9th, 2017, Oxford, United Kingdom

   Co-located with International Conference on Functional Programming (ICFP)


Dear Racket community,

Commercial Users of Functional Programming (CUFP) 2017 is now seeking
tutorials proposals.

Co-located with International Conference on Functional Programming (ICFP),
Commercial Users of Functional Programming (CUFP) will take place in Oxford, 
U.K.
from 7th to 9th of September, 2017. CUFP is devoted to showcase the state of
the art of functional programming in industrial settings.

We are looking for tutors who would like to host half-day tutorial sessions
of the following topics:

* Introductions to functional programming languages, e.g., Haskell, OCaml,
 Scala, F#, Scheme, Erlang, Racket, Clojure.
* Advanced programming languages, concepts, or applications, e.g., Agda, Idris,
 F*, Coq, Eff.
* Applications of functional languages in particular areas, including web,
 high-performance computing, and finance.
* Tools and techniques supporting state of the art functional programming, e.g.,
 ReasonML, TypeScript, Elm, QuickCheck, FlowType.
* Theory. Type theory, category theory, abstract algebra, ongoing or new
 research, or anything useful or interesting to functional programmers.

**Proposal submission deadline is May 25th**

Details can be found at: http://cufp.org/2017/call-for-tutorials.html


Kindly,
Runhang Li, CUFP 2017 tutorials co-chair

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


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

2017-04-25 Thread David Storrs
Great.  Thanks, Phillip!

On Tue, Apr 25, 2017 at 2:14 PM, Philip McGrath 
wrote:

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

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

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

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


-Philip

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

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

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

2017-04-25 Thread David Storrs
On Mon, Apr 24, 2017 at 9:46 PM, Philip McGrath 
wrote:

> Another thing that might be relevant:
>>
>> In contrast, direct assignment to a parameter (by calling the parameter
>> procedure with a value) changes the value in a thread cell, and therefore
>> changes the setting only for the current thread. http://docs.racket-
>> lang.org/reference/parameters.html
>
>
> Also, do you want multiple underlying connections of the same virtual
> connection to potentially use different values for the
> user/database/password/port?
>

Nope, a given dbh should only be connected to one DB.



>
> If not, the most recent way I've dealt with this sort of thing is to come
> up with some type of "database connection spec" — for a quick example, I'll
> use a hash table — and then do some things with parameter guards, opaque
> structures, and a tiny macro to keep the details away from higher-level
> code.
>
> I think code might be clearer than a description, so here's a minimal
> sketch:
>
>
I admit that I had to stare at this for a few minutes and look up some
details (e.g. how hash/dc works), but when it clicked my reaction was
"Racket. Is. Epic."

Thank you for this; it's exactly what I needed and I'll definitely use it.
Two questions:

1) This line was intended to reference (current-database-handle), not
(current-database), right?
[_ (force (database-handle-promise (current-database)))]))

2) We're already using hashes for data passing in a lot of areas because
(a) they are really convenient and (b) my co-founder and I both come from
Perl backgrounds.  In this particular case, though, it seems like maybe I
should define a struct for the database spec instead of a hash, as hash/dc
validates the keys and values that happen to exist in the hash, as opposed
to validating that the hash has a given set of keys/values.  Does this make
sense or am I overcomplicating things?

Dave

NB:  I'm glad you used hashes for the demo, though, as it was much easier
to follow and introduced me to the hash/dc contract.


#lang racket
>
> (require db
>  )
>
> (struct database-handle (promise))
>
> (define database-spec/c
>   (or/c database-handle?
> (hash/dc [k (or/c 'user 'database 'password 'port)]
>  [v (k)
> (case k
>   [(user database password)
>string?]
>   [(port)
>natural-number/c]
>   [else none/c])])))
>
> (define default-database-spec
>   #hasheq([user . "postgres"]
>   [database . "test-db"]
>   [password . "mellon"]
>   [port . 5433]))
>
>
> (define/contract current-database-handle
>   (parameter/c database-spec/c database-handle?)
>   (let ([initialize
>  (λ (spec)
>(if (database-handle? spec)
>spec
>(let ([u (hash-ref spec 'user)]
>  [d (hash-ref spec 'database)]
>  [p (hash-ref spec 'password)]
>  [prt (hash-ref spec 'port)])
>  (database-handle
>   (delay (virtual-connection
>   (connection-pool
>(λ ()
>  (postgresql-connect
>   #:user u
>   #:database d
>   #:password p
>   #:port prt
>   )])
> (make-parameter (initialize default-database-spec)
> initialize)))
>
> (define-syntax db
>   (syntax-id-rules ()
> [_ (force (database-handle-promise (current-database)))]))
>
> (provide database-handle? ;keep constructor & accessor private
>  database-spec/c
>  current-database-handle
>  db
>  )
>
>
>
> On Mon, Apr 24, 2017 at 7:19 PM, David Storrs 
> wrote:
>
>>
>>
>> On Mon, Apr 24, 2017 at 4:43 PM, Scott Moore 
>> wrote:
>>
>>> Parameters are thread local, and from reading the docs of
>>> virtual-connection and connection-pool, I think they create new threads to
>>> handle the connections. These threads are probably created before you
>>> parameterize, and thus see the original values.
>>>
>>> Try replacing the virtual-connection stuff with a single call to
>>> do-connect, and see if that works. (Obviously not the real fix, but may
>>> help identify the error).
>>>
>>>
>> This was exactly it.  Thanks, Scott.
>>
>> Now I just need to figure out how to work around it.
>>
>>
>>> On Apr 24, 2017, 4:35 PM -0400, David Storrs ,
>>> wrote:
>>>
>>> I'm finding parameters confusing and was hoping someone could explain
>>> them for me.  The following is a simplified version of our production code;
>>> I'm expecting it to fail but it does not.  What am I not understanding?
>>>
>>> The sequence goes:
>>>
>>> *) db.conf creates and provides some parameters (db username, db
>>> password, db name, db port) and a function for creating datab

Re: [racket-users] Any work on demo.racket-lang.org?

2017-04-25 Thread Matthew Butterick

> On Apr 25, 2017, at 3:14 AM, Tim Brown  wrote:
> 
> 1 Volume: there are 932 tasks implemented on Rosetta Code; all of
>  which have some value. Since I have contributed a fair number of
>  these, I know that there is a good amount of time required to just
>  review each of these pages. 



PS about Rosetta Code generally. As a user, its utility is hugely undermined by 
the fact that I can't take code from the site and easily adapt / reuse it (at 
least, if I want to comply with the GFDL). 

http://www.gnu.org/licenses/fdl-1.2.html 


IMO a library of sample Racket code ought to be available under the same 
license as Racket (IIRC we are heading toward MIT/Apache)

https://github.com/racket/racket/issues/1570 


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


Re: [racket-users] Any work on demo.racket-lang.org?

2017-04-25 Thread Tim Brown
Matthew,

Food for thought -- so here’s a bit of thinking out loud.

On Tuesday, April 25, 2017 at 3:42:32 AM UTC+1, Matthew Butterick wrote:
> Instead of a wiki, perhaps consider collecting demo code samples into
> a new Racket package & adding explanations via Scribble docs. In turn,
> these will be automatically published at docs.racket-lang.org. 

Not a bad idea at all. There are a few content management issues that
need to be considered:

1 Volume: there are 932 tasks implemented on Rosetta Code; all of
  which have some value. Since I have contributed a fair number of
  these, I know that there is a good amount of time required to just
  review each of these pages. A lot of effort would be involved in
  cherry-picking tasks for “special treatment”. So the first pass would
  be to download as much as I can and (this is what I tend to do when I
  panic) stick it between  tags.

2 Quality: see above regards the  tags. Once the examples are collected
  they will need some improvement:
  - task descriptions need to be wikitext->scribbled
  - the prose of the task descriptions need to be edited
  - the Racket itself needs to be sanitised. Some of it is a bit
minimalist referring back to the original implementation in another
language which *is* properly documented
  - if we’re going for bonus points, it needs chunking down
- and maybe even (provide’ing) if some of this is to be of immediate
  use
  - other meta-data like tagging and proper attribution need to be added
  Until all of these quality issues are addressed, we have something
  kicking about in the Racket documentation that is less than we expect.
  An ugly-examples package could resolve that.

3 Synchronisation: since I'm considering scraping code and “task”
  descriptions from external sources; there needs to be an ability to
  ensure that both the local and original versions are kept consistent.
  If only by flagging that they are not. Although this could be yet more
  meta-data.

A question: does scribble or Racket documentation system have a place
for meta-data. I would want to tag examples as “string”, “algorithm”,
“string algorithm”. Otherwise a thousand tasks will be impossible to
search.

  - Off the back of that; if there are all these new pages to search,
would this also make the current documentation search overwhelmingly
cluttered? (There could be an index page for each tag, I suppose, so
there would just be a “String Examples” page)

Whether these can be fully addressed using git, or whether some
“third-party” collaborative effort system is needed (i.e. a wiki or
workflow system that will do the heavy lifting of the above) just to get
a handle on this; one would want to explore.

That said, the evidence of the current Racket documentation seems to be
that once quality documentation (and code) is in git, it is well
curated. My problem is just getting there.

> For instance:
> 
> http://docs.racket-lang.org/aoc-racket/
> 
> Bonus points for using `scribble/lp`.

I suspect I will go for an intermediate language. The chance of falling
on a format that does what is needed first time round is slim; and if,
for example, I need the description moving below the code -- much better
that it is done in a template. But LP is good.

There is another approach I have read of
“Code Guide” http://natpryce.com/articles/000798.html:
> Code Guide is a kind of opposite of Literate Programming.

Fascinating little experiment. But LP, being not-so-interactive can be
printed onto paper.



I’m kinda seeing why this in the “Larger Projects” section.

Tim Brown

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


[racket-users] Re: Any work on demo.racket-lang.org?

2017-04-25 Thread Tim Brown
Greg,

On Monday, April 24, 2017 at 9:13:30 PM UTC+1, Greg Trzeciak wrote:
> Regarding the Rosetta Code scraper - I have 90% of the task completed - I 
> will post my code on github sometime tomorrow. It still needs some work to 
> have it published - the number of code samples is huge so is the variety of 
> issues encountered - one I haven't resolved is around MathML conversion into 
> scribble doc. I will post more with a link to github repo. 

I'd be interested to see it. Confession time, though... something like this has 
been on my to to list for years now; so I have a box full of RC scrapers! (Plus 
there are a number of RC tasks specifically for scraping RC).

> I don't know what's the story behind scheme cookbook as there was once a 
> website you can get from the web archive: 
> https://web.archive.org/web/20150318225436/http://schemecookbook.org/

I was introduced to that on the IRC channel.
If it's on the Internet, it can be scraped!

Tim

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