Re: Understanding vars

2013-03-22 Thread Nicola Mometto

Opened ticket with fix + test
http://dev.clojure.org/jira/browse/CLJ-1187

Mark Engelberg writes:

 On Tue, Mar 19, 2013 at 12:57 AM, Bronsa brobro...@gmail.com wrote:

 If I remember correctly, this is a bug due to the fact that constant empty
 literals are handled in a special way from the compiler.


 Interesting.  I see you are correct that the problem only occurs on
 metadata attached to an empty literal.  So does that mean this is a known
 bug?

 --

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




Re: Understanding vars

2013-03-19 Thread Marko Topolnik
On Tuesday, March 19, 2013 4:41:33 AM UTC+1, puzzler wrote:

 On Mon, Mar 18, 2013 at 8:31 PM, Kemar ke.m...@gmail.com javascript:wrote:

 Explicitly derefing the var and calling meta on it works:

 (meta @#'c) - {:amazing true}

 No idea as to why though...


 Quirky.  I assume that explicitly derefing the var defeats the speed 
 benefits of  ^:const, yes?


The way speed is achieved for :const is that it is given the same treatment 
as Java's *compile-time constants*, so you're not even touching the var 
when you refer to it by name. Now, *meta* could be accepted as a special 
case, explicitly detected by the compiler, but that mechanism would once 
again be easily defeated. So I'd say it's not a bug, but a case of *you 
can't have your cake and eat it, too.*
*
*
-marko

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




Re: Understanding vars

2013-03-19 Thread Marko Topolnik


 The way speed is achieved for :const is that it is given the same 
 treatment as Java's *compile-time constants*, so you're not even touching 
 the var when you refer to it by name. Now, *meta* could be accepted as a 
 special case, explicitly detected by the compiler, but that mechanism would 
 once again be easily defeated. So I'd say it's not a bug, but a case of *you 
 can't have your cake and eat it, too.*


On second thought, I my be wrong since the meta is not on the var, but on 
the map object itself. Maybe it really is just a bug due to which the 
compiled-in value doesn't have metadata copied to it.

-marko
 

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




Re: Understanding vars

2013-03-19 Thread Bronsa
If I remember correctly, this is a bug due to the fact that constant empty
literals are handled in a special way from the compiler.
Il giorno 19/mar/2013 08.49, Marko Topolnik marko.topol...@gmail.com ha
scritto:

 The way speed is achieved for :const is that it is given the same
 treatment as Java's *compile-time constants*, so you're not even
 touching the var when you refer to it by name. Now, *meta* could be
 accepted as a special case, explicitly detected by the compiler, but that
 mechanism would once again be easily defeated. So I'd say it's not a bug,
 but a case of *you can't have your cake and eat it, too.*


 On second thought, I my be wrong since the meta is not on the var, but on
 the map object itself. Maybe it really is just a bug due to which the
 compiled-in value doesn't have metadata copied to it.

 -marko


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




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




Re: Understanding vars

2013-03-19 Thread Marko Topolnik
Indeed:

(def ecr (with-meta [1] {:amazing true}))
(def ^:const c ecr)

(meta ecr) - {:amazing true}
(meta c) - {:amazing true}

On Tuesday, March 19, 2013 8:57:28 AM UTC+1, Nicola Mometto wrote:

 If I remember correctly, this is a bug due to the fact that constant empty 
 literals are handled in a special way from the compiler.
 Il giorno 19/mar/2013 08.49, Marko Topolnik 
 marko.t...@gmail.comjavascript: 
 ha scritto:

 The way speed is achieved for :const is that it is given the same 
 treatment as Java's *compile-time constants*, so you're not even 
 touching the var when you refer to it by name. Now, *meta* could be 
 accepted as a special case, explicitly detected by the compiler, but that 
 mechanism would once again be easily defeated. So I'd say it's not a bug, 
 but a case of *you can't have your cake and eat it, too.*


 On second thought, I my be wrong since the meta is not on the var, but on 
 the map object itself. Maybe it really is just a bug due to which the 
 compiled-in value doesn't have metadata copied to it.

 -marko
  

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



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




Re: Understanding vars

2013-03-19 Thread Mark Engelberg
On Tue, Mar 19, 2013 at 12:57 AM, Bronsa brobro...@gmail.com wrote:

 If I remember correctly, this is a bug due to the fact that constant empty
 literals are handled in a special way from the compiler.


Interesting.  I see you are correct that the problem only occurs on
metadata attached to an empty literal.  So does that mean this is a known
bug?

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




Re: Understanding vars

2013-03-19 Thread Bronsa
I remember finding out about it a few months ago.
I don't know whether or not there is a jira ticket for it, I'll check out.

If nobody can get a patch for this, I'll try and see if I can work out one
in the next days
Il giorno 19/mar/2013 09.02, Mark Engelberg mark.engelb...@gmail.com ha
scritto:

 On Tue, Mar 19, 2013 at 12:57 AM, Bronsa brobro...@gmail.com wrote:

 If I remember correctly, this is a bug due to the fact that constant
 empty literals are handled in a special way from the compiler.


 Interesting.  I see you are correct that the problem only occurs on
 metadata attached to an empty literal.  So does that mean this is a known
 bug?

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




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




Re: Understanding vars

2013-03-18 Thread Marko Topolnik
On Monday, March 18, 2013 7:16:17 PM UTC+1, puzzler wrote:


 It used to be that a common way to refactor this for best performance 
 would be:

 (let [pi (compute-estimate-of-pi)]
   (defn f [x]
   ; Do stuff with pi here
 ))

 
This is just about the same as

(def ^:const pi (compute-estimate-of-pi))

(defn f [x] ...)

Otherwise, for a regular static var you pay AtomicBoolean.get + volatile 
read of the actual value. For a dynamic var you pay much more 
(ThreadLocal.get() + hashmap lookup).

-marko

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




Re: Understanding vars

2013-03-18 Thread Mark Engelberg
On Mon, Mar 18, 2013 at 12:38 PM, Marko Topolnik
marko.topol...@gmail.comwrote:

 This is just about the same as

 (def ^:const pi (compute-estimate-of-pi))



OK, just tried out ^:const in my code and it seems to strip off any meta
data associated with the object stored in the var.  That ruins its utility
for my purposes.

(def ecr (with-meta [] {:amazing true}))
(def ^:const c ecr)

(meta ecr) - {:amazing true}
(meta c) - nil

Bug?

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




Re: Understanding vars

2013-03-18 Thread Kemar
Explicitly derefing the var and calling meta on it works:

(meta @#'c) - {:amazing true}

No idea as to why though...


Am Dienstag, 19. März 2013 03:45:57 UTC+1 schrieb puzzler:

 On Mon, Mar 18, 2013 at 12:38 PM, Marko Topolnik 
 marko.t...@gmail.comjavascript:
  wrote:

 This is just about the same as

 (def ^:const pi (compute-estimate-of-pi))



 OK, just tried out ^:const in my code and it seems to strip off any meta 
 data associated with the object stored in the var.  That ruins its utility 
 for my purposes.

 (def ecr (with-meta [] {:amazing true}))
 (def ^:const c ecr)

 (meta ecr) - {:amazing true}
 (meta c) - nil

 Bug?


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




Re: Understanding vars

2013-03-18 Thread Mark Engelberg
On Mon, Mar 18, 2013 at 8:31 PM, Kemar ke.mar...@gmail.com wrote:

 Explicitly derefing the var and calling meta on it works:

 (meta @#'c) - {:amazing true}

 No idea as to why though...


Quirky.  I assume that explicitly derefing the var defeats the speed
benefits of  ^:const, yes?

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