[CM] About set!

Christos Vagias chris.actondev at gmail.com
Sat Jun 27 13:44:07 PDT 2020


Hi all,

I'm diving slowly into s7, and I stumbled upon this
---
(define (inc! x)
  (format #t "increasing x: ~A" x)
  (set! x (+ 1 x))
  (format #t "x is now ~A" x))

(define x 0)
(inc! x)
(inc! x)
x ;; x is still 0

---

What is my basic misunderstanding here?
Of course I could make a pure function (inc x), but I want to know what
happens here.

I have the vague idea that one could manage to have this inc! function with
environments.
"box" from chez scheme is more or less the concept i'm going for
https://cisco.github.io/ChezScheme/csug9.5/objects.html#./objects:s82

(let ([incr!
       (lambda (x)
         (set-box! x (+ (unbox x) 1)))])
  (let ([b (box 3)])
    (incr! b)
    (unbox b))) => 4

How does one implement this in s7?

Thanks,
Christos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20200627/fa3e9a35/attachment.html>


More information about the Cmdist mailing list