Skip to content

Commit a423894

Browse files
committed
Use length compare funs from Alexandria/Serapeum
1 parent 1537405 commit a423894

24 files changed

+70
-73
lines changed

command-line.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ directories and if files based on their extensions."
459459
(cond
460460
(project-p
461461
(best-guess guesses))
462-
((= 1 (length sources))
462+
((length= 1 sources)
463463
;; For a single file either return the guess, or return
464464
;; SIMPLE if no language matched.
465465
(or (car guesses) 'simple))
466-
((= 1 (length (remove-duplicates guesses)))
466+
((length= 1 (remove-duplicates guesses))
467467
;; Multiple non-project files must all be equal to return a guess.
468468
(or (car guesses) 'simple))))))
469469
(guess-helper sources nil)))

components/clang-tokens.lisp

+11-11
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ SOFTWARE."))
7272
(let ((children (child-asts root)))
7373
(switch ((ast-class root) :test #'equal)
7474
(:AddrLabelExpr
75-
(assert (<= 2 (length (source-text root))))
75+
(assert (length<= 2 (source-text root)))
7676
(list (token-from-string "&&") (token-from-string "identifier")))
7777
(:ArraySubscriptExpr
78-
(assert (= 2 (length children)))
78+
(assert (length= 2 children))
7979
(append (tokenize (first children))
8080
(list (token-from-string "["))
8181
(tokenize (second children))
8282
(list (token-from-string "]"))))
8383
;; no tokens, just proceed to children
8484
(:AttributedStmt (tokenize-children children))
8585
(:BinaryOperator
86-
(assert (= 2 (length children)))
86+
(assert (length= 2 children))
8787
(append (tokenize (first children))
8888
(list (token-from-string (ast-opcode root)))
8989
(tokenize (second children))))
@@ -101,7 +101,7 @@ SOFTWARE."))
101101
(tokenize-children (cdr children))))
102102
(:CharacterLiteral (list (token-from-string "char-literal")))
103103
(:CompoundAssignOperator
104-
(assert (= 2 (length children)))
104+
(assert (length= 2 children))
105105
(append (tokenize (first children))
106106
(list (token-from-string (ast-opcode root)))
107107
(tokenize (second children))))
@@ -121,7 +121,7 @@ SOFTWARE."))
121121
(tokenize-children children)
122122
(list (token-from-string "}"))))
123123
(:ConditionalOperator
124-
(assert (= 3 (length children)))
124+
(assert (length= 3 children))
125125
(append (tokenize (first children))
126126
(list (token-from-string "?"))
127127
(tokenize (second children))
@@ -186,7 +186,7 @@ SOFTWARE."))
186186
;; initializer is the last child
187187
(tokenize (lastcar children)))))
188188
(:DoStmt
189-
(assert (= 2 (length children)))
189+
(assert (length= 2 children))
190190
(append (list (token-from-string "do"))
191191
(tokenize (first children))
192192
(list (token-from-string "while")
@@ -234,7 +234,7 @@ SOFTWARE."))
234234
;; split a-ls on : to get types
235235
(types (mapcar [#'token-from-string #'first {split ":\\s*"}]
236236
a-ls)))
237-
(assert (= (length types) (1- (length children))) ()
237+
(assert (length= types (1- (length children))) ()
238238
"Types = ~a, Children = ~a" types children)
239239
(append (list (token-from-string "generic")
240240
(token-from-string "("))
@@ -256,7 +256,7 @@ SOFTWARE."))
256256
(tokenize (first children))
257257
(list (token-from-string ")"))
258258
(tokenize (second children))
259-
(when (= 3 (length children))
259+
(when (length= 3 children)
260260
(cons (token-from-string "else")
261261
(tokenize (third children))))))
262262
(:ImaginaryLiteral (list (token-from-string "i-literal")))
@@ -286,7 +286,7 @@ SOFTWARE."))
286286
(not dot))
287287
(list (token-from-string "->"))
288288
(list (token-from-string ".")))))
289-
(assert (= 1 (length children)))
289+
(assert (length= 1 children))
290290
(append (tokenize (first children))
291291
dash-dot
292292
(list (token-from-string "identifier")))))
@@ -324,7 +324,7 @@ SOFTWARE."))
324324
(list (token-from-string ")"))))
325325
(:StringLiteral (list (token-from-string "string-literal")))
326326
(:SwitchStmt
327-
(assert (= 2 (length children)))
327+
(assert (length= 2 children))
328328
(append (list (token-from-string "switch")
329329
(token-from-string "("))
330330
(tokenize (first children))
@@ -371,7 +371,7 @@ SOFTWARE."))
371371
(prog1 (tokenize (nth child children))
372372
(incf child)))))))
373373
(:WhileStmt
374-
(assert (= 2 (length children)))
374+
(assert (length= 2 children))
375375
(append (list (token-from-string "while")
376376
(token-from-string "("))
377377
(tokenize (first children))

components/in-memory-fodder-database.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Otherwise, consider all ASTs."
9191
(full-stmt
9292
(ast-database-full-stmt-list db))
9393
(t (ast-database-list db))))))
94-
(if (and limit (< limit (length snippets)))
94+
(if (and limit (length< limit snippets))
9595
(mapcar {aref (coerce snippets 'vector)}
9696
(random-sample-without-replacement (length snippets) limit))
9797
snippets)))

components/lexicase.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
The same individual may be selected multiple times."
2626
(without-compiler-notes
2727
(assert
28-
(= 1 (length (remove-duplicates population :key [#'length #'fitness])))
28+
(length= 1 (remove-duplicates population :key [#'length #'fitness]))
2929
(population)
3030
"All fitness vectors must be the same length."))
3131
(iter (for n below max-size)

components/multi-objective.lisp

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ PREDICATES is a list of functions, of equal length to the fitness
4141
values, which are used to compare each element of the fitness values.
4242
"
4343
(every (lambda (compare)
44-
(assert (eq (length (fitness candidate))
45-
(length (fitness compare))))
46-
(assert (eq (length (fitness candidate))
47-
(length predicates)))
48-
44+
(assert (length= (fitness candidate)
45+
(fitness compare)
46+
predicates))
4947
(and (some #'funcall predicates (fitness candidate)
5048
(fitness compare))
5149
(notany #'funcall predicates (fitness compare)

components/serapi-io.lisp

+3-3
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ command or an invalid Coq command, NIL otherwise."
648648
"Return T if SEXPR is tagged as VernacImport or VernacRequire, NIL otherwise."
649649
;; ASTs for imports have length 2 where the first element is located info
650650
;; and the second is either VernacImport or VernacRequire.
651-
(and (= 2 (length sexpr))
651+
(and (length= 2 sexpr)
652652
(is-loc-info (first sexpr))
653653
(or (is-type (intern "VernacImport" :sel/cp/serapi-io)
654654
(second sexpr))
@@ -945,7 +945,7 @@ Return a list of IDs for the ASTs that were added."
945945
(defun tokenize-coq-type (type-string)
946946
(labels ((find-matching-paren (str pos depth)
947947
(cond
948-
((equal pos (length str)) nil)
948+
((length= pos str) nil)
949949
((and (equal (elt str pos) #\)) (zerop depth))
950950
pos)
951951
((equal (elt str pos) #\))
@@ -1034,7 +1034,7 @@ Use Ident for unqualified names and Qualid for qualified names."
10341034
{intern _ :sel/cp/serapi-io } ]
10351035
(cdr quals))))
10361036
(when (and quals (listp quals))
1037-
(if (= 1 (length quals))
1037+
(if (length= 1 quals)
10381038
(wrap-coq-constr-expr #!`(CRef ,(MAKE-COQ-IDENT ID) ()))
10391039
(wrap-coq-constr-expr
10401040
#!`(CRef

components/test-suite.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ By default, sum the results of applying `evaluate' to each test-case using
408408
(note 2 "Failed test ~A~%" test)
409409
(pushnew test (failed-tests test-suite)
410410
:test 'equal :key 'program-args) ;track failed tests
411-
(if (> (length (failed-tests test-suite)) *max-failed-tests*)
411+
(if (length> (failed-tests test-suite) *max-failed-tests*)
412412
(setf (failed-tests test-suite)
413413
(subseq (failed-tests test-suite) 0
414414
*max-failed-tests*)))

software-evolution-library.lisp

+7-7
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ Each crossover and mutation will be paired with one of the following tags;
457457
(push (cons (mutation-key crossed mutation)
458458
*fitness-evals*)
459459
*mutation-improvements*)
460-
(when (>= (length *mutation-improvements*)
461-
*max-saved-mutation-improvements*)
460+
(when (length>= *mutation-improvements*
461+
*max-saved-mutation-improvements*)
462462
(setf *mutation-improvements*
463463
(butlast *mutation-improvements*))))
464464
(push (setf result (list effect *fitness-evals* fit old-fit))
@@ -854,7 +854,7 @@ number will automatically be promoted).")
854854
"Incorporate SOFTWARE into POPULATION, keeping POPULATION size constant."
855855
(push software *population*)
856856
(loop :while (and *max-population-size*
857-
(> (length *population*) *max-population-size*))
857+
(length> *population* *max-population-size*))
858858
:do (evict)))
859859

860860
(defvar *tie-breaker-predicate* #'>
@@ -948,7 +948,7 @@ Default selection function for `tournament'."
948948
(unless (and (null variant) (null mutation-info))
949949
(collect variant into variants)
950950
(collect mutation-info into infos)))
951-
(while (< (length variants) count))
951+
(while (length< variants count))
952952
(finally (return (values variants infos))))))
953953

954954
(defun validate-evolution-parameters ()
@@ -993,7 +993,7 @@ evolutionary loop:
993993
(defun remove-elite-individuals ()
994994
"Remove *ELITISM* individuals from population and return them."
995995
(assert (and (typep *elitism* '(integer 0 *))
996-
(< *elitism* (length *population*)))
996+
(length< *elitism* *population*))
997997
(*elitism*)
998998
"*ELITISM* is out of range--must be an integer >0 ~
999999
and < (length *POPULATION*)")
@@ -1234,7 +1234,7 @@ This differs from how evolve works."
12341234
;; after the select operation.
12351235
(- *max-population-size* *elitism*)))
12361236
(add-elite-individuals elite-individuals)
1237-
(assert (<= (length *population*) *max-population-size*))))
1237+
(assert (length<= *population* *max-population-size*))))
12381238
(if (and period period-fn (zerop (mod *generations* period)))
12391239
(funcall period-fn))
12401240
:finally (deinitialize-evolutionary-loop))))
@@ -1271,7 +1271,7 @@ list of the mutations applied to produce those children."
12711271

12721272
(defun simple-select (population max-size &aux new-pop)
12731273
(declare (ignorable population)) ; tournament uses global *population*
1274-
(iter (until (= max-size (length new-pop)))
1274+
(iter (until (length= max-size new-pop))
12751275
(restart-case (push (tournament) new-pop)
12761276
(ignore-failed-selection ()
12771277
:report "Ignore failed `tournament' selection."))))

software/asm.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Used by `homologous-crossover'."
161161
(aget :id (elt (genome obj) id))))
162162
(let* ((id-a (lookup-id a point-a))
163163
;; adjust if id-a is beyond length of b
164-
(start (if (>= id-a (length (genome b)))
164+
(start (if (length>= id-a (genome b))
165165
(1- (length (genome b)))
166166
id-a))
167167
;; max value we can add to start and still have a valid index in b

software/clang-expression.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ This is used to intern string names by `expression'."
9090
"
9191
(cond
9292
((listp expression)
93-
(assert (= 3 (length expression)))
93+
(assert (length= 3 expression))
9494
(format nil "(~a ~a ~a)"
9595
(expression-to-c (second expression))
9696
(symbol-name (car expression))
@@ -153,7 +153,7 @@ This is used to intern string names by `expression'."
153153
(cond
154154
((listp expression)
155155
;; TODO: support functions/operators with different arity
156-
(unless (= (length expression) 3)
156+
(unless (length= 3 expression)
157157
(error (make-condition 'eval-error
158158
:text (format nil
159159
"Wrong number of arguments. Expected 2 got ~a"

software/clang.lisp

+5-6
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ Other keys are allowed but are silently ignored.
813813
(%push :full-stmt full-stmt)
814814
(%push :guard-stmt guard-stmt)
815815
(%push :opcode opcode)
816-
(%push :name (when (= (length declares) 1)
816+
(%push :name (when (length= declares 1)
817817
;; clang name attribute is not aggregated
818818
(ast-name (first declares))))
819819
(make-instance 'clang-ast
@@ -1446,7 +1446,7 @@ software object."))
14461446
(lastcar (child-asts guarded))))
14471447
(:IfStmt
14481448
(let ((children (child-asts guarded)))
1449-
(if (= 2 (length children))
1449+
(if (length= 2 children)
14501450
;; If with only one branch.
14511451
(compose-children (second children))
14521452
;; If with both branches.
@@ -2204,7 +2204,7 @@ already in scope, it will keep that name.")
22042204
(bind (((head . tail) path)
22052205
(children (children tree)))
22062206
(assert (>= head 0))
2207-
(assert (< head (length children)))
2207+
(assert (length< head children))
22082208
(if tail
22092209
;; Recurse into child
22102210
(replace-nth-child tree head (helper (nth head children) tail))
@@ -4163,7 +4163,7 @@ on various ast classes"))
41634163

41644164
(defun ast-args-equal (args1 args2)
41654165
"Compare two lists as returned by AST-ARGS"
4166-
(and (= (length args1) (length args2))
4166+
(and (length= args1 args2)
41674167
(every #'ast-arg-equal args1 args2)))
41684168

41694169
(defmethod ast-declares ((c string)) nil)
@@ -6419,8 +6419,7 @@ children.")
64196419
(let* ((children (children ast))
64206420
(new-children (mapcar (lambda (a) (remove-asts-if a fn))
64216421
(remove-if fn children))))
6422-
(unless (and (= (length children)
6423-
(length new-children))
6422+
(unless (and (length= children new-children)
64246423
(every #'eql children new-children))
64256424
(setf (children ast) new-children)))
64266425
ast)

software/coq.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ unqualified type names."
652652
(type-matches (string ty1) (string ty2)))
653653
;; Two type lists of the same length: check that every element
654654
;; matches.
655-
((and (listp ty1) (listp ty2) (= (length ty1) (length ty2)))
655+
((and (listp ty1) (listp ty2) (length= ty1 ty2))
656656
(every #'identity (mapcar #'type-matches ty1 ty2)))
657657
(t nil)))
658658
((:flet extend-env (type scopes))
@@ -664,7 +664,7 @@ E.g., for type \"bool\", the list includes \"(implb true) : bool -> bool\" and
664664
(name (first type))
665665
(type-ast (second type)))
666666
;; Ensure that TYPE is a function (has at least 1 :->).
667-
(when (< 1 (length split-type))
667+
(when (length< 1 split-type)
668668
;; Iterate over SCOPES, finding items with the correct type.
669669
(iter (for (scope-name scope-ast colon . scope-ty) in scopes)
670670
(declare (ignorable colon))

software/cpp.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
(nlet rec ((pos 0)
5555
(bracket-count 0)
5656
(acc nil))
57-
(if (>= pos (length string))
57+
(if (length>= pos string)
5858
(if (> bracket-count 0)
5959
;; Not actually delimiters. E.g. operator<.
6060
string

software/elf-risc.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
(elt (genome elf) (third mut))))))
107107
(:swap (elf-swap elf (second mut) (third mut)))))
108108
elf
109-
(assert (= (length (genome elf)) starting-length)
109+
(assert (length= (genome elf) starting-length)
110110
(elf) "mutation ~S changed size of genome [~S -> ~S]"
111111
mut starting-length (length (genome elf)))))
112112

@@ -160,7 +160,7 @@ A value of nil means never replace.")
160160
:do
161161
(cond
162162
;; don't cross borders or leave the genome
163-
((or (member (+ s1 i) borders) (>= (+ s1 i) (length genome)))
163+
((or (member (+ s1 i) borders) (length>= (+ s1 i) genome))
164164
(setf forwards-p nil))
165165
((or (member (- s1 i) borders) (< (- s1 i) 0))
166166
(setf backwards-p nil))

software/expression.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163

164164
(defmethod pick-bad-binop-left ((obj expression))
165165
"DOCFIXME"
166-
(flet ((binopp (subtree) (and (listp subtree) (= 3 (length subtree)))))
166+
(flet ((binopp (subtree) (and (listp subtree) (length= 3 subtree))))
167167
(some->> (iter (for i below (size obj))
168168
(collect (list i (subtree (genome obj) i))))
169169
(remove-if-not (lambda-bind ((i subtree))
@@ -177,7 +177,7 @@
177177

178178
(defmethod pick-bad-binop-right ((obj expression))
179179
"DOCFIXME"
180-
(flet ((binopp (subtree) (and (listp subtree) (= 3 (length subtree)))))
180+
(flet ((binopp (subtree) (and (listp subtree) (length= 3 subtree))))
181181
(some->> (iter (for i below (size obj))
182182
(collect (list i (subtree (genome obj) i))))
183183
(remove-if-not (lambda-bind ((i subtree))

software/forth.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(nreverse out))))
3636
(with-open-file (in path)
3737
(loop :for line = (read-line in nil) :while line :append
38-
(if (and (> (length line) 2) (string= "#! " (subseq line 0 3)))
38+
(if (and (length> line 2) (string= "#! " (subseq line 0 3)))
3939
(prog1 nil (setf (shebang forth) line))
4040
(mapcar [#'list {cons :code}]
4141
(mapcan (lambda (el)

software/parseable.lisp

+3-3
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ RECURSIVE is passed, recursive AST children will also be returned.")
259259
(:method :before ((ast ast)
260260
&aux (children (remove nil (children ast))))
261261
(assert (or (null (ast-annotation ast :child-order))
262-
(= (length children)
263-
(length (ast-annotation ast :child-order))))
262+
(length= children
263+
(ast-annotation ast :child-order)))
264264
(ast)
265265
"The number of elements in the AST's :child-order annotation ~
266266
defining the order of the children does not match the number ~
@@ -985,7 +985,7 @@ the `genome' of the software object."
985985
(:method (function (ast ast) &aux (deepest 0) result)
986986
(do-tree (node ast :index rpath :value result)
987987
(when (and (funcall function node)
988-
(> (length rpath) deepest))
988+
(length> rpath deepest))
989989
(setf result node
990990
deepest (length rpath)))
991991
nil)))

0 commit comments

Comments
 (0)