On Jul 25, 2015, at 12:20 AM, Alexander D. Knauth <alexan...@knauth.org> wrote:

> 
> On Jul 24, 2015, at 11:29 PM, sagyo12341...@gmail.com wrote:
> 
>> Nice to meet you.
>> 
>> 
>> I'm a racket beginner and I'm not a English speaker. Please forgive my poor 
>> skills.
>> 
>> In racket tutorials or HtDP, it uses some local definitions, as follows:
>> 
>> (define (f x)
>> (local [((define g x) (add1 x))]
>>   (f (g x)))).
>> 
>> I'm not sure about the difference from the code:
>> 
>> (define (f x)
>> (define (g x) (add1 x))
>> (f (g x))).
>> 
>> Please help me. Thank you.
>> 
>> Taro
> 
> Other than the misplaced paren typo in the first bit of code, these will do 
> exactly the same thing.

It's a matter of style. (Unless of course you're in an HTDP language that 
doesn't support internal definitions.)

There are times when I prefer local, for instance, when I want to clearly 
separate the definitions from the last expression, or when I want to indent the 
definitions more than the last expression.  

But there are also many times when an internal definition context is just more 
convenient, since comes with less keystrokes, less parens, and less 
indentation, and a bit more flexibility, especially if I want to put some 
debugging or error checking code in 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.

Reply via email to