Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Linus? Whose that? -- clueless newbie on #Linux


devel / comp.lang.lisp / .Re: Straight From the Trenches Nooby Stumper

SubjectAuthor
o .Re: Straight From the Trenches Nooby StumperRobert L.

1
.Re: Straight From the Trenches Nooby Stumper

<supa4g$jhe$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16893&group=comp.lang.lisp#16893

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!51iH3q7oRZapw4YGobHTdQ.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: Straight From the Trenches Nooby Stumper
Date: Fri, 18 Feb 2022 23:29:22 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <supa4g$jhe$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="20014"; posting-host="51iH3q7oRZapw4YGobHTdQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Fri, 18 Feb 2022 23:29 UTC

Kenneth Tilton wrote:

> You are given a simple-vector and a list of malformed ranges, malformed
> in that the second value is the last one to /keep/ vs. what subseq wants
> as the end parameter: the first one to omit. But all ranges are pairs
> (even if only one value is thus delimited) and the pairs are guarnteed
> to be ordered and well-formed and not to go out of bounds, so there is that.
>
> Your mission is to return a simple-vector with those values excised.
>
> (defun excise-ranges (seq ranges)
> ....)
>
> such that:
>
> (excise-ranges #(0 1 2 3) '((0 0)))
> -> #(1 2 3)
>
> (excise-ranges #(0 10 20 30 40) '((1 2)(4 4)))
> -> #(0 30)
>
>
> And do it better than I, which should not be too hard from the looks of
> the mess below (if you scroll down far enough).
>
> hth,kt
>
>
> (bk-defun excise-ranges (seq ranges)
> (loop with length = (length seq)
> and s1 = (when (plusp (caar ranges))
> (subseq seq 0 (caar ranges)))
> for (r1 r2) on ranges
> collect (subseq seq (1+ (cadr r1)) (if r2 (car r2) length))
> into ss
> finally (return (apply 'concatenate 'simple-vector s1 ss))))

Gauche Scheme and Racket

(use srfi-1) ;; circular-list for Gauche
or
(require srfi/1) ;; circular-list & concatenate & unfold for Racket
(require srfi/26) ;; cut for Racket
(require srfi/43) ;; vector->list for Racket

(define (excise-ranges seq ranges)
(let* ((flat (concatenate ranges))
(well-formed (map + flat (circular-list 0 1)))
(to-keep `(0 ,@well-formed ,(vector-length seq)))
(pairs (unfold null? (cut take <> 2) cddr to-keep)))
(list->vector
(append-map (cut apply vector->list seq <>) pairs))))

(excise-ranges #(0 1 2 3) '((0 0)))
===>
(1 2 3)

(excise-ranges #(0 10 20 30 40) '((1 2)(4 4)))
===>
(0 30)

(excise-ranges #(a b c d e) '((0 0) (4 4)))
===>
(b c d)

(excise-ranges #(a b c d e) '((0 4)))
===>
()


devel / comp.lang.lisp / .Re: Straight From the Trenches Nooby Stumper

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor