Hello List, I am rather a newbie in GiNaC and in C++ (but I am very familiar with another CAS and with C): I have just noticed that: lst list; list = lst(lst(1,1),lst(2,4),lst(3,9)); gives a list of list as expected, whereas lst list; list = lst(1,1),lst(2,4),lst(3,9); gives the first list (namely lst(1,1)) is it a bug ? or is it a wrong thing to do ? Thanks in advance, Jerome
Hello, On Sun, Feb 04, 2007 at 02:19:42AM +0800, Jerome BENOIT wrote:
I have just noticed that:
lst list; list = lst(lst(1,1),lst(2,4),lst(3,9));
gives a list of list as expected, whereas
lst list; list = lst(1,1),lst(2,4),lst(3,9);
Probably you want this: list = ex(lst(1, 1)), lst(2, 4), lst(3,9);
gives the first list (namely lst(1,1))
Not exactly, your code gives lst(1, 1) as opposed to lst(lst(1, 1)).
is it a bug ?
No. This is how C++ function overload resolution works. There are several overloaded instances of operator= in the lst class: lst& operator=(const lst&); container_init<ex, std::list> operator=(const ex&); First one gives the best match (no type conversion form lst to ex is necessary), so your code basically reads as: class foo { int i; public: foo(); foo(int i_); foo& operator=(const foo& o); }; void demo() { // lst list; foo a; // list = lst(1, 1), lst(2, 4), lst(3, 9); a = foo(1), foo(2), foo(3); } foo::foo() { i = 0; } foo::foo(int i_) { i = i_; } foo& foo::operator=(const foo& o) { if (&o != this) i = o.i; return *this; }
or is it a wrong thing to do ?
There is nothing wrong about list of lists. But the code operating on such lists will be [probably] somewhat inefficient. Best regards, Alexei -- All science is either physics or stamp collecting.
Hello, thanks for the reply. Actually I use list of lists to perform quick test. A last question: is there any king of NULL (as in Maple) object in GiNaC ? Thanks in advance, Jerome Sheplyakov Alexei wrote:
Hello,
On Sun, Feb 04, 2007 at 02:19:42AM +0800, Jerome BENOIT wrote:
I have just noticed that:
lst list; list = lst(lst(1,1),lst(2,4),lst(3,9));
gives a list of list as expected, whereas
lst list; list = lst(1,1),lst(2,4),lst(3,9);
Probably you want this:
list = ex(lst(1, 1)), lst(2, 4), lst(3,9);
gives the first list (namely lst(1,1))
Not exactly, your code gives lst(1, 1) as opposed to lst(lst(1, 1)).
is it a bug ?
No. This is how C++ function overload resolution works. There are several overloaded instances of operator= in the lst class:
lst& operator=(const lst&); container_init<ex, std::list> operator=(const ex&);
First one gives the best match (no type conversion form lst to ex is necessary), so your code basically reads as:
class foo { int i; public: foo(); foo(int i_); foo& operator=(const foo& o); };
void demo() { // lst list; foo a; // list = lst(1, 1), lst(2, 4), lst(3, 9); a = foo(1), foo(2), foo(3); }
foo::foo() { i = 0; } foo::foo(int i_) { i = i_; } foo& foo::operator=(const foo& o) { if (&o != this) i = o.i; return *this; }
or is it a wrong thing to do ?
There is nothing wrong about list of lists. But the code operating on such lists will be [probably] somewhat inefficient.
Best regards, Alexei
-- Jerome BENOIT jgmbenoit_at_mailsnare_dot_net
Dear Alexei, ASh> I propose this patch instead: Yes, this is better, but ASh> + if (eb.info(rational_function)) should it be like that: + if (eb.info(info_flags::rational_function)) Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://maths.leeds.ac.uk/~kisilv/
Hello, I have just tried: it does not work as I want. In Maple, my_list := [ 1, 2, 3, 4, 5, NULL]; gives the list [1,2,3,4,5] . The idea is that inside a script the elements of the list can be easily commented or uncommented. my_list := [ 1, 2, # 3, # 4, # 5, NULL]; gives [1,2] . can we do that with GiNaC ? Thanks in advance, Jerome Sheplyakov Alexei wrote:
Hello,
On Mon, Feb 05, 2007 at 02:36:03AM +0800, Jerome BENOIT wrote:
A last question: is there any king of NULL (as in Maple) object in GiNaC ?
May be fail()?
Best regards, Alexei
-- Jerome BENOIT jgmbenoit_at_mailsnare_dot_net
Hello! On Sat, Feb 17, 2007 at 06:50:29PM +0800, Jerome BENOIT wrote:
my_list := [ 1, 2, 3, 4, 5, NULL];
gives the list [1,2,3,4,5] .
GiNaC does not support such (to put it mildly) weird objects.
The idea is that inside a script the elements of the list can be easily commented or uncommented.
my_list := [ 1, 2, # 3, # 4, # 5, NULL];
gives [1,2] .
can we do that with GiNaC ?
lst my_list; my_list = 1, 2/*, 3, 4, 5*/ ; Best regards, Alexei -- All science is either physics or stamp collecting.
participants (3)
-
Jerome BENOIT
-
varg@theor.jinr.ru
-
Vladimir Kisil