Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "function_expansion"

Title:Help for writing function-like macros
Rating:
(1/1)
Latest version:0.1.2
SHA1 sum:a5e72c6b021b260352cdf8865b81f536d1c8b035
Author:Michael Hendricks <michael@ndrix.org>
Maintainer:Michael Hendricks <michael@ndrix.org>
Packager:Michael Hendricks <michael@ndrix.org>
Home page:http://packs.ndrix.com/function_expansion/index.html
Download URL:http://packs.ndrix.com/function_expansion/function_expansion-0.1.2.tgz

Reviews

Write a review or add a rating.
One of the eternal annoyances of Prolog is the inability to provide functions like those baked into the language. Now you can. It's glorious!
Saturday 04 May 2013, Michael T. Richter

Details by download location

VersionSHA1#DownloadsURL
0.1.0182778ae2cb4ee06df81cdc6a5c45764d10a75a18http://packs.ndrix.com/function_expansion/function_expansion-0.1.0.tgz
0.1.113d13fe589bc28af1f05df621107e39688dc08a61http://packs.ndrix.com/function_expansion/function_expansion-0.1.1.tgz
0.1.213483604fe59af9c45bf9ab02473bfc1a7f8877f1https://github.com/esad/function_expansion.git
2a1c5957081c83f87d8f2500ee30e48a12e0352f131http://packs.ndrix.com/function_expansion/function_expansion-0.1.2.tgz
a5e72c6b021b260352cdf8865b81f536d1c8b0355https://github.com/esad/function_expansion.git

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).

Contents of pack "function_expansion"

Pack contains 9 files holding a total of 6.3K bytes.