Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Mercury

Date:04/20/05
Author:Fergus Henderson
URL:n/a
Comments:0
Info:http://www.cs.mu.oz.au/~zs/mercury.html
Score: (3.00 in 104 votes)
A purely declarative logic programming language. 
<a href="http://www.cs.mu.oz.au/~zs/mercury.html">Click</a> for more information.

% file: beer.m
% author: Fergus Henderson <fjh@cs.mu.oz.au>
% date: Thursday 9th November 1995

:- module beer.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- import_module int.

main --> beer(99).

:- pred beer(int::in, io__state::di, io__state::uo) is det.

beer(N) -->
	( { N = 0 } ->
		io__write_string("Go to the store and buy some more!")
	;
		bottles(N),
		io__write_string(" on the wall,\n"),
		bottles(N),
		io__write_string(".\n"),
		io__write_string("Take one down, pass it around,\n"),
		{ N1 is N - 1 },
		bottles(N1),
		io__write_string(" on the wall.\n\n"),
		beer(N1)
	).

:- pred bottles(int::in, io__state::di, io__state::uo) is det.

bottles(N) -->
	( { N = 0 } ->
		io__write_string("No more bottles of beer")
	; { N = 1 } ->
		io__write_string("1 bottle of beer")
	;
		io__write_int(N),
		io__write_string(" bottles of beer")
	).

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: