Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAMED-CLOSURE is broken -- environment sharing #1

Open
kchanqvq opened this issue Jan 23, 2022 · 0 comments
Open

NAMED-CLOSURE is broken -- environment sharing #1

kchanqvq opened this issue Jan 23, 2022 · 0 comments

Comments

@kchanqvq
Copy link
Owner

Thanks to u/style-warning:

(defun rw (x)
  (values (named-closure:nclo reader () x)
          (named-closure:nclo writer (y) (setf x y))))

(defun rw* (x)
  (values (lambda () x)
          (lambda (y) (setf x y))))

(defun test (c)
  (multiple-value-bind (r w) (funcall c 0)
    (format t "> ~D~%" (funcall r))
    (funcall w 1)
    (format t "> ~D~%" (funcall r))))

then

CL-USER> (test #'rw)
> 0
> 0
NIL
CL-USER> (test #'rw*)
> 0
> 1
NIL

Potential fix:

  1. Use reader/writer (native) closures in the funcallable instance slots.
  2. If we know about the CL implementation, use the internal value cells.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant