Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Dijkstra probably hates me. -- Linus Torvalds, in kernel/sched.c


devel / comp.lang.tcl / Can I force brackets on every list item even if they have no spaces?

SubjectAuthor
* Can I force brackets on every list item even if they have noLuc
`- Re: Can I force brackets on every list item even if they have noChristian Gollwitzer

1
Can I force brackets on every list item even if they have no spaces?

<20230324025149.5fde13e9@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: luc@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Can I force brackets on every list item even if they have no
spaces?
Date: Fri, 24 Mar 2023 02:51:49 -0300
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20230324025149.5fde13e9@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="dcb2d873224748b170e47a65327d1cdc";
logging-data="1632987"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zIxNZK1TGfI4+jVlIuKqQ1MX9eSahuz4="
Cancel-Lock: sha1:qduZkZk2vujE+Cr+Rw2bIySl1EY=
 by: Luc - Fri, 24 Mar 2023 05:51 UTC

I have loaded some information into one long list. Example:

418 {When did you see him last?} 419 {Wilford speaks with difficulty.}
420 What? 421 {- Yesterday morning.}

Now, note that item #420 is not enclosed in brackets because it doesn't
have any spaces.

And that is throwing a spanner in my works because I am translating
all that text, then 'What?' becomes 'O quê?' and an error occurs when
the translated data is supposed to be inserted into the database.

I will have to redesign the entire proc unless there is a way to force
every item of a list to be internally represented in brackets even if
it has no spaces. Is there such a miracle?

--
Luc
>>

Re: Can I force brackets on every list item even if they have no spaces?

<tvjh2v$1ic7n$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Can I force brackets on every list item even if they have no
spaces?
Date: Fri, 24 Mar 2023 07:47:58 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <tvjh2v$1ic7n$1@dont-email.me>
References: <20230324025149.5fde13e9@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 24 Mar 2023 06:47:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="834772329c38693e47a3bf28936e2a0f";
logging-data="1650935"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YgJ8Uy79JLKY5KiT+BoelLX6mCCYIh3I="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.9.0
Cancel-Lock: sha1:+bpTUBIQV9eGD5KMv1fupZOiWwY=
In-Reply-To: <20230324025149.5fde13e9@lud1.home>
 by: Christian Gollwitzer - Fri, 24 Mar 2023 06:47 UTC

Am 24.03.23 um 06:51 schrieb Luc:
> I have loaded some information into one long list. Example:
>
> 418 {When did you see him last?} 419 {Wilford speaks with difficulty.}
> 420 What? 421 {- Yesterday morning.}
>
> Now, note that item #420 is not enclosed in brackets because it doesn't
> have any spaces.
>
> And that is throwing a spanner in my works because I am translating
> all that text, then 'What?' becomes 'O quê?' and an error occurs when
> the translated data is supposed to be inserted into the database.

You're doing it wrong, then. If you do it like this:

set info {418 {When did you see him last?} 419 {Wilford speaks with
difficulty.} 420 What? 421 {- Yesterday morning.}}

string map {What? {O quê?}} $info

Then you will end up with the problem you describe - because "string
map" doesn't know that it is a list. You will get similar / worse
problems if your replacement contains other metacharacters like braces
{} or quotes "

Instead, you need to translate the elements of the list. E.g. like this:

lmap x $info {string map {What? {O quê?}} $x}

(bin) 52 % lmap x $info {string map {What? {O quê?}} $x}
418 {When did you see him last?} 419 {Wilford speaks with difficulty.}
420 {O quê?} 421 {- Yesterday morning.}

Note that this also translates the keys (the numbers). YOu can do a
pairwise processing like this:

(bin) 53 % lmap {key x} $info {list $key [string map {What? {O quê?}} $x]}
{418 {When did you see him last?}} {419 {Wilford speaks with
difficulty.}} {420 {O quê?}} {421 {- Yesterday morning.}}

However, this adds another level of grouping over each pair, which you
need to subsequently remove (e.g. by concat), or do it in a foreach loop
instead of lmap.

Are the numbers unique keys, by any chance? Then this is in fact a
dictionary, not a list, and you can use "dict map" to translate only the
values:

dict map {key x} $info {string map {What? {O quê?}} $x}

> I will have to redesign the entire proc unless there is a way to force
> every item of a list to be internally represented in brackets even if
> it has no spaces. Is there such a miracle?

No there isn't and you shouldn't do that, you should apply list
operations to lists and string operations to strings, in order to avoid
any problems.

Christian


devel / comp.lang.tcl / Can I force brackets on every list item even if they have no spaces?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor