Skip to content

Commit 2d86c31

Browse files
committed
Seems like Samuel Christie was trying to get len to count the final element of improper lists; may be a good idea. Make that work while making length of symbols be 0 (http://arclanguage.org/item?id=14970).
1 parent 29de976 commit 2d86c31

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

arc.arc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,15 +1779,17 @@
17791779
(defgeneric len(x)
17801780
(if x ($.length $.ac-denil.x) 0))
17811781

1782+
; (len '(1 2 3)) => 3
1783+
; (len 'a) => 0
1784+
; (len '(1 2 . 3)) => 3
17821785
(defmethod len(x) cons
1783-
((afn (x l)
1784-
(aif (and acons.x cdr.x)
1785-
(self it ++.l)
1786-
++.l))
1787-
x 0))
1786+
(if
1787+
(acons cdr.x) (+ 1 (len cdr.x))
1788+
(no cdr.x) 1
1789+
2)) ; dotted list
17881790

17891791
(defmethod len(x) sym
1790-
(if x 1 0))
1792+
0)
17911793

17921794
(defmethod len(x) vec
17931795
($.vector-length x))

0 commit comments

Comments
 (0)