From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/111830 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeong Dal Newsgroups: gmane.comp.tex.context Subject: simplifying repeated macro calls in metafun Date: Mon, 21 Jun 2021 08:30:06 +0900 Message-ID: <37CA77E7-D38A-4A5A-A2C9-D734345D4586@me.com> References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Content-Type: multipart/mixed; boundary="===============3647374270380807259==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32448"; mail-complaints-to="usenet@ciao.gmane.io" To: "list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl" Original-X-From: ntg-context-bounces@ntg.nl Mon Jun 21 01:30:48 2021 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lv6tr-0008IT-BU for gctc-ntg-context-518@m.gmane-mx.org; Mon, 21 Jun 2021 01:30:47 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id BBE7E2846F5; Mon, 21 Jun 2021 01:30:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id maHervmNk2z3; Mon, 21 Jun 2021 01:30:18 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id CB562284938; Mon, 21 Jun 2021 01:30:18 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 7DA15284931 for ; Mon, 21 Jun 2021 01:30:15 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Vk7Gq6vVC0Yj for ; Mon, 21 Jun 2021 01:30:14 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=17.58.6.56; helo=pv50p00im-ztdg10021801.me.com; envelope-from=haksan@me.com; receiver= Original-Received: from pv50p00im-ztdg10021801.me.com (pv50p00im-ztdg10021801.me.com [17.58.6.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 84C122846F5 for ; Mon, 21 Jun 2021 01:30:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1624231812; bh=p7LSwDbwAIWeKhxyQwl1H9ZI84mG2lGZGWkxi+gKl2g=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=L8lVdHFtYUzBCVzfFE/RgN2UmFBiHZ822WjfM+ibpUxgYvsIByundRl5yM/+hsMZ8 Hnd3+d4FIk9X5vG7lw/OOZhMLSsQ3AWRskFJlSMvYV5DGDLCd8bgUBsCfLpE4vcha9 yfpWmpSXQa8BdAwWBEP/fYscoZ3PZqvjRqtorC6j3CD1sDfhx7QweFI4XpGkpcoumM tQR08Ke7hhkxTbK/41afRx+dG4Hy97KAsIgzp0lddGM6SGLSp4eIx5aMDei58MSENu zy947slQacLbVLZSnNnBoBFD86olm0TGYM/tgz297rjxkBCmmb+WtExOWBM0ikTfh4 c4Ua7Cua1A8gg== Original-Received: from smtpclient.apple (unknown [222.232.154.22]) by pv50p00im-ztdg10021801.me.com (Postfix) with ESMTPSA id DF91F3600CA for ; Sun, 20 Jun 2021 23:30:10 +0000 (UTC) In-Reply-To: X-Mailer: Apple Mail (2.3654.100.0.2.22) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-20_14:2021-06-20, 2021-06-20 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=846 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2106200163 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:111830 Archived-At: --===============3647374270380807259== Content-Type: multipart/alternative; boundary="Apple-Mail=_7811994A-1A1C-44C6-B448-DEE1950F0DF4" --Apple-Mail=_7811994A-1A1C-44C6-B448-DEE1950F0DF4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, I defined a macro definition in metafun, and draw figures using = \startbuffer[] =E2=80=A6 \stopbuffer and \processMPbuffer[]. As you see in the attached code, the same macro definition is used = repeatedly by changing the numeric argument.=20 Is there a better way to simplify the code, for example, using = \dorecurse and recurselevel? Thank you for reading. Best regards, Dalyoung \startbuffer[UDBasic] pair A,B,C,D; pair E, F, G, H; path p,q; numeric ang,maxNum; u:=3D1in; A=3D(.95*TextWidth,u); B=3D(0,u); C=3D(0,0); D=3D(.95*TextWidth,0); p :=3D A--B--C--D; q :=3D (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle; z0=3D(.1u,0); =20 vardef nextPt (expr M,N) =3D=20 if ypart(N) =3D 0:=20 H :=3D whatever[N, N + dir(.5*angle(M-N))*u] =3D whatever[A,B]; else: H :=3D whatever[N, N + dir(.5*angle(M-N))*u] =3D whatever[C,D]; fi; H enddef; def grayUD(expr i) =3D draw G -- if ypart(B)=3Dypart(G): B -- C else: C -- B fi --z[i]; filldraw z[i]+2*(G-z[i])*u -- z[i] -- z[i+1] -- z[i+1]+(G-z[i])*u = -- cycle withcolor .75white;=20 draw G -- z[i+1] dashed evenly; draw z[0] for k=3D0 upto i: --z[k] endfor dashed evenly; clip currentpicture to q; enddef; def linesUD(expr i) =3D draw p; draw z0 for k=3D0 upto i+1: --z[k] endfor dashed evenly; setbounds currentpicture to boundingbox q; enddef; \stopbuffer \startbuffer[UDpts] ang :=3D 40; z[1] =3D whatever[z[0], z[0]+dir(ang)*u] =3D whatever[A,B]; G :=3D whatever[z[0], z[0]+dir(2*ang)*u] =3D whatever[A,B]; for k =3D 2 upto 20: z[k] =3D nextPt(z[k-2],z[k-1]); maxNum :=3D k; exitif xpart(z[k]) > TextWidth; endfor; \stopbuffer \startbuffer[UD0] draw p; setbounds currentpicture to boundingbox q; \stopbuffer \startbuffer[UD1] grayUD(0); \stopbuffer \startbuffer[UD11] linesUD(0); \stopbuffer \startbuffer[UD2] G :=3D z0; grayUD(1) \stopbuffer \startbuffer[UD21] linesUD(1); \stopbuffer \startbuffer[UD3] G :=3D z1; grayUD(2); \stopbuffer \startbuffer[UD31] linesUD(2); \stopbuffer \startbuffer[UD4] G :=3D z2; grayUD(3); \stopbuffer \startbuffer[UD41] linesUD(3); \stopbuffer \startbuffer[UD5] G :=3D z3; grayUD(4); \stopbuffer \startbuffer[UD51] linesUD(4); \stopbuffer \startbuffer[UDFinal] draw p; draw z0--z1--z2--z3--z4--z5--z6--z7--z8 dashed evenly; setbounds currentpicture to boundingbox q; \stopbuffer \starttext \processMPbuffer[UDBasic,UDpts,UD0] \processMPbuffer[UDBasic,UDpts,UD1] \processMPbuffer[UDBasic,UDpts,UD11] \processMPbuffer[UDBasic,UDpts,UD2] \processMPbuffer[UDBasic,UDpts,UD21] \processMPbuffer[UDBasic,UDpts,UD3] \processMPbuffer[UDBasic,UDpts,UD31] \processMPbuffer[UDBasic,UDpts,UD4] \processMPbuffer[UDBasic,UDpts,UD41] \processMPbuffer[UDBasic,UDpts,UD5] \processMPbuffer[UDBasic,UDpts,UD51] \processMPbuffer[UDBasic,UDpts,UDFinal] \stoptext --Apple-Mail=_7811994A-1A1C-44C6-B448-DEE1950F0DF4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Hi,

I defined a = macro definition in metafun, and draw figures using \startbuffer[] =E2=80=A6= \stopbuffer and \processMPbuffer[].
As you see in the = attached code, the same macro definition is used repeatedly by changing = the numeric argument. 
Is there a better way to simplify = the code, for example, using \dorecurse and = recurselevel?

Thank= you for reading.

Best regards,

Dalyoung

\startbuffer[UDBasic]
pair = A,B,C,D;
pair E, F, G, H;
= path p,q;
numeric ang,maxNum;
= u:=3D1in;
A=3D(.95*TextWidth,u); B=3D(0,u); C=3D(0,0); D=3D(.95*TextWidth,0);
p :=3D A--B--C--D;
q :=3D (TextWidth,1.5u)--(0,1.5u)--(0,-.5u)--(TextWidth,-.5u)--cycle;
z0=3D(.1u,0);
= vardef nextPt (expr = M,N) =3D
= if ypart(N) =3D 0:
H :=3D whatever[N, N + dir(.5*angle(M-N))*u] = =3D whatever[A,B];
else:
H :=3D= whatever[N, N + dir(.5*angle(M-N))*u] = =3D whatever[C,D];
fi;
H
enddef;

def grayUD(expr i) =3D
draw G -- if ypart(B)=3Dypart(G): = B -- C else: C -- B fi --z[i];
filldraw z[i]+2*(G-z[i])*u= -- z[i] -- z[i+1] = -- z[i+1]+(G-z[i])*u= -- cycle withcolor = .75white;
draw G -- z[i+1] = dashed evenly;
draw z[0] for k=3D0 upto i: --z[k] = endfor dashed evenly;
clip currentpicture to = q;
enddef;

= def linesUD(expr = i) =3D
draw = p;
draw z0 for k=3D0 upto i+1: --z[k] = endfor dashed evenly;
setbounds = currentpicture to boundingbox q;
= enddef;
\stopbuffer

\startbuffer[UDpts]
ang :=3D 40;
z[1] =3D whatever[z[0], = z[0]+dir(ang)*u] = =3D whatever[A,B];
G :=3D whatever[z[0], z[0]+dir(2*ang)*u] = =3D whatever[A,B];
for k =3D 2 upto 20:
z[k] = =3D nextPt(z[k-2],z[k-1]);
maxNum :=3D k;
= exitif xpart(z[k]) > TextWidth;
= endfor;
\stopbuffer
\startbuffer[UD0]
draw p;
= setbounds currentpicture to boundingbox q;
\stopbuffer
\startbuffer[UD1]
grayUD(0);
\stopbuffer
\startbuffer[UD11]
linesUD(0);
\stopbuffer
\startbuffer[UD2]
G :=3D z0;
grayUD(1)
\stopbuffer
\startbuffer[UD21]
linesUD(1);
\stopbuffer
\startbuffer[UD3]
G :=3D z1;
grayUD(2);
\stopbuffer
\startbuffer[UD31]
linesUD(2);
\stopbuffer
\startbuffer[UD4]
G :=3D z2;
grayUD(3);
\stopbuffer
\startbuffer[UD41]
linesUD(3);
\stopbuffer
\startbuffer[UD5]
G :=3D z3;
grayUD(4);
\stopbuffer
\startbuffer[UD51]
linesUD(4);
\stopbuffer
\startbuffer[UDFinal]
draw p;
draw= z0--z1--z2--z3--z4--z5--z6--z7--z8 dashed evenly;
setbounds = currentpicture to boundingbox q;
\stopbuffer
\starttext
\processMPbuffer[UDBasic,UDpts,UD0]
\processMPbuffer[UDBasic,UDpts,UD1]
\processMPbuffer[UDBasic,UDpts,UD11]
\processMPbuffer[UDBasic,UDpts,UD2]
\processMPbuffer[UDBasic,UDpts,UD21]
\processMPbuffer[UDBasic,UDpts,UD3]
\processMPbuffer[UDBasic,UDpts,UD31]
\processMPbuffer[UDBasic,UDpts,UD4]
\processMPbuffer[UDBasic,UDpts,UD41]
\processMPbuffer[UDBasic,UDpts,UD5]
\processMPbuffer[UDBasic,UDpts,UD51]
\processMPbuffer[UDBasic,UDpts,UDFinal]
\stoptext





= --Apple-Mail=_7811994A-1A1C-44C6-B448-DEE1950F0DF4-- --===============3647374270380807259== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============3647374270380807259==--