Elisp: Sequence. Join, Convert
Convert to Vector, Join Vectors
vconcat-
(vconcat sequence1 sequence2 etc)- Join Sequence
- Return a vector.
If a sequence is a string, each character is converted into a integer of its Code Point
;; join vectors (vconcat (vector 3 4) (vector "a" "b")) ;; [3 4 "a" "b"] ;; join vector and list (vconcat (vector 3 4) (list "a" "b")) ;; [3 4 "a" "b"] ;; If a sequence is a string, each character is converted into a integer of its Codepoint (vconcat "abc") ;; [97 98 99]
Convert to List, Join Lists
append-
(append sequence1 sequence2 etc)- Join Sequence
- Return a list.
🛑 warning: if you want result to be Proper List , the last element must be a proper list, or
nil.;; join lists (append (list 1 2) (list 3 4)) ;; (1 2 3 4) ;; convert vector to list (append (vector 1 2 3) nil) ;; (1 2 3) ;; this creates improper list (append (vector 1 2 3) (vector 4 5)) ;; (1 2 3 . [4 5]) ;; this creates proper list (append (vector 1 2 3) (vector 4 5) nil) ;; (1 2 3 4 5) ;; join vectors and lists to list (append (vector 1 2 3) (vector 4 5) (list 6)) ;; (1 2 3 4 5 6) ;; proper list ;; If a sequence is a string, each character is converted into a integer of its Codepoint (append "abc" nil) ;; (97 98 99)
Sequence to String
Join Sequences, to List or Vector
seq-concatenate-
(seq-concatenate TYPE SEQUENCE...)join sequences, into a list or vector.
(this is a generalized version of
vconcatandappend);; to list (seq-concatenate 'list (list 1 2 3) (vector 4 5 6)) ;; (1 2 3 4 5 6) ;; to vector (seq-concatenate 'vector (list 1 2 3) (vector 4 5 6)) ;; [1 2 3 4 5 6] ;; to string (seq-concatenate 'string (list 97 98) (vector 99 100)) ;; "abcd" ;; integer is considered as char id ;; 97 is char a
Convert a Sequence to List or Vector
seq-into-
(seq-into SEQUENCE TYPE)convert sequence to a specific TYPE.
TYPE is one of:
'vector'list'string(this is a generalized version of
vconcatandappend)(seq-into (list 3 4) 'vector) ;; [3 4] (seq-into (vector 3 4) 'list) ;; (3 4) (seq-into "abc" 'list) ;; (97 98 99) ;; string elements are converted to char. ;; 97 is the codepoint for the char a (seq-into "abc" 'vector) ;; [97 98 99] (seq-into (vector 97 98 99) 'string) ;; "abc" ;; nested item is not converted (seq-into (list 3 4 (list 3 4)) 'vector) ;; [3 4 (3 4)] (seq-into (vector 3 4 (vector 5 6)) 'list) ;; (3 4 [5 6])