-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlegacy.lsp
111 lines (91 loc) · 3.28 KB
/
legacy.lsp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
;; regacy.lsp --- legacy functions (current newLISP v.10.2.4)
;; (module "macro.lsp")
;; @syntax (replace-assoc key alit)
;; @syntax (replace-assoc key alist replace)
(define-macro (replace-assoc )
(case (length $args)
(2 (replace (assoc (eval (args 0))
(eval (args 1)))
(eval (args 1))))
(3 (setf (assoc (eval (args 0))
(eval (args 1)))
(eval (args 2))))
(true
(throw-error "missing argument")))
(eval (args 1)))
;; (macro (replace-assoc Key Alist Rep)
;; (setf (assoc Key Alist) Rep))
;; set-assoc/assoc-set
;; ref-set
;; @syntax (set-nth int-nth-1 [int-nth-2 ...] list|array exp-replacement)
;; @syntax (set-nth int-nth-1 str str-replacement)
;; @syntax (set-nth (list|array int-nth-1 [int-nth-2 ...]) exp-replacement)
;; @syntax (set-nth (str int-nth-1) str-replacement)
;; set-nth works like nth-set, except instead of returning the replaced
;; element, it returns the entire changed expression. For this reason,
;; set-nth is slower on larger data objects.
(define-macro (set-nth )
(cond
;; (set-nth (seq idx) rep) -> (setf (seq idx) rep)
((and (list? (args 0))
(or (list? (eval (args 0 0)))
(array? (eval (args 0 0)))
(string? (eval (args 0 0)))
(and (context? (eval (args 0 0)))
(default (eval (args 0 0))))
))
(setf (eval (args 0)) (eval (args 1))))
;; (set-nth idx str rep) -> (setf (str idx) rep)
((and (number? (eval (args 0)))
(string? (eval (args 1))))
(setf ((eval (args 1)) (eval (args 0)))
(eval (args 2))))
;; (set-nth idx1 [idx2 ...] seq rep) -> (setf (seq '(idx1 idx2 ...)) rep)
((number? (eval (args 0)))
(setf ((eval (args -2)) (map eval (0 -2 (args))))
(eval (args -1))))
(true
(throw-error (list "value or sequence expected" (args 0))))
))
;; Sets the int-nth element of a list or array with the evaluation of
;; exp-replacement and returns the old element.
(define nth-set set-nth)
(define set! setq)
;; NOTE: Old inc/dec function returns integer (now float)
(define _inc inc)
(constant 'inc
(lambda-macro (place (num 1))
(++ (eval (eval place)) (eval num))))
(define _dec dec)
(constant 'dec
(lambda-macro (place (num 1))
(-- (eval (eval place)) (eval num))))
(define (error-number err) (nth 0 (or err (sys-error))))
(define (error-text err) (nth 1 (or err (sys-error))))
(define (concat) (join (args)))
(define (environ)
(map (lambda (e)
(string (e 0) "=" (e 1)))
(env)))
(define (getenv var) (env var))
(define (putenv var value) (env var value))
(define read-url get-url)
(define (net-cleanup)
"Closes all open sockets."
(map net-close (net-sessions))
true)
(define (read-process str-process) (exec str-process))
(define (write-process str-process str-stdin) (exec str-process str-stdin))
;; newlisp v.10.1.2
(define (name sym-context (bool nil))
(cond (bool (prefix sym-context))
(true (term sym-context))))
(unless (< (sys-info -2) 9909)
(define _write-line write-line)
(constant 'write-line
(lambda (buffer fdevice)
(_write-line fdevice buffer))))
;; Swithces break mode on or off.
;; (define break trace)
(context MAIN)
;; EOF