Get a frame of lines from a table by filter

Q&A's, tips, howto's
Locked
lyl
Posts: 44
Joined: Sun Mar 25, 2018 5:00 am

Get a frame of lines from a table by filter

Post by lyl »

I have a table like this:

Code: Select all

(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:

Code: Select all

(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?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Get a frame of lines from a table by filter

Post by Lutz »

Code: Select all

> (slice lst 1 3)
(("11" "12" "13") ("21" "22" "23") ("31" "32" "33"))
> 
http://www.newlisp.org/downloads/newlis ... html#slice

Or shorter:

Code: Select all

> (1 3 lst)
(("11" "12" "13") ("21" "22" "23") ("31" "32" "33"))
See here:
http://www.newlisp.org/downloads/newlis ... rest_slice

Locked