Re: [julia-users] Static type fields

2015-01-02 Thread lapeyre . math122a
I guess that many people coming from a common OO language will look for 
this and it seems natural to look in the
manual in the sections 'Types' or 'Methods'.  Maybe somewhere near the 
discussion of fields in
 Composite Types 
http://julia.readthedocs.org/en/latest/manual/types/#composite-types.  It 
looks like before Immutable Composite Types 
http://julia.readthedocs.org/en/latest/manual/types/#immutable-composite-types
 
would be good. For instance: (with existing surrounding text)

 You can also change the values as one would expect:
blah
blah

You can associate static data with a type like this:
   static_data(::Type{MyObj}) = 1
   static_data(::Type{MyOtherObj}) = 2

Composite types with no fields are singletons 


On Thursday, January 1, 2015 8:34:48 AM UTC+1, ele...@gmail.com wrote:



 On Thursday, January 1, 2015 11:45:00 AM UTC+10, Jameson wrote:

 method dispatch on the object type does a remarkably good job at 
 providing this functionality without needing a specialized feature:

 static_data(::Type{MyObj}) = 1
 static_data(::Type{MyOtherObj}) = 2


 Would like to document this, but not sure where it should go?
  



 On Wed Dec 31 2014 at 8:23:40 PM Josh Langsfeld jdl...@gmail.com wrote:

 I currently am trying to solve a problem where I have many composite 
 types and I would like to associate some data with each type, such that 
 every instance has access to it. Obviously, in C++ I would just create a 
 static member variable. 

 Is there a good way to go about this in Julia? Currently, I have it 
 working by using a global Dict mapping DataType objects to their associated 
 data but I really don't like this. Something more naive like just adding 
 that field to every object instance also strikes me as unnecessary and 
 wasteful. I haven't seen any significant discussion about static fields on 
 the lists or on github so is this something that could be considered for 
 addition to the language?

 Thanks,
 Josh



Re: [julia-users] Static type fields

2015-01-01 Thread Jameson Nash
possibly the FAQ? seems like there might need to be a section added for
Common Design Patterns

On Thu Jan 01 2015 at 2:34:50 AM ele...@gmail.com wrote:



 On Thursday, January 1, 2015 11:45:00 AM UTC+10, Jameson wrote:

 method dispatch on the object type does a remarkably good job at
 providing this functionality without needing a specialized feature:

 static_data(::Type{MyObj}) = 1
 static_data(::Type{MyOtherObj}) = 2


 Would like to document this, but not sure where it should go?




 On Wed Dec 31 2014 at 8:23:40 PM Josh Langsfeld jdl...@gmail.com wrote:

 I currently am trying to solve a problem where I have many composite
 types and I would like to associate some data with each type, such that
 every instance has access to it. Obviously, in C++ I would just create a
 static member variable.

 Is there a good way to go about this in Julia? Currently, I have it
 working by using a global Dict mapping DataType objects to their associated
 data but I really don't like this. Something more naive like just adding
 that field to every object instance also strikes me as unnecessary and
 wasteful. I haven't seen any significant discussion about static fields on
 the lists or on github so is this something that could be considered for
 addition to the language?

 Thanks,
 Josh




Re: [julia-users] Static type fields

2015-01-01 Thread Josh Langsfeld
This seems like a good solution for the read-only case but is there an
option for a mutable variable?

Happy new year's, everyone!
On Dec 31, 2014 8:45 PM, Jameson Nash vtjn...@gmail.com wrote:

 method dispatch on the object type does a remarkably good job at providing
 this functionality without needing a specialized feature:

 static_data(::Type{MyObj}) = 1
 static_data(::Type{MyOtherObj}) = 2

 On Wed Dec 31 2014 at 8:23:40 PM Josh Langsfeld jdla...@gmail.com wrote:

 I currently am trying to solve a problem where I have many composite
 types and I would like to associate some data with each type, such that
 every instance has access to it. Obviously, in C++ I would just create a
 static member variable.

 Is there a good way to go about this in Julia? Currently, I have it
 working by using a global Dict mapping DataType objects to their associated
 data but I really don't like this. Something more naive like just adding
 that field to every object instance also strikes me as unnecessary and
 wasteful. I haven't seen any significant discussion about static fields on
 the lists or on github so is this something that could be considered for
 addition to the language?

 Thanks,
 Josh




[julia-users] Static type fields

2014-12-31 Thread Josh Langsfeld
I currently am trying to solve a problem where I have many composite types 
and I would like to associate some data with each type, such that every 
instance has access to it. Obviously, in C++ I would just create a static 
member variable. 

Is there a good way to go about this in Julia? Currently, I have it working 
by using a global Dict mapping DataType objects to their associated data 
but I really don't like this. Something more naive like just adding that 
field to every object instance also strikes me as unnecessary and wasteful. 
I haven't seen any significant discussion about static fields on the lists 
or on github so is this something that could be considered for addition to 
the language?

Thanks,
Josh


Re: [julia-users] Static type fields

2014-12-31 Thread Jameson Nash
method dispatch on the object type does a remarkably good job at providing
this functionality without needing a specialized feature:

static_data(::Type{MyObj}) = 1
static_data(::Type{MyOtherObj}) = 2

On Wed Dec 31 2014 at 8:23:40 PM Josh Langsfeld jdla...@gmail.com wrote:

 I currently am trying to solve a problem where I have many composite types
 and I would like to associate some data with each type, such that every
 instance has access to it. Obviously, in C++ I would just create a static
 member variable.

 Is there a good way to go about this in Julia? Currently, I have it
 working by using a global Dict mapping DataType objects to their associated
 data but I really don't like this. Something more naive like just adding
 that field to every object instance also strikes me as unnecessary and
 wasteful. I haven't seen any significant discussion about static fields on
 the lists or on github so is this something that could be considered for
 addition to the language?

 Thanks,
 Josh



Re: [julia-users] Static type fields

2014-12-31 Thread elextr


On Thursday, January 1, 2015 11:45:00 AM UTC+10, Jameson wrote:

 method dispatch on the object type does a remarkably good job at providing 
 this functionality without needing a specialized feature:

 static_data(::Type{MyObj}) = 1
 static_data(::Type{MyOtherObj}) = 2


Would like to document this, but not sure where it should go?
 



 On Wed Dec 31 2014 at 8:23:40 PM Josh Langsfeld jdl...@gmail.com 
 javascript: wrote:

 I currently am trying to solve a problem where I have many composite 
 types and I would like to associate some data with each type, such that 
 every instance has access to it. Obviously, in C++ I would just create a 
 static member variable. 

 Is there a good way to go about this in Julia? Currently, I have it 
 working by using a global Dict mapping DataType objects to their associated 
 data but I really don't like this. Something more naive like just adding 
 that field to every object instance also strikes me as unnecessary and 
 wasteful. I haven't seen any significant discussion about static fields on 
 the lists or on github so is this something that could be considered for 
 addition to the language?

 Thanks,
 Josh