Simon,
Sorry to follow up so quickly on my own post, but I'm not able to figure
out how to use generated functions for this purpose. Consider:
modifyField!(a,k,Val{:isadded}, true)
The generated-function routine modifyField! needs to know the base type of
a. In other words, there exists some base type, say Immut, such that a is
an array of Immut's or a dict of Immut's or some other container, and
:isadded is one of the fields of Immut. (The generator function
modifyField! needs to know about Immut in order to enumerate all of its
other fields).
I don't see how to determine this base type within the generator. Say, for
example, that the type of a is Array{Immut,1}. I was hoping that one of
the following introspective calls would work:
methodswith(typeof(a), setindex!, false)
methodswith(typeof(a), setindex!, true)
but neither worked -- the first did not return any methods, whereas the
second returned a huge list of methods without any clear winner. Another
possibility might be:
code_typed(getindex, (typeof(a), typeof(k))
but I didn't know how to analyze this output for the general case; it seems
like determining the return value of getindex is as hard as the halting
problem!
Thanks,
Steve
On Monday, June 1, 2015 at 5:57:19 PM UTC-4, Simon Byrne wrote:
>
> That's some impressive metaprogramming. In v0.4, you should be able to do
> this without the "maker" functions, using generated functions
>
> http://julia.readthedocs.org/en/latest/manual/metaprogramming/#generated-functions
>
> As far as an interface goes, I would suggest a macro, e.g. so that the
> user could write something like
>
> @modify! a[i].field = new
>
>
> On Monday, 1 June 2015 03:09:29 UTC+1, [email protected] wrote:
>>
>> Following up on an earlier discussion that I started in this newsgroup, I
>> have written a small package that provides a routine to modify a field of
>> an immutable object in the case that the object is inside a container.
>> Please refer to:
>>
>> https://github.com/StephenVavasis/Modifyfield.jl
>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FStephenVavasis%2FModifyfield.jl&sa=D&sntz=1&usg=AFQjCNEMQeocqbzVy4CBDgPjAQNZhmq8Fg>
>>
>> Feedback is welcome.
>>
>>
>>