-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide reference-like functionality to MapLookup. #113
Comments
Instead of defining a new type, you could pass a list with a single |
I'm not 100% sure what you're trying to say, but it sounds like it would work. There are many ways of doing this, I chose a method that would require fewest changes to the existing Kranc code. |
I was going to attach a patch to the issue but it looks like github's issue tracker doesn't support attachments. I'll push a branch as soon as LSU's network problems are resolved or I figure out a way around them. |
you can compare branch and master, which gives you a nice diff in the -erik On Wednesday, January 14, 2015, David M. Koppelman [email protected]
Erik Schnetter [email protected] |
The key/value store implemented by the functions in MapLookup is
passed by value. This requires that the store is passed up and down
the evaluation stack. (Down to a called function, and back up to the
caller if caller needs callee's modifications.)
In this ticket provide a reference type value. (Note: This is
something that I have working, I'm not asking for anyone else to do
it.)
Here is a quick example:
calcs = { Name -> "Fred" }
c2 = mapRefAdd[calcs,Later]; // Add a reference-type key, Later. Value unset.
// c2: { Name -> "Fred", Later -> someString },
c3 = c2;
// c3: { Name -> "Fred", Later -> someString },
mapRefSet[c3, Later, 123]; // Set the value for Later.
// c2: { Name -> "Fred", Later -> 123 },
// c3: { Name -> "Fred", Later -> 123 },
mapReplace[c3, Later, 456]; // Either mapRefSet or mapReplace can be used.
// c2: { Name -> "Fred", Later -> 456 },
// c3: { Name -> "Fred", Later -> 456 },
Notice that the value of Later in c2 has changed even though mapRefSet
and mapRefSet operated on c3.
My immediate need for this is to retrieve values for the stencil
bounding box and resolved "Automatic" value of "Where", which are
currently computed in code which does not return the "calcs" key/value
store.
An alternative would be to refactor the code so that it does pass
the calcs store up the evaluation stack. That's not as easy as it
sounds because I'd need to know which modified or added values should
be passed back to the caller. With the reference type I am proposing
those values which should be visible are explicitly named with
mapRefAdd.
Here is how this is implemented:
mapRefSet[calcs,Key] generates a string, valKey, (using MMA's built in
symbol naming mechanism) and uses that as the value.
mapRefSet[calcs,Key,Value] will look up valKey using Key and then add
a definition: obarray[valKey] = Value.
lookup[calcs,Key] will return obarray[valKey]. Symbol obarray is
defined so that non-reference types evaluate to themselves and unset
reference types throw an error.
I'll post a patch and maybe push the change to a new branch.
The text was updated successfully, but these errors were encountered: