Browse files

make copy work with nested lists and tables

  • Loading branch information...
1 parent 2978053 commit 4a5bad8a4fa3c60a6e270285c5a98af9d0faf17f @akkartik akkartik committed Nov 12, 2012
Showing with 24 additions and 21 deletions.
  1. +24 −21 arc.arc
View
45 arc.arc
@@ -80,12 +80,11 @@
; (def list args args)
-(def copylist (xs)
- (if (no xs)
- nil
- (cons (car xs) (copylist (cdr xs)))))
-
-(def list args (copylist args))
+(def list args
+ (if no.args
+ nil
+ (cons car.args
+ (apply list cdr.args))))
(def idfn (x) x)
@@ -1254,22 +1253,26 @@
(def write-table (h (o o (stdout)))
(write (tablist h) o))
+(def copylist (xs)
+ (if acons.xs
+ (cons (copylist car.xs)
+ (copylist cdr.xs))
+ xs))
+
(def copy (x . args)
- (let x2 (case (type x)
- sym x
- cons (copylist x) ; (apply (fn args args) x)
- string (let new (newstring (len x))
- (forlen i x
- (= (new i) (x i)))
- new)
- table (let new (table)
- (each (k v) x
- (= (new k) v))
- new)
- (err "Can't copy " x))
- (map (fn ((k v)) (= (x2 k) v))
- (pair args))
- x2))
+ (ret ans (case type.x
+ sym x
+ cons copylist.x
+ string (let new (newstring len.x)
+ (forlen i x
+ (= new.i x.i))
+ new)
+ table (ret new (table)
+ (each (k v) x
+ (= new.k copy.v)))
+ (err "Can't copy " x))
+ (map (fn ((k v)) (= ans.k v))
+ pair.args)))
(def shr (n m)
(shl n (- m)))

0 comments on commit 4a5bad8

Please sign in to comment.