Skip to content
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

Open
dmkoppelman opened this issue Jan 14, 2015 · 5 comments
Open

Provide reference-like functionality to MapLookup. #113

dmkoppelman opened this issue Jan 14, 2015 · 5 comments
Assignees

Comments

@dmkoppelman
Copy link
Collaborator

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.

@dmkoppelman dmkoppelman self-assigned this Jan 14, 2015
@eschnett
Copy link
Collaborator

Instead of defining a new type, you could pass a list with a single mapRef to the caller. The caller can the modify the list. The modification is then visible in the caller.

@dmkoppelman
Copy link
Collaborator Author

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.

@dmkoppelman
Copy link
Collaborator Author

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.

@dmkoppelman
Copy link
Collaborator Author

I've pushed the branch, its dmk-chemora. Since I can't attach a patch, here's a command for generating the patch:

git diff 607e2f4 b4fde28

@eschnett
Copy link
Collaborator

you can compare branch and master, which gives you a nice diff in the
browser.

-erik

On Wednesday, January 14, 2015, David M. Koppelman [email protected]
wrote:

I've pushed the branch, its dmk-chemora. Since I can't attach a patch,
here's a command for generating the patch:

git diff 607e2f4 b4fde28

Reply to this email directly or view it on GitHub.<
https://ci5.googleusercontent.com/proxy/-eZ8QdAXGhq9STsnhtaAmbcKazbhdKlO0flZr04JbjPu0pw8bm-cMhSKL4Xu_cwsJXqrh-IOX-c4Moi47aMGnoWlGyljbhEX1AnwLsHQvOX5hy0Cm6y2G-NFh5HpAUIkyzDI9w1K-NiI8b0YeKK9s-1pImYjeA=s0-d-e1-ft#https://github.com/notifications/beacon/AANCCiNwIFrIZ1WGquqb0wA4JTH0Mnqoks5nhwKVgaJpZM4DSilG.gif

Erik Schnetter [email protected]
http://www.perimeterinstitute.ca/personal/eschnetter/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants