Skip to content

Commit d64c074

Browse files
NJdevPronjanin
authored andcommitted
Update README
1 parent e2a4784 commit d64c074

10 files changed

Lines changed: 462 additions & 0 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "windows-gcc-x64",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"compilerPath": "gcc",
9+
"cStandard": "${default}",
10+
"cppStandard": "${default}",
11+
"intelliSenseMode": "windows-gcc-x64",
12+
"compilerArgs": [
13+
""
14+
]
15+
}
16+
],
17+
"version": 4
18+
}

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "C++ Launch",
3+
"type": "cppdbg",
4+
"request": "launch",
5+
"program": "${workspaceFolder}/minilisp",
6+
"stopAtEntry": false,
7+
"customLaunchSetupCommands": [
8+
{ "text": "target-run", "description": "run target", "ignoreFailures": false }
9+
],
10+
"launchCompleteCommand": "exec-run",
11+
"linux": {
12+
"MIMode": "gdb",
13+
"miDebuggerPath": "/usr/bin/gdb"
14+
},
15+
"osx": {
16+
"MIMode": "lldb"
17+
},
18+
"windows": {
19+
"MIMode": "gdb",
20+
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
21+
},
22+
"configurations": [
23+
24+
]
25+
}

.vscode/settings.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"C_Cpp_Runner.cCompilerPath": "/usr/bin/gcc",
3+
"C_Cpp_Runner.cppCompilerPath": "/usr/bing++",
4+
"C_Cpp_Runner.debuggerPath": "/usr/bingdb",
5+
"C_Cpp_Runner.cStandard": "",
6+
"C_Cpp_Runner.cppStandard": "",
7+
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
8+
"C_Cpp_Runner.useMsvc": false,
9+
"C_Cpp_Runner.warnings": [
10+
"-Wall",
11+
"-Wextra",
12+
"-Wpedantic",
13+
"-Wshadow",
14+
"-Wformat=2",
15+
"-Wcast-align",
16+
"-Wconversion",
17+
"-Wsign-conversion",
18+
"-Wnull-dereference"
19+
],
20+
"C_Cpp_Runner.msvcWarnings": [
21+
"/W4",
22+
"/permissive-",
23+
"/w14242",
24+
"/w14287",
25+
"/w14296",
26+
"/w14311",
27+
"/w14826",
28+
"/w44062",
29+
"/w44242",
30+
"/w14905",
31+
"/w14906",
32+
"/w14263",
33+
"/w44265",
34+
"/w14928"
35+
],
36+
"C_Cpp_Runner.enableWarnings": true,
37+
"C_Cpp_Runner.warningsAsError": false,
38+
"C_Cpp_Runner.compilerArgs": [],
39+
"C_Cpp_Runner.linkerArgs": [],
40+
"C_Cpp_Runner.includePaths": [],
41+
"C_Cpp_Runner.includeSearch": [
42+
"*",
43+
"**/*"
44+
],
45+
"C_Cpp_Runner.excludeSearch": [
46+
"**/build",
47+
"**/build/**",
48+
"**/.*",
49+
"**/.*/**",
50+
"**/.vscode",
51+
"**/.vscode/**"
52+
],
53+
"C_Cpp_Runner.useAddressSanitizer": false,
54+
"C_Cpp_Runner.useUndefinedSanitizer": false,
55+
"C_Cpp_Runner.useLeakSanitizer": false,
56+
"C_Cpp_Runner.showCompilationTime": false,
57+
"C_Cpp_Runner.useLinkTimeOptimization": false,
58+
"C_Cpp_Runner.msvcSecureNoWarnings": false
59+
}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ CTRL-Z SUSPEND PROCESS
7878
```
7979

8080
The REPL also saves the history of commands in the file history.txt
81+
<<<<<<< HEAD
82+
=======
83+
84+
Known bugs:
85+
* Operators "and" and "or" do not work like their typical Lisp counterpart
86+
because they evaluate all their operands at the same time instead of one
87+
by one.
88+
89+
90+
Original README
91+
=======
92+
>>>>>>> 0822c20 (Update README)
8193
This file is loaded at startup, so one can recall previous commands.
8294

8395
Future improvements:

examples/library.lisp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
(defun list (x . y) (cons x y))
2+
3+
;; (let1 var val body ...)
4+
;; => ((lambda (var) body ...) val)
5+
(defmacro let1 (var val . body)
6+
(cons (cons 'lambda (cons (list var) body))
7+
(list val)))
8+
9+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10+
;;; Control structures
11+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12+
13+
(defmacro cond (rest)
14+
(if (= () rest)
15+
()
16+
(if (= (car (car rest)) t)
17+
(car (cdr (car rest)))
18+
(list 'if
19+
(car (car rest))
20+
(car (cdr (car rest)))
21+
(cond (cdr rest))))))
22+
23+
;; (and e1 e2 ...)
24+
;; => (if e1 (and e2 ...))
25+
;; (and e1)
26+
;; => e1
27+
(defmacro and (expr . rest)
28+
(if rest
29+
(list 'if expr (cons 'and rest))
30+
expr))
31+
32+
;; (or e1 e2 ...)
33+
;; => (let1 <tmp> e1
34+
;; (if <tmp> <tmp> (or e2 ...)))
35+
;; (or e1)
36+
;; => e1
37+
;;
38+
;; The reason to use the temporary variables is to avoid evaluating the
39+
;; arguments more than once.
40+
(defmacro or (expr . rest)
41+
(if rest
42+
(let1 var (gensym)
43+
(list 'let1 var expr
44+
(list 'if var var (cons 'or rest))))
45+
expr))
46+
47+
;; (when expr body ...)
48+
;; => (if expr (progn body ...))
49+
(defmacro when (expr . body)
50+
(cons 'if (cons expr (list (cons 'progn body)))))
51+
52+
;; (unless expr body ...)
53+
;; => (if expr () body ...)
54+
(defmacro unless (expr . body)
55+
(cons 'if (cons expr (cons () body))))
56+
57+
58+
59+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60+
;;; List operators
61+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62+
63+
;; Applies each element of lis to pred. If pred returns a true value, terminate
64+
;; the evaluation and returns pred's return value. If all of them return (),
65+
;; returns ().
66+
(defun any (lis pred)
67+
(when lis
68+
(or (pred (car lis))
69+
(any (cdr lis) pred))))
70+
71+
;;; Applies each element of lis to fn, and returns their return values as a list.
72+
(defun map (lis fn)
73+
(when lis
74+
(cons (fn (car lis))
75+
(map (cdr lis) fn))))
76+
77+
;; Returns nth element of lis.
78+
(defun nth (lis n)
79+
(if (= n 0)
80+
(car lis)
81+
(nth (cdr lis) (- n 1))))
82+
83+
;; Returns the nth tail of lis.
84+
(defun nth-tail (lis n)
85+
(if (= n 0)
86+
lis
87+
(nth-tail (cdr lis) (- n 1))))
88+
89+
;; Returns a list consists of m .. n-1 integers.
90+
(defun %iota (m n)
91+
(unless (<= n m)
92+
(cons m (%iota (+ m 1) n))))
93+
94+
;; Returns a list consists of 0 ... n-1 integers.
95+
(defun iota (n)
96+
(%iota 0 n))
97+
98+
;; Returns a new list whose length is len and all members are init.
99+
(defun make-list (len init)
100+
(unless (= len 0)
101+
(cons init (make-list (- len 1) init))))
102+
103+
;; Applies fn to each element of lis.
104+
(defun for-each (lis fn)
105+
(or (not lis)
106+
(progn (fn (car lis))
107+
(for-each (cdr lis) fn))))
108+

examples/test.lisp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(defun list (x . y) (cons x y))
2+
3+
(defun count-down (n)
4+
(if (= n 0)
5+
0
6+
(progn (println n)
7+
(count-down (- n 1)))))
8+
9+
(count-down 20)
10+
11+
(defun fact (n)
12+
(if (= n 0)
13+
1
14+
(* n (fact (- n 1)))))
15+
16+
(fact 10)
17+

history.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
(defmacro unless (condition expr)
2+
(list 'if condition () expr))
3+
(macroexpand (unless (= x 1) '(x is not 1)))
4+
(defmacro unless (condition expr)(list ('if condition () expr)))
5+
(defun list (x . y)(cons x y))
6+
(defmacro unless (condition expr)(list ('if condition () expr)))
7+
(defun list (x . y)(cons x y))
8+
(defmacro unless (condition expr)(list ('if condition () expr)))
9+
(list 1 2 3)
10+
(list '(1 2) 3)
11+
(list (list 1 2) 3)
12+
(defmacro unless (condition expr)(list ('if condition () expr)))
13+
(list (list 1 2) 3)
14+
(list 3)
15+
'(3)
16+
(cons 1 2)
17+
(+ (length '('hello 'world)) 44)
18+
(if (> 3 2) (progn (println 'hello) (println 'yo)) (+ 2 3))
19+
(if (> 3 2) (progn (println 'hello) (println 'yo) (println 'titi)) (+ 2 3))
20+
(quote (hello world 1 2 3))
21+
(quote (what is (going on) here?))
22+
(define my-variable (quote hello))
23+
(println my-variable)
24+
(setq my-variable 43)
25+
(println my-variable)
26+
(defun sq(n) (* n n))
27+
(sq 4)
28+
sq
29+
(defun list (x . y)(cons x y))
30+
'(1 2 3 4)
31+
(list 1 2 3 4)
32+
(defun sq(n) (* n n))
33+
(and () t)
34+
(and t ())
35+
(and t t t t t)
36+
(and t t t ())
37+
(and () ())
38+
(or t t)
39+
(or)
40+
(or t ())
41+
(or () ())
42+
(or () () t)
43+
(defun sq (n) (* n n))
44+
(sq 5)
45+
(defun sq (n) (* n n))
46+
(sq 5)
47+
(+ 1 1)
48+
(reverse '( 1 2 3))
49+
(reverse (1 2 3))
50+
(reverse 1 2 3)
51+
(reverse (list 1 2 3))
52+
(reverse 1 2 3 4 5 6 7)
53+
(reverse (1 2 3))
54+
(reverse '(1 2 3))
55+
(+ 1 1)
56+
(list 1 2 3)
57+
(iota 10)
58+
(iota 100)
59+
(+ 1 2)
60+
(+ 1 1)
61+
(hanoi 7)
62+
(hanoi 9)
63+
(hanoi 8)
64+
(load "examples/test")
65+
(load "examples/test.lisp")
66+
(+ 1 1)
67+
(load "examples/library.lisp")
68+
(iota 1000)
69+
(load "examples/library.lisp")
70+
(iota 1000)
71+
(iota 100)
72+
(+ 1 1)
73+
(iota 100)
74+
(+ 1 1)
75+
(+ 2 (+ 3 4))
76+
(defun sq(n) (* n n))
77+
(sq 5)
78+
(* 5 (sq 5))
79+
(* 3 4 5)
80+
(* 3 4 (* 4 6))
81+
(* 12 24)
82+
(defun factorial (n) (if (= n 0) 1 (* n (factorial (- n 1))) ) )
83+
(factorial 5)
84+
(fact 12)
85+
(fact 13)
86+
(fact 14)
87+
(fact 12)
88+
q

0 commit comments

Comments
 (0)