Add gint to apply a function with a probability
This commit is contained in:
parent
ea141d8fe4
commit
1f0b56cc5a
10
gists.org
10
gists.org
|
@ -527,6 +527,16 @@ It turns out it didn't work as well as I hoped, paredit steals the RET binding s
|
||||||
:post-process-template #'my/dwim-shell-command/convert-path-cygwin))
|
:post-process-template #'my/dwim-shell-command/convert-path-cygwin))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
* Apply maybe
|
||||||
|
|
||||||
|
#+begin_src elisp :tangle gists/apply-maybe.el
|
||||||
|
(defun my/apply-maybe (f probability &rest args)
|
||||||
|
"Apply function F with a certain PROBABILITY [0-1)."
|
||||||
|
(if (< (random 100) (* probability 100))
|
||||||
|
(apply f args)
|
||||||
|
'my/not-applied))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
* Meta
|
* Meta
|
||||||
** License
|
** License
|
||||||
|
|
||||||
|
|
5
gists/apply-maybe.el
Normal file
5
gists/apply-maybe.el
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
(defun my/apply-maybe (f probability &rest args)
|
||||||
|
"Apply function F with a certain PROBABILITY [0-1)."
|
||||||
|
(if (< (random 100) (* probability 100))
|
||||||
|
(apply f args)
|
||||||
|
'my/not-applied))
|
Loading…
Reference in a new issue