Given this code: (define (foo) (define num (+ 1 1)) ; result of a function that is program-local (define size (file-size "/some/path")) ; result of a function that touches the disk, but result never used (define other-size (file-size "/some/other/path")) ; result of function that touches disk, result is used (displayln other-size) (define x 7) ; binding of constant value, binding is never used (define (bar) ; binding of function, function is never used (displayln "bar")) #t)
(for ((i 5)) (foo)) Will any of the above items be compiled away? How many times will each thing be expanded and compiled -- is bar defined and compiled five separate times, only once, or not at all? Separate but related question: Perl has the 'state' declaration, which says "Declare this as a local variable, but keep it around with its value preserved after you exit the function." For example: sub foo { state $x = 0; say $x++; } # $x is not visible in this scope foo(); foo(); foo(); Output: 0 1 2 Is there a simple way to achieve the same thing in Racket? -- 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.