File: test01.dats

package info (click to toggle)
ats2-lang 0.4.2-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 40,500 kB
  • sloc: ansic: 389,898; makefile: 7,136; javascript: 1,852; lisp: 811; sh: 657; php: 573; python: 387; perl: 365
file content (62 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(*
** For testing ats2cpp
*)

(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)

#define ATS_DYNLOADFLAG 0

(* ****** ****** *)
//
extern
fun
fact(n: int): int = "ext#"
//
implement
fact(n) = if n > 0 then n * fact(n-1) else 1
//
(* ****** ****** *)
//
extern
fun
ffact(n: int): double = "ext#"
//
implement
ffact(n) = if n > 0 then n * ffact(n-1) else 1.0
//
(* ****** ****** *)

implement
main0() = () where
{
//
val () = println! ("fact(10) = ", fact(10))
val () = println! ("ffact(10) = ", ffact(10))
//
} (* end of [main0] *)

(* ****** ****** *)

/*
%{$

#include <stdio.h>

int main()
{
  printf("fact(10) = %i\n", fact(10));
  printf("ffact(10) = %f\n", ffact(10));
  return 0;
}

%} // end of [%{$]
*/

(* ****** ****** *)

(* end of [test01.dats] *)