Download A Beginners Guide to Visual Prolog
Transcript
domains <domainName> = <typeExpression> <sizeDescription> <rangeDescription>. The <sizeDescription> indicates the number of bits that should internally in memory be used for the values in <domainName>. For <sizedescription> you use the word “bitsize” followed by the (integral) number of bits. The <rangeDescription> denotes the value range of the values in <domainName>, it consists of a minimum and a maximum value. The <rangeDescription> is indicated by two (integral) numbers between square brackets, separated by two dots. So to declare that a domain with the Name “newDomain” contains integer values, has a range from 0 to 10 and should be stored in 8 bits we declare (and define): domains newDomain = integer bitsize 8 [0..10]. If <sizeDescription> is omitted, then the compiler will assume it to be the same as the parent domain. If there is no parent domain, it will become the natural size for the processor. If a <rangeDescription> is omitted, the range of the parent domain is used. If there is no parent domain, then the range will depend on the <SizeDescription>. E.g. an unsigned num ber that is stored in 8 bits cannot be larger than 255 (decimal). Of course you must not specify a range where the minimum exceeds the maximum. Also minimal and maximal limits should satisfy the limits implied by the specified <SizeDescription>. If you want to, you can use arithmetic expressions for <sizeDescripton> and <rangeDescripton>, but they must result in a number at compile time. An example: constants three = 3. domains subint = integer [0..three]. Real Domains Real domains are used to represent numbers with fractional parts (i.e. floating point numbers). Real domains can be used to represent very large and very small numbers. The built-in domain “real” has the natural precision for the processor architecture (or the precision given by the compiler). Just like it is done with integers, you declare a real domain by stating: domains <realDomainName> = real <realPrecisionDescription> <realRangeDescription>. After the word “real” you can specify two special properties of the new domain: <realPrecisionDescription> and <realRangeDescription>. The <realPrecisionDescription> declares precision of the domain, measured in number of decimal digits, that is the number of digits right of the decimal point. You specify the <realPrecisionDescription> by declaring the keyword “digits” followed by the (integral) number of digits that should be used in the decimal part. If <realPrecisionDescription> is omitted then it will become the same as for the parent domain. If there is no parent domain, then it will be the natural precision for the processor or given by the compiler (in Visual Prolog v.6 the compiler limit is 15 digits). The precision has upper and lower limits given by the compiler, if the precision that you specify is larger than that limit, then numbers will only obtain the processor (compiler) specified precision anyway. 143