Bill Allombert on Sun, 20 Nov 2011 17:46:27 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Backward compatibility


On Sun, Nov 20, 2011 at 08:32:53AM -0500, Charles Greathouse wrote:
> I was trying to write a quick script that would work for both newer
> (2.4.3 through 2.6.x) and older versions of gp.  For example, I would
> like to use warning() in the new versions and a print statement in old
> ones.  I thought it would be convenient to define
> 
> if(lex(version(),[2,4,3])<0,{warning(s:str)=print("Warning: "s)});
> 
> but this breaks in recent versions -- "variable name expected".  Is
> there a better way to do this?

You can do
if(lex(version(),[2,4,3])<0,eval("warning(s)=print(\"Warning: \"s)"));
or
if(lex(version(),[2,4,3])<0,(mywarning(s:str)=print("Warning: "s));alias("warning","mywarning"));

or you can rename warning to mywarning in your code and do
if(lex(version(),[2,4,3])<0,mywarning(s:str)=print("Warning: "s),alias("mywarning","warning"));

(Note that, if you use alias you must do it before reading any code that use
warning/mywarning).

Cheers,
Bill.

PS: you used @list.cr.yp.to. Redirected to @pari