From the NannyMUD documentation

LAST CHANGE

2000-12-23

TOPIC

NAME

        class3 - A log from TMI, part 3.

DESCRIPTION

        This is part 3 of some logs from TMI.
 

	Profezzorn says: I don't know what to teach today, and the crowd is
			 very mixed, so I really don't know...
	A small gnome appears and cleans some of the boards that are empty.
	The gnome leaves again.
	Klang says: i know this is intermediate class, and i am a beginner,
		    i'll just watch.
	Profezzorn says: I am open to suggestions, or we could talk
			 optimizations
	Profezzorn says: another topic is: common mistakes
	Savage says: anything really
	Profezzorn says: file handling?
	Savage says: I have a lot to learn :-)
	Heckler shrugs helplessly.
	Savage smiles happily.
	Profezzorn shrugs helplessly.
	Heckler says: the zen approach to coding ?
	Profezzorn says: ok, well, I'll start by describing the operators
			 &, - and ^  if that is ok
	Savage says: file handlings good for me
	Klang says: ok!
	Bclinton says:  oh yes!
	Savage shrugs helplessly.
	Bclinton says:  that's something i don't know yet
	Savage smiles happily.
	Profezzorn smiles happily.
	Bclinton says:  & that is
	Profezzorn says: ok, I guess you all know what - does to numbers
	Bclinton nods solemnly.
	Profezzorn says: but
	Profezzorn says: - can also be used on arrays
	Profezzorn says: at least in most drivers it can
	Profezzorn says: then it returns an array containing all items in the
			 first array that aren't present in the second array
	Bclinton says:  syntax?
	Heckler says: array1 - array2
	Bclinton nods solemnly.
	Profezzorn says: so, for instance ({1,2,3,4,3})-({1,3}) will return
			 ({2,4})
	Bclinton says:  heh, sure
	Profezzorn says: it also works for arrays of strings or objects
	Profezzorn says: - on arrays is _very_ useful from time to time
	Bclinton says:  cool
	Bclinton says:  well what is slice_array good for then?
	Profezzorn says: even though it is a fast operation, it takes lot
			 more time than - on numbers though
	Alcides arrives.
	Profezzorn says: slice_array ? there is no such efun in most drivers
	Bclinton says:  ahh
	Bclinton says:  ok
	Savage says: hmm
	Profezzorn says: anyway, if you're into mathematics:
	Profezzorn says: array1- array2 takes
			 C1*sizeof(array2)*log2(sizeof(array2))+
			 C2*log2(sizeof(array2)*sizeof(array1) time
	Profezzorn says: where C1 and C2 are small constants
	Bclinton gasps in astonishment!
	Heckler says: glad I don't have to remember that =)
	Savage says: heh
	Bclinton says:  indeed
	Profezzorn smiles happily.
	Heckler shakes profezzorns hand.
	Bclinton grins evilly.
	Heckler says: boffin ;P
	Profezzorn says: anyway, let's move on to the & operator
	Profezzorn says: do you know what the & operator does to ints?
	Bclinton says:  uhm one question
	Savage says: no
	Bclinton says:  to -
	Profezzorn says: yes bclinton?
	Bclinton says:  in other words: substract all elements in arr2 from
			 arr1 ?
	Profezzorn says: yes
	Bclinton says:  ok
	Profezzorn says: and return a new array containing the result
	Bclinton nods solemnly.
	Heckler says: but will subtract both duplicates ?
	Savage says: hmm.
	Heckler says: ({2,3,2})-({2}) = ({3}) or ({3,2}) ?
	Savage says: its maskin' them out?
	Profezzorn says: yes, ({1,1,1,1,1,2})-({1}) will return ({2})
	Bclinton nods solemnly.
	Heckler says: thought so =)
	Profezzorn says: anyway, the & operator stands for bitwize 'and'
	Profezzorn says: (compare with && which is logical 'and')
	Savage says: right - wot's bitwize?
	Bclinton chuckles politely.
	Bclinton says:  indeed
	Profezzorn says: ok, numbers are represented by bits
	Klang says: x & y means eather, and x && y mean both?
	Profezzorn says: an integer is 32 bits on a standard LPMUD
	Profezzorn says: wrong klang
	Scytale arrives.
	Scytale smiles happily.
	Profezzorn says: x || y means either
	Bclinton nods solemnly.
	Bclinton bows to scytale.
	Bclinton smiles happily.
	Scytale bows gracefully.
	Profezzorn says: anyway, you know how integers are represented?
	Bclinton says:  101100010111...
	Profezzorn says: right
	Profezzorn says: where every bit is worth twice as much as the one to
			 it's immediate right
	Profezzorn says: the rightmost is worth 1
	Profezzorn says: and they represent the sum of those marked with '1'
	Profezzorn says: anyway x & y means an integer with all bits set in
			 both x and y
	Savage says: hmm..
	Bclinton says:  ahhh
	Profezzorn says: so 15 = 00001111 and 42 = 00101010
	Bclinton says:  like if you do '11010' & '01100' you will get '11110' ?
	Profezzorn says: and 15 & 42 = 00001010 = 12
	Bclinton says:  ahh
	Bclinton nods solemnly.
	Bclinton says:  i see
	Profezzorn says: the bits has to be set in both numbers bclinton
	Bclinton nods solemnly.
	Bclinton says:  would my example be '|' ?
	Alcides says: btw, are old logs of these lessons available ?
	Savage says: can you say that as an "if..." then?
	Profezzorn says: the operation you described, where the bit is set
			 in _either_ is '|'
	Bclinton nods solemnly.
	Bclinton says:  i see
	Profezzorn says: yes alcides, they are available, read the board in
			 the corridor
	Alcides says: thankyou 
	Alcides leaves east.
	Profezzorn says: pardon, what did you ask savage?
	Bclinton says:  sure
	Bclinton says:  if (vara & varb) ...
	Savage says: like "if both are 1 then .."?
	Heckler says: can u give a useful example of & dont see what use it
		      is..
	Alcides arrives.
	Profezzorn says: hmm, for logical things like that you usually use
			 && or ||
	Alcides leaves east.
	Profezzorn says: & and | are not very much used in lpc, not on
			 numbers anyway
	Profezzorn says: but
	Heckler says: but on the bits ?
	Profezzorn says: & can be used on arrays as well
	Alcides arrives.
	Bclinton raises a hand.
	Bclinton says:  oops
	Savage smiles happily.
	Profezzorn smiles at bclinton.
	Bclinton smiles happily.
	Savage says: oh forgot
	Bclinton says:  wanted to raise my eyebrow...heh
	Scytale grins evilly.
	Bclinton smiles happily.
	Profezzorn says: array1 & array2 means
			 'all items present in both array1 and array2'
	Heckler says: have something u can put on the projector Prof ?
	Bclinton says:  ahh
	Heckler says: Ahhh nevermind, follow u now
	Bclinton grins evilly.
	Profezzorn says: no, not at the present heckler
	Bclinton says:  so '|' would also work for arrays then?
	Heckler says: its okie got it now.. just wondered how binary values
		      of numbers was opf use - got it..
	Profezzorn says: ({1,2,3,4}) & ({4,5,6,7}) would return ({4})
	Savage says: gotcha
	Bclinton says:  cool
	Profezzorn says: but, old drivers has a bug in the typechecking of '&
	Klang says: what would these be used for?
	Profezzorn says: '&'
	Heckler says: just quicking was uf doing in(array1) && in(array2)
	Profezzorn says: what are you trying to say heckler?
	Savage says: quicking?
	Bclinton grins evilly.
	Heckler says: that & can be used instead of &&...
		      quickling = quicker + tired fingers
	Profezzorn says: well, no heckler
	Bclinton says:  uhm no
	Bclinton grins evilly.
	Savage grins evilly.
	Bclinton says:  my god
	Profezzorn says: you'd have to use a loop as well
	Heckler says: sorry got a bit lost... my Neap tides are bugging me...
	Heckler nods solemnly.
	Heckler says: gotcha
	Savage smiles happily.
	Profezzorn says: I can give an example of how to use &
	Klang says: please do! :)
	Profezzorn says: I have on my area on nannymud a thing that wants to
			 see if someone has been on my area for a long time
	Profezzorn says: every 12 minutes it checks stores an array of all
			 users() that are on my area
	Profezzorn says: let
	Profezzorn says: let's say that a is the array stored, b is the one
			 stored 12 minutes ago, and c the one stored 24
			 minutes ago
	Profezzorn says: then a&b&c will be those people that has been on my
			 area at those times
	Savage says: yeah!
	Klang says: i have seen the light!
	Bclinton nods solemnly.
	Heckler says: this a way to bug u on Nanny ?? idle in your area ? ;)
		      - I follow it
	Profezzorn says: well, actually, what happens is that if you idle on
			 my area, beelzebub will visit you :)
	Bclinton says:  isn't this like a member_array for several elements?
	Heckler falls down laughing.
	Klang says: i have found that out prof..
	Klang says: i didn't want to sell my soul :)
	Profezzorn says: it could be solved with member_array, but not as
			 neatly :)
	Bclinton says:  well yes
	Scytale smiles happily.
	Profezzorn says: and not as fast either
	Bclinton says:  that's what i mean..it's just like a member_array
			for more than one element
	Bclinton nods solemnly.
	Savage smiles happily.
	Klang says: so member_array is just a function to make it easier,
		    but not neccessarily more efficient?
	Bclinton says:  member_array only works for 1 elemen i think
	Profezzorn says: a1 & a2 takes C1*sizeof(a1)*log2(sizeof(a1))+
			 C1*sizeof(a2)*log2(sizeof(a2))+
			 C2*sizeof(a1)+C2*sizeof(a2) time
	Bclinton screams loudly!
	Bclinton chuckles politely.
	Profezzorn says: where C1 and C2 are small constants, (not the same
			 constants as before though) :)
	A small gnome appears and cleans some of the boards that are empty.
	The gnome leaves again.
	Profezzorn says: member_array is the function to use when you _know_ 
			 what you are looking for
	Heckler says: damn can't faint
	Bclinton says:  well HOW small..
	Scytale grins evilly.
	Klang says: if we were to code that, we'd just need a1 & a2, not the
		    long mishmash of mathmatics?
	Bclinton says:  huh
	Bclinton says:  profezzorn
	Profezzorn says: the mathematics isn't useful really :)
	Scytale says: Wish i wasnt a politics student...Math looks so nice :)
	Bclinton says:  if you are looking for var1 in an array
	Profezzorn says: yes bclinton?
	Bclinton says:  don't you do then like member_array(var1,array)
	Profezzorn says: yes
	Profezzorn says: same thing if you're looking for var1 in two arrays
	Bclinton says:  i mean...if you don't just have one var var1, but
			several vars...like var1,var2,var3
	Bclinton says:  you can use & then
	Profezzorn says: well, yes, you can
	Bclinton says:  i mean you can look for those 3 vars in the array in
			one operation
	Bclinton says:  you couldn't do that with member_array, could you
	Profezzorn says: no
	Bclinton says:  so its like a member_array for more than one var
	Profezzorn says: you could do ({var1,var2,var2}) & array
	Savage says: unkown var
	Bclinton says:  exactly
	Bclinton says:  ok that's what i wanted to know
	Profezzorn says: but, it's rarely what you want though
	Bclinton says:  i just wanted to say that it's comparable to
			member_array
	Profezzorn says: yes, it is
	Klang says: isn't member_array() just a function that is built from
		    a&b etc?
	Bclinton nods solemnly.
	Profezzorn says: no klang
	Klang sighs deeply.
	Bclinton grins evilly.
	Bclinton says:  anyone here who wants to open a new mud soon :)
	Profezzorn says: it couldn't be, as member array returns the 
			_place_ in the array
	Scytale grins evilly.
	Bclinton smiles happily.
	Klang says: ah. ok.
	Profezzorn says: but & just returns the common elements
	Bclinton pokes scytale in the ribs.
	Bclinton grins evilly.
	Profezzorn says: & could be built with member_array and loops, but
			 not very efficient
	Bclinton nods solemnly.
	Profezzorn says: anyway, about the '|' operator
	Profezzorn says: it can't be used on arrays, but + does the same job
			 on arrays really
	Klang says: brb, but don't wait for me.
		    i've got the scroll back on. :)
	Bclinton says:  huh
	Bclinton says:  that's not true
	Bclinton says:  i think
	Bclinton says:  wouldn^t '|' be
	Profezzorn says: + returns all elements present in array1 or array2,
			 right?
	Bclinton says:  that ({1,2,3,4}) | ({2,4,6,8})
			returns ({1,2,3,4,6,8}) ?
	Bclinton says:  i thought + adds the arrays together
	Bclinton says:  so that multiple elements will also be present more
			than one time in the returning arr
	Profezzorn says: well, theoreticaly you are right bclinton
	Bclinton nods solemnly.
	Profezzorn says: but it doesn't work like that
	Bclinton says:  oh
	Profezzorn says: and often you don't care if the same element is there
			 twice
	Bclinton nods solemnly.
	Profezzorn says: actually, there is a trick I learnt a few days ago 
			to remove duplicates from an array
	Profezzorn says: I am not sure if it works on all muds, but it works
			 on a standard 3.1.2 driver
	Bclinton smiles happily.
	Profezzorn says: and that is to do array1 & array1
	Bclinton says:  amylaar that is?
	Profezzorn says: it probably works on amylaar too
	Bclinton nods solemnly.
	Scytale says: 3.1.2 == no sprintf and no printf
	Bclinton says:  what's a 3.1.2 driver then?
	Profezzorn says: 3.1.2 is Lars driver
	Bclinton says:  ahh
	Savage says: wot I got
	Bclinton says:  standard 'LPmud' driver ?
	Scytale nods solemnly.
	Profezzorn says: yes
	Bclinton nods solemnly.
	Profezzorn says: anyway, now we have just one operator left
	Profezzorn says: and that's '^'
	Profezzorn says: also called 'xor' (exclusive or)
	Bclinton nods solemnly.
	Bclinton says:  heh
	Savage says: hmm..
	Ktaylor arrives.
	Profezzorn says: on bits it returns those bits that are in either 
			 the first, or the second, but not both
	Bclinton says:  is there a '^^' operator?
	Profezzorn says: same thing on arrays
	Profezzorn says: no, there is no ^^ operator
	Bclinton nods solemnly.
	Profezzorn says: because it is not useful
	Profezzorn says: any questions regarding ^ ?
	Savage smiles happily.
	Heckler shakes and quivers like a bowlful of jelly.
	Bclinton shakes and quivers like a bowlful of jelly.
	Heckler giggles inanely.
	Bclinton says:  example:
	Klang says: so ({1,2,3,4})^({2,3,4,5}) would be 1 and 5?
	Bclinton says:  ({1,2,3}) ^ ({2,3,4}) would return ({1,4}) ?
	Profezzorn says: yes, that is correct klang
	Bclinton smiles happily.
	Bclinton nods solemnly.
	Bclinton grins evilly.
	Profezzorn nods solemnly.
	Klang smiles happily.
	Savage smiles happily.
	Profezzorn says: of these operators, - and & are most useful on arrays
	Profezzorn says: and + of course :)
	Bclinton smiles happily.
	Savage nods solemnly.
	Profezzorn says: so, what shall we talk about now? :)
	Bclinton smiles happily.
	Bclinton says:  hmmm
	Bclinton says:  quickly about kind of var definitions
	Bclinton says:  like nomask, private etc
	Profezzorn says: nomask = may not be redefined by inherit or shadows
	Profezzorn says: private = may not be called by inheriting objects
	Profezzorn says: static = may not be called by other objects
	Profezzorn says: public = doesn't do anything
	Profezzorn says: anything else?
	Scytale says: status
	Profezzorn says: status is just an alias for int
	Bclinton says:  that's easy
	Scytale smiles happily.
	Savage nods solemnly.
	Heckler says: common errors, apart from my typos =)
	Profezzorn says: ok, some common errors
	Bclinton says:  hey proz
	Bclinton says:  uh prof
	Profezzorn says: yes?
	Bclinton says:  isn't status just one bit?
	Klang says: static wielded in weapon.c, you cannot call if(wielded)
		    from another object then?
	Bclinton says:  0 or 1 ?
	Profezzorn says: nope
	Bclinton says:  no??
	Bclinton says:  stupid
	Profezzorn nods solemnly.
	Bclinton says:  you would only use 1 bit instead of 32 then
	Profezzorn says: klang, static was meant on a function, not a variable
	Klang says: ah.
	Bclinton says:  oh
	Bclinton says:  nomask seems to be very useful for security
	Scytale nods solemnly.
	Profezzorn says: private has meaning for variables as well, but not
			 static
	Alcides says: not for save_object() even ?
	Profezzorn says: right, forgot
	Bclinton says:  yeah
	Bclinton smiles happily.
	Profezzorn says: static on a variable means that it won't be
			 saved/restored by save_object and restor_object
	Savage says: huh?
	Savage says: Oh, gotyah
	Profezzorn says: well, we're soon out of time
	Bclinton smiles happily.
	Savage thanks profezzorn.
	Savage says: that was great!
	Bclinton smiles happily.
	Profezzorn says: I think we'll skip the 'common problems' discussion
			 until another day
	Bclinton shakes profezzorns hand.
	Savage says: really good
	Profezzorn says: any more questions?
	Bclinton says:  hmm
	Klang says: open questioning?
	Bclinton says:  is exit() supported by all new drivers?
	Bclinton says:  like mudos, amylaar
	Profezzorn says: Bclinton: I don't know, but I think so
	Bclinton nods solemnly.
	Profezzorn says: klang?
	Klang says: i have to find my question.. :)
	Profezzorn raises a hand.
	Alcides says: it isn't supported by CD
	Profezzorn says: I hate this soul.c
	Heckler says: bring your own in from N...
	Bclinton grins evilly.
	Bclinton says:  INDEED
	Savage smiles happily.
	Profezzorn says: well, Klang, you can ask me on Nanny, because I
			 will close this class now