• This repository has been archived on 09/Nov/2017
  • Stars
    star
    111
  • Rank 303,872 (Top 7 %)
  • Language
    Clojure
  • Created almost 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 Repositories

1

lamina

not under active development - event-driven workflows for clojure
Clojure
708
star
2

automat

better automata through combinators
Clojure
586
star
3

rhizome

simple graph and tree visualization
Clojure
446
star
4

penumbra

not under active development - idiomatic opengl bindings for clojure
Clojure
353
star
5

virgil

your own personal JVM psychopomp
Clojure
274
star
6

vertigo

heterogeneous structs for clojure
Clojure
208
star
7

riddley

code-walking without caveats
Clojure
193
star
8

clj-tuple

efficient small collections for clojure
Java
179
star
9

narrator

expressive, composable stream analysis
Clojure
153
star
10

sleight

whole-program transformations in clojure
Clojure
98
star
11

calx

not under active development - idiomatic opencl bindings for clojure
Clojure
84
star
12

collection-check

fuzz testing for alternate clojure data structures
Clojure
64
star
13

pushkin

shall we play a game?
Clojure
59
star
14

immutable-bitset

space-efficient immutable integer sets
Clojure
51
star
15

immutable-int-map

a map optimized for integer keys
Clojure
40
star
16

aloha

a simple, friendly webserver
Clojure
36
star
17

cambrian-collections

a veritable explosion of data structures
Clojure
29
star
18

cantor

not under active development - primitive math for clojure
Clojure
26
star
19

clj-radix

a persistent radix tree, for efficient nested maps
Clojure
21
star
20

lein-jammin

a window into your stuck process
Clojure
18
star
21

everything-will-flow

necessary code for my upcoming clojure/west 2015 talk
Clojure
17
star
22

duel

a testing ground for programs that play go
Clojure
10
star
23

bizarro-collections

you got your clojure semantics in my mutable hash-map
Java
7
star
24

ergo

a monte-carlo simulator for computer go
C++
5
star
25

scrawl

the graphical equivalent of the fibonacci sequence
Clojure
4
star
26

java9-failure

Clojure
1
star
27

aleph.io

static website for aleph
CSS
1
star