Actually nvm. Whoever wrote such macro could have just used `begin0` 
instead.

On Monday, October 1, 2018 at 2:34:23 PM UTC-4, Phil Nguyen wrote:
>
> (Racket 7.0) This program runs in no time:
>
> (define (sum n acc)
>   (if (> n 0)
>       (sum (- n 1) (+ acc n))
>       acc))
>
> (collect-garbage) (collect-garbage) (collect-garbage)
> (time (sum 10000000 0))
> ; cpu time: 47 real time: 57 gc time: 0
> ; 50000005000000
>
> This slightly modified program runs significantly slower:
>
> (define (sum n acc)
>   (if (> n 0)
>       (let ([ans (sum (- n 1) (+ acc n))])
>         ans)
>       acc))
>
> (collect-garbage) (collect-garbage) (collect-garbage)
> (time (sum 10000000 0))
> ; cpu time: 1719 real time: 1872 gc time: 1064
> ; 50000005000000
>
> While the call to `sum` in the second program is not in tail position, I 
> wonder if this kind of code happens often enough from macro expansion to 
> benefit from an optimization.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to