https://github.com/mndrix/function_expansion
Help for writing function-like macros
https://github.com/mndrix/function_expansion
Last synced: 7 months ago
JSON representation
Help for writing function-like macros
- Host: GitHub
- URL: https://github.com/mndrix/function_expansion
- Owner: mndrix
- License: unlicense
- Archived: true
- Created: 2013-01-18T22:49:52.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-10-27T19:06:47.000Z (over 9 years ago)
- Last Synced: 2024-05-01T22:45:07.635Z (about 2 years ago)
- Language: Prolog
- Size: 148 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
- awesome-prolog - function_expansion - Function-like macros. (Development)
README
# Synopsis
:- use_module(library(function_expansion)).
user:function_expansion(incr(N), X, X is N+1).
main :-
format('After 2 comes ~p~n', [incr(2)]).
# Description
Prolog doesn't offer function syntax. Anything one can do with
functions, she can do with predicates. The syntax is a little
verbose because it requires an auxiliary variable.
For example, one might approximate pi:
pi(3.14159).
main :-
pi(Pi),
format('pi is roughly ~p~n', [Pi]).
It's often obnoxious to think up a name for an auxiliary variable.
function_expansion/3 lets you write macros so that `pi` can be included
directly in format's arguments. Auxiliary variables are generated for
you at compile time.
Repository available on GitHub: https://github.com/mndrix/function_expansion
# Installation
Using SWI-Prolog 6.3 or later:
$ swipl
1 ?- pack_install(function_expansion).