Compare length of two strings: Difference between revisions

Content added Content deleted
m (Fix order)
Line 704: Line 704:
R: 'abcdef' is 6 characters in length.
R: 'abcdef' is 6 characters in length.
R: 'abcd' is 4 characters in length.
R: 'abcd' is 4 characters in length.
</pre>

=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
(defun sort-and-print-strings (strings)
(dolist (s (sort (copy-list strings) #'> :key #'length))
(format t "~A ~A~%" (length s) s)))

(sort-and-print-strings '("Lisp" "stands" "for" "List" "Processing"))
</syntaxhighlight>
{{out}}
<pre>
10 Processing
6 stands
4 Lisp
4 List
3 for
</pre>
</pre>


Line 726: Line 743:
"Rosetta" (length: 7)
"Rosetta" (length: 7)
"Code" (length: 4)
"Code" (length: 4)
</pre>

=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
(defun sort-and-print-strings (strings)
(dolist (s (sort (copy-list strings) #'> :key #'length))
(format t "~A ~A~%" (length s) s)))

(sort-and-print-strings '("Lisp" "stands" "for" "List" "Processing"))
</syntaxhighlight>
{{out}}
<pre>
10 Processing
6 stands
4 Lisp
4 List
3 for
</pre>
</pre>