Contents | Index | < Browse | Browse >

7.4.  Boolean Routines

     These routines are	typically used in  conditionals	 and
loops.	 However,  traditional	bit-masking may	be done	with
$and and $or.


$and	( $and a b c ... ) -> Returns the bitwise AND of the
	vector	a b c ....  Note that since this is the	bit-
	wise AND, care must be	taken  in  conditions  since
	ANDing	two  non-zero  values  does  not necessarily
	return a non-zero value.

	Example:
		     ($and 2 4)	is 0 (0b0001 AND 0b0010	= 0b0000)
		     ($and 3 7)	is 3 (0b0011 AND 0b0111	= 0b0011)
		     ($and 1 1)	is 1 (0b0001 AND 0b0001	= 0b0001)



$or	( $or a	b c ...	) -> Returns the bitwise OR  of	 the
	vector a b c ....

	Example:
		     ($or 0 0) is 0  (0b0000 OR	0b0000 = 0b0000)
		     ($or 1 2) is 3  (0b0001 OR	0b0010 = 0b0011)
		     ($or 1 1) is 1  (0b0001 OR	0b0001 = 0b0001)



$not	( $not num ) ->	Returns	zero if	num is non-zero	 and
	one  if	 num is	zero.  Note that this is BOOLEAN NOT
	and not	BITWISE	NOT.  BITWISE NOT could	be coded  as
	($minus	 ($minus  0  %1)  1)  for a two's complement
	machine.

	Example:
		     ($not 0) is 1
		     ($not 1) is 0
		     ($not 5) is 0



$yorn	( $yorn	) -> Waits for the player to type a line  of
	input,	returns	 one  if  this	line begins with the
	letter 'Y' or 'y', and returns zero otherwise.	Note
	that no	prompt is automatically	made for this input.

	Example:
		     ($say "Are	you sure you want to quit? ")
		     (IF ($yorn) THEN
			     ($say "OK.	 Goodbye!n")
			     ($spec 3)
		      ELSE
			     ($say "Whew! That was a close one!n")
		     )



$pct	( $pct num ) ->	Returns	one num	percent	of the	time
	and  zero  the rest of the time.  This is equivalent
	to ($ge	num ($rand 100)).

	Example:
		     (IF ($pct 30) THEN
			     ($say "The	troll swings at	you, and hits!n")
		      ELSE
			     ($say "The	troll's	axe misses you by a hair!n")
		     )



$eq	( $eq num1 num2	) -> Returns one if num1 is equal to
	num2 and zero otherwise.

	Example:
		     ($setg loc	($loc .ME))
		     (IF ($eq @loc room1) THEN
			     ($say "You	are in room 1.n")
		     )



$ne	( $ne num1 num2	) -> Returns  one  if  num1  is	 not
	equal to num2 and zero otherwise.

	Example:
		     ($setg loc	($loc .ME))
		     (IF ($ne @LastLoc @loc) THEN
			     ($say "You've moved since I last checked!n")
		     )



$lt	( $lt num1 num2	) -> Returns one  if  num1  is	less
	than num2 and zero otherwise.

	Example:
		     (IF ($lt @Score 100) THEN
			     ($say "You	are a novice adventurern")
		     )



$gt	( $gt num1 num2	) -> Returns one if num1 is  greater
	than num2 and zero otherwise.

	Example:
		     (IF ($gt @Score 1000) THEN
			     ($say "You	are a super master grand ")
			     ($say "champion mongo adventurer!!!n")
		     )



$le	( $le num1 num2	) -> Returns one  if  num1  is	less
	than or	equal to num2 and zero otherwise.

	Example:
		     (IF ($le @Score 1000) THEN
			     ($say "You	are a pretty good adventurer.n")
		     )



$ge	( $ge num1 num2	) -> Returns one if num1 is  greater
	than or	equal to num2 and zero otherwise.

	Example:
		     (IF ($ge @Weight 200) THEN
			     ($say "The	ice breaks under your weight!n")
		     )