| Bill Allombert on Thu, 02 Apr 2009 19:55:31 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: character input to functions |
On Thu, Apr 02, 2009 at 12:01:49PM -0500, cino hilliard wrote:
>
> Exactly what I said. I want to input without having to do the 4 extra keystrokes
> for quotes for each number.
Four ? Two should suffice I think.
> Suppose in the dessert I stumble upon an old and fragial scroll of thousands
> of numbers in base 32. I have a base(b1,b2,n) that converts n base r1 to r2.
> I want to determine if the base 32 numbers are prime or not. Now depending,
> on the starting number, This works.
>
> g(n) = isprime(eval(base(32,10,n))).
>
> (10:50:38) gp > g(12345ab)
> *** too many parameters in user-defined function call: g(12345ab)
> ^---
>
> So we put n in quotes.
>
> (10:52:33) gp > g("12345ab")
> %30 = 0
>
> Yep. That works. I guess I could pay my assistent to simply type in the quotes
> so we would not get the error. Or I could make him think on each number:
> "To quote or not to quote." This is a terible idea(Sorry Willie).
OK, so I will give you a tip for free ( so you will save money!):
make your assistant to write all the numbers in a text file 'numbers.txt'
without quotes and one by lines,
then add the quotes with sed -e 's/.*/"&"/' and read the file under GP
with readvec.
> Because thinking will
> get errors on input. The input should be rote for maximum accuracy. Then the
> creative juices abound. Why can't Pari accept all inputs without quotes?
Because this would conflict with existing syntax:
1e3
? g(n)=n
? g(1e3)
%9 = 1000.0000000000000000000000000000000000
?g(1+1)
%10 = 2
etc.
You do not want 1000.000 to appears in your sequence!
Maybe what you want is:
sread()=extern("read a; echo \\\"$a\\\"")
g(n)=
{
v=vector(n);
for(i=1,n,
s=sread();
if(s=="",return(vecextract(v,1<<(i-1)-1)));
v[i]=s);
v
}
Now do g(100) and start typing your numbers.
Enter an empty line for stopping.
Cheers,
Bill.