shithub: sl

Download patch

ref: 46c9dda9f4646dc98ba727ba0de916f23fabd1a7
parent: 86a953cd83d7d4ff8e4940b6469659af9cfede49
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Apr 24 12:39:15 EDT 2025

fix length> and length= for one-element sequences that aren't lists

--- 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    "
@@ -332,8 +332,8 @@
 in-env? 7)
             index-of #fn("n31J40q:01<C5082:7001=82KM63:" #(index-of) index-of 9) inlineable?
             #fn("n10<85B;3t0485<20Q;3i047185T51;3]04727385T52;3O047485T2552S;3@047685T270=5162:" #(λ
-ineable? 9)
-            io-readall #fn("n1205021850524228561:" #(#fn(buffer)
+ineable? 9)
+            io-readall #fn("n1205021850524228561:" #(#fn(buffer)
 io-readall 8)
             io-readline #fn("n12002162:" #(#fn(io-readuntil) #\newline) io-readline 7) io-readlines
             #fn("n17071062:" #(read-all-of io-readline) io-readlines 7) iota #fn("n17071062:" #(map-int
@@ -527,7 +527,7 @@
 ength) 1- #fn("n1A0F~920Gp:" 8)) subseq-av 9)
   vec-alloc arr? #fn(type-of) #fn("n120A0E63:" #(#fn(arr-alloc)) 8)) subseq 10)
             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/system.sl
+++ b/src/system.sl
@@ -527,13 +527,11 @@
    work and always terminates."
   :doc-group list
   (cond ((< n 0)     NIL)
-        ((= n 0)     (atom? seq))
         ((cons? seq) (length= (cdr seq) (- n 1)))
         (else        (= (length seq) n))))
 
 (def (length> seq n)
   (cond ((< n 0)     T)
-        ((= n 0)     (and (cons? seq) seq))
         ((cons? seq) (length> (cdr seq) (- n 1)))
         (else        (> (length seq) n))))
 
--- a/test/unittest.sl
+++ b/test/unittest.sl
@@ -200,6 +200,20 @@
 (assert (equal? 0 (if (and '(1) 1 'x NIL) 2 0)))
 (assert (equal? 0 (if (or NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL) 2 0)))
 
+; bounded length tests
+(assert (length> #(1) 0))
+(assert (not (length> #(1) 1)))
+(assert (not (length> #() 0)))
+(assert (length= #() 0))
+(assert (not (length= #() 1)))
+(assert (not (length= #(1) 0)))
+(assert (length> '(1) 0))
+(assert (not (length> '(1) 1)))
+(assert (not (length> '() 0)))
+(assert (length= '() 0))
+(assert (not (length= '() 1)))
+(assert (not (length= '(1) 0)))
+
 ; proper/dotted/circular list tests
 (assert (not NIL))
 (assert (not (cons? NIL)))