ref: 0c6a147ba320d1665fd80f4a4d427c3c4e8b992a
parent: 5a4fb16e97cf9ed17c7d80cbfb17c7412d544da6
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Apr 24 12:54:52 EDT 2025
length: return the length in full runes when passed a string
--- a/boot/sl.boot
+++ b/boot/sl.boot
@@ -54,10 +54,10 @@
oup . doc)) aref ((:doc-group . builtin)) *properties* ((:doc-group . prop)) vec ((:doc-group . builtin)) >= ((:doc-group . compare)) sym? ((:doc-group . builtin)) zero? ((:doc-group . compare)) length= ((:doc-group . list)) positive? ((:doc-group . compare)) doc-for ((:doc-group . doc)) aset! ((:doc-group . builtin)) T ((:doc-see)) car ((:doc-group . list)
(:doc-group . builtin)) *builtins* ((:doc-group . builtin)) str ((:doc-group . string)) cons ((:doc-group . list)
(:doc-group . builtin)) - ((:doc-group . builtin)) remprop ((:doc-group . prop)) <= ((:doc-group . compare)) rand ((:doc-group . rand)) negative? ((:doc-group . compare)) Instructions ((:doc-group . builtin)) file ((:doc-group . io)) rand-double ((:doc-group . rand)) cdr ((:doc-group . list)
--group . builtin)) str ((:doc-group . string)) cons ((:doc-group . list)
+-group . builtin)) str ((:doc-group . string)) cons ((:doc-group . list)
c-group . prop)) <= ((:doc-group . compare)) rand ((:doc-group . rand)) negative? ((:doc-group . compare)) Instructions ((:doc-group . builtin)) file ((:doc-group . io)) rand-double ((:doc-group . rand)) cdr ((:doc-group . list)
(:doc-group . builtin)) atom? ((:doc-group . builtin)) vec? ((:doc-group . builtin)) / ((:doc-group . builtin)) equal? ((:doc-group . compare)
-? ((:doc-group . compare) (:doc-group . builtin)) io? ((:doc-group . io)) eof-object? ((:doc-group . io)) list ((:doc-group . builtin)) apply ((:doc-group . builtin)) help ((:doc-group . doc)) rand-u32 ((:doc-group . rand)) = ((:doc-group . compare)
+? ((:doc-group . compare) (:doc-group . builtin)) io? ((:doc-group . io)) eof-object? ((:doc-group . io)) list ((:doc-group . builtin)) apply ((:doc-group . builtin)) help ((:doc-group . doc)) rand-u32 ((:doc-group . rand)) = ((:doc-group . compare)
oc-group . io)) list ((:doc-group . builtin)) apply ((:doc-group . builtin)) help ((:doc-group . doc)) rand-u32 ((:doc-group . rand)) = ((:doc-group . compare)
(:doc-group . builtin)) rand-u64 ((:doc-group . rand)) not ((:doc-group . builtin)) separate-doc-from-body ((:doc-group . doc)) set-cdr! ((:doc-group . list)
(:doc-group . builtin)) fn? ((:doc-group . builtin)) help-print-header ((:doc-group . doc)) lz-pack ((:doc-group . compress)) arg-counts ((:doc-group . builtin)) eq? ((:doc-group . compare)
@@ -100,7 +100,7 @@
200r3e3:" #(aref) 7) mark-label #fn("n22002122e21e4:" #(emit
quote label) 8) quasiquote #fn("n1700E62:" #(bq-process) 7) > #fn("z12021e1721510e163:" #(#fn(nconc)
< reverse) 8) when #fn("z1200211Pqe4:" #(if begin) 8) help #fn("O100010003000W1000J60q?14W2000J7071?241;3<0422231520P13;02410e3@3007588265275882752IIIIIb;b<288;29_514288<2:_514282;?=514282<87>1?>514282=??51402>CM02?2@8<>18?2A7B26528=5252@$089;J5048:3\xe3082888:2C154475882D527E2F8@527E2G8@52893H07H7I2J898A535147K50@30q48B3W07K5047H2L5147K5042?2M8;>18B5247K50@30q^1^1^1413c07K5047H2N5147K5042?2O8;>18?2A7B26528>525247K50@30q47P50@g07H2Q13<02R12S52@402T05341JE00R3@00ZJ;07H2U51@30q47K5047P60:" #(#(:print-header
-88:2C154475882D527E2F8@527E2G8@52893H07H7I2J898A535147K50@30q48B3W07K5047H2L5147K5042?2M8;>18B5247K50@30q^1^1^1413c07K5047H2N5147K5042?2O8;>18?2A7B26528>525247K50@30q47P50@g07H2Q13<02R12S52@402T05341JE00R3@00ZJ;07H2U51@30q47K5047P60:" #(#(:print-header
+88:2C154475882D527E2F8@527E2G8@52893H07H7I2J898A535147K50@30q48B3W07K5047H2L5147K5042?2M8;>18B5247K50@30q^1^1^1413c07K5047H2N5147K5042?2O8;>18?2A7B26528>525247K50@30q47P50@g07H2Q13<02R12S52@402T05341JE00R3@00ZJ;07H2U51@30q47K5047P60:" #(#(:print-header
12S52@402T05341JE00R3@00ZJ;07H2U51@30q47K5047P60:" #(#(:print-header
0) help-print-header #fn(sym) ":doc-" doc getprop *doc* *formals-list* #0#
#fn("n313?02021820>2162:72504738251474061:" #(#fn(for-each)
@@ -110,7 +110,7 @@
#fn("n3A051370082P:82:" 6) <) table-keys-filter-sort 9) groups #fn(for-each)
#fn("n1707105122A<7302452515347560:" #(princ caddr ": " getprop *doc* newline) 11)
#fn(get) *properties* :kind *doc-extra* filter #fn("n10<20Q:" #(:doc-fmt) 6)
-9) "Members:" #fn("n1A<070021522263:" #(getprop *formals-list* " ") 9)
+9) "Members:" #fn("n1A<070021522263:" #(getprop *formals-list* " ") 9)
" " "" " (undefined)") 21) defstruct #fn("z0700=5185<85=0<I21228887>2?9514863H0738874862589Pe15252@30q42627e188e178875163:" #(separate-doc-from-body
#0# #fn("n12002152853=0220E8553@300853<02208552@402324752627AF5351285229862:7;882<528764:" #(#fn(str-find)
"\n\n" #fn(str-sub) "" #fn(str-split) print-to-str #fn(list*) defstruct "\n" #fn(str) "\n\n "
@@ -498,11 +498,12 @@
t-syntax! 8) sort
#fn("O200010003000W2000J7071?240=J400:0<7223182870>42418287>362:" #(#(:key 0) identity
call-with-values #fn("n07021AF92>393=62:" #(partition
-nconc) sort :key) 12)) sort 8)
- splice-form? #fn("n10B;3X040<20Q;JN040<21Q;JD040<22Q;3:04730r252;J704022Q:" #(unquote-splicing
- unquote-nsplicing unquote length>) splice-form? 7)
+nconc) sort :key) 12)) sort 8)
+ splice-form? #fn("n10B;3X040<20Q;JN040<21Q;JD040<22Q;3:04730r252;J704022Q:" #(unquote-splicing
+ unquote-nsplicing unquote length>) splice-form? 7)
#fn("n120AF52420A062:" #(#fn(io-write)) 7)
- #fn(io->str)) str-join 8)
+ #fn("n120AF52420A062:" #(#fn(io-write)) 7)
+ #fn(io->str)) str-join 8)
3207182122051~52062:" #(#fn(str) str-rep #fn(str-length)) str-lpad 10)
str-map #fn("n2205021151EI8887L23O0422860231885251524748851?8@\f/^14258661:" #(#fn(buffer)
#fn(str-length) #fn(io-putrune) #fn(str-rune) 1+ #fn(io->str)) str-map 13)
@@ -527,7 +528,7 @@
("n1A0F~920Gp:" 8)) subseq-av 9)
vec-alloc #fn(str-sub) arr? #fn(type-of) #fn("n120A0E63:" #(#fn(arr-alloc)) 8)) subseq 12)
sym-set-doc #fn("z2Ib720872187>1_51422151883601@401<88360q@401=2387<825224Z3\xb40893\xaf0258926528<<8<=77288>528?;3H04298?51297:8?2;2<5351~8?;3?04232=8@>18>52748=8AP26527>02?8B5348:3>07>02@8:53@30q^1^1^1^1^1^1^1@30q48;B3[07A02B527C2D8<>18;527>02B7E8<8=5253^1^1@30q47F60:" #(#0#
-8;B3[07A02B527C2D8<>18;527>02B7E8<8=5253^1^1@30q47F60:" #(#0#
+8;B3[07A02B527C2D8<>18;527>02B7E8<8=5253^1^1@30q47F60:" #(#0#
23>07185Er253@4085A<0=51P:" #(length> subseq) formals-clean 9)
#fn(str?) #fn(map) str-join #fn(str-split) "\n" any #fn("n1E20051L2;3B04210E5222Q;34040:" #(#fn(str-length)
#fn(str-rune) #\space) 7) #fn(length) str-trim " " "" #fn("n170A2105152390220A62:0:" #(<= #fn(length)
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -101,6 +101,8 @@
}
if(isrune(a))
return fixnum(runelen(torune(a)));
+ if(isstr(a))
+ return size_wrap(u8_runelen(cvalue_data(a), cv_len(ptr(args[0])), nil));
if(iscvalue(a) && cv_class(ptr(a))->eltype != nil)
return size_wrap(cvalue_arrlen(a));
if(isvec(a))
--- a/src/system.sl
+++ b/src/system.sl
@@ -563,12 +563,9 @@
(cdr fst)))
(def (subseq seq start (end NIL))
- (def strlen (and (str? seq) (str-length seq)))
- (def (length>? seq n)
- (if strlen (> strlen n) (length> seq n)))
- (unless (length>? seq (1- start)) (bounds-error "start" start))
+ (unless (length> seq (1- start)) (bounds-error "start" start))
(unless (<= start end) (bounds-error "start <= end" (list start end)))
- (and end (not (length>? seq (1- end))) (bounds-error "end" end))
+ (and end (not (length> seq (1- end))) (bounds-error "end" end))
(def (subseq-l seq n)
(if (= n 0)
(copy-list seq (and end (- end start)))
--- a/test/unittest.sl
+++ b/test/unittest.sl
@@ -595,7 +595,7 @@
(def s2 "hello \t \n world\n ")
(assert (eq? 21 (sizeof s)))
-(assert (eq? 21 (length s)))
+(assert (eq? 11 (length s)))
(assert (eq? 11 (str-length s)))
(assert (eq? 11 (str-length s 0)))
(assert (eq? 10 (str-length s 2 (sizeof s) nil)))