Karim Belabas on Wed, 11 Sep 2024 08:11:43 +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: Karim Belabas <Karim.Belabas@math.u-bordeaux.fr>
- Date: Wed, 11 Sep 2024 08:11:37 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1726035099; c=relaxed/relaxed; bh=him+pW6p0EGBW9BPcFLN4nE/Kff2+adbEA18s4/S8Z0=; h=DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; b=FxsPB2Nasuux8/42trmcljw78icbGj+qJyUZl9pGOVhBpPm5pKJxiyc/BN98ICZvDKnUQLkiljIaZaDXe4iAxrpSdAWt589Fghr4BMoYwg1hFY3ZzPAqlBMpXblXb49m93GfXo4LGVdek8VyD6YLYleCFocqJbCwobJNR0fV4SpHkoOmTAuaLguHM7HyF7DwHW4Ioefm2750YdZzXoZxR4RGUCwiAyaQ78MvSeuJ//7s4aOtY5uOap5Kwpi9JVAev3lInnQnlbYfKP8ABp9mD7LQLs2RVo3soDKj4p6VW7y422g7YtHR3DHFjG5TFhZ9hf99i/G1A9XnNIqWZ5aj+19QueAZ2NHjTLHkaRz/IlpxUsHW96QTkw3OFO4gdFq/OKZTozdjqf3lxd4RqJK6teQsUJoe5hyEgn3Qzs/pqoH6OwXkZk3bXtBzS6uKnxody3v48isbez6jrKhasNBXCPutUlhROahvBkrneMHtCXlEnv9cdEJNkNXhU9VYaMD8JXe86IzDLoxwxElX3pb7ke0paXzap2BNgwqcZ6yCf/xdSJBpn4CCuGu29RIsjRza/LalaxR62M+YKPu+hOgidgAfhggPkfkq+KpiLC4Ikq/XPZTsrX16NYfqoF5HIPwKHPZQfRN6pbcoQDYfV/oo+JRFpp3UWrXfDCbWdOrBW/I=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1726035099; cv=none; b=l9uWsuCamE4/FJTABylA9vU8uvy8aFBrH6SloCaV9UIiuI5qPkQjW8nJlCFlWHX+naQYCTTQsVJEA/kwK4HmpK9EMzWrkGkjEiuAVDCxr2Pey9jIwoVAkwG81xQM2//2N7faYC1qf+pDEh1WhjQhsIJ5VieuCz20d/t5yyeIp5nNjdCJzwTuBYH4WPKF1Ti5niNgHZFyhv+y7s+eb/NuYevTFU4hYCAR/uBC47ibWtoab+1fJ3DTHVF/FU+6TNN6XHJodl3ZP1IPyoAoNQbUQlImpWHJGh65lFz/bb8w95NT1MIEIfkfamHz/VWjq7go+I+ANIONKemY9oCZ24O+jMo2MSopFpogXA1jVuBxDr5zFwBKoh/5EbH4b/lGJ/IgYOnoKcT3khOKaASNAruD/b43luVGdcqq+lhT5JxC0391fuSo2Sg/l0IGV6oYgZhhexLTuAMoKikjc+M5jSiwvQ9XNu5FxfmtIuAkodtu3uUY/KjkOM3umepmEtHchiVsMHDztzqB7efUHJx1iMV5fATK1xKv4gbKcEFtiuEsOLEIsjp99nC/REcZfpXlmknmJKznHBT35nBn3YE4iEa4d09izkRQRU+DrQFRKkmrI4Hfe0Gdmsvc6rnYJAVUqVYeMXsJ2GHvsAkcHTuv+mq97lZvktm+EGp81IdHWw9S7go=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Cc: pari-users@pari.math.u-bordeaux.fr
- Delivery-date: Wed, 11 Sep 2024 08:11:43 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1726035099; bh=him+pW6p0EGBW9BPcFLN4nE/Kff2+adbEA18s4/S8Z0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rQFrqPs0ySb9pPn2YHDfkRdurb6oLKBPXRpPw0oGWzcQDzoKntRs+MlpmJCgtOxvS 1WAyDrs9ZROfarwFCzFtmgR9Zxs1bSus5eRG9xVQDZ9hwBUCUAE0DU43KNsS1OYMKk J8ZGvLjWY5F8ZRfrPrulFgHS+Pzp/rA0XaIOnT7BlFLqvgQsHYAWbYy02hiR4xbyl3 7bLJCey8PjpgYToULBRXN59D3miypvcdpHWzKOA4TBpzXIzaA6jiyxWtA0KIrcapVS XbVmxbFg/fyg8yK1WQZrAT43Ff6443uerCR35ijGh/Yw6qDYV3GLDRGTQ1E5QtGW/Z 5mb01VttLhBa/8CvIn2ccPS4jkfcdjRQZWhUliSz0YWMWgoHBlmrRf5GidJ0lVijVq ji20zpwokBw0jBspnDDo2asPW7ptZpza+oA4SB/jDTr31UHT00tk+Jk6hALd2/EouF SCpbFvM9YBv0/e23pG7mkQ1YmFi83O6rB9pUbAtpv8DLfWor4ApeWITVVsktPYC+iX t7NThmdnaLh9V6z3sSQrFMsV9zMC2b7mf/LroKXsy2QWv7AORNz+AakXv6cAOaAET9 H4CiB1KsAtitFmPQK2DqBLWq6KpfehXI4pYTvdZcRI71fRqLYKPsvFwrqE2/pxj532 Wrd+aNY4fJN0swLXkhHZzZgU=
- In-reply-to: <CAEdMSjdx3rWpvmNCh+LewFoZy93bJVXBXm0rhd-SA9cYUxJWbA@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>
Hi,
just add my(One, Two, Three, Four, Five, Six) to the body of f.
Those will be lexically scoped to f.
Cheers,
K.B.
* Joe Slater [2024-09-11 03:15]:
> I want to be able to specify binary combinations of options the way that,
> e.g., vecsort() does. I couldn't see a way to do that so I created a
> function, makeoptions(), that returns a vector in the form
> ["a=1","b=2",...] and I use eval() on that vector to create those variables
> within my function. My problem is that eval() creates them with global
> scope, and I can't see a way to make them local.
>
> /* Takes a string containing a list of option names and a number whose
> binary digits represents those options. Returns variables set accordingly.
> */
> makeoptions(s="",options=0)=
> {
> if(s=="",return());
> my(v=strsplit(s," "));
> return(vector(#v,i,(Str(v[i],"=",bitand(2^(i-1),options)<>0))))
> }
> /* A function that uses makeoptions() */
> f(n)={
> my(a=eval(makeoptions("One Two Three", n)));
> my(b=eval(makeoptions("Four Five Six", n+1)));
> print("a=",One,Two,Three);
> print("b=",Four,Five,Six);
> }
>
> Here's the output from my function:
> (10:31) > f(2)
> a=010
> b=110
> (10:31) > One \\ Should be undefined
> %2 = 0
> (10:32) > Four \\ Should be undefined
> %3 = 1
> Is there a way to make these variables local, or another way to achieve
> what I want: local named variables set at run time without having a routine
> along the lines of Opt1=bitand(options,1); Opt2=bitand(options,2); ...
>
> Thanks,
> Joe Slater
--
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/