(defn spam-s ;Define function calles spam-s that spams a string with the letter s
[in] ;Takes one argument, a string.
(if (empty? in) ;If the input string is empty, we've reached the end
"ssssss" ;so return a bunch of s
(str "sssss" ;If there's still more string go go, concatenate some s
(first in) ;with the first character in the input string
(spam-s (rest in))))) ;and whatever you get when you spam-s the rest of the input string
function spamS (stri)
local newStr= ""
for i = 1, #stri do
local c = str:sub(i,i)
if c =="s" then
local spam= math.random()*10
for times=0,spam do
newStr=newStr.."s"
end
else
newStr=newStr..c
end
end
end
(defn spam2
[in]
(if (empty? in) ;If the input string is empty
"" ;return an empty string
(str (first in) ;If not, return the first character
(if (or (= (first in) \s) ;followed by... if the first character is s or S
(= (first in) \S))
(apply str (repeat (rand-int 10) \s)) ;a random number of s
"") ;or nothing, if the character wasn't s or S
(spam2 (rest in))))) ;And follow all that with whatever you get by spamming the rest of the string.
user=> (defn spam2 [in] (if (empty? in) "" (str (first in) (if (or (= (first in) \s) (= (first in) \S)) (apply str (repeat (rand-int 10) \s)) "") (spam2 (rest in)))))
#'user/spam2
user=> (spam2 "This is Sparta!")
"Thisssss isss Sssssssparta!"
user=> (spam2 "This is Sparta!")
"Thissssssssss isssssssss Ssssssssssparta!"
user=> (spam2 "This is Sparta!")
"Thissss isssssss Ssssssssparta!"
user=> (spam2 "This is Sparta!")
"Thissssssss isssssssss Ssparta!"
user=> (spam2 "This is Sparta!")