Калькулятор

 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
#!/home/trizer/Hobby/lisp_v2/build/playLisp
#Operations
setq functions
(quote (
(func (a b)(+ a b))
(func (a b)(- a b))
(func (a b)(* a b))
(func (a b)(/ a b))
));
#Operation names
setq func_names (quote
(
"sum"
"sub"
"mul"
"div"
)
);
defun main (a)
{
while T
{
setq tmp func_names;
setq i 1;
while (!= tmp nil)
{
print i ". " (car tmp);
setq tmp (cdr tmp);
setq i (+ i 1);
};
print i ". Exit";
setq n (ask "Enter n: " );
if (|| (< n 1) (> n i))
{
print "Bad number, repeat please";
continue;
};
if (== n i) (return 1);
setq a (ask "Enter a: ");
setq b (ask "Enter b: ");
setq tmp functions;
while (!= n 1)
{
setq tmp (cdr tmp);
setq n (- n 1);
};
print "Result = " ((exec (exec (car tmp))) a b);
};
};
main 0;