Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Remember: use logout to logout.


devel / comp.lang.lisp / safe subseq

SubjectAuthor
* safe subseqBigos
+* Re: safe subseqSpiros Bousbouras
|`* Re: safe subseqTom Russ
| `* Re: safe subseqJeff Barnett
|  `* Re: safe subseqSpiros Bousbouras
|   `- Re: safe subseqJeff Barnett
`- Re: safe subseqSam Steingold

1
safe subseq

<687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:620a:178c:: with SMTP id ay12mr1091367qkb.109.1643970514747;
Fri, 04 Feb 2022 02:28:34 -0800 (PST)
X-Received: by 2002:a9d:4c8c:: with SMTP id m12mr826316otf.178.1643970514525;
Fri, 04 Feb 2022 02:28:34 -0800 (PST)
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.lisp
Date: Fri, 4 Feb 2022 02:28:34 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=82.29.0.89; posting-account=7RMTtAoAAAAl53cGsT2A48BtOsVJ7mF2
NNTP-Posting-Host: 82.29.0.89
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>
Subject: safe subseq
From: ruby.object@googlemail.com (Bigos)
Injection-Date: Fri, 04 Feb 2022 10:28:34 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: Bigos - Fri, 4 Feb 2022 10:28 UTC

Why there is no safe version of subseq that with string would return an empty string when outside the string boundaries?

I have tried following code with strings. Is it correct?

(defun subseq-safe (sequence start &optional end)
"Safe subseq SEQUENCE START END makes sure we stay within sequence boundaries"
(let ((ls (length sequence)))
(subseq sequence
(max 0
(min start
ls))
(when end
(min end
ls)))))

Re: safe subseq

<Zgis+wy4zqp+NE5k1@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: safe subseq
Date: Fri, 4 Feb 2022 13:49:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <Zgis+wy4zqp+NE5k1@bongo-ra.co>
References: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 4 Feb 2022 13:49:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2063501ef094db2070980814d2a58fbe";
logging-data="18561"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VzHkCvxgCVbuJaxdlGRUM"
Cancel-Lock: sha1:ZY/JrdD9AToCaYZPSBgZTfneO3o=
In-Reply-To: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Fri, 4 Feb 2022 13:49 UTC

On Fri, 4 Feb 2022 02:28:34 -0800 (PST)
Bigos <ruby.object@googlemail.com> wrote:
> Why there is no safe version of subseq that with string would return
> an empty string when outside the string boundaries?
>
> I have tried following code with strings. Is it correct?
>
> (defun subseq-safe (sequence start &optional end)
> "Safe subseq SEQUENCE START END makes sure we stay within sequence boundaries"
> (let ((ls (length sequence)))
> (subseq sequence
> (max 0
> (min start
> ls))
> (when end
> (min end
> ls)))))

(subseq-safe "abcdef" -2) returns the whole string although -2 is outside
the string boundaries. (subseq-safe "abcdef" 0 -2) enters the debugger.
So your function does not achieve what you say you want.

Speaking in general terms , if one wants a subsequence and provides for
example a negative starting point , chances are higher that there is a
bug somewhere rather than that they want the negative starting point to
silently be turned into 0 before extracting the subsequence. But if
anyone really wants such a functionality , they can write it easily enough.

I note also that SUBSEQ works with SETF which subseq-safe doesn't and
perhaps this is what you prefer.

--
vlaho.ninja/prog

Re: safe subseq

<e5b9ac39-64e9-4afc-9575-9eeb3b0dcf59n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ac8:7e8c:: with SMTP id w12mr296340qtj.342.1644000434393;
Fri, 04 Feb 2022 10:47:14 -0800 (PST)
X-Received: by 2002:a05:6808:168b:: with SMTP id bb11mr188717oib.184.1644000433858;
Fri, 04 Feb 2022 10:47:13 -0800 (PST)
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.lisp
Date: Fri, 4 Feb 2022 10:47:13 -0800 (PST)
In-Reply-To: <Zgis+wy4zqp+NE5k1@bongo-ra.co>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8000:7603:1703:256f:d8a2:ba81:41ea;
posting-account=05zmAwoAAAAJZM-3jv1hCWLHGZQceqwA
NNTP-Posting-Host: 2603:8000:7603:1703:256f:d8a2:ba81:41ea
References: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com> <Zgis+wy4zqp+NE5k1@bongo-ra.co>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e5b9ac39-64e9-4afc-9575-9eeb3b0dcf59n@googlegroups.com>
Subject: Re: safe subseq
From: taruss@google.com (Tom Russ)
Injection-Date: Fri, 04 Feb 2022 18:47:14 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: Tom Russ - Fri, 4 Feb 2022 18:47 UTC

On Friday, February 4, 2022 at 5:49:47 AM UTC-8, Spiros Bousbouras wrote:
> On Fri, 4 Feb 2022 02:28:34 -0800 (PST)
> Bigos <ruby....@googlemail.com> wrote:
> > Why there is no safe version of subseq that with string would return
> > an empty string when outside the string boundaries?
> >
> > I have tried following code with strings. Is it correct?
> >
> > (defun subseq-safe (sequence start &optional end)
> > "Safe subseq SEQUENCE START END makes sure we stay within sequence boundaries"
> > (let ((ls (length sequence)))
> > (subseq sequence
> > (max 0
> > (min start
> > ls))
> > (when end
> > (min end
> > ls)))))

Some other observations.
* This function will still fail, for example with (SUBSEQ-SAFE "0123456789" 5 3).
* The regular SUBSEQ has the invariant that it *always* returns a sequence of length (end - start)
* When applied to lists, determining the length of the sequence is an O(n) operation, so a call like
(SUBSEQ very-long-list 0 5) would have worse performance.
* +1 to Spiro's observation about the dangers of silently discarding negative indices.

Re: safe subseq

<stjtqu$le4$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: safe subseq
Date: Fri, 4 Feb 2022 12:12:28 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <stjtqu$le4$1@dont-email.me>
References: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>
<Zgis+wy4zqp+NE5k1@bongo-ra.co>
<e5b9ac39-64e9-4afc-9575-9eeb3b0dcf59n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 4 Feb 2022 19:12:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f27e4dec8e79cf8282126516c50708ab";
logging-data="21956"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KKjpVu1ZqVMk0IPxIXMiROvsD+sUkEc4="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:UMkwa0rDOn4gBJZOMM93wiBwLaQ=
In-Reply-To: <e5b9ac39-64e9-4afc-9575-9eeb3b0dcf59n@googlegroups.com>
Content-Language: en-US
 by: Jeff Barnett - Fri, 4 Feb 2022 19:12 UTC

On 2/4/2022 11:47 AM, Tom Russ wrote:
> On Friday, February 4, 2022 at 5:49:47 AM UTC-8, Spiros Bousbouras wrote:
>> On Fri, 4 Feb 2022 02:28:34 -0800 (PST)
>> Bigos <ruby....@googlemail.com> wrote:
>>> Why there is no safe version of subseq that with string would return
>>> an empty string when outside the string boundaries?
>>>
>>> I have tried following code with strings. Is it correct?
>>>
>>> (defun subseq-safe (sequence start &optional end)
>>> "Safe subseq SEQUENCE START END makes sure we stay within sequence boundaries"
>>> (let ((ls (length sequence)))
>>> (subseq sequence
>>> (max 0
>>> (min start
>>> ls))
>>> (when end
>>> (min end
>>> ls)))))
>
> Some other observations.
> * This function will still fail, for example with (SUBSEQ-SAFE "0123456789" 5 3).
> * The regular SUBSEQ has the invariant that it *always* returns a sequence of length (end - start)
> * When applied to lists, determining the length of the sequence is an O(n) operation, so a call like
> (SUBSEQ very-long-list 0 5) would have worse performance.
> * +1 to Spiro's observation about the dangers of silently discarding negative indices.

Is length really an order n operation in most Lisps? I think strings are
stored as arrays and arrays have headers with length information.
--
Jeff Barnett

Re: safe subseq

<P5tL9fVhHPZhP4qWr@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: safe subseq
Date: Fri, 4 Feb 2022 19:23:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <P5tL9fVhHPZhP4qWr@bongo-ra.co>
References: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com> <Zgis+wy4zqp+NE5k1@bongo-ra.co> <e5b9ac39-64e9-4afc-9575-9eeb3b0dcf59n@googlegroups.com>
<stjtqu$le4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 4 Feb 2022 19:23:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2063501ef094db2070980814d2a58fbe";
logging-data="4664"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pACzp/NSofuCt3qvTaEb4"
Cancel-Lock: sha1:u9ICbUolExMfnIcLFjMcRXgxm4A=
In-Reply-To: <stjtqu$le4$1@dont-email.me>
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Fri, 4 Feb 2022 19:23 UTC

On Fri, 4 Feb 2022 12:12:28 -0700
Jeff Barnett <jbb@notatt.com> wrote:
> On 2/4/2022 11:47 AM, Tom Russ wrote:
> >
> > Some other observations.
> > * This function will still fail, for example with (SUBSEQ-SAFE "0123456789" 5 3).
> > * The regular SUBSEQ has the invariant that it *always* returns a
> > sequence of length (end - start)
> > * When applied to lists, determining the length of the sequence is an
^^^^^^^^^^^^^^^^^^^^^^
> > O(n) operation, so a call like
> > (SUBSEQ very-long-list 0 5) would have worse performance.

[...]

> Is length really an order n operation in most Lisps? I think strings are
> stored as arrays and arrays have headers with length information.

Re: safe subseq

<stjvrn$ghh$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: safe subseq
Date: Fri, 4 Feb 2022 12:47:01 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <stjvrn$ghh$1@dont-email.me>
References: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>
<Zgis+wy4zqp+NE5k1@bongo-ra.co>
<e5b9ac39-64e9-4afc-9575-9eeb3b0dcf59n@googlegroups.com>
<stjtqu$le4$1@dont-email.me> <P5tL9fVhHPZhP4qWr@bongo-ra.co>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 4 Feb 2022 19:47:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f27e4dec8e79cf8282126516c50708ab";
logging-data="16945"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MEc6co5CfYTd4/QpO8sHC3DvoNEmE6I0="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:1tMaDethQOPqKV1Nz4Hp1hc5jFI=
In-Reply-To: <P5tL9fVhHPZhP4qWr@bongo-ra.co>
Content-Language: en-US
 by: Jeff Barnett - Fri, 4 Feb 2022 19:47 UTC

On 2/4/2022 12:23 PM, Spiros Bousbouras wrote:
> On Fri, 4 Feb 2022 12:12:28 -0700
> Jeff Barnett <jbb@notatt.com> wrote:
>> On 2/4/2022 11:47 AM, Tom Russ wrote:
>>>
>>> Some other observations.
>>> * This function will still fail, for example with (SUBSEQ-SAFE "0123456789" 5 3).
>>> * The regular SUBSEQ has the invariant that it *always* returns a
>>> sequence of length (end - start)
>>> * When applied to lists, determining the length of the sequence is an
> ^^^^^^^^^^^^^^^^^^^^^^
>>> O(n) operation, so a call like
>>> (SUBSEQ very-long-list 0 5) would have worse performance.
>
> [...]
>
>> Is length really an order n operation in most Lisps? I think strings are
>> stored as arrays and arrays have headers with length information.

Oops!
--
Jeff Barnett

Re: safe subseq

<lz5ypqy3c4.fsf@3c22fb11fdab.ant.amazon.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sds@gnu.org (Sam Steingold)
Newsgroups: comp.lang.lisp
Subject: Re: safe subseq
Date: Mon, 07 Feb 2022 12:49:15 -0500
Organization: disorganization
Lines: 32
Message-ID: <lz5ypqy3c4.fsf@3c22fb11fdab.ant.amazon.com>
References: <687d92fb-a568-483b-95f9-2b9b1bb650den@googlegroups.com>
Reply-To: sds@gnu.org
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="7da544b425c22be210cae0f3d5dd91ad";
logging-data="31482"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PNOXnMC1qx/A4uLrPgqLy"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin)
Cancel-Lock: sha1:6/hEkt50oaho+DjLRNa/JUk8ZF8=
sha1:wnu93Wqamv9khdMUbVOB0SBnYMs=
Return-Receipt-To: sds@gnu.org
X-Disclaimer: You should not expect anyone to agree with me.
X-Attribution: Sam
 by: Sam Steingold - Mon, 7 Feb 2022 17:49 UTC

> * Bigos <ehol.bowrpg@tbbtyrznvy.pbz> [2022-02-04 02:28:34 -0800]:
>
> Why there is no safe version of subseq that with string would return an empty string when outside the string boundaries?
>
> I have tried following code with strings. Is it correct?
>
> (defun subseq-safe (sequence start &optional end)
> "Safe subseq SEQUENCE START END makes sure we stay within sequence boundaries"
> (let ((ls (length sequence)))
> (subseq sequence
> (max 0
> (min start
> ls))
> (when end
> (min end
> ls)))))

In addition to all the problems others mentioned, this does not seem to
be _useful_.

If you are extending `subseq`, it would seem to be more useful for
"weird" indexes to _add_ functionality, e.g., to treat negative indexes
as starting from the end (i.e., take start and end modulo length of sequence).

Cf. slice in python (https://docs.python.org/3/library/functions.html#slice)
and `s[i:j:k]` in https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

--
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://thereligionofpeace.com https://jij.org
Money does not buy happiness, but it helps to make unhappiness comfortable.


devel / comp.lang.lisp / safe subseq

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor