• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • Std/strings
            • Pretty-printing
            • Printtree
            • Base64
            • Charset-p
            • Strtok!
            • Cases
            • Concatenation
              • Revappend-chars
              • Join
                • Append-chars
                • Cat
                • Rchars-to-string
                • Prefix-strings
              • Html-encoding
              • Character-kinds
              • Substrings
              • Strtok
              • Equivalences
              • Url-encoding
              • Lines
              • Explode-implode-equalities
              • Ordering
              • Numbers
              • Pad-trim
              • Coercion
              • Std/strings/digit-to-char
              • Substitution
              • Symbols
            • String-listp
            • Stringp
            • Length
            • Search
            • Remove-duplicates
            • Position
            • Coerce
            • Concatenate
            • Reverse
            • String
            • Subseq
            • Substitute
            • String-upcase
            • String-downcase
            • Count
            • Char
            • String<
            • String-equal
            • String-utilities
            • String-append
            • String>=
            • String<=
            • String>
            • Hex-digit-char-theorems
            • String-downcase-gen
            • String-upcase-gen
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Concatenation

    Join

    Concatenate a list of strings with some separator between.

    Signature
    (join x separator) → joined
    Arguments
    x — Guard (string-listp x).
    Returns
    joined — Type (stringp joined).

    (join x separator) joins together the list of strings x, inserting the string separator between the members. For example:

    (join '("a" "b" "c") ".") = "a.b.c"
    (join '("a" "b" "c") "->") = "a->b->c"

    We always return a string; an empty x results in the empty string, and any empty strings within x just implicitly don't contribute to the result.

    Any sort of string concatenation is slow, but join is reasonably efficient: it creates a single character list for the result (in reverse order) without any use of coerce, then uses rchars-to-string to build and reverse the result string.

    Definitions and Theorems

    Function: join-aux

    (defun join-aux (x separator acc)
      (declare (xargs :guard (string-listp x))
               (type string separator))
      (cond ((atom x) acc)
            ((atom (cdr x))
             (revappend-chars (car x) acc))
            (t (let* ((acc (revappend-chars (car x) acc))
                      (acc (revappend-chars separator acc)))
                 (join-aux (cdr x) separator acc)))))

    Function: join$inline

    (defun join$inline (x separator)
      (declare (type string separator))
      (declare (xargs :guard (string-listp x)))
      (let ((acl2::__function__ 'join))
        (declare (ignorable acl2::__function__))
        (mbe :logic (cond ((atom x) "")
                          ((atom (cdr x)) (str-fix (car x)))
                          (t (cat (car x)
                                  separator (join (cdr x) separator))))
             :exec (rchars-to-string (join-aux x separator nil)))))

    Theorem: stringp-of-join

    (defthm stringp-of-join
      (b* ((joined (join$inline x separator)))
        (stringp joined))
      :rule-classes :type-prescription)

    Theorem: join-aux-removal

    (defthm join-aux-removal
      (implies (and (string-listp x)
                    (stringp separator))
               (equal (join-aux x separator acc)
                      (revappend (coerce (join x separator) 'list)
                                 acc))))

    Theorem: list-equiv-implies-equal-join-1

    (defthm list-equiv-implies-equal-join-1
      (implies (list-equiv x x-equiv)
               (equal (join x separator)
                      (join x-equiv separator)))
      :rule-classes (:congruence))

    Theorem: streqv-implies-equal-join-2

    (defthm streqv-implies-equal-join-2
      (implies (streqv separator separator-equiv)
               (equal (join x separator)
                      (join x separator-equiv)))
      :rule-classes (:congruence))

    Theorem: istreqv-implies-istreqv-join-2

    (defthm istreqv-implies-istreqv-join-2
      (implies (istreqv separator separator-equiv)
               (istreqv (join x separator)
                        (join x separator-equiv)))
      :rule-classes (:congruence))