Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Boku no Pico

Name: Anonymous 2011-05-27 15:06

Here is why Lisp unpopular...

http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)

Ruby:         ["a", "b", "c"].join("-")
Perl:         join( '-', ('a', 'b', 'c'));
C#:           String.Join("-", {"a", "b", "c"})

Common Lisp:  (format nil "~{~a~^-~}" '("a" "b" "c"))

Name: Anonymous 2011-05-27 21:20

>>12
append doesn't do what you think it does (it appends lists).

What you actually want is this:
(concatenate 'string string1 string2 ...)
But you would actually have to make that into an (apply #'concatenate 'string strings) where strings could be made by "zipping" (just a mapcar of the string sequence and a make-list of the delimiter) without the last element of the string and the delimiter.

This is how I personally implemented my string-join, it's some 4-5 lines of CL, however to tell you the truth, the format solution is better, and probably as fast if you use the formatter macro.
Here's a possible formatter expansion which implements string-join:

#'(LAMBDA
      (STREAM
       &OPTIONAL
       (#:FORMAT-ARG1064
        #:FORMAT-ARG1065
        (ERROR ...))
       &REST SB-FORMAT::ARGS)
    (DECLARE (IGNORABLE STREAM))
    (BLOCK NIL
      (LET* ((SB-FORMAT::ORIG-ARGS #:FORMAT-ARG1064)
             (SB-FORMAT::ARGS SB-FORMAT::ORIG-ARGS))
        (DECLARE (IGNORABLE SB-FORMAT::ORIG-ARGS SB-FORMAT::ARGS))
        (LOOP (WHEN (NULL SB-FORMAT::ARGS) (RETURN))
              (PRINC (IF SB-FORMAT::ARGS
                         (POP SB-FORMAT::ARGS)
                         (ERROR ...))
                     STREAM)
              (WHEN
                  (LET ((#:FVAR455 NIL) (#:FVAR456 NIL) (#:FVAR457 NIL))
                    (COND (#:FVAR457 (<= #:FVAR455 #:FVAR456 #:FVAR457))
                          (#:FVAR456 (EQL #:FVAR455 #:FVAR456))
                          (#:FVAR455 (EQL #:FVAR455 0))
                          (T (NULL SB-FORMAT::ARGS))))
                (RETURN))
              (WRITE-STRING #:FORMAT-ARG1065 STREAM))))
    SB-FORMAT::ARGS)


(This was edited in 2 places by hand because I somewhat hate format's language and can't remember how to properly back up an argument in a list, but I'm pretty sure a way exists, as long as you don't mind writing some linenoise)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List