Permalink
Browse files

Arrays version, but don't rebase.

  • Loading branch information...
0 parents commit 0e3ac57819bc467f8412b8d905d1d9391db54266 @smithzvk committed Jun 14, 2011
Showing with 32 additions and 0 deletions.
  1. +32 −0 versioned-arrays.lisp
@@ -0,0 +1,32 @@
+
+(defpackage :versioned-arrays
+ (:use :cl :bt)
+ (:export #:make-versioned-array
+ #:varef ))
+
+(in-package :versioned-arrays)
+
+(modf-def:defstruct ver-array mods array)
+
+(defun make-versioned-array (dimensions
+ &rest args
+ &key (element-type t)
+ initial-element initial-contents
+ adjustable fill-pointer
+ displaced-to displaced-index-offset )
+ "Make a versioned array."
+ (when (or adjustable fill-pointer displaced-to displaced-index-offset)
+ (error "The capabilities: adjustable, fill-pointer, displaced-to, displaced-index-offset are not implemented yet") )
+ (make-ver-array :mods nil :array (apply #'make-array dimensions args)) )
+
+(defun varef (v-arr &rest idx)
+ (let ((result
+ (iter:iter (iter:for (new-val . jdx) in (ver-array-mods v-arr))
+ (iter:finding new-val such-that (equal idx jdx)) )))
+ (if result
+ result
+ (apply #'aref (ver-array-array v-arr) idx) )))
+
+(modf:define-modf-function varef 1 (new-val v-arr &rest idx)
+ (modf:modf (ver-array-mods v-arr)
+ (cons (cons new-val idx) (ver-array-mods v-arr)) ))

0 comments on commit 0e3ac57

Please sign in to comment.