[metapost] Function defined by a sum

Hans Hagen pragma at wxs.nl
Fri Nov 2 13:59:23 CET 2007


Nicolas FRANCOIS wrote:

> Thanks. Someone on another list gave me something more "TeXish" :
> 
> vardef sum_sin(expr x,n)=
>   0
>   for k:=1 upto n:
>     + sin(k*x)/x
>     endfor
> enddef;
> 
> I thought something like this could work. But I don't know exactly why.
> Is this something like "token replacement", like in TeX ? Where can this
> be explained in the Metapost documentation ?

well, definitely not texish because tex has no 'functions' like mp

the for loop is fully expandable and it makes up the final value which 
is returned because it's a vardef

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the metapost mailing list