I wouldn't suggest using `set!` that way -- I'm a big fan of internal `define`.
Sam
On Thu, Jul 6, 2017 at 12:19 PM, David Storrs wrote:
>
>
> On Thu, Jul 6, 2017 at 8:53 AM, Sam Tobin-Hochstadt
> wrote:
>>
>> Just for clarity, here's an example
On Thu, Jul 6, 2017 at 8:53 AM, Sam Tobin-Hochstadt
wrote:
> Just for clarity, here's an example using `set!` and `define`,
> although I wouldn't really suggest this style:
>
> #lang typed/racket
>
> (: f : Real -> Real)
> (define (f x)
> (define rand-value (random))
>
Just for clarity, here's an example using `set!` and `define`,
although I wouldn't really suggest this style:
#lang typed/racket
(: f : Real -> Real)
(define (f x)
(define rand-value (random))
(define new-value (+ x rand-value))
(set! new-value (- new-value x))
new-value)
Sam
On Wed,
Well, after a bit of fiddling, I've discovered I can indeed do what I need to,
with a judicious use of "let" for creating a swag of random values, and
ensuring that their use is all within the scope of let. So far, all good!
On Thursday, 6 July 2017 10:54:53 UTC+10, Royall Spence wrote:
>
Sounds like two questions wrapped into one. When it comes to setting
names to values, Scheme programming encourages the use of a "let"
expression to bind values to names inside of a (usually narrow) scope
rather than assigning a value to a variable. See more here:
I'm doing a little programming which requires the use of some random numbers.
Basically I add a random value at one stage, and subtract it a bit later.
Something like this pseudo-code (where "x" is an existing variable):
set rand_value <- (random)
set new_value <- x + rand_value
...
6 matches
Mail list logo