#203 closed bug (fixed)
writelist for strings
Reported by: | gorzel | Owned by: | somebody |
---|---|---|---|
Priority: | minor | Milestone: | 3-1-1 |
Component: | dontKnow | Version: | 3-1-0 |
Keywords: | Cc: |
Description
At the end of
http://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=1773
I remarked that writelist does not work for string.
To see that this is indeed the case, just execute completely the example provided with writelist.
LIB "inout.lib"; ring r; ideal i=x,y,z; list k="Hi",nameof(basering),i,37; writelist("zumSpass","lustig",k); read("zumSpass"); list lustig; lustig[1]=string( Hi); lustig[2]=string( r); lustig[3]=ideal( x,y,z); lustig[4]=int( 37);
Completely means that we now have to take execute the string and
take a look at the result.
> execute(_); > lustig; [1]: [2]: (32003),(x,y,z),(dp(3),C) [3]: _[1]=x _[2]=y _[3]=z [4]: 37
So what we see, is that the first slot is the empty string but
not the string Hi as intended.
> typeof(lustig[1]); string > lustig[1]==""; 1
This is not a of Singular but a misunderstood usage of the cast string.
string(xxx) does convert the identifier to a string, but it does not give the string xxx.
To obtain the string with the cast string( ), have to write either string(\"xxx\") or simply omit the cast and write \"xxx\".
See these examples.
> defined(hallo); 0 > string(hallo); > _ == ""; 1 > string("hallo"); hallo > int hello = 100; > string(hello); 100
Therefore the for-loop in writelist needs a further distinction of cases. Choose this code with the case-switch:
for(int i=1;i<=size(L);i=i+1 ) { while(1){ if (typeof(L[i]) == "intmat") { write(fil," "+nam+"["+string(i)+"]="+ "intmat(intvec("+string(L[i])+ "),"+string(nrows(L[i]))+","+string(ncols(L[i]))+");"); break; } if ( typeof(L[i])== "matrix") { write(fil," "+nam+"["+string(i)+"]="+ "matrix(ideal("+string(L[i])+ "),"+string(nrows(L[i]))+","+string(ncols(L[i]))+");"); break; } if ( typeof(L[i])== "string") { write(fil," "+nam+"["+string(i)+"]=\""+L[i]+"\";"); break; } else { write(fil," "+nam+"["+string(i)+"]="+typeof(L[i])+"(",string(L[i])+");"); break; } } }
Then try again the example, where we put a > at the beginning of the file name to overwrite the old file.
> ring r; > ideal i=x,y,z; > list k="Hi",nameof(basering),i,37; > writelist(">zumSpass","lustig",k); > read("zumSpass"); list lustig; lustig[1]="Hi"; lustig[2]="r"; lustig[3]=ideal( x,y,z); lustig[4]=int( 37); > execute(_); > lustig; [1]: Hi [2]: r [3]: _[1]=x _[2]=y _[3]=z [4]: 37
Now slot 1 contains the string Hi, but another problem seems to occur: Slot 2 just contains the string r but not the ring definition.
Yet this problem is due to the wrong usage of nameof(basering) in the example. With the wrong code writelist, the identifier r was converted to string and we got (32003),(x,y,z),(dp(3),C).
If we want this, then write
list k="Hi",string(basering),i,37;
But what correctly needs to be passed to the list k, is the
ring itself, but not just its name.
list k="Hi",basering,i,37;
Then once again it works fine:
> ring r; > ideal i=x,y,z; > list k="Hi",basering,i,37; > writelist(">zumSpass","lustig",k); > read("zumSpass"); list lustig; lustig[1]="Hi"; lustig[2]=ring( (32003),(x,y,z),(dp(3),C)); lustig[3]=ideal( x,y,z); lustig[4]=int( 37); > execute(_); > lustig; [1]: Hi [2]: // characteristic : 32003 // number of vars : 3 // block 1 : ordering dp // : names x y z // block 2 : ordering C [3]: _[1]=x _[2]=y _[3]=z [4]: 37
(There are still something else one could complain about.)
writelist removed