Clojure wrapper for https://blockchain.info/api

2017-11-08 Thread eliassonaand via Clojure
blockchain.info provides an API for building bitcoin apps. 
This is a clojure wrapper for it.
https://github.com/eliassona/bchain


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Bitcoind API for Clojure/Java (experimental).

2017-10-26 Thread eliassonaand via Clojure
 

I'm interested in Bitcoin and cryptocurrencies.

So I installed bitcoind on my laptop and started playing with the CLI. 

I also tried some Java and Clojure libs that builds on top of the CLI.


After a while I decided to write my own library for it.  

Specifically I wanted to see if it was possible to parse information from 
the CLI, (which is mostly in JSON format)

and generate the API for Clojure and Java by using AOT, Instaparse, macros 
etc.

Don't really know if it's usable for anyone but it was a fun exercise.


The result can be found here: https://github.com/eliassona/bitcoinrpc



Anders



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Partial question

2016-02-25 Thread eliassonaand via Clojure
Hi, is this want you want?
https://github.com/eliassona/apartial

Regards Anders

Den tisdag 23 februari 2016 kl. 19:14:33 UTC+1 skrev Fernando Abrao:
>
> Hello all,
>
> I´m trying to do something like:
>
> (defn log [type message & {:keys [id idVe] :or {id "LOCAL" idVe "END"}}] 
>  (println (str id ": " type " -> " message "<- " idVe)))
>
>
> (def debug (partial log "DEBUG" ?? :idVe "COM"))
>
>
> Is there any way to do what I want? Pass arguments to log and add the 
> :idVe into the end? Is the partial the best using to do this?
>
> Regards,
>
> Fernando
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Lisp interpreter

2015-02-08 Thread eliassonaand via Clojure
I've implemented a Lisp interpreter as a way of understanding the 
eval/apply procedure in Lisp.

Here is the link to the code: https://github.com/eliassona/mylisp.

For me it was a great learning exercise into the foundation of computer 
science according to SICP. 
It was very interesting to see how everything gets evaluated and applied 
recursively. 
Interesting to see that a macro is just one more eval!

The interpreter is implemented in 130 lines of Clojure code.







-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


instaparse questions

2013-11-18 Thread eliassonaand
 

Hi, 

I'm trying to use instaparse to differentiate between identifiers and 
keywords.

The following code is from the tutorial.

(def unambiguous-tokenizer
  (insta/parser
sentence = token (whitespace token)*
 token = keyword | !keyword identifier
 whitespace = #'\\s+'
 identifier = #'[a-zA-Z]+'
 keyword = 'cond' | 'defn'))

The above parser works fine for: 

(insta/parse unambiguous-tokenizer cond id defn)

It recognizes cond and defn as keywords and id as identifier.

But if an identifier starts with a keyword such as condid:

(insta/parse unambiguous-tokenizer condid id defn)

It doesn't work anymore. (I want it to recognize condid as an identifier 
not a misspelled keyword)

Does anybody know how to make that work?

Thanks

--anders

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


the snake game with core.async and swing

2013-08-02 Thread eliassonaand
Below is a little (stupid) snake game I wrote using core.async and swing.
It uses channels for timer, keyboard input and repaint to make everything 
nice and sequential.
Thought it could be a nice example of the power of core.async.

I'm not an experienced clojure/lisp developer so I'd be happy if someone 
could give me some feedback on the code.
Is it clojure idiomatic?
Am I using core.async properly?
etc.

Thanks
--anders


(ns my-test
  (use [midje.sweet])
  (require [clojure.core.async :as async :refer :all])
  (import [javax.swing JFrame JButton JPanel SwingUtilities])
  (import [java.awt Color Dimension])
  (import [java.awt.event ActionListener WindowAdapter KeyListener]))


(defn map-chan [f in]
  (let [c (chan)]
(go (loop []
  (when-let [v (f (! in))]
(! c v))
  (recur)))
c))

(defn start-timer! []
  (let [c (chan)]
(go (while true (! (timeout 250)) (! c :go)))
c))

(defn closing-channel [frame]
  (let [c (chan)]
(.addWindowListener frame
(proxy [WindowAdapter] []
  (windowClosing [e] (put! c e
c))

(defn array-of [coordinates index]
  (int-array (map #(nth % index) coordinates)))

(defn points-of [coordinates]
  [(array-of coordinates 0) (array-of coordinates 1)])

(defn draw-poly-line [canvas coordinates]
  (SwingUtilities/invokeLater
   (fn []
 (let [[x-points y-points] (points-of coordinates)
   g (.getGraphics canvas)
   prev-color (.getColor g)]
  (.setColor g Color/BLACK)
  (.drawPolyline g x-points y-points (count coordinates))
  (.setColor g prev-color)

(def step 5)
(defmulti calc-new-pos (fn[xy prev-pos dir] [xy dir]))
(defmethod calc-new-pos [:x :right][xy prev-pos dir] (+ prev-pos step))
(defmethod calc-new-pos [:x :left][xy prev-pos dir] (- prev-pos step))
(defmethod calc-new-pos [:y :down][xy prev-pos dir] (+ prev-pos step))
(defmethod calc-new-pos [:y :up][xy prev-pos dir] (- prev-pos step))
(defmethod calc-new-pos :default [xy prev-pos dir] prev-pos)

(defn calc-snake [dir snake-obj counter]
  (let [[l-x l-y] (last snake-obj)
old-snake (if (= (mod counter 2) 0) snake-obj (rest snake-obj))]
(conj (vec old-snake) [(calc-new-pos :x l-x dir) (calc-new-pos :y l-y 
dir)])))

(facts snake positions
   (fact snake moves and grows
 (calc-snake :right [[1 2]] 2) = [[1 2] [6 2]]
 (calc-snake :right [[2 2]] 4) = [[2 2] [7 2]])
   (facts snake moves
  (calc-snake :right [[1 2]] 1) = [[6 2]]
  (calc-snake :down [[1 2]] 1) = [[1 7]]
  (calc-snake :left [[10 2]] 1) = [[5 2]]
  (calc-snake :up [[10 7]] 1) = [[10 2]]
  ))

(def key-to-dir-map {37 :left, 38 :up, 39 :right, 40 :down})

(defn key-channel [obj]
  (let [c (chan)]
(.addKeyListener obj
 (reify KeyListener
   (keyTyped [_ e] )
   (keyPressed [_ e] )
   (keyReleased [_ e]
 (put! c e
c))

(defn create-canvas [paint-channel]
  (proxy [JButton] []
 (getPreferredSize [] (Dimension. 300 300))
 (paintComponent [g]
   (go
 (proxy-super paintComponent g)
 (! paint-channel :repaint)

(defmulti inside-window? (fn [dir canvas pos] dir))
(defmethod inside-window? :left [dir canvas [x _]] (= x (.getX canvas)))
(defmethod inside-window? :right [dir canvas [x _]] (= x (+ (.getX canvas) 
(.getWidth canvas
(defmethod inside-window? :up [dir canvas [_ y]] (= y (.getY canvas)))
(defmethod inside-window? :down [dir canvas [_ y]] (= y (+ (.getY canvas) 
(.getHeight canvas



(def initial-snake (vec  (map (fn [x] [x 10])  (take 20 (iterate (partial + 
step) 0)


(defn game-rules-ok? [snake dir canvas]
  (and
   (apply distinct? snake)
   (inside-window? dir canvas (last snake

(facts game rules
   (let [canvas (JButton.)]
 (.setBounds canvas 0 0 10 10)
 (facts inside window
(game-rules-ok? [[0 0]] :right canvas) = truthy
(game-rules-ok? [[11 0]] :right canvas) = falsey
(game-rules-ok? [[11 0]] :left canvas) = truthy
(game-rules-ok? [[11 0]] :up canvas) = truthy
(game-rules-ok? [[11 0]] :down canvas) = truthy
(game-rules-ok? [[11 11]] :down canvas) = falsey)
 (facts snake eating itself
  (game-rules-ok? [[0 0] [0 0]] :right canvas) = falsey
  (game-rules-ok? [[0 0] [1 0]] :right canvas) = true
  )))
(defn you-loose! [cc]
  (println you loose!)
  (put! cc :close))


(defn snake [cc]
  (let [paint-channel (chan)
timer-channel (start-timer!)
canvas (create-canvas paint-channel)
dir-channel (map-chan #(key-to-dir-map (.getKeyCode %)) 
(key-channel canvas))
]
(go
 (loop [last-dir :right
   snake-obj 

Re: core.async + swing

2013-07-30 Thread eliassonaand


Den måndagen den 29:e juli 2013 kl. 16:44:50 UTC+2 skrev 
eliass...@yahoo.com:

 Hi, I'm playing around with core.async a bit.
 Is it possible to put java.awt.Graphics object into a channel and do the 
 drawing in a go loop consuming this channel.
 The problem I'm having is that when I consume the channel, core.async has 
 switched to another thread. I'm not in the Swing thread anymore.
 Is there a way to stay in the Swing thread while doing this?
  
 This is how I setup the producer:

 (defn create-canvas [paint-channel]
   (proxy [JButton] []
  (getPreferredSize [] (Dimension. 300 300))
  (paintComponent [g]
(go
  (proxy-super paintComponent g)
  (! paint-channel g) ;I've tried put! too

 Thanks!
 --anders




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: core.async + swing

2013-07-30 Thread eliassonaand
Hi Tim, 
I did try invokeLater before unsuccessfully. I think the problem was that 
the Graphics I passed on the channel wasn't valid anymore. This time around 
I tried getting the graphics with Component.getGraphics instead, inside 
invokeLater. That worked!
By the way, I think core.async is fantastic, what a relief to get rid of 
all the callbacks.
Thanks so much for your help and for core.async!
--anders
  

Den måndagen den 29:e juli 2013 kl. 16:52:31 UTC+2 skrev tbc++:

 I recommend using invokeLater to send a fn to Swing to do the rendering.


 http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)
  

 If you need Swing to notify the go channel when the rendering is complete, 
 you can do something like this:

 (go
   (let [c (chan)]
 (SwingUtilities/invokeLater (fn [] (do ...stuff ) (close! c)))
 (! c)))

 Wrap in a macro if you find yourself doing it a lot:

 (go (in-swing-and-wait
...stuff...))

 Timothy 


 On Mon, Jul 29, 2013 at 8:44 AM, eliass...@yahoo.com javascript:wrote:

 Hi, I'm playing around with core.async a bit.
 Is it possible to put java.awt.Graphics object into a channel and do the 
 drawing in a go loop consuming this channel.
 The problem I'm having is that when I consume the channel, core.async has 
 switched to another thread. I'm not in the Swing thread anymore.
 Is there a way to stay in the Swing thread while doing this?
  
 This is how I setup the producer:

 (defn create-canvas [paint-channel]
   (proxy [JButton] []
  (getPreferredSize [] (Dimension. 300 300))
  (paintComponent [g]
(go
  (proxy-super paintComponent g)
  (! paint-channel g) ;I've tried put! too

 Thanks!
 --anders


  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




 -- 
 “One of the main causes of the fall of the Roman Empire was that–lacking 
 zero–they had no way to indicate successful termination of their C 
 programs.”
 (Robert Firth) 


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




core.async + swing

2013-07-29 Thread eliassonaand
Hi, I'm playing around with core.async a bit.
Is it possible to put java.awt.Graphics object into a channel and do the 
drawing in a go loop consuming this channel.
The problem I'm having is that when I consume the channel, core.async has 
switched to another thread. I'm not in the Swing thread anymore.
Is there a way to stay in the Swing thread while doing this?
 
This is how I setup the producer:

(defn create-canvas [paint-channel]
  (proxy [JButton] []
 (getPreferredSize [] (Dimension. 300 300))
 (paintComponent [g]
   (go
 (proxy-super paintComponent g)
 (! paint-channel g) ;I've tried put! too

Thanks!
--anders


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: anaphoric macro?

2013-07-24 Thread eliassonaand
Hi Alex,
That works perfect!
I've another (possibly stupid) question.
If I want this to work with your macro:

(def abc [a b c])

(def-name abc a)

How could I get that to work?
Thanks,
--anders

Den tisdagen den 23:e juli 2013 kl. 09:48:18 UTC+2 skrev Alex Baranosky:

 Hi Anders,

 (defmacro def-name [name-vec  body]
   `(let ~(vec (interleave (map symbol name-vec)
   name-vec))
~@body))

 user= (macroexpand '(def-name [a b c] 1 2 3))
 (let* [a a b b c c] 1 2 3)

 user= (def-name [a b c] a)
 a
 user= (def-name [a b c] b)
 b
 user= (def-name [a b c] (str a b))
 ab

 Best,
 Alex

 On Tue, Jul 23, 2013 at 12:18 AM, eliass...@yahoo.com javascript:wrote:

 Hi,
 I want to write a macro that introduces new variables from data.
 The data is a vector and looks like this for example: [a b c]

 I want to use the macro like this:
 (def-names [a b c] (str a b))

 What code I want the macro to produce from the above is the following:
 (let [a a
b b
c c]
   (str a b))

 Is it possible to do that?
 Is it a good thing to do that or is it bad practice?

 Thanks
 --anders
   
  

 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




anaphoric macro?

2013-07-23 Thread eliassonaand
Hi,
I want to write a macro that introduces new variables from data.
The data is a vector and looks like this for example: [a b c]

I want to use the macro like this:
(def-names [a b c] (str a b))

What code I want the macro to produce from the above is the following:
(let [a a
   b b
   c c]
  (str a b))

Is it possible to do that?
Is it a good thing to do that or is it bad practice?

Thanks
--anders
  
 

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: anaphoric macro?

2013-07-23 Thread eliassonaand
Thanks a lot guys, I'll try it out tomorrow.
Anders

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.