OLD | NEW |
| (Empty) |
1 part of petitparser.lisp; | |
2 | |
3 /// The standard library. | |
4 class Standard { | |
5 | |
6 /// Imports the standard library into the [environment]. | |
7 static Environment import(Environment environment) { | |
8 evalString(lispParser, environment, _standardLibrary); | |
9 return environment; | |
10 } | |
11 | |
12 /// A simple standard library, should be moved to external file. | |
13 static String _standardLibrary = """ | |
14 ; null functions | |
15 (define null '()) | |
16 (define (null? x) (= '() x)) | |
17 | |
18 ; booleans | |
19 (define true (and)) | |
20 (define false (or)) | |
21 | |
22 ; list functions | |
23 (define (length list) | |
24 (if (null? list) | |
25 0 | |
26 (+ 1 (length (cdr list))))) | |
27 | |
28 (define (append list1 list2) | |
29 (if (null? list1) | |
30 list2 | |
31 (cons (car list1) (append (cdr list1) list2)))) | |
32 | |
33 (define (list-head list index) | |
34 (if (= index 0) | |
35 (car list) | |
36 (list-head | |
37 (cdr list) | |
38 (- index 1)))) | |
39 | |
40 (define (list-tail list index) | |
41 (if (= index 0) | |
42 (cdr list) | |
43 (list-tail | |
44 (cdr list) | |
45 (- index 1)))) | |
46 | |
47 (define (for-each list proc) | |
48 (while (not (null? list)) | |
49 (proc (car list)) | |
50 (set! list (cdr list)))) | |
51 | |
52 (define (map list proc) | |
53 (if (null? list) | |
54 '() | |
55 (cons (proc (car list)) | |
56 (map (cdr list) proc)))) | |
57 | |
58 (define (inject list value proc) | |
59 (if (null? list) | |
60 value | |
61 (inject | |
62 (cdr list) | |
63 (proc value (car list)) | |
64 proc))) | |
65 """; | |
66 } | |
OLD | NEW |