Search Top Index
HELP DEFINE_PROLOG Robert Duncan, April 1993 Syntax form for defining Prolog predicates in Pop-11. define :prolog <declaration> <name>/<arity>(<arguments>); <body> enddefine; NOTE: you must have the Prolog subsystem loaded before using this. ------------------------------------------------------------------------ 1 Overview ------------------------------------------------------------------------ The prolog define-form simplifies the creation of Prolog predicates from Pop-11. For example, the definition: define:prolog hello/0(contn); lvars contn; printf('Hello world\n'); chain(contn); enddefine; defines the predicate hello/0 which can then be executed from Prolog like this: ?- hello. Hello world yes The define form can be thought of as a syntactic interface to prolog_valof, and indeed the previous example could equally well have been written as: procedure(contn); lvars contn; printf('Hello world\n'); chain(contn); endprocedure -> prolog_valof("hello", 0); Consequently, the procedure itself must be written to use the continuation-passing style (see PLOGHELP * PROLOG_VALOF). ------------------------------------------------------------------------ 2 Description ------------------------------------------------------------------------ Compiling the definition: define :prolog <declaration> <name> / <arity> (<arguments>) ; <body> enddefine; creates an entirely new predicate with the given functor <name> and <arity>; any existing version of that predicate will be lost. The <name> part can be written either as a word or string: string quotes are useful if the name cannot be read as a single Pop-11 item, or if it needs to be separated from the following "/" token. The <arity> must be a non-negative integer. The <declaration> part controls the status of the predicate identifier being declared. It is optional; if present, it should consist of some valid combination of words from the set: global nonglobal vars constant procedure These have their usual meanings: specifying global or nonglobal determines whether the predicate will be visible in any subsections of the current section (where a section is the same as a Prolog module); vars or constant determines whether or not the predicate can be redefined, like declaring it as a user_predicate or a system_predicate in Prolog (predicate identifiers are always permanent, so lvars and lconstant declarations are not allowed). The procedure declaration is allowed but redundant: predicate identifiers are always procedure type. If the <declaration> part is omitted or incomplete, the usual define defaults apply depending on the current compile mode. The procedure itself must be written to use the continuation-passing style: when the predicate is called from Prolog, the procedure will be invoked with an appropriate continuation argument. --- C.all/help/define_prolog --- Copyright University of Sussex 1993. All rights reserved.