This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(define (myslice xs
idx
(len (if (< idx 0)
(- idx)
(- (length xs) idx))))
(if (or (>= idx (length xs)) (< idx (- (length xs))))
(if (list? xs) '()
(string? xs) "")
(begin
(setq idx (if (>= idx 0) idx (+ idx (length xs))))
(if (< len 0)
(slice xs
(let (new-idx (+ 1 idx len)) (if (>= new-idx 0) new-idx 0))
(let (abs-len (abs len)) (if (<= abs-len (+ 1 idx)) abs-len (+ 1 idx)))
)
(slice xs idx len)
)
)
)
)
;; test
(setq a '(0 1 2 3 4 5))
(setq b "Hello World")
(myslice a 2) ;;->(2 3 4 5)
(myslice a 3 2) ;;->(3 4)
(myslice a 3 4) ;;->(3 4 5)
(myslice a 3 -4) ;;->(0 1 2 3)
(myslice a 3 -5) ;;->(0 1 2 3)
(myslice a 6 -2) ;;->()
(myslice a -7 2) ;;->()
(myslice a 8 -2) ;;->()
(myslice a -3 2) ;;(3 4)
(myslice a -3 -3) ;;(1 2 3)
(myslice a -3 -8) ;;(0 1 2 3)
(myslice b 4 3) ;;->"o W"
(myslice b 4 12) ;;->"o World"
(myslice b -4 -6) ;;-> "llo Wo"
(myslice b -4 -18) ;;-> "Hello Wo"
(myslice b 20 6) ;;-> ""
(slice '(a b c d e f) 2 -2) → (c d)
If int-length is negative, slice will take the parameter as offset counting from the end and copy up to that offsetQuote
(myslice '(0 1 2 3 4 5) 2 -2) ->(1 2)
(myslice '(0 1 2 3 4 5) 4 -3) ->(2 3 4)
(myslice '(0 1 2 3 4 5) 4 -1) ->(4)
(myslice "newLISP" 4 -2) ->"LI"
(setq lst '(("header1" "header2" "header3") ( "11" "12" "13") ("21" "22" "23") ("31" "32" "33") ("41" "42" "43" )))
(filter (and (>= $idx 1) (<= $idx 3)) lst) ;; '(( "11" "12" "13") ("21" "22" "23") ("31" "32" "33") ) wanted.
Here is a solution (probably not the only one, nor the best) :Quote from: "newBert"
newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
> (select '(0 1 2 3 4) (difference (index true? '(0 1 2 3 4)) '(1 2)))
(0 3 4)
> ;; maybe clearer:
>
(let (lst '(0 1 2 3 4))
(select lst (difference (index true? lst) '(1 2))))
(0 3 4)
>
(load "01-寻找当前目录下是否有所需文件.lsp")
newlisp main.lsp
" in this directory of console, error message given:ERR: problem accessing file in function load : "01-寻找当前目录下是否有所需文件.lsp"Quote
(select '(0 1 2 3 4) '(1 2))
->(1 2)
(filter (not (find $idx '(1 2))) '(0 1 2 3 4))
(define (f converse-rate-list (define rate converse-rate) )
body in which "rate" instead of converse-rate-list is use....)