feat: extensible lenses, add functionalize method for fset

This commit is contained in:
Edward Langley
2025-02-01 12:54:06 -08:00
parent 7618f95482
commit 742a155e91
2 changed files with 28 additions and 5 deletions

View File

@ -210,10 +210,26 @@ contain the new value at the location focused by the lens."
(defun a-lens (cb)
(lambda (foo)
(fw.lu:prog1-bind (new (clone foo))
(setf (a new)
(funcall cb (a foo))))))
(setf (a new)
(funcall cb (a foo))))))
(view 'a-lens
(over 'a-lens '1+
(set 'a-lens 2
(make-instance 'foo :a 1)))) #|
==> 3 |#)
(defgeneric generic-lens (rec cb loc)
(:method ((rec hash-table) cb loc)
(funcall (funcall (make-hash-table-lens loc)
cb)
rec))
(:method ((rec vector) cb loc)
(funcall (funcall (make-list-lens loc)
cb)
rec)))
(defun lens (loc)
"extensible lens using a multimethod for internal implementation"
(lambda (cb)
(lambda (rec)
(generic-lens rec cb loc))))