Skip to content

Commit bed2d7b

Browse files
committed
add some functions
1 parent 787b837 commit bed2d7b

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

Diff for: help.lsp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(define (apropos str (do-print true))
2+
"Return symbols that matches the regexp."
3+
(let ((acc (find-all str (symbols) $it
4+
(lambda (x y)
5+
(regex x (term y))))))
6+
(when (and acc do-print)
7+
(dolist (item acc)
8+
(cond
9+
((primitive? (eval item))
10+
(println item "\t" "<primitive>"))
11+
((lambda? (eval item))
12+
(println item "\t" "<lambda>"))
13+
((macro? (eval item))
14+
(println item "\t" "<macro>"))
15+
("else"
16+
(println item)))))
17+
acc))

Diff for: math.lsp

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
;;; math.lsp
2+
3+
;(import "msvcrt" "log10")
4+
(define (log10 n) (log n 10))

Diff for: regex.lsp

+15
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,20 @@
3636
PRECOMPILED 0x10000
3737
)
3838

39+
;; 正規表現のオプション(//six)を数値に変換するヘルパー関数
40+
;; v.10.6.2 より直接指定が利用可能
41+
(define (re kwd)
42+
(letn ((opt 0)
43+
(|| (lambda (i) (setq opt (| opt i)))))
44+
(dostring (c kwd)
45+
(case (char c)
46+
("i" (|| 1)) ; PCRE_CASELESS
47+
("m" (|| 2)) ; PCRE_MULTILINE
48+
("s" (|| 4)) ; PCRE_DOTALL
49+
("x" (|| 8)) ; PCRE_EXTENDED
50+
(true (throw-error "unknown keyword"))))
51+
opt))
52+
53+
3954
(context MAIN)
4055
;;; EOF

Diff for: sequence.lsp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;;; sequence.lsp
2+
3+
(define (sample seq)
4+
(unless (or (list? seq)
5+
(string? seq))
6+
(throw-error "Error:LIST_OR_STRING_EXPECTED"))
7+
;;(first (randomize seq true))
8+
(seq (rand (length seq))))
9+
10+
;; syntax: (range [from] to [step])
11+
(define (range)
12+
(case (length (args))
13+
(1 (sequence 0 (args 0)))
14+
(2 (sequence (args 0) (args 1)))
15+
(3 (sequence (args 0) (args 1) (args 2)))
16+
(true '())))

Diff for: system.lsp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;;; system.lsp
2+
3+
(define (has x)
4+
(let ((features '(("library" 0x040)
5+
("utf8" 0x080)
6+
("newlisp64" 0x100)
7+
("ipv6" 0x200)
8+
("ffi" 0x400))))
9+
(!= 0 (& (or (lookup (lower-case x) features) 0)
10+
(sys-info -1)))))
11+
12+
(define (die)
13+
(if (args) (write 2 (apply format (args))))
14+
(exit))
15+
16+
(define (%bits i (len 64))
17+
(replace " " (format (string "%" len "s") (bits i)) "0"))

Diff for: unicode.lsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; unicode.lsp
1+
;;; unicode.lsp
22

33
(define (utf8?)
44
"Non-nil means newLISP is UTF-8 eoncoding are supported."

Diff for: utils.lsp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
;;; utils.lsp
2+
3+
(define (compose)
4+
"Compose function right-associatively."
5+
(letex ((_fns (reverse (args))))
6+
(lambda (x)
7+
(dolist (f '_fns)
8+
(setf x (f x)))
9+
x)))

0 commit comments

Comments
 (0)