Remove contrib.flow
It's not tested, and sure enough, a glance at the code suggests that `case` and `switch` will evaluate their first argument once for every clause, which is unlikely to be desirable. I say remove it, but if anybody wants to fix and test and re-add `case` (and change it to a square-bracket syntax like `cond`), be my guest.
This commit is contained in:
parent
38d11bd455
commit
407a79591a
@ -1,58 +0,0 @@
|
||||
==========
|
||||
Flow
|
||||
==========
|
||||
|
||||
.. versionadded:: 0.10.1
|
||||
|
||||
The ``flow`` macros allow directing the flow of a program with greater ease.
|
||||
|
||||
|
||||
Macros
|
||||
======
|
||||
|
||||
.. _case:
|
||||
.. _switch:
|
||||
|
||||
case
|
||||
-----
|
||||
|
||||
``case`` allows you to decide based on the value of a variable.
|
||||
|
||||
|
||||
Usage: `(case variable val1 (body1) val2 (body2) ...)`
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: hy
|
||||
|
||||
(require [hy.contrib.flow [case]])
|
||||
|
||||
(defn temp-commenter [temp]
|
||||
(case temp
|
||||
-10 (print "It's freezing. Turn up the thermostat!")
|
||||
15 (print "Sounds about average.")
|
||||
45 (print "Holy smokes. It's hot in here!")
|
||||
(print "I don't even know.")))
|
||||
|
||||
|
||||
switch
|
||||
-----
|
||||
|
||||
``switch`` allows you to run code based on the value of a variable.
|
||||
A final extra body allows for a default case.
|
||||
|
||||
|
||||
Usage: `(switch var (cond1) (body1) (cond2) (body2) ... )`
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: hy
|
||||
|
||||
(require [hy.contrib.flow [switch]])
|
||||
|
||||
(defn temp-commenter [temp]
|
||||
(switch temp
|
||||
(<= 10.0) (print "Better wear a jacket!")
|
||||
(<= 25.0) (print "Brace yourselves. Summer is coming!")
|
||||
(<= 30.0) (print "Time to get some ice cream.")
|
||||
(print "Sounds like a heat wave")))
|
@ -11,7 +11,6 @@ Contents:
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
|
||||
flow
|
||||
loop
|
||||
multi
|
||||
profile
|
||||
|
@ -1,24 +0,0 @@
|
||||
;; Additional flow macros
|
||||
|
||||
|
||||
(defmacro/g! switch [variable &rest args]
|
||||
(setv g!comp (car args))
|
||||
(setv g!body (car (cdr args)))
|
||||
(setv g!rest (cdr (cdr args)))
|
||||
(setv g!cond `(~(car g!comp) ~variable ~@(cdr g!comp)))
|
||||
(if g!rest
|
||||
(if (cdr g!rest)
|
||||
`(if ~g!cond ~g!body (switch ~variable ~@g!rest))
|
||||
`(if ~g!cond ~g!body ~@g!rest))
|
||||
`(if ~g!cond ~g!body)))
|
||||
|
||||
(defmacro/g! case [variable &rest args]
|
||||
(setv g!value (car args))
|
||||
(setv g!body (car (cdr args)))
|
||||
(setv g!rest (cdr (cdr args)))
|
||||
(setv g!cond `(= ~variable ~g!value))
|
||||
(if g!rest
|
||||
(if (cdr g!rest)
|
||||
`(if ~g!cond ~g!body (case ~variable ~@g!rest))
|
||||
`(if ~g!cond ~g!body ~@g!rest))
|
||||
`(if ~g!cond ~g!body)))
|
Loading…
x
Reference in New Issue
Block a user