> On Oct 13, 2017, at 9:19 PM, David Storrs <david.sto...@gmail.com> wrote: > > On Fri, Oct 13, 2017 at 2:57 PM, Matthias Felleisen > <matth...@ccs.neu.edu> wrote: >> >>> On Oct 13, 2017, at 2:55 PM, David Storrs <david.sto...@gmail.com> wrote: >>> >>> On Fri, Oct 13, 2017 at 2:50 PM, David Storrs <david.sto...@gmail.com> >>> wrote: >>>> Coming from a Perl background, I've long had a convention of naming >>>> private functions with a leading underscore, e.g. _do-the-thing. Is >>>> there a standard Racket convention for this and, if so, what is it? >>> >>> Addendum: I know that I can define functions inside the function for >>> which they are the helper, but my understanding is that if I do that >>> then the helper function is recompiled every time the parent function >>> is executed. >>> >>> (define (flurble args) >>> (define (helper-func) ...do stuff...) >>> (helper-func ...)) >>> >>> (for ((i 10000)) >>> (flurble i)) ; helper-func will be built 10,000 times, right? >> >> >> No it isn’t recompiled. But the run-time may allocate a closure a second >> time. >> Lambda lifting and similar techniques should avoid this but not necessarily >> in >> the current compiler. > > > (define (foo x) > (for ((i 10000)) > (define (bar) x) > (bar))) > > So bar will be allocated 10,000 times in the above? How about baz and > jaz in the below?
This kind of situation is covered by ‘lightweight closure’ conversion, which we added in the late 90s and should still be there. Note how all instances of bar are identical. No need to re-allocate. > > > (define (foo x) > (define (baz) 8) > (define (jaz) x) > (println (jaz)) > (baz)) > > (for ((i 10000)) > (foo 7)) Again, baz is covered trivially. Only a whole-program analysis can confirm that foo is applied to only 7 and therefor jaz is the same closure on every call to foo. ;; - - - Note that programs can use eq? to compare closures. I am ignoring this aspect. -- 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.