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

Feature Request: Provide a default value #21

Open
phmarek opened this issue Jan 26, 2024 · 3 comments
Open

Feature Request: Provide a default value #21

phmarek opened this issue Jan 26, 2024 · 3 comments

Comments

@phmarek
Copy link

phmarek commented Jan 26, 2024

Currently it's not possible to run

(incf (accesses o (1 :type array)) 15)

because the initial value is NIL, which can't be incremented.

How about allowing this here?

(incf (accesses o (1 :type array :default 0)) 15)
@vindarel
Copy link

Hi, wdyt of this?

(incf (or (accesses …) 
           0))

@phmarek
Copy link
Author

phmarek commented Jan 28, 2024

Well, to be honest, I don't like it.

(let ((x (make-hash-table)))
  (incf (or (gethash 1 x) 0)))

doesn't work either (at least in SBCL), and it reads like (incf 0) which hurts my eyes. Sorry.

The point is that the read-form and the write-form of access:accesses need to be different, right?

@phoe
Copy link
Collaborator

phoe commented Jan 28, 2024

If we follow the gethash example, in (incf (gethash 1 x 0)) the 0 default value is evaluated and possibly discarded if the hash table already has a value. I assume that modifying accesses with a default would need to work the same way in order to maintain the semantics of "the place should look the same no matter if we read or write from it".

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

3 participants