From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/14989 Path: main.gmane.org!not-for-mail From: Jonathan Nicholl Newsgroups: gmane.comp.tex.context Subject: Re: ntg-context digest, Vol 1 #715 - 2 msgs Date: Fri, 9 Apr 2004 19:43:04 +0100 Sender: ntg-context-admin@ntg.nl Message-ID: References: <20040407100011.502.3539.Mailman@ref.ntg.nl> Reply-To: ntg-context@ntg.nl NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 (Apple Message framework v613) Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1081536526 29881 80.91.224.253 (9 Apr 2004 18:48:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 9 Apr 2004 18:48:46 +0000 (UTC) Original-X-From: ntg-context-admin@ntg.nl Fri Apr 09 20:48:31 2004 Return-path: Original-Received: from ref.vet.uu.nl ([131.211.172.13] helo=ref.ntg.nl) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BC13H-0001XY-00 for ; Fri, 09 Apr 2004 20:48:31 +0200 Original-Received: from ref.ntg.nl (localhost.localdomain [127.0.0.1]) by ref.ntg.nl (Postfix) with ESMTP id 41F2310B74; Fri, 9 Apr 2004 20:45:06 +0200 (MEST) Original-Received: from outbound.kcl.ac.uk (elder.kcl.ac.uk [137.73.2.27]) by ref.ntg.nl (Postfix) with ESMTP id B9A8910B2C for ; Fri, 9 Apr 2004 20:43:09 +0200 (MEST) Original-Received: from [137.73.2.10] (helo=redwood.kcl.ac.uk) by outbound.kcl.ac.uk outbound with esmtp id 1BC11G-0003tG-Ad for ntg-context@ntg.nl; Fri, 09 Apr 2004 19:46:26 +0100 Original-Received: from [80.189.146.65] (gr.189.146.65.dial.global.net.uk [80.189.146.65]) by redwood.kcl.ac.uk with SMTP id i39IhMC4027288 for ; Fri, 9 Apr 2004 19:43:23 +0100 (BST) In-Reply-To: <20040407100011.502.3539.Mailman@ref.ntg.nl> Original-To: ntg-context@ntg.nl X-Mailer: Apple Mail (2.613) X-KCL-MailScanner: Found to be CLEAN X-MailScanner-From: jonathan.nicholl@kcl.ac.uk Errors-To: ntg-context-admin@ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.0.13 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.comp.tex.context:14989 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:14989 On 7 Apr 2004, at 11:00, ntg-context-request@ntg.nl wrote: > In the following code : > > vardef list = > A , B , C , A > enddef; > > def triangle = > forsuffixes $=list: > pair T.$; > endfor; > enddef; > > beginfig(1) > triangle; > > path T; > > T.A = (2,3); > T.B = (3,5); > T.C = (2,6); > > T = T.A -- T.B -- T.C -- cycle; > draw T; > > endfig; > > end; > > > In macro "list" if i give just "def" instead of "vardef" the program > works fine. > But with "vardef" i'm getting many errors. > I'm not able to figure this out. > Please help; > > thanx in advance. > Vinuth. Vinuth, I've been trying to get clear about issues like this recently. Perhaps my answer will not be completely correct. But here goes. One difference between 'def' and 'vardef' is that 'def' makes the symbolic token which follows into a spark, whereas vardef leaves it as a tag. (This is the language that Knuth uses in his Metafont Book.) The difference between sparks and tags is the readiness with which Metafont interprets their meaning. So far as Metafont is concerned, your input consists of a stream of tokens, and at some point in its digestion of your input file it has to interpret each of these tokens. But the stage of digestion at which it interprets a symbolic token depends on whether it is a spark or a tag. It interprets sparks sooner than it interprets tags. Generally speaking - there are ways to prevent it - Metafont interprets sparks in its mouth, whereas the stage at which it interprets tags depends on the circumstances. This is why your program works if you define the symbolic token 'list' using 'def': 'list' becomes a spark whose meaning is 'A,B,C,A'. As soon as Metafont reads 'for suffixes $=list' it interprets 'list', replacing it with 'A,B,C,A'. So writing 'forsuffixes $=list' is equivalent to writing 'forsuffixes $=A,B,C,A'. Perhaps you have guessed now why your program does not work if you define 'list' using 'vardef': 'list' remains a tag and so when Metafont reads 'forsuffixes $=list' it does not interpret it at once. In fact, it never interprets it. For the tags in the suffixes of variable names are never interpreted, and 'forsuffixes' causes 'list' to be treated as the suffix of a variable name. The tags in the suffixes of variable names just form part of the name. Only the subscripts in the suffixes of variable names are interpreted. 'forsuffixes $=list: pair T.$[]; endfor;' is equivalent to 'pair T.list;' Look at the following program: 1 vardef list = 2 1 3 enddef; 4 5 forsuffixes $=list: 6 T $ = 2; 7 endfor; 8 9 show(T list); 10 show(T 1); 11 show(T [list]); 12 13 end; Lines 1-3 assign the meaning the number 1 to the variable name 'list'; they are equivalent to 'list := 1;'. Lines 5-7 make the number 2 the meaning of the variable name 'T list'; they are equivalent to 'T list = 2;'. Line 9 produces the output '>>2', because 2 is the value of 'T list'. Line 10 produces the output '>>T1' because the variable has no value; 'T1' is undefined. Line 11 is interesting. The square brackets around 'list' force evaluation of the variable 'list', so 'show(T [list]);' is equivalent to 'show(T 1);'. The output is '>>T1' again. What do you think that the output of the following program will be? def list = 1 enddef; forsuffixes $=list: T $ = 2; endfor; show(T list); show(T 1); show(T [list]); end; In summary, vardef is intended for giving meanings to variable names. You should be suspicious of 'vardef list = A,B,C,A; enddef;' because A,B,C,A cannot be the value of a variable name. (I assume that this was Hans's point, when he said that Metapost lacks the concept of a list.) If you want to understand things like this, I strongly recommend that you read Knuth's Metafont Book. It makes everything very clear, and nowhere else is the detail explained. The most relevant chapters are the ones on variables, macros, and loops. Best wishes, Jonathan Afterthought: to grasp the difference between a name and the meaning of the name compare '"Vinuth" contains six letters' with 'Vinuth contains six letters.'