Re-writing difference lists in Prolog ------------------------------------- Prolog will automatically create difference lists if the programmer uses a special form syntax. This is now part of standard Prolog. These are usually called Definite Clause Grammars. They have also been called by the very descriptive term "Metamorphosis Grammars". You form a DCG by creating an almost literal copy of a context free grammar's production rules. Nonterminals begin with a lower case letter. Terminals are (normally) specified as a list of one element. four_digit --> thousands, three_digit. three_digit --> hundreds, two_digit. two_digit --> tens, one_digit. one_digit --> ones. thousands --> digit, thousand. hundreds --> digit, hundred. tens --> digity_thing. ones --> digit. thousand --> [thousand]. hundred --> [hundred]. digity_thing --> [twenty]. digity_thing --> [thirty]. digity_thing --> [forty]. digity_thing --> [fifty]. digity_thing --> [sixty]. digity_thing --> [seventy]. digity_thing --> [eighty]. digity_thing --> [ninety]. digit --> [one]. digit --> [two]. digit --> [three]. digit --> [four]. digit --> [five]. digit --> [six]. digit --> [seven]. digit --> [eight]. digit --> [nine]. /*--------------------------------------------------------------- To get the whole thing started: phrase(four_digit,[one,thousand,two,hundred,thirty,four],X) ---------------------------------------------------------------*/