Opened 14 years ago
Closed 10 years ago
#95 closed proposed feature (fixed)
Aliases in Singular?
Reported by: | Oleksandr | Owned by: | Oleksandr |
---|---|---|---|
Priority: | minor | Milestone: | 3-1-1 |
Component: | singular-kernel | Version: | |
Keywords: | alias | Cc: | seelisch |
Description
At the moment we have at least one alias: basering, which is used very often.
I think it would be useful to have generic aliases. For instance alias parameters to procedures will allow one to save memory by making no copies for huge objects and set attribues for complicated reusable objects for later reuse and caching of already computed object properties etc...
Since alias is just a syntax sugar for object name, at first we may simply add a function to query an object by (string) name, and come up with a new syntax for alias later on.
Attachments (1)
Change History (10)
comment:1 Changed 14 years ago by
Component: | ALL → singular-kernel |
---|---|
Keywords: | alias added |
Owner: | changed from somebody to hannes |
Priority: | major → minor |
comment:2 Changed 14 years ago by
Nice idea, but difficult to do - and difficult to manage: what we really want here is a "call by name" for procedure parameters.
The other aspaect: reference objects by its name - is laready in Singular (since version 1.2, if my memory is correct): see `
comment:3 follow-up: 4 Changed 14 years ago by
I agree - this is what is actually needed.
Where can one look for "reference objects by its name"?
Besides: I was thinking about C++-like syntax:
ring r; poly p = var(1); poly& A = p; proc Test(poly p){} Test(A); // makes a copy of p proc TestA(poly& p){} TestA(A); // no convertion/copy! TestA(p); // p is implicitly converted into an alias and thus no copy
It seems to me that aliases should be just plain variables and have the same parents/contexts as original variables.
comment:4 Changed 14 years ago by
Replying to motsak:
Where can one look for "reference objects by its name"?
See my (guest) answer in:
http://www.singular.uni-kl.de/forum/viewtopic.php?t=1680
` `
is mentioned in the Handbook as special character 3.5.2, but seems not to be explained.
comment:5 Changed 14 years ago by
Cc: | seelisch added |
---|---|
Owner: | changed from hannes to Oleksandr |
Thanks for explaing!
It seems that my description above is a bit confusing, so please let me explain: in Singular interpretator Objects (rings/ideals/modules/polys etc) have name, ID, type, attributes... So i imagined myself simply some special syntax for the approach 2 below:
ring r;ideal I = maxideal(1);ideal J = I; // Approach 1: do evrything by hand inline: proc computeReg(def I) // COPY! Bad for HUGE objects! { if( typeof(attrib(I, "reg")) == "string" ) { "............. LOOOOONG COMPUTATIONS HERE .................... "; attrib(I, "reg", 11); } return( attrib(I, "reg") ); } attrib(I); // no attributes attrib(I, "reg", computeReg(I)); // Main step! This is very limited and may be very complicated! attrib(I); // 'reg'!!! computeReg(I); // No long computations any more!!! // Approach 2: alias == 'name of object' proc computeReg2(n) // NO OBJECT COPY! Simply use `name` instead of object everywhere... { if( typeof(attrib(`n`, "reg")) == "string" ) { "............. LOOOOONG COMPUTATIONS HERE .................... "; attrib(`n`, "reg", 11); } return( attrib(`n`, "reg") ); } attrib(J); // no attribues computeReg2(nameof(J)); // Almost perfect but one needs to write nameof(J) instead of J!!! attrib(J); // 'reg'!!!! computeReg2(nameof(J)); // No long computations any more!!!
comment:6 follow-up: 7 Changed 14 years ago by
Frank, wrote:
The appropriate data structure for what you would like to have is a cache from which pre-computed objects may be retrieved by name and/or id, and/or some other sensible mechanism of querying. I can see your point, as it would make programming easier sometimes. But I also see a problem with that, as we do not have object locking in our C/C++ Singular code. That means that once an object has been created, our Singular code does NOT ensure that this object will stay unmodified during its lifetime. Especially - as I understand our code - parameters of procedures are quite often side-effected (and thus modified) inside the procedure. But this implies that cached objects may be subject to unexpected changes (assuming that you would want to cache by reference) unless you cache physical copies of these objects. We should talk about that after the new release; perhaps in our next meeting.
comment:7 Changed 14 years ago by
Replying to seelisch:
The appropriate data structure for what you would like to have is a cache from which pre-computed objects may be retrieved by name and/or id, and/or some other sensible mechanism of querying. I can see your point, as it would make programming easier sometimes. But I also see a problem with that, as we do not have object locking in our C/C++ Singular code. That means that once an object has been created, our Singular code does NOT ensure that this object will stay unmodified during its lifetime. Especially - as I understand our code - parameters of procedures are quite often side-effected (and thus modified) inside the procedure. But this implies that cached objects may be subject to unexpected changes (assuming that you would want to cache by reference) unless you cache physical copies of these objects.
There seems to be some confusion, please see my post above.
We should talk about that after the new release; perhaps in our next meeting.
Clearly this will not be done for the new release.
comment:8 Changed 14 years ago by
Milestone: | → Releases 3-1-1 and higher |
---|
comment:9 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
seems to be done by Alex (http://www.singular.uni-kl.de:8002/trac/ticket/450)
We already have listvar: