Adding to other replies:

At Thu, 20 Jul 2017 13:32:49 -0400, David Storrs wrote:
> Will any of the above items be compiled away?

You can compile a module with `raco make` and look at the compiled code
with `raco decompile`. If I put your code in a module and try that, the
output includes

    (define-values
     (_foo)
     (lambda ()
       ....
       (begin
         (values (file-size '"/some/path"))
         (let ((local22 (file-size '"/some/other/path")))
           (begin
             (|_displayln:p@(lib "racket/private/misc.rkt")|
              (#%sfs-clear local22))
             '#t)))))

So, you can see that the compiler discarded an addition that always
produces 2, and it discarded the unused `bar` function. It also got rid
of the unused `size` variable, but it preserved everything else as a
run-time computation.

> 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."

Assuming that you really want to do that and you really want a `state`
form:

  (define-syntax (state stx)
    (syntax-parse stx
      [(_ var:id rhs:expr)
       (with-syntax ([lifted-var (syntax-local-lift-expression #'rhs)])
         #'(define-syntax var (make-rename-transformer #'lifted-var)))]))

  (define (f v)
    (state accum 0)
    (set! accum (+ v accum))
    accum)

  (f 1)
  (f 2)

-- 
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.

Reply via email to