Re: [core.logic] What's the difference between "q" and a fresh LVar? Or: "java.lang.ClassCastException: clojure.core.logic.LVar cannot be cast to java.lang.Number"

2016-04-09 Thread Kevin Downey
Check 'lein deps :tree' for conflicting core.logic versions, and delete
the target directory to make sure you don't have old classfiles sitting
around.

On 04/09/2016 04:47 AM, Daniel Ziltener wrote:
> Oops, yes, in my actual code it was both ":db/id", so that's not the
> issue. It's really confusing - today, it works. No idea why. I restarted
> the REPL multiple times to try it, and it never worked. Today it worked
> with the exact same code file on the first try. After getting a very
> strange exception that "clojure.core.logic.core" couldn't be compiled
> due to "clojure.lang.Compiler$CompilerException:
> java.lang.ClassNotFoundException:
> clojure.core.logic.protocols.ITreeConstraint,
> compiling:(clojure/core/logic.clj:1:1)
>java.lang.ClassNotFoundException:
> clojure.core.logic.protocols.ITreeConstraint". I'm thoroughly confused,
> but I hope it will keep working.
> 
> Am Samstag, 9. April 2016 03:45:00 UTC+2 schrieb red...@gmail.com:
> 
> Hard to say, the class cast exception will have more information in it
> that could cast light on the issue. You also are using :id in one
> variation, and :db/id in the other.
> 
> On 04/08/2016 05:46 PM, Daniel Ziltener wrote:
> > Hi clj,
> >
> > I'm trying to do some simple core.logic stuff. My input is a
> vector of
> > maps, which I turn into a source for core.logic using
> > |
> > (defn make-datamap-rel [datapile]
> >   (fn [q]
> > (fn [a]
> >   (to-stream
> >(map #(unify a % q) (flatten datapile))
> > |
> >
> > Now I have written two variants for solving my problem. The first
> works
> > flawlessly:
> > |
> > (defn-find-cat-and-tag-id [pile cat]
> >   (let [datamap-rel (make-datamap-rel pile)]
> > (run*[q]
> > (datamap-rel (partial-map {:id q :category cat}))
> > )))
> > |
> >
> > The second variant throws the ClassCastException:
> > |
> > (defn-find-cat-and-tag-id [pile cat]
> >   (let [datamap-rel (make-datamap-rel pile)]
> > (run*[q]
> >   (fresh [qid]
> > (datamap-rel (partial-map {:db/id qid :category cat}))
> > (==q qid)
> > 
> > |
> >
> > I have no idea why this fails. It just doesn't make any sense. Any
> ideas?
> >
> > Best regards,
> > zilti
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com 
> > .
> > For more options, visit https://groups.google.com/d/optout
> .
> 
> 
> -- 
> And what is good, Phaedrus,
> And what is not good—
> Need we ask anyone to tell us these things?
> 
> -- 
> 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.


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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.co

Re: Clojure IoT?

2016-04-09 Thread Bruce Durling
Gregg,

We've done a fair bit as has opensensors.io and xively/pachube. What
have you been doing?

cheers,
Bruce

On Sat, Apr 9, 2016 at 11:38 PM, Gregg Reynolds  wrote:
> A very general question : is anybody other than me working with Clojure for
> IoT stuff?
>
> --
> 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.

-- 
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.


Clojure IoT?

2016-04-09 Thread Gregg Reynolds
A very general question : is anybody other than me working with Clojure for
IoT stuff?

-- 
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: Extracting tags from parsed html

2016-04-09 Thread Danny Freeman
Thanks for the reply! I like how simple the solution is. I ended up with a 
function looking like this:

(defn get-tags
  [tag html]
  (let [tags (-> (clojure.zip/xml-zip html)
 (xml-> clojure.data.zip/descendants tag))]
(for [t tags]
  (first t

The data structure I get from this makes it really easy to extract all the 
href's out as well.

On Saturday, April 9, 2016 at 4:27:10 PM UTC-4, James Reeves wrote:
>
> If you parse into data structure compatible with clojure.xml, then you can 
> use an XML zipper to find the links in the document.
>
>   (-> s
>   pl.danieljanus.tagsoup/parse-xml
>   clojure.zip/xml-zip
>   (clojure.data.zip/xml-> clojure.data.zip/descendants :a))
>
> - James
>
> On 9 April 2016 at 20:15, Danny Freeman 
> > wrote:
>
>> I have been working on a program that will take a website, and extract 
>> all the links from the body of the HTML page. I am using tagsoup 
>>  to create a tree structure from 
>> an html page. 
>>
>> The current issue I am running into is traversing the tree structure and 
>> pulling out all the links. I have a function that will parses the tree 
>> using a for loop and recursion, but it does not feel very idiomatic. The 
>> list it returns is filled with vectors of emtpy lists and nil values. I can 
>> flatten out the data structure and grab everything I need out of it, but it 
>> feels clunky. I was looking for some tips on how I could impore my code, 
>> since this is the first complicated clojure program I have written. 
>>
>> Here is the code I have written for extracting the a tags out of the html 
>> tree.
>>
>> (defn get-tags 
>>   ([tag html]
>> (get-tags tag [] html))
>>
>>   ([tag found html]
>> (if html
>>   (for [el html]
>> (if (vector? el)
>>   (if (= (soup/tag el) tag)
>> (conj found el)
>> (->> (soup/children el)
>>(remove #(or (string? %) (nil? %)))
>>(get-tags tag found)
>>(conj found
>>
>> It gets called with this something like this. Normally the site would be 
>> a lot bigger, but I deleted a lot of the tree for this post.
>>
>> (def html-tree 
>> [:body
>>  {}
>>  [:a
>>   {:href "conditionedtransiti.php", :shape "rect", :style "display: 
>> none;"}
>>   "triangular-nordic"]
>>  [:table
>>   {}
>>   [:tr
>>{}
>>[:td
>> {:colspan "1", :rowspan "1"}
>> [:a
>>  {:href "/files/", :shape "rect"}
>>  [:img {:src "truck.gif", :title "Slug's File Archive"}]]]
>>[:td
>> {:colspan "1", :rowspan "1"}
>> [:a {:href "/docs/", :shape "rect"} [:img {:src "magnify.gif"}]]]
>>[:td
>> {:colspan "1", :rowspan "1"}
>> [:a
>>  {:href "
>> http://forecast.weather.gov/MapClick.php?lat=35.045627427000454&lon=-85.30967786199966
>> ",
>>   :shape "rect"}
>>  "Forecast"]
>> [:br {:clear "none"}]
>> [:a
>>  {:href "
>> http://radar.weather.gov/radar.php?rid=htx&product=N0R&overlay=1110&loop=no
>> ",
>>   :shape "rect"}
>>  "Radar"]
>> [:br {:clear "none"}]
>> [:a {:href "http://news.google.com/";, :shape "rect"} "News"]
>> [:br {:clear "none"}]]
>>[:td
>> {:colspan "1", :rowspan "1"}
>> [:a {:href "http://reddit.com";, :shape "rect"} "Reddit"]
>> [:br {:clear "none"}]
>> [:a {:href "http://digg.com";, :shape "rect"} "Digg"]
>> [:br {:clear "none"}])
>>
>> (get-tags :a html-tree)
>>
>> This evaluates to 
>> (nil
>>  nil
>>  [[:a
>>{:href "conditionedtransiti.php", :shape "rect", :style "display: 
>> none;"}
>>"triangular-nordic"]]
>>  [([([([[:a
>>  {:href "/files/", :shape "rect"}
>>  [:img {:src "truck.gif", :title "Slug's File Archive"}]]])]
>>  [([[:a {:href "/docs/", :shape "rect"} [:img {:src 
>> "magnify.gif"}]]])]
>>  [([[:a
>>  {:href "
>> http://forecast.weather.gov/MapClick.php?lat=35.045627427000454&lon=-85.30967786199966
>> ",
>>   :shape "rect"}
>>  "Forecast"]]
>>[()]
>>[[:a
>>  {:href "
>> http://radar.weather.gov/radar.php?rid=htx&product=N0R&overlay=1110&loop=no
>> ",
>>   :shape "rect"}
>>  "Radar"]]
>>[()]
>>[[:a {:href "http://news.google.com/";, :shape "rect"} "News"]]
>>[()])]
>>  [([[:a {:href "http://reddit.com";, :shape "rect"} "Reddit"]]
>>[()]
>>[[:a {:href "http://digg.com";, :shape "rect"} "Digg"]]
>>[()])])])])
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You receive

[ANN] clojure.java.jdbc 0.5.5

2016-04-09 Thread Sean Corfield
What?
org.clojure/java.jdbc “0.5.5”
Clojure contrib wrapper for JDBC database operations

Where?
https://github.com/clojure/java.jdbc#change-log

Why?
In the previous versions (0.5.0 and earlier), options to most functions 
were specified as inline unrolled keyword/value arguments:

(jdbc/query db [“select * from foo where id = ?” pk]
 :row-fn :name :result-set-fn first :identifiers identity)

Whilst this style of argument is convenient from the REPL, it becomes 
increasingly awkward as you start composing functions – you start having to use 
`apply` and `mapcat identity` and so on.

Version 0.5.5 introduces a single options map argument into all 
functions that previously took unrolled keyword/value arguments. It is the 
optional, last argument in all cases (see caveat below).

(jdbc/query db [“select * from foo where id = ?” pk]
 {:row-fn :name :result-set-fn first :identifiers identity})

   Version 0.5.5 continues to support the unrolled option arguments but 
considers them deprecated – and using them will cause a DEPRECATED message to 
be printed to stdout (this was already true for `db-transaction` which was 
deprecated in favor of `with-db-transaction` back in version 0.3.0).

Plans?
Version 0.5.6 will further clean up the calling syntax for several 
functions. Expect a few API additions and a few more deprecations.
Version 0.6.0 will remove all deprecated functionality (including the 
old API which continued in java.jdbc.deprecated for several versions). 

Caveat?
Two functions were problematic since they were already variadic in 
their regular arguments: `insert!` and `create-table-ddl`. In order to flag the 
(optional) options map, these now expect an `:options` argument followed by the 
actual options map. I am considering introducing new functions with better 
argument lists in 0.5.6 to clean this up.

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)




-- 
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: Extracting tags from parsed html

2016-04-09 Thread James Reeves
If you parse into data structure compatible with clojure.xml, then you can
use an XML zipper to find the links in the document.

  (-> s
  pl.danieljanus.tagsoup/parse-xml
  clojure.zip/xml-zip
  (clojure.data.zip/xml-> clojure.data.zip/descendants :a))

- James

On 9 April 2016 at 20:15, Danny Freeman  wrote:

> I have been working on a program that will take a website, and extract all
> the links from the body of the HTML page. I am using tagsoup
>  to create a tree structure from
> an html page.
>
> The current issue I am running into is traversing the tree structure and
> pulling out all the links. I have a function that will parses the tree
> using a for loop and recursion, but it does not feel very idiomatic. The
> list it returns is filled with vectors of emtpy lists and nil values. I can
> flatten out the data structure and grab everything I need out of it, but it
> feels clunky. I was looking for some tips on how I could impore my code,
> since this is the first complicated clojure program I have written.
>
> Here is the code I have written for extracting the a tags out of the html
> tree.
>
> (defn get-tags
>   ([tag html]
> (get-tags tag [] html))
>
>   ([tag found html]
> (if html
>   (for [el html]
> (if (vector? el)
>   (if (= (soup/tag el) tag)
> (conj found el)
> (->> (soup/children el)
>(remove #(or (string? %) (nil? %)))
>(get-tags tag found)
>(conj found
>
> It gets called with this something like this. Normally the site would be a
> lot bigger, but I deleted a lot of the tree for this post.
>
> (def html-tree
> [:body
>  {}
>  [:a
>   {:href "conditionedtransiti.php", :shape "rect", :style "display: none;"}
>   "triangular-nordic"]
>  [:table
>   {}
>   [:tr
>{}
>[:td
> {:colspan "1", :rowspan "1"}
> [:a
>  {:href "/files/", :shape "rect"}
>  [:img {:src "truck.gif", :title "Slug's File Archive"}]]]
>[:td
> {:colspan "1", :rowspan "1"}
> [:a {:href "/docs/", :shape "rect"} [:img {:src "magnify.gif"}]]]
>[:td
> {:colspan "1", :rowspan "1"}
> [:a
>  {:href "
> http://forecast.weather.gov/MapClick.php?lat=35.045627427000454&lon=-85.30967786199966
> ",
>   :shape "rect"}
>  "Forecast"]
> [:br {:clear "none"}]
> [:a
>  {:href "
> http://radar.weather.gov/radar.php?rid=htx&product=N0R&overlay=1110&loop=no
> ",
>   :shape "rect"}
>  "Radar"]
> [:br {:clear "none"}]
> [:a {:href "http://news.google.com/";, :shape "rect"} "News"]
> [:br {:clear "none"}]]
>[:td
> {:colspan "1", :rowspan "1"}
> [:a {:href "http://reddit.com";, :shape "rect"} "Reddit"]
> [:br {:clear "none"}]
> [:a {:href "http://digg.com";, :shape "rect"} "Digg"]
> [:br {:clear "none"}])
>
> (get-tags :a html-tree)
>
> This evaluates to
> (nil
>  nil
>  [[:a
>{:href "conditionedtransiti.php", :shape "rect", :style "display:
> none;"}
>"triangular-nordic"]]
>  [([([([[:a
>  {:href "/files/", :shape "rect"}
>  [:img {:src "truck.gif", :title "Slug's File Archive"}]]])]
>  [([[:a {:href "/docs/", :shape "rect"} [:img {:src "magnify.gif"}]]])]
>  [([[:a
>  {:href "
> http://forecast.weather.gov/MapClick.php?lat=35.045627427000454&lon=-85.30967786199966
> ",
>   :shape "rect"}
>  "Forecast"]]
>[()]
>[[:a
>  {:href "
> http://radar.weather.gov/radar.php?rid=htx&product=N0R&overlay=1110&loop=no
> ",
>   :shape "rect"}
>  "Radar"]]
>[()]
>[[:a {:href "http://news.google.com/";, :shape "rect"} "News"]]
>[()])]
>  [([[:a {:href "http://reddit.com";, :shape "rect"} "Reddit"]]
>[()]
>[[:a {:href "http://digg.com";, :shape "rect"} "Digg"]]
>[()])])])])
>
> --
> 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.
>

-- 
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, 

Puzzle solving in Clojure

2016-04-09 Thread Cornelius Goh
Just my 2-cent suggestion : at your Permutation recursion function,  may be try 
"recur" instead. 

-- 
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.


Extracting tags from parsed html

2016-04-09 Thread Danny Freeman
I have been working on a program that will take a website, and extract all 
the links from the body of the HTML page. I am using tagsoup 
 to create a tree structure from an 
html page. 

The current issue I am running into is traversing the tree structure and 
pulling out all the links. I have a function that will parses the tree 
using a for loop and recursion, but it does not feel very idiomatic. The 
list it returns is filled with vectors of emtpy lists and nil values. I can 
flatten out the data structure and grab everything I need out of it, but it 
feels clunky. I was looking for some tips on how I could impore my code, 
since this is the first complicated clojure program I have written. 

Here is the code I have written for extracting the a tags out of the html 
tree.

(defn get-tags 
  ([tag html]
(get-tags tag [] html))

  ([tag found html]
(if html
  (for [el html]
(if (vector? el)
  (if (= (soup/tag el) tag)
(conj found el)
(->> (soup/children el)
   (remove #(or (string? %) (nil? %)))
   (get-tags tag found)
   (conj found

It gets called with this something like this. Normally the site would be a 
lot bigger, but I deleted a lot of the tree for this post.

(def html-tree 
[:body
 {}
 [:a
  {:href "conditionedtransiti.php", :shape "rect", :style "display: none;"}
  "triangular-nordic"]
 [:table
  {}
  [:tr
   {}
   [:td
{:colspan "1", :rowspan "1"}
[:a
 {:href "/files/", :shape "rect"}
 [:img {:src "truck.gif", :title "Slug's File Archive"}]]]
   [:td
{:colspan "1", :rowspan "1"}
[:a {:href "/docs/", :shape "rect"} [:img {:src "magnify.gif"}]]]
   [:td
{:colspan "1", :rowspan "1"}
[:a
 {:href 
"http://forecast.weather.gov/MapClick.php?lat=35.045627427000454&lon=-85.30967786199966";,
  :shape "rect"}
 "Forecast"]
[:br {:clear "none"}]
[:a
 {:href 
"http://radar.weather.gov/radar.php?rid=htx&product=N0R&overlay=1110&loop=no";,
  :shape "rect"}
 "Radar"]
[:br {:clear "none"}]
[:a {:href "http://news.google.com/";, :shape "rect"} "News"]
[:br {:clear "none"}]]
   [:td
{:colspan "1", :rowspan "1"}
[:a {:href "http://reddit.com";, :shape "rect"} "Reddit"]
[:br {:clear "none"}]
[:a {:href "http://digg.com";, :shape "rect"} "Digg"]
[:br {:clear "none"}])

(get-tags :a html-tree)

This evaluates to 
(nil
 nil
 [[:a
   {:href "conditionedtransiti.php", :shape "rect", :style "display: none;"}
   "triangular-nordic"]]
 [([([([[:a
 {:href "/files/", :shape "rect"}
 [:img {:src "truck.gif", :title "Slug's File Archive"}]]])]
 [([[:a {:href "/docs/", :shape "rect"} [:img {:src "magnify.gif"}]]])]
 [([[:a
 {:href 
"http://forecast.weather.gov/MapClick.php?lat=35.045627427000454&lon=-85.30967786199966";,
  :shape "rect"}
 "Forecast"]]
   [()]
   [[:a
 {:href 
"http://radar.weather.gov/radar.php?rid=htx&product=N0R&overlay=1110&loop=no";,
  :shape "rect"}
 "Radar"]]
   [()]
   [[:a {:href "http://news.google.com/";, :shape "rect"} "News"]]
   [()])]
 [([[:a {:href "http://reddit.com";, :shape "rect"} "Reddit"]]
   [()]
   [[:a {:href "http://digg.com";, :shape "rect"} "Digg"]]
   [()])])])])

-- 
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: Attempt At Futures

2016-04-09 Thread Leonardo Borges

Something like imminent might be useful here. In particular the section
about combinators: https://github.com/leonardoborges/imminent#combinators


On Sat, Apr 9, 2016 at 9:33 PM Gary Verhaegen 
wrote:

> You could:
>
> * Create all futures *without* deref'ing them, so they all start in
> parallel;
> * Loop through the futures, asking them if they have finished, and print
> those that have (and remove them from the list)
>
> But if you want to get each result as it comes back, it's probably a
> better fit for core.async than plain futures. I would suggest creating a
> channel with multiple producers and a single consumer, where each producer
> gets a site and the consumer prints the result. That way, you get the
> results as they come.
>
> Here is a rough draft:
>
> (ns cjr-http-test.core
>   (:require [clj-http.client :as client]
>
>
> [clojure.core.async :as async :refer [!!]]))
> (defn get-heads
>   [sites]
>   (mapv (fn [site] (future {:head (client/head site)
> :url site}))
> sites))
> (def sites ["http://www.google.com";
> "http://www.yahoo.com";
> "http://www.bing.com";])
> (defn use-futures
>   []
>   (let [head-requests (get-heads sites)]
> (loop [to-check head-requests checked []]
>   (cond (and (empty? checked) (empty? to-check))
> :finished
>
> (empty? to-check)
> (recur checked [])
>
> (realized? (first to-check))
> (do (-> to-check first deref :url println)
> (recur (rest to-check) checked))
>
> :else (recur (rest to-check) (cons (first to-check) checked))
> (defn use-async
>   []
>   (let [ch (async/chan)
> producers (mapv (fn [site]
>   (doto (Thread. #(>!! ch {:head (client/head site)
>:url site}))
> (.start)))
> sites)
> close-chan (doto (Thread. (fn []
> (mapv #(.join %) producers)
> (async/close! ch)))
>  (.start))]
> (loop [v (   (if (nil? v) :finished
> (do (-> v :url println)
> (recur (
> --
> 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.
>

-- 
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.


[ANN] geheimnis 0.1.0 - RSA + AES for clj & cljs

2016-04-09 Thread Christian Weilbach
>From the README:

Implementation of cross-platform (clj, cljs) cryptography. The library
supports AES/CBC/Pkcs7Padding with a 256 bit key and RSA with
arbitrary keysize. If you need something which is not provided, please
open an issue. While `geheimnis` is not supposed to cover all
cryptographic options like OpenSSL compatibility with a big set of
chiffres, common and useful algorithms should be provided with a solid
implementation. `geheimnis` is supposed to be batteries included on
Clojure level, so doing the right thing should be easy.

https://github.com/replikativ/geheimnis


RSA is implemented directly with BigIntegers, so if you like it feel
free to hack around. Elliptic curve crypto would also be nice, but RSA
should be good enough. The problem is probably rather lack of
randomness in some Browsers.

I hope this is useful to somebody else.

Let's encrypt with Clojure ;)
Christian

-- 
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: leiningen dependency management

2016-04-09 Thread Chris Price
We run into this sort of thing quite a bit.  Our solution so far has been:

1. Always use `:pedantic? :abort` in the project file.  It can be annoying, 
but we've found that's much better to get annoying errors about version 
conflicts at build time than to get cryptic failures at runtime, such as 
the one that you described with schema.
2. Any time `:pedantic?` surfaces a conflicting transitive dependency 
between two libraries, we add an explicit dependency for the transitive 
dependency to resolve the conflict.  We usually have a section at the top 
of our dependencies list reserved for these transitive dependency 
resolutions, with some comments around it explaining that these aren't 
"normal" dependencies.  Doing it this way seems to give us more warning 
when new versions of upstream libraries come into use, whereas 
`:exclusions` is more likely to silently ignore those situations.

I've also been hacking on support for "managedDependencies" 
(https://github.com/technomancy/leiningen/issues/2067), which would allow 
you to specify common dependency versions in a parent project file and 
hopefully eliminate some of the dependency-version-whack-a-mole that seems 
to creep in when you start working with a large number of libraries.

On Friday, April 8, 2016 at 12:36:50 PM UTC-7, Sven Richter wrote:
>
> Hi,
>
> I have a library A that I use in project B. Now, library A makes use of 
> plumatics schema, as well as project B. I wonder what the best practice is 
> here. 
> Include schema in library A's dependencies? Or only declare a 
> dev-dependency on schema in library A?
>
> If I declare a dev-dependency I require every project that depends on 
> library A to include schema as a dependency, otherwise it will not work (I 
> have seen that with database libs for instance). I find that a bit unlucky, 
> because one might end up referring a lot of libs that other libraries 
> depend on.
>
> Or, include it as a direct dependency in library A. But then strange 
> things may happen as I had it with schema. Library A included schema v 
> 1.0.5 and project B schema v 1.0.3. 
> Now when I executed code in project B I had a weird schema error saying 
> that something in the schema is wrong, during compile time. In the end it 
> turned out that I have to require schema v 1.0.5 in project B too to make 
> it work. This is even more troublesome, as I make every project, that 
> depends on my library, depend on a transitive dependency in a specific 
> version.
>
> Looking at gradle for instance there is a configuration called 
> 'providedCompile' which means it is used for compilation of the library, 
> but not a transitive dependency if I include that library. Is there 
> something similar for leiningen?
>
> Best Regards,
> Sven
>

-- 
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: [core.logic] What's the difference between "q" and a fresh LVar? Or: "java.lang.ClassCastException: clojure.core.logic.LVar cannot be cast to java.lang.Number"

2016-04-09 Thread Daniel Ziltener
Oops, yes, in my actual code it was both ":db/id", so that's not the issue. 
It's really confusing - today, it works. No idea why. I restarted the REPL 
multiple times to try it, and it never worked. Today it worked with the 
exact same code file on the first try. After getting a very strange 
exception that "clojure.core.logic.core" couldn't be compiled due to 
"clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException: 
clojure.core.logic.protocols.ITreeConstraint, 
compiling:(clojure/core/logic.clj:1:1)
   java.lang.ClassNotFoundException: 
clojure.core.logic.protocols.ITreeConstraint". I'm thoroughly confused, but 
I hope it will keep working.

Am Samstag, 9. April 2016 03:45:00 UTC+2 schrieb red...@gmail.com:
>
> Hard to say, the class cast exception will have more information in it 
> that could cast light on the issue. You also are using :id in one 
> variation, and :db/id in the other. 
>
> On 04/08/2016 05:46 PM, Daniel Ziltener wrote: 
> > Hi clj, 
> > 
> > I'm trying to do some simple core.logic stuff. My input is a vector of 
> > maps, which I turn into a source for core.logic using 
> > | 
> > (defn make-datamap-rel [datapile] 
> >   (fn [q] 
> > (fn [a] 
> >   (to-stream 
> >(map #(unify a % q) (flatten datapile)) 
> > | 
> > 
> > Now I have written two variants for solving my problem. The first works 
> > flawlessly: 
> > | 
> > (defn-find-cat-and-tag-id [pile cat] 
> >   (let [datamap-rel (make-datamap-rel pile)] 
> > (run*[q] 
> > (datamap-rel (partial-map {:id q :category cat})) 
> > ))) 
> > | 
> > 
> > The second variant throws the ClassCastException: 
> > | 
> > (defn-find-cat-and-tag-id [pile cat] 
> >   (let [datamap-rel (make-datamap-rel pile)] 
> > (run*[q] 
> >   (fresh [qid] 
> > (datamap-rel (partial-map {:db/id qid :category cat})) 
> > (==q qid) 
> >  
> > | 
> > 
> > I have no idea why this fails. It just doesn't make any sense. Any 
> ideas? 
> > 
> > Best regards, 
> > zilti 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com  
> > . 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
> -- 
> And what is good, Phaedrus, 
> And what is not good— 
> Need we ask anyone to tell us these things? 
>

-- 
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: Attempt At Futures

2016-04-09 Thread Gary Verhaegen
You could:

* Create all futures *without* deref'ing them, so they all start in
parallel;
* Loop through the futures, asking them if they have finished, and print
those that have (and remove them from the list)

But if you want to get each result as it comes back, it's probably a better
fit for core.async than plain futures. I would suggest creating a channel
with multiple producers and a single consumer, where each producer gets a
site and the consumer prints the result. That way, you get the results as
they come.

Here is a rough draft:

(ns cjr-http-test.core
  (:require [clj-http.client :as client]
[clojure.core.async :as async :refer [!!]]))
(defn get-heads
  [sites]
  (mapv (fn [site] (future {:head (client/head site)
:url site}))
sites))
(def sites ["http://www.google.com";
"http://www.yahoo.com";
"http://www.bing.com";])
(defn use-futures
  []
  (let [head-requests (get-heads sites)]
(loop [to-check head-requests checked []]
  (cond (and (empty? checked) (empty? to-check))
:finished

(empty? to-check)
(recur checked [])

(realized? (first to-check))
(do (-> to-check first deref :url println)
(recur (rest to-check) checked))

:else (recur (rest to-check) (cons (first to-check) checked))
(defn use-async
  []
  (let [ch (async/chan)
producers (mapv (fn [site]
  (doto (Thread. #(>!! ch {:head (client/head site)
   :url site}))
(.start)))
sites)
close-chan (doto (Thread. (fn []
(mapv #(.join %) producers)
(async/close! ch)))
 (.start))]
(loop [v ( v :url println)
(recur (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: leiningen dependency management

2016-04-09 Thread 'Sven Richter' via Clojure
Hi,

Thanks for your responses. I will go and try the :provided profile and see 
how it works out.

Thanks,
Sven

Am Samstag, 9. April 2016 02:51:15 UTC+2 schrieb Daniel Ziltener:
>
> Hi Sven,
>
> When you're sure the project depending your library does also has a 
> dependency on a third library, it's best to use the ":provided" profile, 
> rather than declaring it in the :dev profile. In your case there are two 
> possible solutions:
> 1. the dependency higher up wins. So if you declare the schema dependency 
> above the dependency on A, this should work.
> 2. modify the dependency vector in B's profile.clj so that it's something 
> like [A "0.1.0" :exclusions [schema]]. See 
> https://github.com/technomancy/leiningen/blob/stable/sample.project.clj#L48 
> for an example.
>
> I hope this helps you.
> zilti
>
> Am Freitag, 8. April 2016 21:36:50 UTC+2 schrieb Sven Richter:
>>
>> Hi,
>>
>> I have a library A that I use in project B. Now, library A makes use of 
>> plumatics schema, as well as project B. I wonder what the best practice is 
>> here. 
>> Include schema in library A's dependencies? Or only declare a 
>> dev-dependency on schema in library A?
>>
>> If I declare a dev-dependency I require every project that depends on 
>> library A to include schema as a dependency, otherwise it will not work (I 
>> have seen that with database libs for instance). I find that a bit unlucky, 
>> because one might end up referring a lot of libs that other libraries 
>> depend on.
>>
>> Or, include it as a direct dependency in library A. But then strange 
>> things may happen as I had it with schema. Library A included schema v 
>> 1.0.5 and project B schema v 1.0.3. 
>> Now when I executed code in project B I had a weird schema error saying 
>> that something in the schema is wrong, during compile time. In the end it 
>> turned out that I have to require schema v 1.0.5 in project B too to make 
>> it work. This is even more troublesome, as I make every project, that 
>> depends on my library, depend on a transitive dependency in a specific 
>> version.
>>
>> Looking at gradle for instance there is a configuration called 
>> 'providedCompile' which means it is used for compilation of the library, 
>> but not a transitive dependency if I include that library. Is there 
>> something similar for leiningen?
>>
>> Best Regards,
>> Sven
>>
>

-- 
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.