Skip to content

Commit

Permalink
Add short example of Java interface.
Browse files Browse the repository at this point in the history
samples/java_interface/short_example.m:
    A Java version of the short example.

samples/java_interface/README.md:
    Add an entry for the new example.

samples/c_interface/README.md:
samples/csharp_interface/README.md:
    Fix wording.
  • Loading branch information
juliensf committed Jan 19, 2022
1 parent 27ed128 commit 0106153
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion samples/c_interface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Mercury C Interface Examples
This directory contains some examples of mixed Mercury/C/C++/Fortran programs
using the foreign language interface.

* [short_example.m](short_example.m) -- A short example of a Mercury code
* [short_example.m](short_example.m) -- A short example of Mercury code
calling C code.

* [mercury_calls_c](mercury_calls_c) -- A detailed example of Mercury code
Expand Down
2 changes: 1 addition & 1 deletion samples/csharp_interface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Mercury C# Interface Examples
This directory contains some examples of mixed Mercury/C# programs using the
foreign language interface.

* [short_example.m](short_example.m) -- A short example of a Mercury code
* [short_example.m](short_example.m) -- A short example of Mercury code
calling C# code.

* [standalone_csharp](standalone_csharp) -- An example of how to call a Mercury
Expand Down
3 changes: 3 additions & 0 deletions samples/java_interface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Mercury Java Interface Examples
This directory contains some examples of mixed Mercury/Java programs using
the foreign language interface.

* [short_example.m](short_example.m) -- A short example of Mercury code
calling Java code.

* [mercury_calls_java](mercury_calls_java) -- A detailed example of Mercury
code calling Java code.

Expand Down
23 changes: 23 additions & 0 deletions samples/java_interface/short_example.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% This is a simple example of using the foreign language interface to call the
% Java method System.out.println().

% This source file is hereby placed in the public domain.

:- module short_example.
:- interface.
:- import_module io.

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

:- implementation.

main(!IO) :-
java_write_line("Hello, world", !IO).

:- pred java_write_line(string::in, io::di, io::uo) is det.
:- pragma foreign_proc("JAva",
java_write_line(S::in, _IO0::di, _IO::uo),
[promise_pure, will_not_call_mercury],
"
System.out.println(S);
").

0 comments on commit 0106153

Please sign in to comment.