-- | Create a mutable variable a name, which can be modified with '@='.
--   After defining the expression, you can refer to it with @$NAME@ in a 'String'.
--   To introduce a new scope, see 'scope'.
--
-- @
-- h <- 'mutable' \"HELLO\" \"Hello World\"
-- \"$HELLO\" '@=' \"$HELLO!\"
-- h        '@=' \"$HELLO!\" -- equivalent to the above
-- 'alert' \"$HELLO\"        -- with 2 exclamation marks
-- @
mutable :: Typeable t => String -> Exp t -> Action (Exp t)
mutable name x = do
    v <- mutable_ x
    vv <- v
    addScope name vv
    return v

-- | Create an unnamed mutable variable, which can be modified with '@='.
--
-- @
-- h <- 'mutable' \"Hello World\"
-- h '@=' 'h' '&' \"!\"
-- 'alert' h
-- @
mutable :: Typeable t => String -> Exp t -> Action (Exp t)
mutable name x = do
    v <- mutable_ x
    vv <- v
    addScope name vv
    return v

-- | Create an unnamed mutable variable, which can be modified with '@='.
--
-- @
-- h <- 'mutable' \"Hello World\"
-- h '@=' 'h' '&' \"!\"
-- 'alert' h
-- @
mutable name x = do
    v <- mutable_ x
    vv <- v
    addScope name vv
    return v

-- | Create an unnamed mutable variable, which can be modified with '@='.
--
-- @
-- h <- 'mutable' \"Hello World\"
-- h '@=' 'h' '&' \"!\"
-- 'alert' h
-- @