Repeat a string: Difference between revisions

Content added Content deleted
(Repeat a string in various BASIC dialents)
m (Emacs Lisp: Use cl-lib, adjust wording)
Line 853: Line 853:


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
Going via a list to repeat the desired string,
Going via a list to repeat the desired string:


<lang lisp>(apply 'concat (make-list 5 "ha"))</lang>
<lang lisp>(apply 'concat (make-list 5 "ha"))</lang>


A single character can be repeated with <code>make-string</code>
A single character can be repeated with <code>make-string</code>:


<lang lisp>(make-string 5 ?x)</lang>
<lang lisp>(make-string 5 ?x)</lang>


With <code>cl.el</code> the loop macro can repeat and concatenate,
The <code>cl-loop</code> macro can repeat and concatenate:


{{libheader|cl-lib}}
<lang lisp>(require 'cl)
<lang lisp>(require 'cl-lib)
(loop repeat 5 concat "ha")</lang>
(cl-loop repeat 5 concat "ha")</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==