help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comic-book-insult


From: Emanuel Berg
Subject: Re: comic-book-insult
Date: Mon, 09 Sep 2019 00:55:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Marcin Borkowski wrote:

> Nice, but a bit wrong. If you try it as an
> interactive function, it won't display the
> result - only return it, but this is of no
> use with M-x.

Right, forgot about that, OK:

(defun scramble-string (str)
  "Randomize the characters of a string."
  (interactive "sscramble me: ")
  (let*((empty-str  "")
        (chars      (delete empty-str (split-string str empty-str)))
        (rand-chars (sort chars (lambda (_ __) (zerop (random 2)))))
        (rand-str   (mapconcat 'identity rand-chars ""))
        )
    (if (called-interactively-p 'any)
        (message rand-str)
      rand-str) ))

>> (defun comic-book-insult ()
>>   (interactive)
>>   (insert (concat (scramble-string "@#$%&") "!") ))
>>
>> ;; (comic-book-insult) ; %@&$#!
>> ;; (comic-book-insult) ; $%#@&!
>
> And this is rather cute, thanks for sharing!

Anytime :)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]