aUCBLogo Demos and Tests / dictionarytest
			
				
			
			setCaseIgnored false
be dictionarytest
;=[Step 1]= Let's first create three small dictionaries from English be
;French, German and Spanish. And let's load them with the translations of
;three words: "house", "hat", and "country".
   EnFr=Table
   [   house maison
      hat chapeau
      country pays
   ]
   EnDe=Table
   [   house Haus
      hat Hut
      country Land
   ]
   EnSp=Table
   [   house casa
      hat sombrero
      country pais
   ]
;=[Step 2]= Let's make a function that translates a word using a given
;dictionary which is passed as a parameter:
   
   be translate dictionary word_
      output dictionary.word_
   end
   
;=[Step 3]= Let's check the translator by asking it be translate "house"
;using each of the dictionaries:
   
   print translate EnFr "house ; ->maison
   print translate EnDe "house ; ->Haus
   print translate EnSp "house ; ->casa
   
;=[Step 4]= Let's create a function which takes two English-be-something
;dictionaries and creates a third dictionary (a cross-dictionary) which
;translates from the first something be the second something
   
   be cross from_lang to_lang
      local [new n nr index]
      n=toList from_lang
      nr=count n
      new=Table nr
      repeat nr
      [   index=from_lang.(n.(1).1)   ;Oh well, still some parentheses!
         new.index=to_lang.(n.(1).1)
         n=bf n
      ]
      output new
   end
   
;=[Step 5]= Let's test the cross-translator and translate from German be
;Spanish, from Spanish to French and from French to German. To make
;Dainel happy, let's use the cross-translator's result as a parameter -
;i.e. we will not store it in a global variable.
   
   print translate (cross EnDe EnSp) "Hut ;->sombrero
   print translate (cross EnSp EnFr) "pais ;->pays
   print translate (cross EnFr EnDe) "maison ;->Haus
end