ProductPromotion
Logo

Clojure

made by https://0x3d.site

GitHub - ztellman/proteus: local. mutable. variables.
local. mutable. variables. Contribute to ztellman/proteus development by creating an account on GitHub.
Visit Site

GitHub - ztellman/proteus: local. mutable. variables.

GitHub - ztellman/proteus: local. mutable. variables.

Proteus gives you back the local mutable variables you've so dearly missed.

usage

Add this to your project.clj:

[proteus "0.1.6"]

Proteus exposes a single macro, proteus/let-mutable:

(use 'proteus)

(let-mutable [x 0]
  (dotimes [_ 100]
    (set! x (inc x)))
  x)

let-mutable gives you variables that can be set using set! within the scope. Since it's unsynchronized and doesn't box numbers, it's faster (often significantly) than Clojure's volatiles, atoms, or refs. However, these variables cannot escape the local scope; if passed into a function or closed over, the current value of the variable will be captured. This means that even though this is unsynchronized mutable state, there's no potential for race conditions.

Unless, of course, you want there to be. It can be sometimes useful to close over the variable rather than the value, for instance when trying to communicate more than the new value from within a swap! call.

(let [a (atom 0)]
  (let-mutable [x :foo]

    (swap! a
      ^:local
      (fn [a]
        (set! x :bar)
        (inc a)))

    x))

Here we've hinted the closure as :local, meaning that it's only called within the local scope. Since this is true for swap!, we can safely use the mutable variable as a side-channel for communication. However, using :local on a non-local closure may have strange, reality-defying effects. Use at your own risk.

That's it. That's the end of the library.

license

Copyright © 2013 Zachary Tellman

Distributed under the MIT License.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory