Loïc Grenié on Fri, 13 Feb 2015 13:33:00 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
- To: Josef Eschgfaeller <esg@unife.it>
- Subject: Re: Function names
- From: Loïc Grenié <loic.grenie@gmail.com>
- Date: Fri, 13 Feb 2015 13:32:52 +0100
- Cc: pari-users <pari-users@pari.math.u-bordeaux.fr>
- Delivery-date: Fri, 13 Feb 2015 13:33:00 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=z9FRk0zWfLGOkkRkigXt2gWDzbsRy064ezCTn1uQbKI=; b=z87djrdt28V8utmRvnAGl4S2A3b7t8y+1lgrpYj9KoDJa3IaUaUJJAxfMfU1b7958x OWZuAuzgk+buRlFFp1xdprQoj0WWxUxcVqt9W/Lq990k/RsYUDBFzAHmKFStZanobwd9 DEZkitTjNCfPE/+6hpVwWACtLgFpAbzxqAcVGn0cGLIwFxbaWGNN8FTp5GiGrcMmmrPv rqV5KLxGxaQ+shUEziuV+eBReGS1/X/8EOCQ1pkscENy71tV5jb/UDA9WN/ASdG4STb5 pdZSFB5a77XP8nXaIHjoNwXGRD/2SsOsFeG+LCB5Z92vR/xPiR8ZLQafDzn2OcbVylcn ib8Q==
- In-reply-to: <CAFBvUasCKbsXXYiuTTacWi+2QVW_PaaZHWSCfGb+hyLzVR7xQg@mail.gmail.com>
- References: <CAFBvUasCKbsXXYiuTTacWi+2QVW_PaaZHWSCfGb+hyLzVR7xQg@mail.gmail.com>
2015-02-13 12:23 GMT+01:00 Josef Eschgfaeller <esg@unife.it>:
> Is there a way to obtain the name
> of a function as a string? I would like
> to generate an output of the form
> --------------------------------------------------
> f 3
> g 9
> h 27
> --------------------------------------------------
> after
> --------------------------------------------------
> f (x) = x
> g (x) = x^2
> h (x) = x^3
>
> F=[f,g,h]
> for (i=1,3, f=F[i]; print(Strprintf("%s: %d",f,f(3))))
> --------------------------------------------------
> But this (as happens with Str(f)) prints the
> function bodies.
This is because variable f contains the body of the function.
You can do the contrary, though:
F=["f","g","h"]
for(i=1,3,my(f=eval(F[i]));print(F[i], ": ", f(3)))
Hope this helps,
Loïc