Path: news.cs.au.dk!news.net.uni-c.dk!uninett.no!news-feed.inet.tele.dk!bofh.vszbr.cz!newspeer.monmouth.com!nntp2.dejanews.com!nnrp1.dejanews.com!not-for-mail From: Andrew Klaassen Newsgroups: comp.lang.beta Subject: Re: Virtual attribute gives Seg Fault when accessed from pattern ref Date: Mon, 03 May 1999 23:47:48 GMT Organization: Deja News - The Leader in Internet Discussion Lines: 94 Message-ID: <7glcj3$tu7$1@nnrp1.dejanews.com> References: <7gi6gi$99i$1@nnrp1.dejanews.com> <372D57DD.41C6@cs.au.dk> <7gkb3t$vho$1@nnrp1.dejanews.com> NNTP-Posting-Host: 207.34.91.201 X-Article-Creation-Date: Mon May 03 23:47:48 1999 GMT X-Http-User-Agent: Mozilla/3.04 (X11; I; Linux 2.2.4 i486) X-Http-Proxy: 1.0 x3.dejanews.com:80 (Squid/1.1.22) for client 207.34.91.201 Xref: news.cs.au.dk comp.lang.beta:11915 In article , nospam2159@cs.au.dk (Peter von der Ahé) wrote: > >>>>> "AK" == Andrew Klaassen writes: > > AK> ... Function: (# ... Printname: (#...#); do ... #); ... do > AK> Function.Printname; (* doesn't compile *) ... > > AK> Why not? > > This will create a new instance of the Pattern "Function.Printname". > Do to that the Function needs to be an object, otherwise Printname has > no origin or surrounding environment. > > "(&Function).Printname" should work. This uses a computed reference. > > A computed reference has the form: > > (EXPRESSION).ATTRIBUTE > > where EXPRESSION must return a reference qualified by something which > has an attribute ATTRIBUTE. > ---snip--- (&Function[]).Printname does the trick. > > Another thing to consider is efficiency, I'm not too concerned about efficiency in this particular case - in the actual code I'm working on, the equivalent of "Printname" will only be used for debugging. If computed referencing makes things more convenient (and I'm still deciding if it will), I'll ignore the performance loss. However, code speed might be important in regard to some of my other functions. Something like, say IntegerPartOfLog2: (# value,i: @integer; enter value do ... exit (i - 1) #); Normally, I'd call this like so: i,a: @integer; do (for i:30000 repeat i -> IntegerPartOfLog2 -> a; ... for); (Don't worry - in the actual code, I use the function far more intelligently than this.) Would my code be faster overall (since the function will be called many times, and since I never need more than one copy of it) if I made IntegerPartOfLog2 a singular object rather than a pattern? (I guess that that would depend on whether i->IntegerPartOfLog2 creates a new instance of the pattern each time it's executed or not.) > if you intend that Function > should be a collection of some methods used for similar things, ---snip--- Actually, Function is intended to be a superpattern for a number of methods that are to be used in the same place and are referenceable (is that a word??) from the same array, as in Function: (# ... PrintName:< (# do inner #) do inner #); F1: Function (# ... PrintName:: (# do 'F1' -> puttext; #) ... do ... #); F2: Function (# ... PrintName:: (# do 'F2' -> puttext; #) ... do ... #); (* etc.*) (* I might also do F1: @Function(#...#) - I haven't decided * yet. There are a few considerations that are still a bit * fuzzy in my mind. *) FunctionArray: [0] ##Function; (* or *) FunctionArray: [0] ^Function; > Cheers, > Peter Thanks, Andrew -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own