changed to an easy-to-maintain numbering system (start at 0 instead of 1)

main
m455 2019-09-23 16:40:26 -04:00
parent 6986920d4d
commit cff79c0dd5
4 changed files with 105 additions and 108 deletions

View File

@ -30,12 +30,12 @@
;; rm ;; rm
[(and [(and
(equal? args-length 2) (equal? args-length 2)
(equal? (vector:vector-member config:remove-command args) 0) (equal? (vector-ref args 0) config:remove-command)
(real? (string->number (vector-ref args 1))) (real? (string->number (vector-ref args 1)))
(positive? (string->number (vector-ref args 1))) (positive? (string->number (vector-ref args 1)))
(not (> (string->number (vector-ref args 1)) (length (util:file->string-list config:path-to-file)))) ;; Length subtract one because the numbering starts at zero
(not (< (string->number (vector-ref args 1)) (car (list:range (length (util:file->string-list config:path-to-file))))))) (not (> (string->number (vector-ref args 1)) (sub1 (length (util:file->string-list config:path-to-file)))))
(util:remove-item-from-list args)] (util:remove-item-from-list args))]
;; init ;; init
[(and [(and

View File

@ -38,25 +38,22 @@
(list:empty? (file->string-list lst))) (list:empty? (file->string-list lst)))
(define (get-removed-item lst args) (define (get-removed-item lst args)
;; Subtract one from what the user chose, because what they are actually (list-ref (file->string-list lst) (string->number args)))
;; viewing is a list starting from "1" rather than "0". Under the hood,
;; the real list starts at 0.
(list-ref (file->string-list lst) (sub1 (string->number args))))
(define (surround-with-quotation-marks args) (define (surround-with-quotation-marks args)
(display (string-append "\"" args "\""))) (display (string-append "\"" args "\"")))
(define (list->dotted-list lst) (define (list->dotted-list lst)
(string-append lst ". ")) (string-append lst "." " "))
(define (list->numbered-list lst) (define (list->numbered-list lst)
;; Take the list made in the first (map), which is ;; Take the list made in the first (map), which is
;; '(1 2 3 ...), and append that to each item in a list ;; '(0 1 2 ...), and append that to each item in a list
(map string-append (map string-append
;; Note: compose starts from the last element in it's ;; Note: compose starts from the last element in it's
;; list. In this case, it starts at (number->string). ;; list. In this case, it starts at (number->string).
(map (compose1 list->dotted-list number->string) (map (compose1 list->dotted-list number->string)
(list:range 1 (add1 (length lst)))) (list:range (length lst)))
lst)) lst))
(define (display-prettified-program-file) (define (display-prettified-program-file)