70 likes | 245 Views
TSSPTS. Климовский Аркадий, мехмат МГУ. (Tiny and Slightly Slow Prolog for T-System:o). Представление правил и целей в виде списков. ( a b c ). b. с. a. Представление правил и целей в виде списков. ( a ( b c ) d ). a. d. b. c.
E N D
TSSPTS Климовский Аркадий, мехмат МГУ
(Tiny and Slightly Slow Prolog for T-System:o) Представление правил и целей в виде списков ( a b c ) b с a
Представление правил и целей в виде списков ( a ( b c ) d ) a d b c
tfun int prove(TList tptrlist_of_goals, TList tptrenvironment, TList tptrdatabase, TList tptrlevel) { TList tptrcop_database; if (list_of_goals==NULL) { printf("\nURA!!!!!\n"); print_bindings(environment, environment); printf("\nexit\n"); return 0; } else { cop_database=copy_list(database); try_each(cop_database, database, cdr (list_of_goals), car (list_of_goals), environment, level); printf("\nunsuccessful exit\n"); return 0; } }
tfun TList tptr try_each(TList tptr database_left, TList tptr database, TList tptr goals_left, TList tptr goal, TList tptr environment, TList tptr level) { TList tptr assertion; TListtptr new_environment; if (database_left==NULL) return NULL; assertion=copy_list(rename_variables(car(database_left), create_list(NULL, level, "empty"))); new_environment=copy_list(unify(goal, car(assertion), environment)); if (new_environment==NULL) return try_each(cdr(database_left), database, goals_left, goal, environment, level); prove(append(cdr(assertion), goals_left), new_environment, database, create_list(NULL,NULL,strcat(level->content,"1"))); return try_each(cdr (database_left), database, goals_left, goal, environment, level); }
tfunTList tptrunify(TList tptrx, TList tptr y, TList tptrenvironment) { TList tptrlistxy; TListtptrt;TList tptrnew_environment; x=copy_list(value(x, environment)); y=copy_list(value(y, environment)); if (variable_p(x)) { t=create_list(NULL, y, "empty"); listxy=create_list(t, x, "empty"); return cons(listxy, environment); } if (variable_p(y)) { t=create_list(NULL, x, "empty"); listxy=create_list(t, y, "empty"); return cons(listxy, environment); }
else { if (atom(x)||atom(y)) { if (equal(x,y)) return environment; else return NULL; } else { new_environment=copy_list(unify(car(x), car(y), environment)); if (new_enviroment!=NULL) { return unify(cdr(x), cdr(y), new_environment); } else return NULL; } } }