• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Html-encoding
        • Character-kinds
        • Substrings
        • Strtok
        • Equivalences
        • Url-encoding
        • Lines
        • Ordering
        • Numbers
        • Pad-trim
          • Rpadstr
          • Rpadchars
          • Lpadchars
            • Lpadstr
            • Trim-bag
            • Trim
          • Coercion
          • Std/strings-extensions
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/io
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Pad-trim

    Lpadchars

    Pad a character-list with spaces on the left.

    (lpadchars x len) extends the character list x to length len by adding spaces on the left. For instance,

    (lpadchars '(#\f #\o #\o) 5)
       -->
    '(#\Space #\Space #\f #\o #\o)

    This is completely dumb: we don't try to account for newlines, tabs, or anything like that, and just add #\Space characters until reaching the desired width.

    If no new spaces are needed, x is returned unchanged and no consing is performed.

    Definitions and Theorems

    Function: lpadchars

    (defun lpadchars (x len)
           (declare (xargs :guard (and (character-listp x) (natp len)))
                    (type integer len))
           (mbe :logic (append (repeat (nfix (- (nfix len) (len x)))
                                       #\Space)
                               (make-character-list x))
                :exec (let* ((x-len (length x))
                             (diff (- len x-len)))
                            (if (< 0 diff)
                                (make-list-ac diff #\Space x)
                                x))))

    Theorem: character-listp-of-lpadchars

    (defthm character-listp-of-lpadchars
            (character-listp (lpadchars x len)))

    Theorem: len-of-lpadchars

    (defthm len-of-lpadchars
            (equal (len (lpadchars x len))
                   (max (len x) (nfix len))))

    Theorem: charlisteqv-implies-equal-lpadchars-1

    (defthm charlisteqv-implies-equal-lpadchars-1
            (implies (charlisteqv x x-equiv)
                     (equal (lpadchars x len)
                            (lpadchars x-equiv len)))
            :rule-classes (:congruence))

    Theorem: icharlisteqv-implies-icharlisteqv-lpadchars-1

    (defthm icharlisteqv-implies-icharlisteqv-lpadchars-1
            (implies (icharlisteqv x x-equiv)
                     (icharlisteqv (lpadchars x len)
                                   (lpadchars x-equiv len)))
            :rule-classes (:congruence))