[racket] Why choose the 'let*' construct over the 'define' construct when both can have sequential scope?
I recommend a macro for these situations, it's almost always what you want:
(thread-through x e_0 e ...)
==
(let ([x e_0])
(set! x e)
...
x)
(you can also use let* here).
This brings across what you're really doing.
On Feb 19, 2015, at 1:32 PM, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> We have let and let*, but only define. I miss define* at times.
>
> This is an error:
>
> (block
> (define x 4)
> (define x (+ x 1))
> (+ x 2))
>
> With a define* it becomes:
>
> (block
> (define x 4)
> (define* x (+ x 1))
> (+ x 2))
>
> which (should) expand to:
>
> (block
> (define x 4)
> (block
> (define x (+ x 1))
> (+ x 2)))
>
> /Jens Axel
>
> 2015-02-19 19:24 GMT+01:00 Laurent <laurent.orseau at gmail.com>:
>> But in such situations you can be vicious and abuse `let` to have your
>> `define`s:
>> (let ()
>> (define x 3)
>> (define y 4)
>> (list x y))
>>
>> It's even more vicious if you use `let*` instead of `let`, but quite less if
>> you use `begin` instead ;)
>>
>>
>>
>> On Thu, Feb 19, 2015 at 5:49 PM, Matthias Felleisen <matthias at ccs.neu.edu>
>> wrote:
>>>
>>>
>>> In some places, you are allowed only one expression, and for that
>>> situation, you need let*.
>>>
>>>
>>> On Feb 19, 2015, at 12:40 PM, Don Green <infodeveloperdon at gmail.com>
>>> wrote:
>>>
>>>> What is/are the reason(s) for choosing the 'let*' construct over the
>>>> 'define' construct?
>>>>
>>>> (define (print-two f)
>>>> (let* ([_ (print (first f))]
>>>> [f (rest f)]
>>>> [_ (print (first f))]
>>>> [f (rest f)])
>>>> f))
>>>>
>>>> (define print-two
>>>> (lambda (f)
>>>> (print (first f))
>>>> (set! f (rest f))
>>>> (print (first f))
>>>> (set! f (rest f))
>>>> f))
>>>>
>>>> (void (print-two '(1 2))) ;=> 12
>>>>
>>>> ____________________
>>>> Racket Users list:
>>>> http://lists.racket-lang.org/users
>>>
>>>
>>> ____________________
>>> Racket Users list:
>>> http://lists.racket-lang.org/users
>>
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>
>
>
>
> --
> --
> Jens Axel Søgaard