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

    From Luc@21:1/5 to All on Fri Mar 24 02:51:49 2023
    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


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Fri Mar 24 07:47:58 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)