mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 06:47:17 +00:00
Implement functional syntax. You can now use `:- func' in a similar manner
Estimated hours taken: 12 Implement functional syntax. You can now use `:- func' in a similar manner to `:- pred'. For example, `:- func foo(int, int) = int.' declares a function, and `:- mode foo(in, in) = out.' defines a mode for it. You can write clauses for functions, such as `foo(X, Y) = Z :- Z is 2*X + Y.' Any term in the head or body of a clause can be a function call, e.g. `bar(X, Y, foo(X, Y))'. Until we have implemented a proper Mercury debugger, this syntax should not be used (except that I might reimplement the functions provided by Prolog's is/2 predicate using this syntax, rather than the current special-case hack in the parser). prog_io.m: Add syntax for declaring and defining functions. Disallow the use of `=' to define modes, as in `:- mode foo = bar.' (Instead, you should use `::'. `==' is also allowed.) Also, use higher-order predicates to simplify some of the rather repetitious parsing code. mercury_to_mercury.m, mercury_to_goedel.m, make_hlds.m, modules.m: Handle new functional syntax. typecheck.m: Add support for functions, function types such as `func(int) = int', and currying. (But there's currently no equivalent to call/N for functions, so function types and currying aren't very useful yet.) undef_types.m: Add support for function types. modes.m: Convert function calls into predicate calls. (This must be done after typechecking is complete, so I put it in mode analysis.) hlds.m: Add new field `pred_or_func' to the pred_info. hlds_out.m: Print out the `pred_or_func' field. higher_order.m, unused_args.m, lambda.m, dnf.m: Pass extra pred_or_func argument to pred_info_init to specify that the thing being created is a predicate, not a function. constraint.m, dependency_graph.m, hlds_out.m: `mercury_output_mode_subdecl' has been renamed `mercury_output_pred_mode_subdecl'. prog_util.m: Add new predicate split_type_and_mode/3. llds.m: Print out /* code for predicate '*'/3 in mode 0 */ rather than /* code for predicate */3 in mode 0 */ to avoid a syntax error in the generated C code.
This commit is contained in:
@@ -316,7 +316,7 @@ XXX this optimization temporarily disabled, see comment above
|
||||
clauses_info_init(Arity, ClausesInfo),
|
||||
pred_info_init(ModuleName, PredName, Arity, TVarSet,
|
||||
ArgTypes, Cond, LambdaContext, ClausesInfo, Status,
|
||||
no, none, PredInfo0),
|
||||
no, none, predicate, PredInfo0),
|
||||
|
||||
%
|
||||
% Create a single mode for the new predicate, and insert
|
||||
|
||||
Reference in New Issue
Block a user