Skip to content

Conversation

@mflatt
Copy link
Contributor

@mflatt mflatt commented Aug 13, 2025

Addresses #969.

@mflatt mflatt merged commit 2f4c2cc into cisco:main Aug 17, 2025
16 checks passed
@LiberalArtist
Copy link
Contributor

While many procedures follow the naming convention type-verb, the precedents set-car! and set-cdr! led me to expect these names to be cas-car! and cas-cdr! (since they abbreviate e.g. compare-and-set-car!). Arguably, this correspondence may already be broken, since we have box-cas! despite set-box!. On the other hand, a difference is that a box is a type of value, whereas car and cdr are fields in a pair type. Chez Scheme doesn't have very many operations on boxes, but box-immutable and box-immobile both use box- as a prefix, whereas the only other entry in the index that uses car or cdr is lisp-cdr (from TSPL).

I don't have a strong opinion beyond “naming things is hard”, but I thought it was worth at least mentioning before this makes it into a release.

@JBThiel
Copy link

JBThiel commented Aug 27, 2025

I suppose the -cas! naming originates from vector-set! and would best be consistent,
else confusing. The vector and bytevector have many -set!
functions, thus vector-cas!.
And box-cas! followed that, being essentially a 1-vector so you don't need an index.

I had proposed pair-cas! with an "index" designator of maybe the symbols 'car / 'cdr
to parallel the (vector-cas! vector index ...), but it's more verbose,
and not many functions take symbol args like that.

car-cas! and cdr-cas! are short and sufficiently mnemonic to me, and follow the
convention so far. Also cas as the suffix connects to the !, looks visually
distinctive.

cas- prefix is sensible too, for the reasons you mention.

I tend to think of cas! as a highly distinct operation, not really a set,
much more complicated than that. It might very well not set, and generally
requires additional logic around it. It's akin to -lock! to my sense,
which all the lock functions have as suffix.

Whether CAS prefix or suffix I'm relatively impartial, except I think it should be consistent, because a distinct conceptual domain.
So since it's -cas! suffix for the vector/box, that should probably continue,
unless wanting to re-think / rename all of them.

@mflatt
Copy link
Contributor Author

mflatt commented Aug 28, 2025

I don't have a strong opinion, either. The other names I consider where pair-car-cas! and pair-cdr-cas! to more closely follow record - field -set!, but there aren't other functions that start pair. So, I went with the way car and cdr could be viewed as abbreviating pair-car and pair-cdr in existing function names — still keeping them at the front and cas! at the end, along the lines of the modern Scheme style and existing cas! functions.

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

Successfully merging this pull request may close these issues.

4 participants