Friday 10th November 1995 Coding Lecture 6 ---------------- Carlin Auditorium You are catapulted back into the late 20th century as you step through the double doors and into the dimness of the back of the Auditorium. As your eyes become accustomed to the lacklight, you begin to appreciate the beauty of this unique Terran decor. More than 200 seats, divided by two wide aisles spread over the main floor. An overhanging balcony provides additional seating. Three luxurious private boxes, obviously for visiting dignitaries, are visible on either side of the expansive walls. Thick red and gold carpeting covers the floor. All seating is upholstered in plush red velvet, a common covering for the era that is being depicted here. Two large gold pillars stand like silent sentinels on either side of a stage that spans the full width of the room. The only hint that you are still in your own time are the three familiar flags; Starfleet, Federation, and that of Starfleet Academy that stand proudly on the left side of the stage. Contents: T'korik WiP(#126vIq) Final Test Section Obvious exits: Out Mark_Farrell smiles. T'korik waves. T'korik stops sabatoging the WiP :) Mark_Farrell chuckles. Mark_Farrell looks around at the mostly empty lecture theatre. You say "I must be on a roll :-)" T'korik grins. I'm here cuz I heard there was free food. Norm has arrived. Norm enters from the Quad. Mark_Farrell grins. Norm stands at attention, "Has it started yet (lecture)?" (10 minutes still counting) You say "I'm just waiting for the week when noone turns up, but I still get the 15 or so requests for lecture logs :-)" T'korik laughs! You say "Not yet. I was going to give it about another 5 minutes to wait for any stragglers." Norm has always been one! T'korik says "You still haven't sent me my logs :)" Norm will be able to come back around 7:15 est. Norm has all of them to date Mark_Farrell guesses that I'll still be here. Norm will one day create a directory for these lectures Gavnuch has arrived. Gavnuch enters from the Quad. You say "Alright, so what are we going to cover this week?" T'korik says "How the hell does iter work? :)" Mark_Farrell grins. You say "Anything else?" T'korik says "How does iter2 work! :)" You say "Okay. So I guess I'll cover iter() then." T'korik grins. Mark_Farrell lags terribly. Norm grin Norm would like to know about that too! Norm must go now, but will stay online, bye! You say "Alright, the principle use of iter() and iter2() are to avoid having to use a dolist." T'korik's nods. T'korik nods. You say "As I have stressed throughout the series, avoiding @commands it a main object of efficient muse code." iter(,) Arguments: 2 Type: General* Returns the results of applying to every word in , replacing ## and v(0) inside with each word in as it goes along. Also, v(2) is replaced with the word # in that is curently being processed. can be up to 50 words long. must be in the format '{[]}'. Some examples will help carify. Examples: [iter(1 2 3 4 5,{[mul(##,2)]})]= 2 4 6 8 10 [iter(5 6 7 8 9 10,{[mul(##,v(2))]})]= 5 12 21 32 45 60 [iter(#1 #2 #7,{[name(v(0))]})]= The_Great_Bird Laura Yngwie * See also: iter2(), Soft-coded functions You say "So, read 'help iter function'" T'korik says "Oi. That was a recent addition!" You say "From that you can see the basic syntax." T'korik nods. Mark_Farrell smiles. "Aye, Tik. If you haven't done recently you should do a 'help functions' too. A lot of the undocumented functions have been added to the list." T'korik nods. You say "Also, read through the help on soft-coded functions that is referenced from the iter page." T'korik says "That's a lot of functions." T'korik nods. Salek has arrived. Salek enters from the Quad. Salek slips in quietly. You say "Anyway, to continue on iter:" T'korik grins. "grimmy could get grumpy" You say "It is basically takes 2 arguements. A list to work on, and the functions to execute multiple times." Mark_Farrell nods. T'korik says "So it's the function equivalent of dolist?" You say "iter(,{})" Mark_Farrell nods at Tik. That's right. You say "The help examples are fairly clear on basic usage. There is one main 'gotcha' - and that is that for every item iterated over, a space is added to the output." T'korik says "Eh?" You say "It can make multiline formatting difficult" You say "For example, you have :" You say "@pe %#=[[iter(1 2 3 4,{%r-[cjust(##,77)]-})]" You say "The problem with that code is that even though you have 79 characters and a carraige return and you might expect that to come out as 4 lines, the extra space after each item means that you get blank lines interspaced." T'korik nods. You say "In effect, you can only have a 78 + CR width line, and not 79 + CR." Norm is back Mark_Farrell compares the @dolist form: You say "@dolist 1 2 3 4=@pe %#=-[[cjust(##,77)]-" T'korik nods. You say "Okay, so using the iter() has saved us 4 @commands at the expense of losing one character of width. Not too bad a tradeoff." T'korik nods. Norm understands You say "There is another drawback though. This is more serious." T'korik grins. "It's softcoded." Norm grin, and agrees with Tik You say "The Muse has a 2000 character limit on register sizes, and so the maximum length of string we can emit using the @pe %#=[[iter(....)] code is 2K." Norm wonders why you would need >that< many Mark_Farrell agrees with you both about the softcode though. "I sent the coders at grimmy hardcode for iter and iter2 about 6 months ago. . ." You say "Well, lets do some quick sums." Norm says "please do" You say "2000 characters at 80 per line means we can do 25 lines." T'korik says "OR, one screenfull." T'korik says "And that's edge-to-edge :)" You say "Take a large starship, with more than 25 crew." You say "The computer has a 'roster' command." Norm nods You say "Ditto for an intruder log, or console manning log, etc." Norm nods You say "In cases such as those you need to use a combination technique, where an @dolist lnum(length of list / max per iter)={@pe %#=[iter(,{})]" Norm has disconnected. You say "Now, because of the potential ugliness of the code for doing extended output, I'm not going to go further with that now." You say "That is, other than to answer any questions on the general method if what I just said didn't make sense." Mark_Farrell looks around. You say "Alright. Down to some 'nice' things you can do with iter2" You say "Iter2() works along similar lines to iter(), except that it can take more arguements." You say "And the nice thing about the arguments is that they are only evaluated once." You say "For instance, say we have:" You say "@dolist =@pe ##=%%N is standing in [[loc(v(#))]." You say "Which emits to a list of players that the enactor is in a particular location." Mark_Farrell ponders and has chosen a bad example, but will explain the principle here. You say "Now, this will evaluate %N and loc(v(#)) multiple times." You say "You can cure this in one of two ways with this example:" You say "The first, instead of using %%N, and [[loc(v(#))], you can use %N and [loc(v(#))]." Note : I didn't explain delaying yet, so using [[ and %% probably doesn't make much sense yet. You say "For the 2nd way, let us assume that there is a pemit() function. (I said it was a bad example)." You say "We can use:" You say "iter(list of players,{[pemit(##,.....]})" You say "If we use iter, we still evaluate the function over and over." You say "Iter2 can take more arguments after the action, and pass these in the stack variables to the function." You say "So : iter2(,{},param1,param2,.....)" You say "As I was saying, when the functions are evaluated, the parameters are passed on the stack." You say "They are evaluated _before_ the functions see them - so, if you had:" You say "iter2(1 2 3 4,{},)" You say "Instead of doing the big function every time you need it in , you can just do it once." Salek nods. Mark_Farrell thinks he made one hell of a hash of explaining that, so let me try some examples. M'Ceepy has arrived. M'Ceepy enters from the Quad. M'Ceepy waves OOCly. You say "@va me=$eta *:@pe %#=Time to planets: [iter2(,{%r[function to show time at speed X]},pow(v(0),3))]" *Salek* Salek: Sorry, I my modem is lagging me... You say "This moves the pow() function outside the iteration loop, and it is only evaluated once." You say "THe result of the pow() is available on in the stack registers for the display functions. (in v(2) in this case)" You say "You could move that a step further because you need to specify your TRC/HRC coords, and could have some command like:" Norm has connected. You say "$eta * * * * *:... where you give it speed, heading, elevation, range and a coord system, and then have iter2(....,....,pow(v(0),3),)" You say "However, unless you need this extra paramter passing, you should use iter(), because as it is simpler that iter2(), it is less strain on grimmy." You say "Okay. That is just about all I have to say on iter and iter2 at the moment. Any questions?" Mark_Farrell looks around. Salek has disconnected. Norm looks at Mr. Farrell Norm grins Norm says "just two now, and I have no questions" You say "Okay. That covers the topics T'korik wanted." Norm says "I suppose he left" Mark_Farrell counts 3. "Anything specific you want me to try to expound on?" Norm thinks Norm says "is there anything related to lcplayers() that's cool?" Salek has connected. Mark_Farrell chuckles. "Define 'cool' Norm says "errr, interesting" Norm :lives on the east coast, so he doesn't use words such as "narly, dude!" Help LCPLAYERS: LCPLAYERS() Arguments: 1 Type: Information Returns a list of the db numbers of all the connected players in that you would see if you were to look at . Thus if the player is set Dark or is hidden, they wouldn't show up on lcplayers(). * See also: lplayers(), lcon() Norm says "anything that tells about the players in the room with you?" You say "Well, short of listing interesting stats for connected players in particular locations, no." Norm says "oh" You say "You can tie it into iter() to produce a list of ranks, empires etc." You say "Specifically, something like 'who' but just for your location." Norm says "actually, that's my next goal, which is why I'm interested in Iter" Mark_Farrell chuckles. Norm says "I've mailed Y, and received a Yngwie like answer, confusing to the bone: "Try Iter()" :)" You say "@va me=$lwho:@pe %#=Players in this location:[iter(lcplayers(loc(v(#)),{%r[class(name(v(0)))] [name(v(0))]}))]" Norm pulls out a sten o PADD Mark_Farrell is surprised Y didn't tell you to come to my lectures :-) Mark_Farrell missed out a bracket or two, but you should be able to sort it out. Norm says "sounds like it's not the first time it's been asked" You say "Well, producing a list of 'interesting' information if fairly easy with either iter() or @dlolist." Norm nods Mark_Farrell takes the code apart: $lwho - simple $ command match. %# and v(#) will be the database number of the person who typed the command. You say "@pe %#= Send the output to the player who did the command. You should always use %# or v(#) instead of %N or v(n) unless you are doing name(v(#)), when v(n) and %N are exactly equivalent. The parser finds it much easier to use the db-number to find an object." You say "Then we have the iter(): iter(,.....), where list = lcplayers(loc(v(#))) - ie, from the inside out - Me -> My Location -> List of connected players in my location." Salek has disconnected. Norm nods You say "Then we take the: iter(....,{}), where functions are: %r[class(name(v(0)))] [name(v(0))]" Norm raises his hand with another topic, If you're done You say "Now, as you know, these functions are called for each item in , and v(0) is the list item, (and v(2) is the list index - ie 1, then 2, then 3...)" Salek has connected. Salek leaves the Auditorium. Salek has left. You say "So, we print a CR, then take the class and name of the player, and print it, followed by a trailing space." You say "working code is on wip/vp" You sense you have new mail from Salek. You say "Okay - question time." Norm raises his hand Mark_Farrell smiles. Shoot. Norm says "perhaps you have addressed this in a previous lecture, but what about the @edit?" You say "Okay, what specifically about @edit?" Norm says "well, I read the help, and it didn't seem to work(although I probably didnn't do it right :) )" Norm says "Rx:|GLJB*#V ," Norm has disconnected. Carlin Auditorium You are catapulted back into the late 20th century as you step through the double doors and into the dimness of the back of the Auditorium. As your eyes become accustomed to the lacklight, you begin to appreciate the beauty of this unique Terran decor. More than 200 seats, divided by two wide aisles spread over the main floor. An overhanging balcony provides additional seating. Three luxurious private boxes, obviously for visiting dignitaries, are visible on either side of the expansive walls. Thick red and gold carpeting covers the floor. All seating is upholstered in plush red velvet, a common covering for the era that is being depicted here. Two large gold pillars stand like silent sentinels on either side of a stage that spans the full width of the room. The only hint that you are still in your own time are the three familiar flags; Starfleet, Federation, and that of Starfleet Academy that stand proudly on the left side of the stage. Contents: M'Ceepy Gavnuch WiP(#126vIq) Final Test Section Obvious exits: Out Mark_Farrell sits on the WiP You say "So guys, any questions, or are you both idle?" Gavnuch grins. M'Ceepy is here and listening. Gavnuch says "ahhh... the old days..." Norm has connected. Gavnuch waxes philosophical. Norm is tempted to get a new phone line! Gavnuch chuckles. Norm grins You say "Right. Back to @edit..." Norm likes the lwho, thanks! You say "Well, @edit object/register={Pattern to match},{Pattern to replace matched patterns with} is the basic format." Norm says "also, @edit seems to be working" Norm says "perfect lag timing" Norm says "I'm not sure if this is a problem or not, but my lwho returns a "*Norm* Norm sees:...." about half-way into the list" You say "Okay, are there any other questions what I can address in 10 minutes?" Norm says "will you come back after the reboot?" Mark_Farrell nods. Norm points up the screen to his previous question :) Mark_Farrell sighs as he queried the lockout on pemit() and was told its probably permanent. Gavnuch says "what is pemi()?" Norm was totally confused by that M'Ceepy nods. "Y, said it would be Dir only." :( Gavnuch says "pemit to a list?" Gavnuch says "guess it's WAYY secret :)" Norm agrees M'Ceepy says "Yeah, inline pemit to a list" Mark_Farrell sighs. Norm says "correction, when it comes up with "Norm just saw...", it repeats the list." Mark_Farrell doesn't have a problem with the lwho on the WiP, Norm. M'Ceepy says "Norm, set yourself quiet to get rid of those messages. But..." Gavnuch says "well if they decide to do that, then all our HD's will just be q-laggy :)" Norm notices that Mark_Farrell must be tired You say "That's 'cause you are not set quiet." Gavnuch says "err q-spammy :)" Norm says "ahhh! much better, thanks" M'Ceepy says "If you set yourself quiet you'll not get certain messages" Mark_Farrell happenned to stumble on it earlier. Norm says "ohh, thanks" Norm is just getting into the deeper side of coding Gavnuch nods, "I didn't know there existed one... :/" Gavnuch shrugs. M'Ceepy says "You don't get the 'set' messages, @edit doesn't show you the editted text, etc." Mark_Farrell nods. It's 00:45 and I have a meeting at 9.30pm EST yet... Grimmy rebooted here, and the lecture drew to a close. For reference: The WIP is left visible between lectures, and has database number #126. Thus you can examine the code on it using examine #126 The next lecture is on the 17th November at 6pm in the Carlin Auditorium. If you have any topics you want covered, please +mail them to me.