newLISP Fan Club

Forum => newLISP in the real world => Topic started by: lyl on April 20, 2019, 05:41:53 PM

Title: Get a frame of lines from a table by filter
Post by: lyl on April 20, 2019, 05:41:53 PM
I have a table like this:
(setq lst '(("header1" "header2" "header3") ( "11" "12" "13") ("21" "22" "23") ("31" "32" "33") ("41" "42" "43" )))

I want to get some continueous lines e.g. from the first line to the third line by this:
(filter (and (>= $idx 1) (<= $idx 3)) lst)  ;; '(( "11" "12" "13") ("21" "22" "23") ("31" "32" "33") ) wanted.

But I find the function "filter" does not support "$idx".

So, is there a better way to achieve this?
Title: Re: Get a frame of lines from a table by filter
Post by: Lutz on April 21, 2019, 05:08:46 AM

> (slice lst 1 3)
(("11" "12" "13") ("21" "22" "23") ("31" "32" "33"))
>

http://www.newlisp.org/downloads/newlisp_manual.html#slice



Or shorter:

> (1 3 lst)
(("11" "12" "13") ("21" "22" "23") ("31" "32" "33"))

See here:

http://www.newlisp.org/downloads/newlisp_manual.html#implicit_rest_slice