Last active
February 21, 2016 22:50
-
-
Save lispm/ded5176e05dc6d5428ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; http://xen.garden/wp/?p=25 | |
; Common Lisp version by Rainer Joswig, [email protected], 2016 | |
(defun create-symbol (prefix suffix) | |
(intern (format nil "~a-~a" prefix suffix) | |
(symbol-package suffix))) | |
(defun make-get-set (name | |
&aux | |
(getter (create-symbol "GET" name)) | |
(setter (create-symbol "SET" name))) | |
(let ((val nil)) | |
(setf (symbol-function getter) (lambda () val) | |
(symbol-function setter) (lambda (new-val) (setf val new-val))) | |
(values))) | |
(mapc #'make-get-set '(bat cat fat)) | |
; Using it: | |
; CL-USER 23 > (mapc #'make-get-set '(bat cat fat)) | |
; (BAT CAT FAT) | |
; CL-USER 24 > (get-bat) | |
; NIL | |
; CL-USER 25 > (get-cat) | |
; NIL | |
; CL-USER 26 > (set-bat 10) | |
; 10 | |
; CL-USER 27 > (set-cat 20) | |
; 20 | |
; CL-USER 28 > (get-bat) | |
; 10 | |
; CL-USER 29 > (get-cat) | |
; 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment