/tutorial/backtracking/tiny_prolog/prolog_commons.e

http://github.com/tybor/Liberty · Specman e · 29 lines · 28 code · 1 blank · 0 comment · 1 complexity · 07a53bca193973ac45b93543b839a5b0 MD5 · raw file

  1. class PROLOG_COMMONS
  2. feature
  3. type_atom, type_integer, type_float, type_compound, type_var: INTEGER is unique
  4. builtins: AVL_DICTIONARY[ROUTINE[ANY,TUPLE[]],PROLOG_FUNCTOR] is
  5. once
  6. create Result
  7. end
  8. atoms: HASHED_DICTIONARY[PROLOG_ATOM,STRING] is
  9. once
  10. create Result
  11. end
  12. get_functor_by_name(name: STRING; arity: INTEGER): PROLOG_FUNCTOR is
  13. do
  14. Result := get_functor_by_atom(get_atom_by_name(name),arity)
  15. end
  16. get_functor_by_atom(atom: PROLOG_ATOM; arity: INTEGER): PROLOG_FUNCTOR is
  17. do
  18. create Result.make(atom,arity)
  19. end
  20. get_atom_by_name(name: STRING): PROLOG_FUNCTOR is
  21. do
  22. Result := atoms.reference_at(name)
  23. if Result = Void then
  24. create Result.make(name.twin)
  25. atoms.add(Result,Result.name)
  26. end
  27. end
  28. end