Re: Best tools for profiling Clojure programs?

2014-07-03 Thread ru
Thank you Niels,

вторник, 1 июля 2014 г., 15:10:42 UTC+4 пользователь Niels van Klaveren 
написал:
>
> A new option for test purposes is included in JDK 1.7.0_40 and up and is 
> called Java Mission Control. It is located in the JDK as /bin/jmc.exe.
>

Is this tool only for Windows? 

>
> With it you can connect to a local java process, or remotely through RMI, 
> and record all kinds of performance characteristics in a Flight Recording. 
> Such a flight recording can be a defined for a limited time, or it can 
> buffer the recording to record only the latest x minutes. Overhead depends 
> on the monitoring template used, but is typically around 2%. These 
> recordings can then be browsed, analyzed and queried in a pretty good 
> interface after the recording has been saved.
>
> To do so, you need to have the following options in your project.clj, and 
> run your project on a JDK > 1.7.0_40
>
> :jvm-opts [
> ; add Flight Recording options
> "-XX:+UnlockCommercialFeatures"
> "-XX:+FlightRecorder"
> ; add RMI connection (to connect to process remotely or 
> running as service/daemon)
> ; this example has NO authentication enabled through the 
> RMI port
> "-Dcom.sun.management.jmxremote"
> "-Dcom.sun.management.jmxremote.port="
> "-Dcom.sun.management.jmxremote.authenticate=false"
> "-Dcom.sun.management.jmxremote.ssl=false"]
>
>
> On Friday, June 20, 2014 3:05:05 PM UTC+2, ru wrote:
>>
>> Hi all,
>>
>> What performance profiling instrument somebody can recommend for Clojure 
>> programs and corresponding documents, articles or tutorials. Thanks in 
>> advance.
>>
>> Sincerely,
>>   Ru
>>
>

-- 
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: Deploying to Clojars no longer works

2014-07-03 Thread Adam Clements
Have you tried upgrading leiningen to the latest version? I don't think you
can deploy from old versions, at least that's been a problem for me in the
past.
On 2 Jul 2014 20:55, "Jacob Goodson"  wrote:

> I have been deploying the same project to clojars for quite a while now(5
> months?); for some reason it decided it no longer wanted to work.  After
> giving my pass phrase I get "peer not authenticated".  I have not changed
> computers nor do I have a new internet connection.  Does anyone know what
> the heck I've done to blow it up?
>
> --
> 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.


Re: Best tools for profiling Clojure programs?

2014-07-03 Thread Jakub Holy
No, it is not. At least it is available on Mac too.

On Thursday, July 3, 2014 9:25:44 AM UTC+2, ru wrote:
>
> Thank you Niels,
>
> вторник, 1 июля 2014 г., 15:10:42 UTC+4 пользователь Niels van Klaveren 
> написал:
>>
>> A new option for test purposes is included in JDK 1.7.0_40 and up and is 
>> called Java Mission Control. It is located in the JDK as /bin/jmc.exe.
>>
>
> Is this tool only for Windows? 
>
>>
>> With it you can connect to a local java process, or remotely through RMI, 
>> and record all kinds of performance characteristics in a Flight Recording. 
>> Such a flight recording can be a defined for a limited time, or it can 
>> buffer the recording to record only the latest x minutes. Overhead depends 
>> on the monitoring template used, but is typically around 2%. These 
>> recordings can then be browsed, analyzed and queried in a pretty good 
>> interface after the recording has been saved.
>>
>> To do so, you need to have the following options in your project.clj, and 
>> run your project on a JDK > 1.7.0_40
>>
>> :jvm-opts [
>> ; add Flight Recording options
>> "-XX:+UnlockCommercialFeatures"
>> "-XX:+FlightRecorder"
>> ; add RMI connection (to connect to process remotely or 
>> running as service/daemon)
>> ; this example has NO authentication enabled through the 
>> RMI port
>> "-Dcom.sun.management.jmxremote"
>> "-Dcom.sun.management.jmxremote.port="
>> "-Dcom.sun.management.jmxremote.authenticate=false"
>> "-Dcom.sun.management.jmxremote.ssl=false"]
>>
>>
>> On Friday, June 20, 2014 3:05:05 PM UTC+2, ru wrote:
>>>
>>> Hi all,
>>>
>>> What performance profiling instrument somebody can recommend for Clojure 
>>> programs and corresponding documents, articles or tutorials. Thanks in 
>>> advance.
>>>
>>> Sincerely,
>>>   Ru
>>>
>>

-- 
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: Best tools for profiling Clojure programs?

2014-07-03 Thread Alex Baranosky
YourKit works well. I've heard good things about JVisualVM, but don't have
experience using it.


On Thu, Jul 3, 2014 at 12:31 AM, Jakub Holy  wrote:

> No, it is not. At least it is available on Mac too.
>
>
> On Thursday, July 3, 2014 9:25:44 AM UTC+2, ru wrote:
>>
>> Thank you Niels,
>>
>> вторник, 1 июля 2014 г., 15:10:42 UTC+4 пользователь Niels van Klaveren
>> написал:
>>>
>>> A new option for test purposes is included in JDK 1.7.0_40 and up and is
>>> called Java Mission Control. It is located in the JDK as /bin/jmc.exe.
>>>
>>
>> Is this tool only for Windows?
>>
>>>
>>> With it you can connect to a local java process, or remotely through
>>> RMI, and record all kinds of performance characteristics in a Flight
>>> Recording. Such a flight recording can be a defined for a limited time, or
>>> it can buffer the recording to record only the latest x minutes. Overhead
>>> depends on the monitoring template used, but is typically around 2%. These
>>> recordings can then be browsed, analyzed and queried in a pretty good
>>> interface after the recording has been saved.
>>>
>>> To do so, you need to have the following options in your project.clj,
>>> and run your project on a JDK > 1.7.0_40
>>>
>>> :jvm-opts [
>>> ; add Flight Recording options
>>> "-XX:+UnlockCommercialFeatures"
>>> "-XX:+FlightRecorder"
>>> ; add RMI connection (to connect to process remotely or
>>> running as service/daemon)
>>> ; this example has NO authentication enabled through the
>>> RMI port
>>> "-Dcom.sun.management.jmxremote"
>>> "-Dcom.sun.management.jmxremote.port="
>>> "-Dcom.sun.management.jmxremote.authenticate=false"
>>> "-Dcom.sun.management.jmxremote.ssl=false"]
>>>
>>>
>>> On Friday, June 20, 2014 3:05:05 PM UTC+2, ru wrote:

 Hi all,

 What performance profiling instrument somebody can recommend for
 Clojure programs and corresponding documents, articles or tutorials. Thanks
 in advance.

 Sincerely,
   Ru

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


Re: Best tools for profiling Clojure programs?

2014-07-03 Thread Alex Baranosky
Woops, posting too late... I typed JVisualVM, but meant to say Java Mission
Control.


On Thu, Jul 3, 2014 at 1:10 AM, Alex Baranosky <
alexander.barano...@gmail.com> wrote:

> YourKit works well. I've heard good things about JVisualVM, but don't have
> experience using it.
>
>
> On Thu, Jul 3, 2014 at 12:31 AM, Jakub Holy  wrote:
>
>> No, it is not. At least it is available on Mac too.
>>
>>
>> On Thursday, July 3, 2014 9:25:44 AM UTC+2, ru wrote:
>>>
>>> Thank you Niels,
>>>
>>> вторник, 1 июля 2014 г., 15:10:42 UTC+4 пользователь Niels van Klaveren
>>> написал:

 A new option for test purposes is included in JDK 1.7.0_40 and up and
 is called Java Mission Control. It is located in the JDK as /bin/jmc.exe.

>>>
>>> Is this tool only for Windows?
>>>

 With it you can connect to a local java process, or remotely through
 RMI, and record all kinds of performance characteristics in a Flight
 Recording. Such a flight recording can be a defined for a limited time, or
 it can buffer the recording to record only the latest x minutes. Overhead
 depends on the monitoring template used, but is typically around 2%. These
 recordings can then be browsed, analyzed and queried in a pretty good
 interface after the recording has been saved.

 To do so, you need to have the following options in your project.clj,
 and run your project on a JDK > 1.7.0_40

 :jvm-opts [
 ; add Flight Recording options
 "-XX:+UnlockCommercialFeatures"
 "-XX:+FlightRecorder"
 ; add RMI connection (to connect to process remotely or
 running as service/daemon)
 ; this example has NO authentication enabled through
 the RMI port
 "-Dcom.sun.management.jmxremote"
 "-Dcom.sun.management.jmxremote.port="
 "-Dcom.sun.management.jmxremote.authenticate=false"
 "-Dcom.sun.management.jmxremote.ssl=false"]


 On Friday, June 20, 2014 3:05:05 PM UTC+2, ru wrote:
>
> Hi all,
>
> What performance profiling instrument somebody can recommend for
> Clojure programs and corresponding documents, articles or tutorials. 
> Thanks
> in advance.
>
> Sincerely,
>   Ru
>
  --
>> 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.


Re: Best tools for profiling Clojure programs?

2014-07-03 Thread Niels van Klaveren
No, also for Oracle JVM on Linux, and 64 bit Mac OS X

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

2014-07-03 Thread cig
Hi 

I have been trying to build a test.check generator for a multi map, without 
much success.
I have a generator which generates ordinary maps:

(def ord-gen
  (gen/fmap (partial zipmap [:port :instr :qty])
(gen/tuple (gen/not-empty gen/string-alpha-numeric)
   (gen/not-empty gen/string-alpha-numeric)
   (gen/frequency [[9 gen/pos-int] [1 gen/neg-int]]

(gen/sample ord-gen 3)
;; => ({:qty 0, :instr "X4", :port "re"} {:qty 0, :instr "v", :port "8"} 
{:qty 1, :instr "3A", :port "7"})

However, I would like to merge this sequence of individual maps into a 
multi-map of the form:

{"re" { "X4" {:qty 0, :instr "X4", :port "re"}}, "8" { "v" {:qty 0, :instr 
"v", :port "8"}}, "7" { "3A" {:qty 1, :instr "3A", :port "7"}}}

The closest I have gotten to achieving this is by realising the 
intermediate steps:

(def gen-cache
  (->>
   (gen/fmap (fn [o]
   (let [{:keys [port instr] :as ord} o]
 (assoc-in {} [port instr] ord)))
 ord-gen)
   (gen/sample)
   (reduce (fn [r m] (merge-with merge r m)) {})
   (gen/return)))


However, this returns the same value constantly (I am aware that, that is 
what gen/return is supposed to do, however, I can not get much else working 
for me). I would Ideally like to bind the ord-gen into the gen-cache 
generator. Any help would be very appreciated.

-- 
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: Deploying to Clojars no longer works

2014-07-03 Thread Zach Oakes
Even on the latest version (2.4.0), I've experienced problems in the last 
three weeks. I believe they've coincided with the site redesign, but they 
may not be related. I sometimes get "Read timed out" when uploading an 
artifact. Since deployments aren't atomic, the library or template will be 
partially uploaded and thus unusable, so I have to increment the version 
number and try again.

On Thursday, July 3, 2014 3:29:17 AM UTC-4, Adam Clements wrote:
>
> Have you tried upgrading leiningen to the latest version? I don't think 
> you can deploy from old versions, at least that's been a problem for me in 
> the past. 
> On 2 Jul 2014 20:55, "Jacob Goodson" > 
> wrote:
>
>> I have been deploying the same project to clojars for quite a while now(5 
>> months?); for some reason it decided it no longer wanted to work.  After 
>> giving my pass phrase I get "peer not authenticated".  I have not changed 
>> computers nor do I have a new internet connection.  Does anyone know what 
>> the heck I've done to blow it up?
>>
>> -- 
>> 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.
>>
>

-- 
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: auto-reloading tests with diffs

2014-07-03 Thread Jake McCrary
Hi Conrad,

Not sure if this will meet your needs but I just tried using 
humane-test-output with lein-test-refresh and had auto-running of tests 
with a nice diff output. If humane-test-output gives you the output you are 
looking for I'd imagine it works with prism as well.

humane-test-output: https://github.com/pjstadig/humane-test-output
lein-test-refresh: https://github.com/jakemcc/lein-test-refresh

Jake

On Wednesday, July 2, 2014 1:25:59 PM UTC-5, Conrad wrote:
>
> FYI, I installed difftest via a plugin entry in my ~/.lein/profiles.clj. 
> This requires me to call "lein difftest", since "lein test" still shows the 
> un-diffed test results. I suspect there's some extra step I need to take to 
> hook difftest into the default error reporting to make it work with "lein 
> prism" but I can't find any documentation for that... any pointers are 
> welcome!
>
> On Wednesday, July 2, 2014 1:16:47 PM UTC-5, Conrad wrote:
>>
>> Hi, I'm doing some tests that require diff reporting (ala "lein 
>> difftest") but want them to autoreload (ala "lein prism").
>>
>> Does anyone know if there's a way to make these libraries function 
>> together? Is there some other approach/library I should be using to get 
>> both diff reporting and autoreloading at once?
>>
>> Thanks for any pointers!
>>
>

-- 
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: clojure.test.check

2014-07-03 Thread Reid Draper
Hi,

I've taken a stab at what I think you want:

(def gen-cache
  (gen/fmap
#(reduce (fn [r m] (merge-with merge r m)) {} %)
(gen/vector (gen/fmap
  (fn [o]
(let [{:keys [port instr] :as ord} o]
  (assoc-in {} [port instr] ord)))
  ord-gen


Instead of using `gen/sample` to create a sequence, I use `gen/vector`. And in 
order to apply the `reduce` function, I use `gen/fmap`.


As an aside, I'm not sure how this is a multi-map. I was under the impression a 
multi-map was simply a map that can store multiple values in the same key.


Reid


On Thursday, July 3, 2014 6:06:29 AM UTC-5, cig wrote:
>
> Hi 
>
> I have been trying to build a test.check generator for a multi map, 
> without much success.
> I have a generator which generates ordinary maps:
>
> (def ord-gen
>   (gen/fmap (partial zipmap [:port :instr :qty])
> (gen/tuple (gen/not-empty gen/string-alpha-numeric)
>(gen/not-empty gen/string-alpha-numeric)
>(gen/frequency [[9 gen/pos-int] [1 gen/neg-int]]
>
> (gen/sample ord-gen 3)
> ;; => ({:qty 0, :instr "X4", :port "re"} {:qty 0, :instr "v", :port "8"} 
> {:qty 1, :instr "3A", :port "7"})
>
> However, I would like to merge this sequence of individual maps into a 
> multi-map of the form:
>
> {"re" { "X4" {:qty 0, :instr "X4", :port "re"}}, "8" { "v" {:qty 0, :instr 
> "v", :port "8"}}, "7" { "3A" {:qty 1, :instr "3A", :port "7"}}}
>
> The closest I have gotten to achieving this is by realising the 
> intermediate steps:
>
> (def gen-cache
>   (->>
>(gen/fmap (fn [o]
>(let [{:keys [port instr] :as ord} o]
>  (assoc-in {} [port instr] ord)))
>  ord-gen)
>(gen/sample)
>(reduce (fn [r m] (merge-with merge r m)) {})
>(gen/return)))
>
>
> However, this returns the same value constantly (I am aware that, that is 
> what gen/return is supposed to do, however, I can not get much else working 
> for me). I would Ideally like to bind the ord-gen into the gen-cache 
> generator. Any help would be very appreciated.
>

-- 
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: Broad question about best-practices for structs

2014-07-03 Thread SharpCoder
Hello Timothy,

Thank you for the response. I've given much thought to your examples and it 
quickly became clear how relevant defprotocol and deftype is. I had no idea 
Clojure provided a mechanism for strongly typed structures like that. I've 
started re-designing my library around this concept and even with my 
limited understanding, the code is becoming much cleaner and simpler!

So thank you for that.

I had a question about designing with defprotocol. While trying to 
implement my protocol "Network", I was struggling with deciding what 
signature to use. Is it better to write lots of functions that compute 
stuff given a concrete input. Or it is better to write functions that 
return "new versions" of the inputted data? I guess my question comes down 
to how other people use libraries. Is there a definitive standard or guide 
for structuring libraries in Clojure? 

One other question was whether methods can be marked "internal" within a 
protocol?

Thank you for your time.
-SharpCoder

On Wednesday, July 2, 2014 9:17:25 AM UTC-7, tbc++ wrote:
>
> defstruct is deprecated. You should use defrecord or deftype instead. You 
> can define operations on these via defprotocol. 
>
> And you can even type hint the members:
>
> (defprotocol IScale 
>   (scale [this ^double amount]))
>
> (deftype Point [^double x ^double y]
>   IScale
>   (scale [this amount]
> (Point. (* x amount) (* y amount
>
> (scale (Point. 10 1))
>
> Timothy
>   
>
>
> On Wed, Jul 2, 2014 at 9:41 AM, SharpCoder  > wrote:
>
>> As an exercise, I'm trying to port a library that I originally wrote in 
>> C#. It's actually a Neural Network, so my imperative design was a pretty 
>> straightforward tree-like structure of nodes that could manipulate state. 
>> During my port to Clojure, I've been writing functions that take multiple 
>> arrays (typically "graph of outputs" and "graph of weights"). Then I 
>> remembered about structs, so I refactored my code to deal with a collection 
>> of structs "node". A node contains a vector of weights and an output. In 
>> this way, I am only passing around a single collection that can represent 
>> my whole neural network.
>>
>> Now I'm running into the fact that I kind of need to update the 
>> structure. So what I've implemented is essentially, each time you calculate 
>> the network output - my code iterates over the list of structs and creates 
>> new ones with the "updated" values. Performance is something that people 
>> don't seem to talk about much with Clojure, but I'm kind of thinking my 
>> approach with structs might not be the best one.
>>
>> My question is, am I approaching this incorrectly? I've seen a lot of 
>> resources that deal with the syntax of Clojure but haven't found a good 
>> guide on actual application design. My usage of structures seems natural to 
>> me, but that makes me question it even more!
>>
>> For anyone interested, here is my code: https://www.refheap.com/87775
>> I'm going to open source the library after many many iterations to 
>> beautify it. I'm sure it's a bit too haphazard to make sense to right now...
>>
>> Thank you for your time!
>> -SharpCoder
>>
>> -- 
>> 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.
>>
>
>
>
> -- 
> “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/d/optout.


Re: Broad question about best-practices for structs

2014-07-03 Thread Timothy Baldridge
There's one other construct that may help you here:

(defrecord Point [x y]
  (scale [this amount]
(assoc this :x (* x amount) :y (* y amount

defrecord acts much like deftype, but creates a new copy of the record via
assoc, you can also do stuff like:

(:x (->Point 10 11))

defrecord creates a constructor function (type name prefixed by ->) and you
can use normal get/assoc/dissoc to work with records as if they were normal
structures.

So yes, defrecord is probably the most idiomatic approach if you need the
functionality of defprotocol. You can also use straight up maps to do much
of this:

{:type :point
 :x 10
 :y 42}

You have three choices then:

1) maps - easy to work with, slower polymorphic dispatch (via multi-methods)
2) records - slightly less easy to work with, faster polymorphic dispatch
3) types - hardest to work with (manual cloning), supports mutation, fast
polymorphic dispatch.

Often I suggest people try working only with hash maps and multi-methods
first, then move on to the other approaches if performance is too low.

Most of the Clojure data-structures are so fast I use those most of the
time.

As far as the rest of your questions go, I often prefix protocol functions
with a dash to indicate they are internal. (-scale point 42).

And you really don't have to type hint functions. That's really only if you
are super concerned about performance. Type hinting signatures allows the
compiler to remove boxing and that sometimes helps. Once again, write the
code so it works, then make it fast.

Timothy Baldridge


On Thu, Jul 3, 2014 at 9:44 AM, SharpCoder 
wrote:

> Hello Timothy,
>
> Thank you for the response. I've given much thought to your examples and
> it quickly became clear how relevant defprotocol and deftype is. I had no
> idea Clojure provided a mechanism for strongly typed structures like that.
> I've started re-designing my library around this concept and even with my
> limited understanding, the code is becoming much cleaner and simpler!
>
> So thank you for that.
>
> I had a question about designing with defprotocol. While trying to
> implement my protocol "Network", I was struggling with deciding what
> signature to use. Is it better to write lots of functions that compute
> stuff given a concrete input. Or it is better to write functions that
> return "new versions" of the inputted data? I guess my question comes down
> to how other people use libraries. Is there a definitive standard or guide
> for structuring libraries in Clojure?
>
> One other question was whether methods can be marked "internal" within a
> protocol?
>
> Thank you for your time.
> -SharpCoder
>
> On Wednesday, July 2, 2014 9:17:25 AM UTC-7, tbc++ wrote:
>
>> defstruct is deprecated. You should use defrecord or deftype instead. You
>> can define operations on these via defprotocol.
>>
>> And you can even type hint the members:
>>
>> (defprotocol IScale
>>   (scale [this ^double amount]))
>>
>> (deftype Point [^double x ^double y]
>>   IScale
>>   (scale [this amount]
>> (Point. (* x amount) (* y amount
>>
>> (scale (Point. 10 1))
>>
>> Timothy
>>
>>
>>
>> On Wed, Jul 2, 2014 at 9:41 AM, SharpCoder  wrote:
>>
>>> As an exercise, I'm trying to port a library that I originally wrote in
>>> C#. It's actually a Neural Network, so my imperative design was a pretty
>>> straightforward tree-like structure of nodes that could manipulate state.
>>> During my port to Clojure, I've been writing functions that take multiple
>>> arrays (typically "graph of outputs" and "graph of weights"). Then I
>>> remembered about structs, so I refactored my code to deal with a collection
>>> of structs "node". A node contains a vector of weights and an output. In
>>> this way, I am only passing around a single collection that can represent
>>> my whole neural network.
>>>
>>> Now I'm running into the fact that I kind of need to update the
>>> structure. So what I've implemented is essentially, each time you calculate
>>> the network output - my code iterates over the list of structs and creates
>>> new ones with the "updated" values. Performance is something that people
>>> don't seem to talk about much with Clojure, but I'm kind of thinking my
>>> approach with structs might not be the best one.
>>>
>>> My question is, am I approaching this incorrectly? I've seen a lot of
>>> resources that deal with the syntax of Clojure but haven't found a good
>>> guide on actual application design. My usage of structures seems natural to
>>> me, but that makes me question it even more!
>>>
>>> For anyone interested, here is my code: https://www.refheap.com/87775
>>> I'm going to open source the library after many many iterations to
>>> beautify it. I'm sure it's a bit too haphazard to make sense to right now...
>>>
>>> Thank you for your time!
>>> -SharpCoder
>>>
>>> --
>>> 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

Re: Why does unquote clone values?

2014-07-03 Thread Pascal Germroth
Hi Atamert,

Here's a gist with the example code: 
https://gist.github.com/neapel/4e502a14e3738b709672

I tried replacing a closure with a dynamically built and evaluated 
>> metafunction but discovered that it was actually slower.
>>
>
> If evaluating code during run is slower than AOT compiling it, it wouldn't 
> surprise me.
>

I didn't actually try AOT compiling it, just using the REPL. As far as I 
understand there shouldn't be a difference in speed, since (eval) runs the 
same compiler as AOT does, and even writes out a .class file.

(possibly unrelated, maybe due to eval, when trying to AOT compile the 
example project by adding `:aot :all` and running `lein jar`, it appears to 
fall into an infinite loop. The JAR file grew to 8GB, but I couldn't list 
its contents.)
 

> I guess f2 runs this much slower than f1 because it doesn't actually pass 
>> a reference to x when unquoting, but clones the value, which means it needs 
>> to compare the lists element-wise.
>>
>
> This is interesting. Were you able to confirm it or are you just guessing? 
> (I'm just curious.) 
>

 The code in the Gist produces a nice table now, here's my result (I 
couldn't reproduce the case where f3 runs as fast as f1 for vectors; but 
it's actually less weird this way)
I think it's quite obvious that f1 compares always references, as does the 
"nil" case, while the "vec" and "map" cases compare by value:

|map |vec |  nil | name |
|++--+--|
|   5 ns |   5 ns | 5 ns |   f1 |
| 558 ns | 134 ns | 6 ns |   f2 |
| 567 ns | 130 ns | 7 ns |   f3 |
| 561 ns | 117 ns | 7 ns |   f4 |

It also dumps the disassembly, we can see that:

f1-map == f1-vec == f1-nil (makes sense, as the reference to the value is 
passed in the constructor of the closure)
f2-map = f3-map, f2-vec = f3-vec, f2-nil = f3-nil (with renaming)
f4-map = f1, f4-vec = f1, f4-nil = f1 (with renaming)
f2-map = f2-vec, except for calling clojure.lang.RT.map / vector.

So there are only three versions of the actual bytecode:
- the closure f1/f4;
- f2 building a new object in its static constructor
- f2-nil using a null constant instead of a field containing null.

importantly, f1/f4 are identical:
public final class F extends clojure.lang.AFunction {
  /* ... static constructor getting clojure.core/= ... */
  Object x;
  public F(Object o) { x = o }
  public Object invoke( Object y ) {
/*basically*/ return (bool (= x y))
  }
}

So why does f4 behave almost like f2/f3?!


Cheers,

-- 
pascal

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


syntax tree manipulation

2014-07-03 Thread Brian Craft
What clojure tools should I be considering for doing syntax tree 
manipulations? In general, I'm recursively matching patterns in subtrees 
and rewriting them. The patterns are usually more complex than, say, 
core.match patterns (e.g. match subtree having vector that contains term, 
and split the term out of the vector and put in its own subtree).

-- 
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: Why does unquote clone values?

2014-07-03 Thread adrian . medina
You're going down a rabbit hole here. Evaluating forms at runtime will 
always result in a slower execution time than a function that doesn't 
evaluate a form at runtime. 

On Thursday, July 3, 2014 11:55:02 AM UTC-4, Pascal Germroth wrote:
>
> Hi Atamert,
>
> Here's a gist with the example code: 
> https://gist.github.com/neapel/4e502a14e3738b709672
>
> I tried replacing a closure with a dynamically built and evaluated 
>>> metafunction but discovered that it was actually slower.
>>>
>>
>> If evaluating code during run is slower than AOT compiling it, it 
>> wouldn't surprise me.
>>
>
> I didn't actually try AOT compiling it, just using the REPL. As far as I 
> understand there shouldn't be a difference in speed, since (eval) runs the 
> same compiler as AOT does, and even writes out a .class file.
>
> (possibly unrelated, maybe due to eval, when trying to AOT compile the 
> example project by adding `:aot :all` and running `lein jar`, it appears to 
> fall into an infinite loop. The JAR file grew to 8GB, but I couldn't list 
> its contents.)
>  
>
>> I guess f2 runs this much slower than f1 because it doesn't actually pass 
>>> a reference to x when unquoting, but clones the value, which means it needs 
>>> to compare the lists element-wise.
>>>
>>
>> This is interesting. Were you able to confirm it or are you just 
>> guessing? (I'm just curious.) 
>>
>
>  The code in the Gist produces a nice table now, here's my result (I 
> couldn't reproduce the case where f3 runs as fast as f1 for vectors; but 
> it's actually less weird this way)
> I think it's quite obvious that f1 compares always references, as does the 
> "nil" case, while the "vec" and "map" cases compare by value:
>
> |map |vec |  nil | name |
> |++--+--|
> |   5 ns |   5 ns | 5 ns |   f1 |
> | 558 ns | 134 ns | 6 ns |   f2 |
> | 567 ns | 130 ns | 7 ns |   f3 |
> | 561 ns | 117 ns | 7 ns |   f4 |
>
> It also dumps the disassembly, we can see that:
>
> f1-map == f1-vec == f1-nil (makes sense, as the reference to the value is 
> passed in the constructor of the closure)
> f2-map = f3-map, f2-vec = f3-vec, f2-nil = f3-nil (with renaming)
> f4-map = f1, f4-vec = f1, f4-nil = f1 (with renaming)
> f2-map = f2-vec, except for calling clojure.lang.RT.map / vector.
>
> So there are only three versions of the actual bytecode:
> - the closure f1/f4;
> - f2 building a new object in its static constructor
> - f2-nil using a null constant instead of a field containing null.
>
> importantly, f1/f4 are identical:
> public final class F extends clojure.lang.AFunction {
>   /* ... static constructor getting clojure.core/= ... */
>   Object x;
>   public F(Object o) { x = o }
>   public Object invoke( Object y ) {
> /*basically*/ return (bool (= x y))
>   }
> }
>
> So why does f4 behave almost like f2/f3?!
>
>
> Cheers,
>
> -- 
> pascal
>

-- 
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: reloading enlive templates

2014-07-03 Thread Curtis Summers
I'm using ring.middleware.force-reload to always reload the namespaces that 
reference my enlive templates.  (only in dev, of course)

https://github.com/citizenparker/ring-middleware-force-reload


Hope that helps,

Curtis

On Wednesday, July 2, 2014 3:14:16 PM UTC-5, Sven Richter wrote:
>
> Hi,
>
> I am trying to reload my enlive templates with a watcher, how it was 
> suggested in this issue: https://github.com/cgrand/enlive/issues/6
>
> I am calling this function of start of my application:
>
>(watcher/watcher ["resources/"]
> (watcher/rate 50) ; poll every 50ms
> (watcher/on-change (fn [file] (do (println "file 
>changed: " file)
>  ;(use 'de.sveri.clj.adspread 
>:reload) ;as soon as I uncomment this, the anonymous function is not 
> called 
>anymore
>
>
> But just like I stated in the comment, as soon as I try to reload a 
> namespace the anonymous function is not executed anymore, whereas without 
> the (use ...) call it gets executed on file change.
> I also tried to call (reload 'namespace) but that did not work either.
>
> Any ideas on how to fix this or make enlive templates reload on change?
>
> 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: syntax tree manipulation

2014-07-03 Thread adrian . medina
If I understand your question correctly, you want to manipulate a deeply 
nested tree-like data structure, right? If that's correct, then perhaps a 
combination of clojure.zip and multimethods will suit your needs. Zippers 
provide a facility to transform (possibly) deeply nested immutable data 
structures in a way that "feels" like you are editing the data structure in 
place when you are actually not. To only manipulate the nodes that match a 
certain pattern, I would suggest writing a multimethod that allows you to 
identify a certain "class" of nodes that necessitate a type of 
modification. That way as you learn more about how your code needs to be 
structured to fit the needs of your data you can add new multimethod 
implementations to fit your needs. The default implementation should 
probably just move to the next loc in the zipper without modifying 
anything. 

On Thursday, July 3, 2014 12:12:35 PM UTC-4, Brian Craft wrote:
>
> What clojure tools should I be considering for doing syntax tree 
> manipulations? In general, I'm recursively matching patterns in subtrees 
> and rewriting them. The patterns are usually more complex than, say, 
> core.match patterns (e.g. match subtree having vector that contains term, 
> and split the term out of the vector and put in its own subtree).
>
>

-- 
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: syntax tree manipulation

2014-07-03 Thread Timothy Baldridge
Zippers, clojure core functions work great if you don't need to query up
the tree as well as down.

For situations where I want pattern-matching like semantics, with the
ability to do arbitrary queries, I've reached for core.logic and/or
Datomic. It's pretty trivial to have some code that turns a tree into
datoms and then you can use core.logic to do joins against that and query.
At that point you've also re-invented parts of Datomic, so if that's an
option (the free version has a in-memory DB), you might consider that.

I've use all of this to query and update DOM like structures in CLJS as
well as query XML data on the server.

Timothy


On Thu, Jul 3, 2014 at 10:30 AM,  wrote:

> If I understand your question correctly, you want to manipulate a deeply
> nested tree-like data structure, right? If that's correct, then perhaps a
> combination of clojure.zip and multimethods will suit your needs. Zippers
> provide a facility to transform (possibly) deeply nested immutable data
> structures in a way that "feels" like you are editing the data structure in
> place when you are actually not. To only manipulate the nodes that match a
> certain pattern, I would suggest writing a multimethod that allows you to
> identify a certain "class" of nodes that necessitate a type of
> modification. That way as you learn more about how your code needs to be
> structured to fit the needs of your data you can add new multimethod
> implementations to fit your needs. The default implementation should
> probably just move to the next loc in the zipper without modifying
> anything.
>
>
> On Thursday, July 3, 2014 12:12:35 PM UTC-4, Brian Craft wrote:
>>
>> What clojure tools should I be considering for doing syntax tree
>> manipulations? In general, I'm recursively matching patterns in subtrees
>> and rewriting them. The patterns are usually more complex than, say,
>> core.match patterns (e.g. match subtree having vector that contains term,
>> and split the term out of the vector and put in its own subtree).
>>
>>  --
> 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.
>



-- 
“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/d/optout.


Re: syntax tree manipulation

2014-07-03 Thread James Reeves
You may want to take a look at seqexp  and
zip-visit .

- James


On 3 July 2014 17:12, Brian Craft  wrote:

> What clojure tools should I be considering for doing syntax tree
> manipulations? In general, I'm recursively matching patterns in subtrees
> and rewriting them. The patterns are usually more complex than, say,
> core.match patterns (e.g. match subtree having vector that contains term,
> and split the term out of the vector and put in its own subtree).
>
>  --
> 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.


Re: Why does unquote clone values?

2014-07-03 Thread Pascal Germroth


On Thursday, July 3, 2014 5:19:56 PM UTC+1, adrian...@mail.yu.edu wrote:
>
> You're going down a rabbit hole here. Evaluating forms at runtime will 
> always result in a slower execution time than a function that doesn't 
> evaluate a form at runtime. 
>

I thought that was the whole point of Clojure?

The REPL is just parsing a string or file and running (eval) on it, I can't 
detect any difference in speed when doing it manually:

(quick-bench ((fn fac [x] (if (zero? x) 1 (* x (fac (dec x) 10)) ; => 
263 ± 9 ns
(eval `(quick-bench ((fn fac# [x#] (if (zero? x#) 1 (* x# (fac# (dec 
x#) 10))) ; 269 ± 8 ns

I'm very sure that the differences I measured are only because the lists 
are being copied instead of passed by reference, which I can understand in 
the case where the disassembly actually shows a copy being constructed. But 
not in the case where the bytecode is exactly the same --- and criterium 
takes a lot of time to warm up etc, all of the same optimisations should 
have been applied (and the dynamic part of the code is not a lot anyway, 
it's just calling AOT-compiled java code anyway. The only difference in 
timing must stem from the element-wise comparison)

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


When to prefer keywords as functions?

2014-07-03 Thread gvim
I'm reading "Cloujure in Action" as an introduction to Clojure and, 
although, I understand a keyword can be used as a function I don't 
understand the difference between:


(ns org.currylogic.damages.http.expenses
   (:require [clojure.data.json :as json-lib]
  [clojure.xml :as xml-core]))

... and

(ns org.currylogic.damages.http.expenses
   (require [clojure.data.json :as json-lib]
 [clojure.xml :as xml-core]))


When is it idiomatic or even preferable to substitute a function with a 
keyword equivalent?



gvim

--
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: Why does unquote clone values?

2014-07-03 Thread adrian . medina
I'm not sure I understand what you're saying here. :( Your example is 
simply benchmarking the same bit of code in each form. Why would evaluating 
one explicitly affect that benchmark? Your original example called eval in 
the body of the functions that you're benchmarking. That is where the 
overhead comes from. 

On Thursday, July 3, 2014 1:05:12 PM UTC-4, Pascal Germroth wrote:
>
>
>
> On Thursday, July 3, 2014 5:19:56 PM UTC+1, adrian...@mail.yu.edu wrote:
>>
>> You're going down a rabbit hole here. Evaluating forms at runtime will 
>> always result in a slower execution time than a function that doesn't 
>> evaluate a form at runtime. 
>>
>
> I thought that was the whole point of Clojure?
>
> The REPL is just parsing a string or file and running (eval) on it, I 
> can't detect any difference in speed when doing it manually:
>
> (quick-bench ((fn fac [x] (if (zero? x) 1 (* x (fac (dec x) 10)) ; => 
> 263 ± 9 ns
> (eval `(quick-bench ((fn fac# [x#] (if (zero? x#) 1 (* x# (fac# (dec 
> x#) 10))) ; 269 ± 8 ns
>
> I'm very sure that the differences I measured are only because the lists 
> are being copied instead of passed by reference, which I can understand in 
> the case where the disassembly actually shows a copy being constructed. But 
> not in the case where the bytecode is exactly the same --- and criterium 
> takes a lot of time to warm up etc, all of the same optimisations should 
> have been applied (and the dynamic part of the code is not a lot anyway, 
> it's just calling AOT-compiled java code anyway. The only difference in 
> timing must stem from the element-wise comparison)
>

-- 
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: When to prefer keywords as functions?

2014-07-03 Thread James Reeves
The "ns" form is a macro that takes a special syntax and always uses the
keyword form, as you have in your first example. Your second example is
incorrect; I'd be surprised if it even ran.

The reason for this is to make it clear that you're not executing the
require function directly, but instead passing options to the ns form.

- James


On 3 July 2014 18:11, gvim  wrote:

> I'm reading "Cloujure in Action" as an introduction to Clojure and,
> although, I understand a keyword can be used as a function I don't
> understand the difference between:
>
> (ns org.currylogic.damages.http.expenses
>(:require [clojure.data.json :as json-lib]
>   [clojure.xml :as xml-core]))
>
> ... and
>
> (ns org.currylogic.damages.http.expenses
>(require [clojure.data.json :as json-lib]
>  [clojure.xml :as xml-core]))
>
>
> When is it idiomatic or even preferable to substitute a function with a
> keyword equivalent?
>
>
> gvim
>
> --
> 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.


Re: clojure.test.check

2014-07-03 Thread cig
Hi Reid

Yes that's exactly what I was trying to achieve. Thank you very much.

As for the multi-maps. I was simply using the term incorrectly, sorry for 
the confusion.

Thanks once again

On Thursday, 3 July 2014 16:44:29 UTC+2, Reid Draper wrote:
>
> Hi,
>
> I've taken a stab at what I think you want:
>
> (def gen-cache
>   (gen/fmap
> #(reduce (fn [r m] (merge-with merge r m)) {} %)
> (gen/vector (gen/fmap
>   (fn [o]
> (let [{:keys [port instr] :as ord} o]
>   (assoc-in {} [port instr] ord)))
>   ord-gen
>
>
> Instead of using `gen/sample` to create a sequence, I use `gen/vector`. And 
> in order to apply the `reduce` function, I use `gen/fmap`.
>
>
> As an aside, I'm not sure how this is a multi-map. I was under the impression 
> a multi-map was simply a map that can store multiple values in the same key.
>
>
> Reid
>
>
> On Thursday, July 3, 2014 6:06:29 AM UTC-5, cig wrote:
>>
>> Hi 
>>
>> I have been trying to build a test.check generator for a multi map, 
>> without much success.
>> I have a generator which generates ordinary maps:
>>
>> (def ord-gen
>>   (gen/fmap (partial zipmap [:port :instr :qty])
>> (gen/tuple (gen/not-empty gen/string-alpha-numeric)
>>(gen/not-empty gen/string-alpha-numeric)
>>(gen/frequency [[9 gen/pos-int] [1 
>> gen/neg-int]]
>>
>> (gen/sample ord-gen 3)
>> ;; => ({:qty 0, :instr "X4", :port "re"} {:qty 0, :instr "v", :port "8"} 
>> {:qty 1, :instr "3A", :port "7"})
>>
>> However, I would like to merge this sequence of individual maps into a 
>> multi-map of the form:
>>
>> {"re" { "X4" {:qty 0, :instr "X4", :port "re"}}, "8" { "v" {:qty 0, 
>> :instr "v", :port "8"}}, "7" { "3A" {:qty 1, :instr "3A", :port "7"}}}
>>
>> The closest I have gotten to achieving this is by realising the 
>> intermediate steps:
>>
>> (def gen-cache
>>   (->>
>>(gen/fmap (fn [o]
>>(let [{:keys [port instr] :as ord} o]
>>  (assoc-in {} [port instr] ord)))
>>  ord-gen)
>>(gen/sample)
>>(reduce (fn [r m] (merge-with merge r m)) {})
>>(gen/return)))
>>
>>
>> However, this returns the same value constantly (I am aware that, that is 
>> what gen/return is supposed to do, however, I can not get much else working 
>> for me). I would Ideally like to bind the ord-gen into the gen-cache 
>> generator. Any help would be very appreciated.
>>
>

-- 
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: Why does unquote clone values?

2014-07-03 Thread Pascal Germroth
On Thursday, July 3, 2014 6:15:32 PM UTC+1, adrian...@mail.yu.edu wrote:

> I'm not sure I understand what you're saying here. :( Your example is 
> simply benchmarking the same bit of code in each form. Why would evaluating 
> one explicitly affect that benchmark? Your original example called eval in 
> the body of the functions that you're benchmarking. That is where the 
> overhead comes from. 
>

No I'm benchmarking the functions returned by f1-4.
They use different ways of generating their return function, i.e. by 
eval'ing the function constructor (fn [] ...) once before the benchmark -- 
the `let [f (f1 v)]` part.
Of course the call to (eval) takes time, but my point is that a function 
that was generated using (eval) is exactly the same as one generated 
statically.

Except somehow when unquoting the x-parameter to create the eval'ed form 
things are being cloned that shouldn't. That's what I'm measuring.

Actually I just found a better example that doesn't need timing etc:

(def x (Object.))
(str x) ; "java.lang.Object@..."
`(str ~x) ; (clojure.core/str #)
(eval `(str ~x)) ; RuntimeException: Can't embed object in code, maybe 
print-dup not defined: java.lang.Object@...
(eval `(str x)) ; "java.lang.Object@..." -- works through resolving user/x

So it's not actually a problem with quoting, that returns a list with str 
and the object as expected.
But eval'ing that list fails because it can't print-dup'ed?! I can't tell 
where that's happening, because it looks like clojure.lang.Parser.eval is 
actually processing the elements of the list as I expected…

>

-- 
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: When to prefer keywords as functions?

2014-07-03 Thread gvim

On 03/07/2014 18:36, James Reeves wrote:


The reason for this is to make it clear that you're not executing the
require function directly, but instead passing options to the ns form.



I don't understand "not executing the require function directly".

I've also seen the when function called as :when in the body of a let 
statement so could you elaborate on this non-macro example? I need to be 
clear on when it is preferable to use a keyword function rather than a 
normal function call.


gvim

--
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: Why does unquote clone values?

2014-07-03 Thread adrian . medina
"No I'm benchmarking the functions returned by f1-4." 

Where did I say different? 

In any event, I'm trying to help you understand why your benchmarking 
results are not aligning with your expectations and assumptions about the 
code you wrote. 

I would really like to help you gain a greater understanding here, but I 
must admit you are coming off as fairly confrontational, so I am hesitant 
to continue this conversation. Good luck. 

On Thursday, July 3, 2014 2:14:51 PM UTC-4, Pascal Germroth wrote:
>
> On Thursday, July 3, 2014 6:15:32 PM UTC+1, adrian...@mail.yu.edu wrote:
>
>> I'm not sure I understand what you're saying here. :( Your example is 
>> simply benchmarking the same bit of code in each form. Why would evaluating 
>> one explicitly affect that benchmark? Your original example called eval in 
>> the body of the functions that you're benchmarking. That is where the 
>> overhead comes from. 
>>
>
> No I'm benchmarking the functions returned by f1-4.
> They use different ways of generating their return function, i.e. by 
> eval'ing the function constructor (fn [] ...) once before the benchmark -- 
> the `let [f (f1 v)]` part.
> Of course the call to (eval) takes time, but my point is that a function 
> that was generated using (eval) is exactly the same as one generated 
> statically.
>
> Except somehow when unquoting the x-parameter to create the eval'ed form 
> things are being cloned that shouldn't. That's what I'm measuring.
>
> Actually I just found a better example that doesn't need timing etc:
>
> (def x (Object.))
> (str x) ; "java.lang.Object@..."
> `(str ~x) ; (clojure.core/str #)
> (eval `(str ~x)) ; RuntimeException: Can't embed object in code, maybe 
> print-dup not defined: java.lang.Object@...
> (eval `(str x)) ; "java.lang.Object@..." -- works through resolving user/x
>
> So it's not actually a problem with quoting, that returns a list with str 
> and the object as expected.
> But eval'ing that list fails because it can't print-dup'ed?! I can't tell 
> where that's happening, because it looks like clojure.lang.Parser.eval is 
> actually processing the elements of the list as I expected…
>
>>

-- 
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: When to prefer keywords as functions?

2014-07-03 Thread adrian . medina
I believe you might have seen :when in the binding vector of either a for 
or deseq form. Their special usage is documented 
here: http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/for

In any event, James explained the distinction quite well. Macros are often 
used to create special syntax for domain specific functionality. In the ns 
macro, this is to simplify the specification for required libraries, 
classes, etc. in a given namespace. You noticed the similarity to the 
standalone 'require', 'use', and 'import' macros for a reason. The ns macro 
was designed to make adding those options to the ns form look and feel like 
the standalone forms.

In the case of the 'for' macro, it is to allow for powerfully expressive 
list comprehensions. This is tangential but I think you might enjoy seeing 
how far you can go with list comprehensions in 
Clojure: 
http://programming-puzzler.blogspot.com/2013/03/logic-programming-is-overrated.html

On Thursday, July 3, 2014 2:24:51 PM UTC-4, g vim wrote:
>
> On 03/07/2014 18:36, James Reeves wrote: 
> > 
> > The reason for this is to make it clear that you're not executing the 
> > require function directly, but instead passing options to the ns form. 
> > 
>
> I don't understand "not executing the require function directly". 
>
> I've also seen the when function called as :when in the body of a let 
> statement so could you elaborate on this non-macro example? I need to be 
> clear on when it is preferable to use a keyword function rather than a 
> normal function call. 
>
> gvim 
>

-- 
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: When to prefer keywords as functions?

2014-07-03 Thread Mauricio Aldazosa
Keywords can be used as a function with a map, so the keyword will search
for itself in the map. Take a look at
http://clojure.org/data_structures#Data%20Structures-Keywords

In the case of the "ns" form, as James pointed out, what is happening is
not a function call. ns is a macro and as such that form will be
transformed before actual evaluation occurs. If you want, you can see the
actual call that will be made when evaluating ns, you can do so by
expanding the macro with:

(macroexpand-1 '(ns org.currylogic.damages.http.expenses
  (:require [clojure.data.json :as json-lib]
[clojure.xml :as xml-core])))

Be aware though that the resulting form may be a little daunting :-)
​

-- 
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: Why does unquote clone values?

2014-07-03 Thread Pascal Germroth
On Thursday, July 3, 2014 7:27:24 PM UTC+1, adrian...@mail.yu.edu wrote:

> "No I'm benchmarking the functions returned by f1-4." 
>
> Where did I say different? 
>

I understood "Your original example called eval in the body of the 
functions that you're benchmarking" as meaning I was running something like
(quick-bench (eval `( (fn [y] ...)  v)  ))
or
(quick-bench ( (eval `(fn [y] ...))  v)  )
But I'm actually calling eval before the benchmark and storing the output:
(let [f (eval `(fn [y] ...))] (quick-bench (f v)))
So the body that's being benchmarked is only the call to the dynamically 
generated function.
Unless I'm totally misunderstanding how Clojure evaluates these things 
[wouldn't surprise me].
 

> I would really like to help you gain a greater understanding here, but I 
> must admit you are coming off as fairly confrontational, so I am hesitant 
> to continue this conversation. Good luck. 
>

Sorry, that wasn't my intention. I kept repeating myself because I'm not 
sure if I'd be understood (since I'm new to Clojure and don't know the 
canonical words).
Also, there are a lot of other discussions where people use eval in tight 
loops and wonder why it's so slow; that and the mention of a difference 
between AOT and eval performance made me think I should make it clear that 
I'm not wondering why eval is slow, but why it's product behaves 
differently.
Using a benchmark to do so was way too indirect anyway, I believe my 
problem may have something to do with the failure of
(eval `(str ~(Object.)))

Cheers,

-- 
pascal

-- 
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: When to prefer keywords as functions?

2014-07-03 Thread Jony Hudson
One thing to note is that while it's true "keywords can be used as 
functions" they can only really do one thing, which is get values from 
maps. That is to say, the keyword-function :foo is equivalent to the 
function #(get % foo). The function :foo has no relationship with the 
function foo, if it is defined. I hope that makes sense!

So, to some approximation, only use keywords as functions as a shorthand 
for getting values from maps. As others have pointed out, although the 
keyword :require is in function position above, that code never actually 
gets executed - it's just data for the ns macro. This can be one of the 
more confusing things to get straight ...


Jony


On Thursday, 3 July 2014 18:11:35 UTC+1, g vim wrote:
>
> I'm reading "Cloujure in Action" as an introduction to Clojure and, 
> although, I understand a keyword can be used as a function I don't 
> understand the difference between: 
>
> (ns org.currylogic.damages.http.expenses 
> (:require [clojure.data.json :as json-lib] 
>[clojure.xml :as xml-core])) 
>
> ... and 
>
> (ns org.currylogic.damages.http.expenses 
> (require [clojure.data.json :as json-lib] 
>   [clojure.xml :as xml-core])) 
>
>
> When is it idiomatic or even preferable to substitute a function with a 
> keyword equivalent? 
>
>
> gvim 
>

-- 
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: noob questions - Hello world + learning

2014-07-03 Thread Evan Zamir
New to Clojure (find it fascinating so far, in large part due to watching 
approximately a billion Rich Hickey vids on YouTube). I had a similar 
question and figured I just resurrect this thread on it.

My naive thought was that when you (re)def a variable, you aren't actually 
copying over the old memory location, but instead simply re-creating a 
pointer to a new value or place in memory. To take this example further, 
I'm wondering what goes on under the hood when I use replace like this:

(def my-vec [1 2 3 4 5])
=> (var user/my-vec)
(def my-vec (assoc my-vec 2 "hello"))
=> (var user/my-vec)
my-vec
=> [1 2 "hello" 4 5]

Is there a good explanation out there of what happens to the old my-vec and 
whether the new my-vec actually overwrites it, points to it, or points to a 
completely new location in memory?

Another way to phrase this question: is this "real" mutability or just the 
appearance of mutability?


On Tuesday, June 15, 2010 4:51:00 AM UTC-7, Joost wrote:
>
> On Jun 14, 10:09 pm, Jared  wrote: 
> > Also, I thought this language is functional but I'm able to do change 
> > declarations in the repl. For example: 
> > user=> (def x 1) 
> > #'user/x 
> > user=> x 
> > 1 
> > user=> (def x 2) 
> > #'user/x 
> > user=> x 
> > 2 
> > user=> (def x (+ 1 x)) 
> > #'user/x 
> > user=> x 
> > 3 
> > 
> > Why does that happen? This seems to go against the ideas of functional 
> > programming. I can do the same things with functions too. 
>
> It's true that def isn't a strictly functional construct. 
>
> That's by design, since def is the construct that allows you to define 
> and set globally accessible vars, which includes all globally 
> accessible functions. 
>
> If you couldn't re-def a var, you couldn't redefine functions while 
> coding (or modify/extent existing functions using macros etc). Clojure 
> (like most Lisps) is a dynamic language with strong support for 
> interactive development - and you need redefineable vars (or something 
> similar) for that. The alternative is to recompile/load the whole 
> program every time you change a function definition. And that sucks 
> too much. 
>
> In idiomatic code, you only use (def) and its variants to set up 
> globally reachable data/functions across all threads and you don't, 
> for example, use def as a way to get "variable variables" - you will 
> get bitten if you try. 
>

-- 
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: noob questions - Hello world + learning

2014-07-03 Thread Andy Fingerhut
In your example, [1 2 3 4 5] allocates and initializes a vector with the 5
elements 1 2 3 4 5.

The first (def my-vec ...) also allocates a Var, and makes it 'point' at
the vector [1 2 3 4 5].

When you do (assoc my-vec 2 "hello"), it looks up the current value pointed
at by my-vec, which is the immutable vector [1 2 3 4 5], and it creates a
new vector [1 2 "hello" 4 5].  That new vector is also immutable.  In the
common case, it does not copy the entire vector [1 2 3 4 5] and then modify
the element 3 to "hello" -- it uses a technique called 'path copying' to
leave most of the memory that has been allocated shared between the two
vectors [1 2 3 4 5] and [1 2 "hello" 4 5].

The second (def my-vec ...) does mutate the 'pointer' for my-vec so that it
no longer points at [1 2 3 4 5], but instead points at [1 2 "hello" 4 5].
This is true mutation, not of the vectors, but of the Var my-vec.  Such
mutation helps support redefinition of functions during interactive REPL
sessions, among other things.

Andy


On Thu, Jul 3, 2014 at 2:39 PM, Evan Zamir  wrote:

> New to Clojure (find it fascinating so far, in large part due to watching
> approximately a billion Rich Hickey vids on YouTube). I had a similar
> question and figured I just resurrect this thread on it.
>
> My naive thought was that when you (re)def a variable, you aren't actually
> copying over the old memory location, but instead simply re-creating a
> pointer to a new value or place in memory. To take this example further,
> I'm wondering what goes on under the hood when I use replace like this:
>
> (def my-vec [1 2 3 4 5])
> => (var user/my-vec)
> (def my-vec (assoc my-vec 2 "hello"))
> => (var user/my-vec)
> my-vec
> => [1 2 "hello" 4 5]
>
> Is there a good explanation out there of what happens to the old my-vec
> and whether the new my-vec actually overwrites it, points to it, or points
> to a completely new location in memory?
>
> Another way to phrase this question: is this "real" mutability or just the
> appearance of mutability?
>
>
> On Tuesday, June 15, 2010 4:51:00 AM UTC-7, Joost wrote:
>>
>> On Jun 14, 10:09 pm, Jared  wrote:
>> > Also, I thought this language is functional but I'm able to do change
>> > declarations in the repl. For example:
>> > user=> (def x 1)
>> > #'user/x
>> > user=> x
>> > 1
>> > user=> (def x 2)
>> > #'user/x
>> > user=> x
>> > 2
>> > user=> (def x (+ 1 x))
>> > #'user/x
>> > user=> x
>> > 3
>> >
>> > Why does that happen? This seems to go against the ideas of functional
>> > programming. I can do the same things with functions too.
>>
>> It's true that def isn't a strictly functional construct.
>>
>> That's by design, since def is the construct that allows you to define
>> and set globally accessible vars, which includes all globally
>> accessible functions.
>>
>> If you couldn't re-def a var, you couldn't redefine functions while
>> coding (or modify/extent existing functions using macros etc). Clojure
>> (like most Lisps) is a dynamic language with strong support for
>> interactive development - and you need redefineable vars (or something
>> similar) for that. The alternative is to recompile/load the whole
>> program every time you change a function definition. And that sucks
>> too much.
>>
>> In idiomatic code, you only use (def) and its variants to set up
>> globally reachable data/functions across all threads and you don't,
>> for example, use def as a way to get "variable variables" - you will
>> get bitten if you try.
>>
>  --
> 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.


Re: Why does unquote clone values?

2014-07-03 Thread Atamert Ölçgen
On Thu, Jul 3, 2014 at 11:55 PM, Pascal Germroth 
wrote:

> Hi Atamert,
>
> Here's a gist with the example code:
> https://gist.github.com/neapel/4e502a14e3738b709672
>
> I tried replacing a closure with a dynamically built and evaluated
>>> metafunction but discovered that it was actually slower.
>>>
>>
>> If evaluating code during run is slower than AOT compiling it, it
>> wouldn't surprise me.
>>
>
> I didn't actually try AOT compiling it, just using the REPL. As far as I
> understand there shouldn't be a difference in speed, since (eval) runs the
> same compiler as AOT does, and even writes out a .class file.
>
>
OK, perhaps I could have phrased it better. I'm not an expert but I believe
REPL does compile the forms you enter to bytecode. It compiles an fn form
into a JVM class that implements IFn. It also compiles a quoted form (such
as `(fn ...) ) but this time it takes the form of a list (as in (list ...)
), IOW it's still data after it is compiled. The latter is executed
directly and the former is evaluated (turned into bytecode and then
executed perhaps).

If I'm wrong on any of these, I'd like to be corrected. I also realize AOT
means something slightly different. Something compiled before REPL is
started, right?


-- 
Kind Regards,
Atamert Ölçgen

-+-
--+
+++

www.muhuk.com

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