https://github.com/stylewarning/cl-locatives
https://github.com/stylewarning/cl-locatives
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stylewarning/cl-locatives
- Owner: stylewarning
- License: bsd-3-clause
- Created: 2023-04-09T22:06:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-09T22:17:17.000Z (about 3 years ago)
- Last Synced: 2025-03-25T23:34:10.390Z (over 1 year ago)
- Language: Common Lisp
- Size: 2.93 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
CL-LOCATIVES
============
By Robert Smith
Locatives are the Lisp equivalent of pointers, minus the
arithmetic. In Lisp terms, they make the concept of "places"
first-class.
The main API consists of the macro LOCATIVE-FOR, which takes as an
argument a place, as you would give to SETF; and the function
DEREFERENCE, which extracts the value of that place, and (SETF
DEREFERENCE), which sets the value of that place.
The following example pretty much sums up the API:
(let* ((x (make-array 5 :initial-element 0))
(l (locative-for (aref x 2))))
(setf (dereference l) 5)
(list l
x
(dereference l)))
gives
(# #(0 0 5 0 0) 5)
as a result. We also have LOCATIVEP, and you can funcall the
LOCATIVE-WRITER of a locative if you need to deal with multiple values
(a rare case).
This code can be very useful for porting over C code which uses
pointers and by-reference values a lot.