Almost working
[lisp-compiler-in-prolog.git] / lisp_library.pl
1 /*******************************************************************
2 *
3 * A Lisp compiler, written in Prolog
4 *
5 * (lisp_library.pl)
6 *
7 * (c) Neil Smith, 2001
8 *
9 * This program provides some built-in functionality for the
10 * Lisp compiler. It requires that the file lisp_compiler.pl has
11 * already been successfully compiled.
12 *
13 * Definitions in this file are given in the Lisp-like syntax
14 * read by this compiler.
15 *
16 *******************************************************************/
17
18
19 second(l) <<==
20 first(rest(l)).
21
22 third(l) <<==
23 first(rest(rest(l))).
24
25
26 % We don't support &rest parameters yet, so we need a different
27 % definition of list for every different number of arguments
28
29 list_1(a) <<==
30 cons(a, nil).
31
32 list_2(a, b) <<==
33 cons(a, list_1(b)).
34
35 list_3(a, b, c) <<==
36 cons(a, list_2(b,c)).
37
38
39 lisp_append(l1, l2) <<==
40 if( null(l1),
41 l2,
42 cons( first(l1),
43 lisp_append(rest(l1),
44 l2))).
45
46
47 mapcar(func, l) <<==
48 if( null(l),
49 nil,
50 cons( lisp_apply(func, list_1(first(l))),
51 mapcar(func, rest(l)))).
52
53