[racket-dev] 2htdp/image Feature Suggestion

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Jun 23 20:11:51 EDT 2014

I think that the prefer-define-over-let applies only to the first let
in this program.

The style guide also would recommend 'cond' over 'if' here, but it
becomes very very important to do that only if there were nested
'let's or 'begin's or the like and you don't have that.

Robby

On Mon, Jun 23, 2014 at 12:32 PM, Jos Koot <jos.koot at gmail.com> wrote:
> In the recommendations of http://docs.racket-lang.org/style/index.html it is
> recommended to use (internal or module top-level) define rather than named
> let.
> I use named let a lot. How would you rewrite the following? For me it is
> rather difficult to make the change without loosing track of the scope of
> the variables. I also have a rather distinct way of indenting.
>
> #lang racket
>
> #|
> A rearrangement of a list L is a list with the same elements as L,
> but possibly in another order.
> Proc make-natural->rearrangement takes a list L and returns a proc.
> Let N be the number of distinct rearrangements of L.
> The returned proc takes an index K less than N and returns the K-th
> distinct rearrangement of L. Two rearrangements R0 and R1 are distinct if
> (not (andmap EQ? R0 R1)).
> EQ? must be an equivalence relation on the elements of L.
>
> E = element
> H = head of L
> T = tail of L (append H T) = L
> K = index
> N = nr of distinct rearrangements of L.
> |#
>
> (define (make-natural->rearrangement L (EQ? equal?))
>  (let ((N (nr-of-rearrangements L EQ?)))
>   (lambda (K)
>    (let rearrange ((L L) (K K) (N N) (result '()))
>     ; Look for the K-th rearrangement of L and put it's elements in result.
>     (if (null? L) result
>      (let pseudo-rotate ((H L) (T '()) (K K))
>       ; Look in subsequent pseudorotations.
>       (let ((E (car H)) (H (cdr H)))
>        (if (member E T EQ?)
>         ; Skip pseudorotation if it's car already was car of a previous one.
>         (pseudo-rotate H (cons E T) K)
>         (let ((M (/ (* N (count-occurrences E L EQ?)) (length L))))
>          ; M is the nr of rearrangements of (append H T)
>          ; computed by means of a recurrent relation.
>          (if (< K M)
>           ; The rearrangement is in this pseudorotation.
>           (rearrange (append H T) K M (cons E result))
>           ; The rearrangement is not in this pseudorotation.
>           ; Look in the following pseudorotation, but decrease K by the
>           ; nr of rearrangements of the skipped pseudorotation.
>           (pseudo-rotate H (cons E T) (- K M))))))))))))
>
> (define (nr-of-rearrangements L EQ?) ...)
> (define (count-occcurrences E L EQ?) ...)
>
>> -----Original Message-----
>> From: dev [mailto:dev-bounces at racket-lang.org] On Behalf Of
>> Asumu Takikawa
>> Sent: lunes, 23 de junio de 2014 7:35
>> To: Kevin Forchione
>> Cc: dev at racket-lang.org
>> Subject: Re: [racket-dev] 2htdp/image Feature Suggestion
>>
>> On 2014-06-22 20:27:21 -0700, Kevin Forchione wrote:
>> >    Thanks! Is there any documentation or guide on which
>> *styles* to prefer in
>> >    writing Racket code? I find myself scratching my head at
>> times in these
>> >    matters!
>>
>> In recent Racket distributions and online docs there's now a style
>> manual:
>>
>>   http://docs.racket-lang.org/style/index.html
>>
>> Cheers,
>> Asumu
>> _________________________
>>   Racket Developers list:
>>   http://lists.racket-lang.org/dev
>
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

Posted on the dev mailing list.