-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandart.lispam
94 lines (65 loc) · 3.08 KB
/
standart.lispam
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
; STANDART LIBRARY
; VERSION 0.2.0
; AUTHOR ALEXANDER MYASNIKOV
; myasnikov.alexander.s@gmail.com
; KERNEL ABSTRACTION
(__kernel_def def (__kernel_macro (k v) (__kernel_def k v)))
(def macro (__kernel_macro (a b) (__kernel_macro a b)))
(def lambda (__kernel_macro (a b) (__kernel_lambda a b)))
(def + (macro (x y) (__kernel_plus x y)))
(def - (macro (x y) (__kernel_minus x y)))
(def * (macro (x y) (__kernel_multiplies x y)))
(def less? (macro (x y) (__kernel_less x y)))
(def equal? (macro (x y) (__kernel_equal x y)))
(def println (macro (x) (__kernel_println x))) ; // TODO args
(def if (macro (c x y) (__kernel_if c x y)))
(def cons (macro (x y) (__kernel_cons x y)))
(def head (macro (x) (__kernel_head x)))
(def tail (macro (x) (__kernel_tail x)))
(def typeof (macro (x) (__kernel_typeof x)))
(def load (macro (x) (__kernel_load x)))
(def quote (macro (x) (__kernel_quote x)))
(def eval (macro (x) (__kernel_eval x)))
(def not? (lambda (x) (if x false true)))
(def greater? (lambda (x y) (less? y x)))
(def not-equal? (lambda (x y) (not (equal? x y))))
(def and (lambda (x y) (if x y false)))
(def or (lambda (x y) (if x true y)))
(def negative (lambda (x) (- 0 x)))
(def abs (lambda (x) (if (greater? x 0) x (negative x))))
(def nil? (lambda (x) (equal? (typeof x) "nil")))
(def bool? (lambda (x) (equal? (typeof x) "bool")))
(def int? (lambda (x) (equal? (typeof x) "int")))
(def double? (lambda (x) (equal? (typeof x) "double")))
(def sring? (lambda (x) (equal? (typeof x) "string")))
(def ident? (lambda (x) (equal? (typeof x) "ident")))
(def list? (lambda (x) (equal? (typeof x) "list")))
(def id (lambda (x) x))
(def reverse (lambda (l)
((def iter (lambda (l res) (
if (nil? l) res (iter (tail l) (cons (head l) res)))))
(iter l ()))))
(def ranger (lambda (a b)
(if (less? a b) (cons a (ranger (+ a 1) b)) ())))
(def range (lambda (a b)
((def iter (lambda (a b res) (
if (less? a b) (iter (+ a 1) b (cons a res)) (res))))
(reverse (iter a b ())))))
(def foldl (lambda (f acc l)
(if (nil? l) acc
(foldl f (f (head l) acc) (tail l)))))
(def foldr (lambda (f acc l)
(if (nil? l) acc
(foldl f (f acc (head l)) (tail l)))))
(def filter (lambda (f l)
((def iter (lambda (f l res) (
if (nil? l) res (iter f (tail l)
(if (f (head l)) (cons (head l) res) res)))))
(reverse (iter f l ())))))
(def fib (lambda (x) (
(def fib (lambda (a b x) (if (greater? x 0) (fib b (+ a b) (- x 1)) (b))))
(fib 1 1 x))))
(def fibr (lambda (x) (if (greater? x 0) (+ (fibr (- x 1)) (fibr (- x 2))) 1)))
(def help (lambda ()
((println "hello, %user%")
(println "standart library: https://github.com/alexandermyasnikov/lisp_interpreter/standart.lispam"))))