Re: FORMAT a list

[email protected] Wed, 14 May 2025 23:39:03 -0400
Newsgroups gmane.lisp.steel-bank.general
Message-ID <[email protected]>
Christopher Stacy <[email protected]> writes:

>
> In SBCL 2.4.6 (Intel MacOS Monterey):
>
> When I FORMAT the following list:
>
> ("SELECT" "this, that" "FROM" "table" "WHERE" "this" "LIKE" "\"foo%\"" 
> "OR"  ("watts" ">" 42 "AND" "jules" ">" "?"))
>
> with (format nil  "~{~A~^ ~}" zz)
>
> I get a ton of gratuitous whitespace between the ">" and the "?".
> In SBCL:   (length (format nil "~{~A~^ ~}" zz))  => 137
> In CCL:     (length (format nil "~{~A~^ ~}" zz))  => 81
>

It is oddly specific to the items in your list.  If any of
them is omitted, then the result is what you would expect.

(let ((zz (list "select" "this, that" "from" "table" "where"
                "this" "like" "\"foo%\"" "or"
                (list "watts" ">" 42 "and" "jules" ">" "?"))))
  (format nil "~{~A~^ ~}" zz))

=>
"select this, that from table where this like \"foo%\" or (watts > 42 and jules >
                                                        ?)"

Now, omit, say, "watts", from the sub-list:

(let ((zz (list "select" "this, that" "from" "table" "where"
                "this" "like" "\"foo%\"" "or"
                (list ">" 42 "and" "jules" ">" "?"))))
  (format nil "~{~A~^ ~}" zz))

=>
"select this, that from table where this like \"foo%\" or (> 42 and jules > ?)"

No excess white-space between ‘>’ and ‘?’.

It does not matter which item is omitted, from "select" to
the ‘?’, the change will produce a "correct" (expected)
result string.

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.


_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help