From 407a79591a42376d1add25c01514b10adfcda194 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Mon, 26 Dec 2016 15:22:11 -0800 Subject: [PATCH] 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. --- docs/contrib/flow.rst | 58 ------------------------------------------ docs/contrib/index.rst | 1 - hy/contrib/flow.hy | 24 ----------------- 3 files changed, 83 deletions(-) delete mode 100644 docs/contrib/flow.rst delete mode 100644 hy/contrib/flow.hy diff --git a/docs/contrib/flow.rst b/docs/contrib/flow.rst deleted file mode 100644 index e99e00e..0000000 --- a/docs/contrib/flow.rst +++ /dev/null @@ -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"))) diff --git a/docs/contrib/index.rst b/docs/contrib/index.rst index 79ac3fc..67c8abe 100644 --- a/docs/contrib/index.rst +++ b/docs/contrib/index.rst @@ -11,7 +11,6 @@ Contents: .. toctree:: :maxdepth: 3 - flow loop multi profile diff --git a/hy/contrib/flow.hy b/hy/contrib/flow.hy deleted file mode 100644 index ae70362..0000000 --- a/hy/contrib/flow.hy +++ /dev/null @@ -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)))