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

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

Re: comic-book-insult


From: Jean Louis
Subject: Re: comic-book-insult
Date: Mon, 9 Sep 2019 10:00:02 +0200
User-agent: Mutt/1.10.1 (2018-07-13)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> [2019-09-08 21:06]:
> (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 ""))
>         )
>     rand-str) )
> 
> (defun comic-book-insult ()
>   (interactive)
>   (insert (concat (scramble-string "@#$%&") "!") ))
> 
> ;; (comic-book-insult) ; %@&$#!
> ;; (comic-book-insult) ; $%#@&!

Thanks, now I learned how to scramble words like this below in
Emacs. But I have no idea what means (lambda (_ __)

(defun scramble-word (word)
  "Randomize the characters of a string but not first and last"
  (let* ((first (substring word 0 1))
         (length (length word))
         (last (substring word (1- length) length))
         (middle (substring word 1 (1- length)))
         (rnd (length middle))
         (empty-str  "")
         (chars (delete empty-str (split-string middle empty-str)))
         (rand-chars (sort chars (lambda (_ __) (zerop (random rnd)))))
         (rand-str (mapconcat 'identity rand-chars ""))
         (word (concat first rand-str last)))
    word))

(defun scramble-string (string)
  (let* ((split (split-string string))
         (out (with-output-to-string
                (dolist (word split)
                  (princ (scramble-word word))
                  (princ " ")))))
    out))

(defun scramble-region (start end)
  "Scramble region"
  (interactive "r")
  (let* ((s (buffer-substring-no-properties start end))
         (replacement (scramble-string s)))
    (delete-region start end)
    (insert replacement)))


(scramble-string "Hello there, Emacs is very cool piece of software")

=> "Hlelo theer, Eamcs is vrey cool peice of sfotware "

Reference:

Why your brain can read jumbled letters:
https://www.mnn.com/lifestyle/arts-culture/stories/why-your-brain-can-read-jumbled-letters

Emcas is the extenisble, customblezia, slef doucmenintg rael time dipsaly 
eidtor. Tihs manaul desrcibes how to eidt wtih Emacs and smoe of the wyas to 
cuostmize it; it crpeoorsnds to GNU Eacms versoin 235.. 


Jean



reply via email to

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