Re: [racket-users] Question about structuring recursive code

2015-09-25 Thread Kaushik Ghose
On Wed, Sep 23, 2015 at 11:40 PM, Alexis King wrote: > > Er, no you can’t... `begin` doesn’t create an internal definition context > (or even a new scope). You can use an empty `let` instead: > > (define (f x) > (if (even? x) > (/ x 2) > (let () > (define a (* x 2)) >

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Alexis King
> Ok. Yeah, if- branches aren't allowed to have definitions, or even sequences > of operations. You can get around this with begin Er, no you can’t... `begin` doesn’t create an internal definition context (or even a new scope). You can use an empty `let` instead: (define (f x) (if (even? x)

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Very neat! Thank you! Best -Kaushik On Wed, Sep 23, 2015 at 7:46 PM, Benjamin Greenman < benjaminlgreen...@gmail.com> wrote: > > On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose > wrote: > >> I haven't gotten to cond yet. > > > Ok. Yeah, if- branches aren't allowed to have definitions, or even > s

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Benjamin Greenman
On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose wrote: > I haven't gotten to cond yet. Ok. Yeah, if- branches aren't allowed to have definitions, or even sequences of operations. You can get around this with begin: (define (f x) (if (even? x) (/ x 2) (begin (define a (* x

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
PS On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose wrote: > Hi! > > On Wed, Sep 23, 2015 at 7:33 PM, Benjamin Greenman < > benjaminlgreen...@gmail.com> wrote: > >> Could you post the "ugly" code? I'm curious because things like this >> compile fine: >> >> The ugly code looks like: (define (f x)

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Hi! On Wed, Sep 23, 2015 at 7:33 PM, Benjamin Greenman < benjaminlgreen...@gmail.com> wrote: > Could you post the "ugly" code? I'm curious because things like this > compile fine: > > (define (f-recur x y) > (cond ((< x 1) > 10) > (else >(define z 3) >(f-recur x y > > I'm d

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Benjamin Greenman
Could you post the "ugly" code? I'm curious because things like this compile fine: (define (f-recur x y) (cond ((< x 1) 10) (else (define z 3) (f-recur x y On Wed, Sep 23, 2015 at 7:25 PM, Kaushik Ghose wrote: > > On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi >> wro

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
> On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi > wrote: > >> On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose >> wrote: >> >> > Can I have any statements in this block that I could have in a (define >> ...) >> > block? Can I have (defines ) for example? >> >> Yes, and yes :) >> > > Hmm. I

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Thank you very much for your help! Best -Kaushik On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi wrote: > On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose > wrote: > > > Can I have any statements in this block that I could have in a (define > ...) > > block? Can I have (defines ) for example

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Pierpaolo Bernardi
On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose wrote: > Can I have any statements in this block that I could have in a (define ...) > block? Can I have (defines ) for example? Yes, and yes :) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. T

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Hi! Thanks for your reply. > (define (f-recur x y) > (cond ((< x 1) > 10) > (else >... something complex > (f-recur x' y' > Can I have any statements in this block that I could have in a (define ...) block? Can I have (defines ) for e

Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Pierpaolo Bernardi
On Wed, Sep 23, 2015 at 3:20 PM, Kaushik Ghose wrote: > e.g. > > (define (f-recur x y) > (if (< x 1) > 10 > (f-recur-2 x y))) > > (define (f-recur-2 x y) > ... something complex here > (f-recur x' y') (define (f-recur x y) (cond ((< x 1) 10) (else

[racket-users] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Hi Folks, In recursive functions there is a termination clause that the function first tests for before proceeding. If the test clause succeeds an immediate value is returned, otherwise, a recursive call is made with some modification of input values. In much code the body of the recursive fun