Re: [racket] Can a #reader be used with (module ...) ?

2014-09-15 Thread Matthew Flatt
There's not currently anything like `#reader` that would hide a closing parenthesis from the reader. I think you could make a new reader that recurs to `read` with an input port that stops consuming input from the original just before a closing parenthesis followed by an EOF --- maybe by peeking a

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread Matthew Butterick
Haha, yes I too checked Racket `shuffle` after I read that. But `shuffle` is mathematically sound. (Was I really surprised?) It doesn't use a random comparator. Rather, it assigns random *keys* to the elements and then uses a standard `<` comparator, which preserves transitivity (net of the nan

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread Asumu Takikawa
On 2014-09-15 21:24:53 -0700, Eric Dobson wrote: > This is different than linked algorithm. This one assigns a random > number from [0,1) to each element where the linked algorithm assigns a > random pairwise ordering to each comparison. > > I don't think there is anything wrong from a correctness

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread Eric Dobson
On Mon, Sep 15, 2014 at 8:50 PM, Asumu Takikawa wrote: > On 2014-09-15 18:57:51 -0700, Matthew Butterick wrote: >> Mike Bostock's visual demonstration of why naive sorting functions are false >> friends. As he and Henglein point out, transitivity of the comparator is >> essential. >> >> http://bos

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread Asumu Takikawa
On 2014-09-15 18:57:51 -0700, Matthew Butterick wrote: > Mike Bostock's visual demonstration of why naive sorting functions are false > friends. As he and Henglein point out, transitivity of the comparator is > essential. > > http://bost.ocks.org/mike/shuffle/compare.html Thanks, that's really int

Re: [racket] Some problem with hash-update!

2014-09-15 Thread Evgeny Odegov
> Using `#:atomic? #t` disables Racket thread switches, but it doesn't > disable GC. > It's not so much about modification as referencing the memory --- > either reading or writing --- across a potential GC. Thank you! It's clear now. > Now that I look closely, I think you need the `bytes-copy!`

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread Matthew Butterick
Mike Bostock's visual demonstration of why naive sorting functions are false friends. As he and Henglein point out, transitivity of the comparator is essential. http://bost.ocks.org/mike/shuffle/compare.html On 09/15/14 2:16 PM, Robby Findler wrote: Fritz Henglein has studied the problem "what

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread Robby Findler
Fritz Henglein has studied the problem "what is a sorting function?" that touches on this kind of thing. http://www.sciencedirect.com/science/article/pii/S1567832608001094 Robby On Monday, September 15, 2014, David Van Horn wrote: > On 9/15/14, 4:53 PM, David Van Horn wrote: > > I don't think

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread David Van Horn
On 9/15/14, 4:53 PM, David Van Horn wrote: > I don't think you made enough examples. Nope - my bad. Cute. Awful, but cute (and there could be correct implementations of sort that would break your rev). David Racket Users list: http://lists.racket-lang.org/users

Re: [racket] on reversing a list by way of sort

2014-09-15 Thread David Van Horn
I don't think you made enough examples. On 9/15/14, 4:48 PM, Daniel Bastos wrote: > Dear Racketeers, I was studying the exercise 20.2.4 of HtDP when I > came up with this way of reversing lists. (Every element is a least > element. Or greatest.) > > (define (f x y) true) > > (define (rev ls) (so

[racket] on reversing a list by way of sort

2014-09-15 Thread Daniel Bastos
Dear Racketeers, I was studying the exercise 20.2.4 of HtDP when I came up with this way of reversing lists. (Every element is a least element. Or greatest.) (define (f x y) true) (define (rev ls) (sort ls f)) Welcome to DrRacket, version 6.0.1 [3m]. Language: Intermediate Student; memory li

[racket] Can a #reader be used with (module ...) ?

2014-09-15 Thread Matthew Butterick
I'm aware that `#lang name ...` is equivalent to `(module id name ...)`. But `#lang` automatically picks up a reader; `module` does not. Is there a way to attach a reader to the `module` form (the idea being that then, within the `module` expression, you could write using the native syntax of

Re: [racket] How best to repeat a function call n times?

2014-09-15 Thread Matthias Felleisen
Welcome to Racket v6.1.0.8. > (define (repeater f count) (for ((i (in-range count))) (f))) > (repeater (lambda () (displayln "hello world")) 10) hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world On Sep 15, 2014, at 1:50 PM,

Re: [racket] How best to repeat a function call n times?

2014-09-15 Thread Robby Findler
Not more efficient, but perhaps more readable: (define (repeater f count) (for ([x (in-range count)]) (f))) On Mon, Sep 15, 2014 at 12:50 PM, George Rudolph wrote: > All, > > I am sure this question has been answered before, but I can’t find it. > > Suppose I want to call some function

[racket] How best to repeat a function call n times?

2014-09-15 Thread George Rudolph
All, I am sure this question has been answered before, but I can't find it. Suppose I want to call some function, either built-in or user-defined, n number of times, and measure the total time it takes. Is there a more efficient or elegant way of doing this than passing the expression to a tail-

Re: [racket] missing solution 20.1.1 ex:sem-funcs

2014-09-15 Thread Matthias Felleisen
Good. On Sep 15, 2014, at 9:20 AM, Daniel Bastos wrote: > On Fri, Sep 12, 2014 at 6:43 PM, > Matthias Felleisen wrote: > > > On Sep 12, 2014, at 4:40 PM, Daniel Bastos wrote: > > > Again, we start with (2) and apply a series of substitutions. > > > > (f f) > > = ( ) ;; since f is

Re: [racket] missing solution 20.1.2 ex:syn-funcs

2014-09-15 Thread Daniel Bastos
On Mon, Sep 8, 2014 at 9:51 PM, Matthias Felleisen wrote: On Sep 2, 2014, at 12:05 PM, Daniel Bastos wrote: > > > Exercise 20.1.2. Argue why the following sentences are legal > > definitions: > > > > (define (f x) (x 10)) > > > > (define (f x) f) > > > > (define (f x y) (x 'a y 'b)) > > > > Solut

Re: [racket] missing solution 20.1.1 ex:sem-funcs

2014-09-15 Thread Daniel Bastos
On Fri, Sep 12, 2014 at 6:43 PM, Matthias Felleisen wrote: > On Sep 12, 2014, at 4:40 PM, Daniel Bastos wrote: > > > Again, we start with (2) and apply a series of substitutions. > > > > (f f) > > = ( ) ;; since f is a > > = ( ) ;; since is a subset of > > > > However, ( ) is not by

Re: [racket] Some problem with hash-update!

2014-09-15 Thread Evgeny Odegov
> I think that changing `_pointer` to `_DWORD` can't be the real answer, > since `_pointer` is at least as large as `_DWORD`. Facepalm. Of course, you're right! Somehow, I've thought that _pointer is twice shorter :) > But I agree that you should use `malloc`, and you should also supply > 'atomi