Created
May 18, 2011 09:20
-
-
Save cassiel/978270 to your computer and use it in GitHub Desktop.
first hack at the monome arc using clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Our legacy Java OSC library: | |
(def transmitter (net.loadbang.osc.comms.UDPTransmitter. (java.net.InetAddress/getByName "localhost") 10332)) | |
; Seriously non-idiomatic code. I'm only 20% of the way through the Joy of Clojure book... | |
(defn xmit [enc buffer] | |
"Transmit to encoder number enc, buffer is a sequence of integers." | |
(let [m (doto (net.loadbang.osc.data.Message. "/example/ring/map") (.addInteger enc))] | |
(doseq [n buffer] (.addInteger m n)) | |
(.transmit transmitter m) | |
)) | |
; There must be a better way to do this bit! | |
(def buf (map (fn [_] 5) (vec (range 64)))) | |
(xmit 1 buf) |
Author
cassiel
commented
May 18, 2011
via email
So in that case... I can see that
```
(#(+ % %) 1)
```
works, and I can sort-of see that
```
(#(%) 1)
```
doesn't, since (%) is evaluated as an expression (whereas
```
(fn [x] x)
```
is fine - the stuff to the right of "]" isn't treated an as s-expr). So what's wrong with
```
(#([%]) 1)
```
?
Oh - right - it's doing([...])
as an evaluation. My Lisp is still a bit shaky...
Mine was completely non-existent before Clojure :-)
And yep, that one got me too. If you're looking for a fn that returns its argument take a look at identity
.
Oh, and as for GitHub's code markup in gist comments - can't get that to work at all. Obviously.
:-) It seems to be Markdown which means you can either surround your code with backticks for inline code such as this
or you can indent by over four spaces
for something
that spans multiple
lines
The Markdown seems to be seriously on the blink...
Here's how I formatted my previous comment:
:-) It seems to be Markdown which means you can either surround your code with backticks for inline code `such as this`
or you can indent by over four spaces
for something
that spans multiple
lines
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment