Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

FORTH IF HONK THEN


programming / comp.lang.tcl / Re: lsearch missing "-stride" option

SubjectAuthor
* lsearch missing "-stride" optionaotto1968
+- Re: lsearch missing "-stride" optionapn
+- Re: lsearch missing "-stride" optionAlexandru
`- Re: lsearch missing "-stride" optionSchelte

1
Subject: lsearch missing "-stride" option
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 29 Apr 2022 07:32 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: aotto1...@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: lsearch missing "-stride" option
Date: Fri, 29 Apr 2022 09:32:58 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <t4g4bb$bqf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Apr 2022 07:32:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4f4ded6548a3560fb5d23fb2a39ac181";
logging-data="12111"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Obb/2Dp3rL8m5y6jnMi5wXXjgAqSJcBo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:fT3SBoNiAttQv11mrYSJ3ow8OGs=
Content-Language: en-US
View all headers
Hi,

I want to use "lsearch" to filter an "array get XXX" output.

array get output return … key1 lst1 ke2 lst2… if "array" values are lists. The "-stride" option in "lsort" treat the FIRST level of output as "conacte" list. my example would do this with "lsearch"

search -all -inline -stride 2 -index {1 0} {a {aa aaa} b {bb bbb} c {aa ccc} aa

 > a {aa aaa} c {aa ccc}

thanks.

mfg.


Subject: Re: lsearch missing "-stride" option
From: apn
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 29 Apr 2022 10:20 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: palm...@yahoo.com (apn)
Newsgroups: comp.lang.tcl
Subject: Re: lsearch missing "-stride" option
Date: Fri, 29 Apr 2022 15:50:05 +0530
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <t4ge4o$m01$1@dont-email.me>
References: <t4g4bb$bqf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Apr 2022 10:20:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="70f1ee2521c75dc4769364e829adbd95";
logging-data="22529"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fC3TBPeBJ5TTHjn4NyFDg"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:ROJ2guDV14o1drSWzfByl3yfWfs=
In-Reply-To: <t4g4bb$bqf$1@dont-email.me>
Content-Language: en-US
View all headers
On 4/29/2022 1:02 PM, aotto1968 wrote:
Hi,

I want to use "lsearch" to filter an "array get XXX" output.

array get output return … key1 lst1 ke2 lst2… if "array" values are lists. The "-stride" option in "lsort" treat the FIRST level of output as "conacte" list. my example would do this with "lsearch"

search -all -inline -stride 2 -index {1 0} {a {aa aaa} b {bb bbb} c {aa ccc} aa

 > a {aa aaa} c {aa ccc}

thanks.

mfg.

Implemented in 8.7 - see https://www.magicsplat.com/blog/tcl87-lists/ for an example.


Subject: Re: lsearch missing "-stride" option
From: Alexandru
Newsgroups: comp.lang.tcl
Date: Sun, 1 May 2022 07:55 UTC
References: 1
X-Received: by 2002:a05:620a:1722:b0:69e:e99a:db06 with SMTP id az34-20020a05620a172200b0069ee99adb06mr4910793qkb.534.1651391718157;
Sun, 01 May 2022 00:55:18 -0700 (PDT)
X-Received: by 2002:a54:468f:0:b0:322:5226:598e with SMTP id
k15-20020a54468f000000b003225226598emr3171070oic.213.1651391717886; Sun, 01
May 2022 00:55:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sun, 1 May 2022 00:55:17 -0700 (PDT)
In-Reply-To: <t4g4bb$bqf$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=87.234.240.54; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 87.234.240.54
References: <t4g4bb$bqf$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <134e6e02-7f9a-4f34-8967-9156be02b9c2n@googlegroups.com>
Subject: Re: lsearch missing "-stride" option
From: alexandr...@meshparts.de (Alexandru)
Injection-Date: Sun, 01 May 2022 07:55:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 65
View all headers
aotto1...@gmail.com schrieb am Freitag, 29. April 2022 um 09:33:03 UTC+2:
Hi,

I want to use "lsearch" to filter an "array get XXX" output.

array get output return … key1 lst1 ke2 lst2… if "array" values are
lists. The "-stride" option in "lsort" treat the FIRST level of output
as "conacte" list. my example would do this with "lsearch"

search -all -inline -stride 2 -index {1 0} {a {aa aaa} b {bb bbb} c {aa
ccc} aa

a {aa aaa} c {aa ccc}

thanks.

mfg.
Since Tcl8.7 is still alpha, here is an implementation in pure Tcl.
You can use Lsearch just as you would use lsearch.

## Pure TCL implementation of the -stride option for lsearch command.
  # \param args arguments as for Tcl command lsearch
  # \return result as lsearch command
proc Lsearch {args} {
  # If there are no options
  if {[llength $args]<=2} {
    return [lsearch {*}$args]
  }
  # Get the preceding options
  set opts [lrange $args 0 end-2]
  # Get the position of the -stride option
  set idx [lsearch $opts -stride]
  # If stride option is not available
  if {$idx<0} {
    # Execute standard lsearch command
    return [lsearch {*}$args]
  # If stride option is available
  } else {
    # Extract last two list arguments, which are the list and the searched string
    lassign [lrange $args end-1 end] l searchstring
    # Get the stride length, which is the value following the -stride option
    set stridelen [lindex $opts [expr {$idx+1}]]
    # Compose a nested list with the length of the sublists equal to the stride length
    set searchlist [ListGroups $l $stridelen]
    # Remove -stride option
    set idx [lsearch $opts -stride]
    set opts [lreplace $opts $idx [expr {$idx+1}]]
    # Execute the standard Tcl command with remaining options
    return [lsearch {*}$opts $searchlist $searchstring]
  }
}
## Group elements of list l into groups of n elements.
  # see http://wiki.tcl.tk/440#pagetoc47290fd7
proc ListGroups {l n} {
  set result [list]
  set len [llength $l]
  for {set p 0} {$p < $len} {incr p $n} {
    lappend result [lrange $l $p [expr {$p+$n-1}]]
  }
  return $result
}


Subject: Re: lsearch missing "-stride" option
From: Schelte
Newsgroups: comp.lang.tcl
Organization: KPN B.V.
Date: Sun, 1 May 2022 10:41 UTC
References: 1
Date: Sun, 1 May 2022 12:41:48 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1
Subject: Re: lsearch missing "-stride" option
Content-Language: en-US
Newsgroups: comp.lang.tcl
References: <t4g4bb$bqf$1@dont-email.me>
From: nos...@wanadoo.nl (Schelte)
In-Reply-To: <t4g4bb$bqf$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$4db4efe9$35b10bdd@b64fbab4275b2df4>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!94.232.112.244.MISMATCH!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 11
Injection-Date: Sun, 01 May 2022 12:41:48 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
View all headers
On 29/04/2022 09:32, aotto1968 wrote:
I want to use "lsearch" to filter an "array get XXX" output.

Considering that the output of [array get XXX] is a valid dict, you can use dict filtering on it to get the desired result:

dict filter [array get XXX] script {k v} {string match aa [lindex $v 0]}


Schelte.


1
rocksolid light 0.7.2
clearneti2ptor