shithub: sl

Download patch

ref: c07007dc7ac255eaed3e1f9da20ba02974d9f950
parent: b2cdf4d1a5f0fe3432782bfd31595124f0cd5a0a
author: spew <spew@cbza.org>
date: Wed Apr 23 09:46:38 EDT 2025

simplify copy-list, add tests

--- a/boot/sl.boot
+++ b/boot/sl.boot
@@ -54,10 +54,10 @@
 ist)
   (: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)
-oc-group . list)
+oc-group . list)
 al? ((:doc-group . compare)
   (:doc-group . builtin))  eqv? ((: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)
-te-doc-from-body ((:doc-group . doc))  set-cdr! ((:doc-group . list)
+te-doc-from-body ((:doc-group . doc))  set-cdr! ((:doc-group . list)
 -group . compress))  arg-counts ((:doc-group . builtin))  eq? ((:doc-group . compare)
   (:doc-group . builtin))  getprop ((:doc-group . prop) (:doc-see . putprop))  vm-stats ((:doc-group . vm))  * ((:doc-group . builtin))  putprop ((:doc-group . prop)
   (:doc-see . getprop))  io->str ((:doc-group . io))))
@@ -96,7 +96,7 @@
 >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
   0) help-print-header #fn(sym) ":doc-" doc getprop *doc* *formals-list* #0#
   #fn("n313?02021820>2162:72504738251474061:" #(#fn(for-each)
- #(#fn(for-each)
+ #(#fn(for-each)
 int) print-sig)
   #fn("n12002152853;0220E8563:0:" #(#fn(str-find) "\n" #fn(str-sub)) first-line)
   #fn("n10B;3B040<20Q;38040T21Q:" #(doc group) doc-group?)
@@ -106,7 +106,7 @@
 formals-list* "    ")) void
   "no help for " #fn(str) " " "" " (undefined)"))  defstruct #fn("z0700=5185<85=0<I21228887>2?9514863H0738824862589Pe15252@30q42627e188e178875163:" #(separate-doc-from-body
   #0# #fn("n12002152853=0220E8553@300853<02208552@402324752627AF5351285229862:7;882<528764:" #(#fn(str-find)
-struct "\n" #fn(str) "\n\n    "
+struct "\n" #fn(str) "\n\n    "
 %defstruct% copy-list))  bcode:ctable #fn("n1200Ke3:" #(aref))  with-output-to #fn("z12021e1220e2e1e17315163:" #(#fn(nconc)
   with-bindings *io-out* copy-list))  catch #fn("n22012122e123242522e2262722e22829e2e3262:22e20e3e42;22e22<22e2e4e3e3:" #(trycatch
   λ #:g470 if and cons? eq? car quote thrown-value cadr caddr raise))  let* #fn("z10H3E02021e1qe17215153e1:2021e173051e1e1720=B3H02024e10=e17215153e1@301515375051e2:" #(#fn(nconc)
@@ -234,8 +234,8 @@
 540r40r4GKMp486360q@9072023524720858;5340r40r4Gr/Mp486360q@907202452475018283=84858657486340q:720268;63:" #(compile-in
   #fn(gensym) emit dup pop compile-short-circuit label) compile-short-circuit)
             compile-sym #fn("n470821E538821C`02282513M073248251513@07502624825163:750278263:88<El23W0750287988=51534833A088=T3:07502:62:q:7502;7<08252534833A088=T3:07502:62:q:" #(lookup-sym
-251513@07502624825163:750278263:88<El23W0750287988=51534833A088=T3:07502:62:q:7502;7<08252534833A088=T3:07502:62:q:" #(lookup-sym
-  global #fn(const?) printable? #fn(top-level-value) emit loadv loadg loada vinfo:index car loadc
+251513@07502624825163:750278263:88<El23W0750287988=51534833A088=T3:07502:62:q:7502;7<08252534833A088=T3:07502:62:q:" #(lookup-sym
+  global #fn(const?) printable? #fn(top-level-value) emit loadv loadg loada vinfo:index car loadc
   capture-var!) compile-sym)
             compile-thunk #fn("n170q21q72051e362:" #(compile-f λ lower-def) compile-thunk)
             compile-while #fn("n4205020507101q72505440r40r4GKMp473024885347101q825447302589534730265240r40r4Gr/Mp47101q835447302788534730248963:" #(#fn(gensym)
@@ -509,7 +509,7 @@
 085A<0=51P:" #(length> subseq) formals-clean)
   #fn(str?) #fn(map) str-join #fn(str-split) "\n" any #fn("n1E20051L2;3B04210E5222Q;34040:" #(#fn(str-length)
   #fn(str-rune) #\space)) #fn(length) str-trim " " "" #fn("n170A2105152390220A62:0:" #(<= #fn(length)
-(str-sub)))
+(str-sub)))
 ))
   #fn(append) void) sym-set-doc)
             table-clone #fn("n12050212285>1q053485:" #(#fn(table)
--- a/src/system.sl
+++ b/src/system.sl
@@ -514,17 +514,15 @@
         (else        (> (length seq) n))))
 
 (def (copy-list seq (n NIL))
-  (def (copy- tail seq n)
+  (def (copy- last seq n)
     (and n (= n 0) (return))
     (unless seq (return))
     (let {[next (cons (car seq) NIL)]}
-      (set-cdr! tail next)
+      (set-cdr! last next)
       (copy- next (cdr seq) (and n (1- n)))))
-  (and (if n (> n 0) T)
-       seq
-       (let {[head (cons (car seq) NIL)]}
-         (copy- head (cdr seq) (and n (1- n)))
-         head)))
+  (let {[fst (cons NIL NIL)]}
+    (copy- fst seq n)
+    (cdr fst)))
 
 (def (subseq seq start (end NIL))
   (unless (length> seq (1- start)) (bounds-error "start" start))
--- a/test/unittest.sl
+++ b/test/unittest.sl
@@ -429,7 +429,11 @@
 
 ;; list copying
 (assert (equal? (copy-list (iota 50)) (iota 50)))
+(assert (equal? (copy-list (iota 50) 51) (iota 50)))
 (assert (equal? (copy-list (iota 50) 25) (iota 25)))
+(assert (not (copy-list NIL 25)))
+(assert (not (copy-list NIL)))
+(assert (not (copy-list (iota 50) 0)))
 (let* {[l (iota 10)]
        [c (copy-list l)]}
   (aset! l 3 5)