Bill Allombert on Fri, 13 Sep 2024 11:02:34 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: How can I keep these values local to my function?
|
- To: Joe Slater <joe@slatermold.com>
- Subject: Re: How can I keep these values local to my function?
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Fri, 13 Sep 2024 11:02:31 +0200
- Cc: pari-users@pari.math.u-bordeaux.fr
- Delivery-date: Fri, 13 Sep 2024 11:02:34 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=math.u-bordeaux.fr; s=2022; t=1726218152; bh=HSPJaYJDDwebr8ecUCnt5i/j0xoN9xe8y1SWXSnXpks=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=q4KVJ5VQwnr6Jq07WQM7i6gvBcSY5fx1WSKfgoOk8M6rlxFMDBzBv8E6nZU4NUw2C jjIc2eHad5bNRCL5pXZHGYM3s/yGxpqfFp3SrF7BPMw+wEI53Xz2b9FvBQt8VbsuH+ dTk38wUQQve9RFzxD9/5zFTVaS7YDgVzyJwBuVn7wQIw7bxzXX84v5bpOfHVZDIb92 PkTyNH5L407Xs3vBCwfd/GQAfp7ySI+kSe6yrLKRA31JWWLyLQgvVdZfFP1b+wwQJL rMuNkt73XaayRWn4SkKinlp/6jpBjv+1GNq3VSonnSl0NrAa395M00cozFI1tUaU1z ZykgmDseQ82Wh7ABYA9zbmf/iHBIWMG4MIZBHAbnHBaFOzI7UT+oM9PaQmVWZ7fgE8 +G6eZrhnqmczk35t1W7Y5UpJQhOLfZIWOrv6V9W7QACT56+w4So0Tl/Zf9dzKCUD3A DmQcagSUGnfYHvwA+qQ9uC9hM/QRI1rAhuOOQe6Kx2QQ7KIqMT1ePwitKHXrMB4Yot /NkZTCGGUht9Og4B1Ye8zbOWMMBwElK7CowJ1Pxqr93X36kCl50gxqxpAOcBgqrFT+ 9dSmfGp/Ff2/rry3SFl7SZU/Mj9qjLOIBIYIJEXfJwrpuoBiacZvvQGFeCy9Q0VG72 wZr0N5LWa1LRRjQAVzvp29V8=
- In-reply-to: <CAEdMSjdFV0TagtJ72=L6atiGSHaDdyXo_ygHR7n4+JRRzkNN3w@mail.gmail.com>
- Mail-followup-to: Joe Slater <joe@slatermold.com>, pari-users@pari.math.u-bordeaux.fr
- References: <CAEdMSjdx3rWpvmNCh+LewFoZy93bJVXBXm0rhd-SA9cYUxJWbA@mail.gmail.com> <ZuE0mYJe_DZwBtRj@math.u-bordeaux.fr> <CAEdMSjdFV0TagtJ72=L6atiGSHaDdyXo_ygHR7n4+JRRzkNN3w@mail.gmail.com>
On Fri, Sep 13, 2024 at 08:56:10AM +1000, Joe Slater wrote:
> That works as far as confining the scope, but I was hoping to have a
> solution which would allow me to define the variables at run time, rather
> than having them hard coded. I'm surprised that there's apparently no way
> to confine the effect of eval() to a local scope. If my variables have to
> be hard coded anyway, I'll probably use something like my([var1, var2,
> var3]=binary((options+8)%8).
The issue is that eval is its own scope!
? eval("local(a=4);print(a)");a
4
%7 = a
Here maybe a solution to your problem:
? myprogram() = { print([foo,bar,baz]); }
? fun(s,z) = eval(Str("local(",s,"=",z,");myprogram()"));
? fun("foo",3)
[3,bar,baz]
? fun("bar",3)
[foo,3,baz]
? fun("baz",3)
[foo,bar,3]
Cheers,
Bill.