
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Demonstrate how to get the address of a variable and how to set the address of a variable.




;;; Demonstration of references by swapping two variables using a function rather than a macro
;;; Needs http://paste.lisp.org/display/71952
(defun swap (ref-left ref-right)
  ;; without with-refs we would have to write this:
  ;; (psetf (deref ref-left) (deref ref-right)
  ;;        (deref ref-right) (deref ref-left))
  (with-refs ((l ref-left) (r ref-right))
    (psetf l r r l)))
 
(defvar *x* 42)
(defvar *y* 0)
 
(swap (ref *x*) (ref *y*))
 
;; *y* -> 42
;; *x* -> 0