Back to Forum | View unanswered posts | View active topics
Topic review - Procedure With External Parameters |
Author |
Message |
|
|
Post subject: |
Re: Procedure With External Parameters |
|
|
With execute the polynomial will just be displayed but you can't work with it. Even an assignment afterwards like poly g = _; is not possible. To have access, you must enclose the string (variable) nameofpoly into the backticks ` ` . These are the delimiter for name substitution See Special characters: http://www.singular.uni-kl.de/Manual/la ... .htm#SEC63Modified solution: Code: > ring R = 0, (x,y,z), dp; > poly f = x+y+z; > string s = "f"; > `s`; x+y+z
> proc p1mod(def R, string nameofpoly) { setring(R); poly g = `nameofpoly`; g = g+1; g; }
> ring S = 0, x, dp; > p1mod(R, "f"); x+y+z+1
With execute the polynomial will just be displayed but you can't work with it. Even an assignment afterwards like [i] poly g = _; [/i]is not possible.
To have access, you must enclose the string (variable) [i]nameofpoly[/i] into the backticks ` ` . These are the delimiter for name substitution
See [b]Special characters[/b]: http://www.singular.uni-kl.de/Manual/latest/sing_36.htm#SEC63
Modified solution: [code] > ring R = 0, (x,y,z), dp; > poly f = x+y+z; > string s = "f"; > `s`; x+y+z
> proc p1mod(def R, string nameofpoly) { setring(R); poly g = `nameofpoly`; g = g+1; g; }
> ring S = 0, x, dp; > p1mod(R, "f"); x+y+z+1 [/code]
|
|
|
|
Posted: Fri Sep 07, 2012 3:56 pm |
|
|
|
|
|
Post subject: |
Re: Procedure With External Parameters |
|
|
One possibility is to define a procedure which takes the ring R as a parameter. Objects inside this ring can then be accessed by their names: Code: proc p1(def R, string nameofpoly) { setring(R); execute(nameofpoly); }
ring R = 0, (x,y,z), dp; poly f = x+y+z; ring S = 0, x, dp; p1(R, "f"); x+y+z
Note that Code: proc p1(ring R, ...)
does not work, see http://www.singular.uni-kl.de/Manual/la ... .htm#SEC81. Another possibility is to use user defined types ("newstructs"), see http://www.singular.uni-kl.de/Manual/la ... htm#SEC216.
One possibility is to define a procedure which takes the ring R as a parameter. Objects inside this ring can then be accessed by their names:
[code] proc p1(def R, string nameofpoly) { setring(R); execute(nameofpoly); }
ring R = 0, (x,y,z), dp; poly f = x+y+z; ring S = 0, x, dp; p1(R, "f"); x+y+z [/code]
Note that [code] proc p1(ring R, ...) [/code] does [b]not[/b] work, see http://www.singular.uni-kl.de/Manual/latest/sing_44.htm#SEC81.
Another possibility is to use user defined types ("newstructs"), see http://www.singular.uni-kl.de/Manual/latest/sing_176.htm#SEC216.
|
|
|
|
Posted: Sat Sep 01, 2012 3:03 pm |
|
|
|
|
|
Post subject: |
Procedure With External Parameters |
|
|
How can one define a procedure which may be called with parameters not in the current ring, such as "imap(R,f)", where the polynomial "f" belongs to the ring "R"?
How can one define a procedure which may be called with parameters not in the current ring, such as "imap(R,f)", where the polynomial "f" belongs to the ring "R"?
|
|
|
|
Posted: Tue Aug 28, 2012 3:19 pm |
|
|
|
|
|
It is currently Fri May 13, 2022 11:05 am
|
|