Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

What this country needs is a good five cent microcomputer.


programming / comp.lang.tcl / Re: Tcl_Obj : What is the recommended way to append a object to another object ?

SubjectAuthor
* Tcl_Obj : What is the recommended way to append a object to anotherNicolas Robert
`* Re: Tcl_Obj : What is the recommended way to append a object toheinrichmartin
 `* Re: Tcl_Obj : What is the recommended way to append a object toNicolas
  `* Re: Tcl_Obj : What is the recommended way to append a object toNicolas Robert
   +* Re: Tcl_Obj : What is the recommended way to append a object toheinrichmartin
   |`* Re: Tcl_Obj : What is the recommended way to append a object toNicolas Robert
   | `* Re: Tcl_Obj : What is the recommended way to append a object toNicolas Robert
   |  `* Re: Tcl_Obj : What is the recommended way to append a object to another obRalf Fassel
   |   `* Re: Tcl_Obj : What is the recommended way to append a object toNicolas Robert
   |    `* Re: Tcl_Obj : What is the recommended way to append a object toNicolas Robert
   |     `* Re: Tcl_Obj : What is the recommended way to append a object tobriang
   |      `* Re: Tcl_Obj : What is the recommended way to append a object toNicolas Robert
   |       `- Re: Tcl_Obj : What is the recommended way to append a object toHarald Oehlmann
   `- Re: Tcl_Obj : What is the recommended way to append a object tobriang

1
Subject: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 08:17 UTC
X-Received: by 2002:a05:620a:248c:b0:6a0:54f8:9077 with SMTP id i12-20020a05620a248c00b006a054f89077mr6644075qkn.500.1652084251998;
Mon, 09 May 2022 01:17:31 -0700 (PDT)
X-Received: by 2002:a9d:6c93:0:b0:605:d7a8:7930 with SMTP id
c19-20020a9d6c93000000b00605d7a87930mr5582042otr.254.1652084251773; Mon, 09
May 2022 01:17:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.swapon.de!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 01:17:31 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=37.26.181.176; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 37.26.181.176
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
Subject: Tcl_Obj : What is the recommended way to append a object to another
object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Mon, 09 May 2022 08:17:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1395
View all headers
Hello ,
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?

Thanks

Nicolas


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: heinrichmartin
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 11:32 UTC
References: 1
X-Received: by 2002:ac8:5754:0:b0:2e1:eee8:be0b with SMTP id 20-20020ac85754000000b002e1eee8be0bmr14334085qtx.349.1652095933928;
Mon, 09 May 2022 04:32:13 -0700 (PDT)
X-Received: by 2002:a05:6870:424b:b0:ed:97b3:7240 with SMTP id
v11-20020a056870424b00b000ed97b37240mr10442570oac.238.1652095933447; Mon, 09
May 2022 04:32:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 04:32:13 -0700 (PDT)
In-Reply-To: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=91.217.55.78; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 91.217.55.78
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Mon, 09 May 2022 11:32:13 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1668
View all headers
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?

StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 14:19 UTC
References: 1 2
X-Received: by 2002:a37:a90e:0:b0:69f:9b8f:86b4 with SMTP id s14-20020a37a90e000000b0069f9b8f86b4mr10979151qke.513.1652105960134;
Mon, 09 May 2022 07:19:20 -0700 (PDT)
X-Received: by 2002:a05:6808:1646:b0:2f7:50ea:85f3 with SMTP id
az6-20020a056808164600b002f750ea85f3mr10711063oib.137.1652105959842; Mon, 09
May 2022 07:19:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 07:19:19 -0700 (PDT)
In-Reply-To: <722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a01:cb05:80b3:5c00:e43c:e0a1:9099:2b43;
posting-account=QVKs0woAAAA2s0yTpj3jArwE8jRk2SUp
NNTP-Posting-Host: 2a01:cb05:80b3:5c00:e43c:e0a1:9099:2b43
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com> <722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: sl1200...@gmail.com (Nicolas)
Injection-Date: Mon, 09 May 2022 14:19:20 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
Le lundi 9 mai 2022 à 13:32:16 UTC+2, heinrichmartin a écrit :
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?
StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.
Hi,
when I work with strings, I use the Tcl_DString API

++


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 18:45 UTC
References: 1 2 3
X-Received: by 2002:a37:7ca:0:b0:69f:7733:27b9 with SMTP id 193-20020a3707ca000000b0069f773327b9mr16794075qkh.493.1652208318793;
Tue, 10 May 2022 11:45:18 -0700 (PDT)
X-Received: by 2002:a05:6870:60a1:b0:e2:b6b8:3e67 with SMTP id
t33-20020a05687060a100b000e2b6b83e67mr794462oae.137.1652208318502; Tue, 10
May 2022 11:45:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 11:45:18 -0700 (PDT)
In-Reply-To: <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.2.241.29; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 93.2.241.29
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Tue, 10 May 2022 18:45:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
Le lundi 9 mai 2022 à 16:19:22 UTC+2, Nicolas a écrit :
Le lundi 9 mai 2022 à 13:32:16 UTC+2, heinrichmartin a écrit :
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?
StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.
Hi,
when I work with strings, I use the Tcl_DString API

++

Thank you both for your answers.
I finally chose this function : Tcl_AppendObjToObj(...)
I have a problem, I have two objects to add to a list one on the left and one on the right.
Tcl_Obj* newlist = Tcl_NewObj();
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_AppendObjToObj(newlist, listObj);
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));

puts "newlist : [newlist]"
newlist : '{a 30 c 40}'

How I can remove my curly braces from my 'listObj' ?
To obtain this result : newlist : 'a 30 c 40'
 
Nicolas


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: heinrichmartin
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 21:10 UTC
References: 1 2 3 4
X-Received: by 2002:a05:620a:16c2:b0:69f:ca37:f6b5 with SMTP id a2-20020a05620a16c200b0069fca37f6b5mr17285613qkn.48.1652217034501;
Tue, 10 May 2022 14:10:34 -0700 (PDT)
X-Received: by 2002:a05:6870:630d:b0:e2:6498:6734 with SMTP id
s13-20020a056870630d00b000e264986734mr1140523oao.3.1652217034215; Tue, 10 May
2022 14:10:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 14:10:33 -0700 (PDT)
In-Reply-To: <c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.233.31; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.233.31
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Tue, 10 May 2022 21:10:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
On Tuesday, May 10, 2022 at 8:45:21 PM UTC+2, Nicolas Robert wrote:
Le lundi 9 mai 2022 à 16:19:22 UTC+2, Nicolas a écrit :
Le lundi 9 mai 2022 à 13:32:16 UTC+2, heinrichmartin a écrit :
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?
StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.
Hi,
when I work with strings, I use the Tcl_DString API

++
Thank you both for your answers.
I finally chose this function : Tcl_AppendObjToObj(...)
I have a problem, I have two objects to add to a list one on the left and one on the right.
Tcl_Obj* newlist = Tcl_NewObj();
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_AppendObjToObj(newlist, listObj);
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));

I am used to the script level, but
* You could init newlist with the left string already or
* reuse the single quote object left and right.
* If I get https://www.tcl-lang.org/man/tcl8.6/TclLib/StringObj.htm right, then Tcl_AppendObjToObj(Tcl_NewStringObj()) could be simplified to Tcl_AppendToObj().
* I have no experience with refCount, i.e. no idea whether this code is leaking objects. (My guess is that all your Tcl_New*Obj have refCount 0, but they should go through refCount 1, because only _dropping_ to zero would free them ...)

puts "newlist : [newlist]"

You seem not to share all code. How do you create listObj above?
If newlist is the implementation of a proc, then look into https://www.tcl-lang.org/man/tcl8.6/TclLib/SetResult.htm

newlist : '{a 30 c 40}'

listObj already holds these braces; appending quotes is _not_ the issue.

How I can remove my curly braces from my 'listObj' ?
To obtain this result : newlist : 'a 30 c 40'

Besides looking elsewhere in your code (as stated above), maybe you should reconsider why you are mixing C and script level Tcl code. I cannot guess the real-world use case here.


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: briang
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 21:52 UTC
References: 1 2 3 4
X-Received: by 2002:a05:622a:1195:b0:2f3:b8bf:46ab with SMTP id m21-20020a05622a119500b002f3b8bf46abmr21529536qtk.190.1652219548280;
Tue, 10 May 2022 14:52:28 -0700 (PDT)
X-Received: by 2002:a05:6808:2395:b0:326:832f:ac29 with SMTP id
bp21-20020a056808239500b00326832fac29mr1036125oib.295.1652219547874; Tue, 10
May 2022 14:52:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 14:52:27 -0700 (PDT)
In-Reply-To: <c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=50.53.75.154; posting-account=f4QznQoAAAAjupLEpV87s_G-96g1Io1w
NNTP-Posting-Host: 50.53.75.154
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <708923df-4b26-4937-a700-f3265eb99c72n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: bgriffin...@gmail.com (briang)
Injection-Date: Tue, 10 May 2022 21:52:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
On Tuesday, May 10, 2022 at 11:45:21 AM UTC-7, Nicolas Robert wrote:
Le lundi 9 mai 2022 à 16:19:22 UTC+2, Nicolas a écrit :
Le lundi 9 mai 2022 à 13:32:16 UTC+2, heinrichmartin a écrit :
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?
StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.
Hi,
when I work with strings, I use the Tcl_DString API

++
Thank you both for your answers.
I finally chose this function : Tcl_AppendObjToObj(...)
I have a problem, I have two objects to add to a list one on the left and one on the right.
Tcl_Obj* newlist = Tcl_NewObj();
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_AppendObjToObj(newlist, listObj);
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));

puts "newlist : [newlist]"
newlist : '{a 30 c 40}'

How I can remove my curly braces from my 'listObj' ?
To obtain this result : newlist : 'a 30 c 40'

Tcl_Obj* newlist = Tcl_NewObj();
Tcl_Obj** elemv;
Tcl_Obj *blank = Tcl_NewStringObj(" ",1);
int elemc, i;
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_ListObjGetElements(interp, listObj, &elemc, &elemv);
/* Tcl_AppendObjToObj(newlist, listObj);  */
/* essentially [join $list " "] */
for(i=0; i<elemc; i++) {
  if (i>0) Tcl_AppendObjToObj(newlist, blank);
  Tcl_AppendObjToObj(newlist, elemv[i]);
}
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));

So the next question is why?  Because the value contained in listObj is a collection of Obj's in the form of a list.  Tcl, when asked, will create a string representation of the collection so that the individual values are retained and the string as a whole can be used as if it were a scalar value.  In essence this is what your example code is asking it to do when calling Tcl_AppendObjToObj(newlist, listObj);

A Tcl_Obj value is not just simply a string.  It is any form of value that also has a string representation that retains its constituent values so that it can be decomposed later when needed.

This would be a good time to go back to the Tcl 12 rules and review them.  https://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm

-Brian


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 22:00 UTC
References: 1 2 3 4 5
X-Received: by 2002:a05:6214:300d:b0:459:2bb:6d14 with SMTP id ke13-20020a056214300d00b0045902bb6d14mr19817820qvb.71.1652220020440;
Tue, 10 May 2022 15:00:20 -0700 (PDT)
X-Received: by 2002:a4a:e2ca:0:b0:35e:b623:8799 with SMTP id
l10-20020a4ae2ca000000b0035eb6238799mr8780047oot.68.1652220020149; Tue, 10
May 2022 15:00:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 10 May 2022 15:00:19 -0700 (PDT)
In-Reply-To: <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.2.241.29; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 93.2.241.29
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com> <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Tue, 10 May 2022 22:00:20 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4893
View all headers
Le mardi 10 mai 2022 à 23:10:36 UTC+2, heinrichmartin a écrit :
On Tuesday, May 10, 2022 at 8:45:21 PM UTC+2, Nicolas Robert wrote:
Le lundi 9 mai 2022 à 16:19:22 UTC+2, Nicolas a écrit :
Le lundi 9 mai 2022 à 13:32:16 UTC+2, heinrichmartin a écrit :
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?
StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.
Hi,
when I work with strings, I use the Tcl_DString API

++
Thank you both for your answers.
I finally chose this function : Tcl_AppendObjToObj(...)
I have a problem, I have two objects to add to a list one on the left and one on the right.
Tcl_Obj* newlist = Tcl_NewObj();
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_AppendObjToObj(newlist, listObj);
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
I am used to the script level, but
* You could init newlist with the left string already or
* reuse the single quote object left and right.
* If I get https://www.tcl-lang.org/man/tcl8.6/TclLib/StringObj.htm right, then Tcl_AppendObjToObj(Tcl_NewStringObj()) could be simplified to Tcl_AppendToObj().
* I have no experience with refCount, i.e. no idea whether this code is leaking objects. (My guess is that all your Tcl_New*Obj have refCount 0, but they should go through refCount 1, because only _dropping_ to zero would free them ...)

puts "newlist : [newlist]"

You seem not to share all code. How do you create listObj above?
If newlist is the implementation of a proc, then look into https://www.tcl-lang.org/man/tcl8.6/TclLib/SetResult.htm
newlist : '{a 30 c 40}'
listObj already holds these braces; appending quotes is _not_ the issue.
How I can remove my curly braces from my 'listObj' ?
To obtain this result : newlist : 'a 30 c 40'
Besides looking elsewhere in your code (as stated above), maybe you should reconsider why you are mixing C and script level Tcl code. I cannot guess the real-world use case here.

You are right , without code you can't see my problem.
I’ll try to follow your advice...

I can’t reproduce my problem with this simple code :
critcl::cproc newlist {Tcl_Interp* interp} ok {

    Tcl_Obj *listObj  = Tcl_NewListObj (0,NULL);

    Tcl_ListObjAppendElement (interp, listObj, Tcl_NewStringObj("a", 1));
    Tcl_ListObjAppendElement (interp, listObj, Tcl_NewIntObj(30));
    Tcl_ListObjAppendElement (interp, listObj, Tcl_NewStringObj("c", 1));
    Tcl_ListObjAppendElement (interp, listObj, Tcl_NewIntObj(40));


    Tcl_Obj* newlist = Tcl_NewObj();
    Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
    Tcl_AppendObjToObj(newlist, listObj);
    Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));

    Tcl_SetObjResult(interp, newlist);

    return TCL_OK;
}

puts [newlist] ; # 'a 30 c 40'

I'll continue



Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Wed, 11 May 2022 17:16 UTC
References: 1 2 3 4 5 6
X-Received: by 2002:a05:620a:2683:b0:69c:8c9c:5f80 with SMTP id c3-20020a05620a268300b0069c8c9c5f80mr19789724qkp.367.1652289372664;
Wed, 11 May 2022 10:16:12 -0700 (PDT)
X-Received: by 2002:a4a:254e:0:b0:35e:679f:5f78 with SMTP id
v14-20020a4a254e000000b0035e679f5f78mr10067520ooe.26.1652289372285; Wed, 11
May 2022 10:16:12 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 11 May 2022 10:16:12 -0700 (PDT)
In-Reply-To: <a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.2.241.29; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 93.2.241.29
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com> <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Wed, 11 May 2022 17:16:12 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5342
View all headers
Le mercredi 11 mai 2022 à 00:00:22 UTC+2, Nicolas Robert a écrit :
Le mardi 10 mai 2022 à 23:10:36 UTC+2, heinrichmartin a écrit :
On Tuesday, May 10, 2022 at 8:45:21 PM UTC+2, Nicolas Robert wrote:
Le lundi 9 mai 2022 à 16:19:22 UTC+2, Nicolas a écrit :
Le lundi 9 mai 2022 à 13:32:16 UTC+2, heinrichmartin a écrit :
On Monday, May 9, 2022 at 10:17:34 AM UTC+2, Nicolas Robert wrote:
I would like to add single quotes, square brackets, newline... to the left and right of my string.
It seems to me that I have several choices...
Tcl_ObjPrintf("%s", x) , Tcl_AppendObjToObj(...).

Can you advise me one ? or another ?
StringCatCmd uses Tcl_AppendObjToObj. That should be a reasonable choice.
Hi,
when I work with strings, I use the Tcl_DString API

++
Thank you both for your answers.
I finally chose this function : Tcl_AppendObjToObj(...)
I have a problem, I have two objects to add to a list one on the left and one on the right.
Tcl_Obj* newlist = Tcl_NewObj();
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_AppendObjToObj(newlist, listObj);
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
I am used to the script level, but
* You could init newlist with the left string already or
* reuse the single quote object left and right.
* If I get https://www.tcl-lang.org/man/tcl8.6/TclLib/StringObj.htm right, then Tcl_AppendObjToObj(Tcl_NewStringObj()) could be simplified to Tcl_AppendToObj().
* I have no experience with refCount, i.e. no idea whether this code is leaking objects. (My guess is that all your Tcl_New*Obj have refCount 0, but they should go through refCount 1, because only _dropping_ to zero would free them ...)

puts "newlist : [newlist]"

You seem not to share all code. How do you create listObj above?
If newlist is the implementation of a proc, then look into https://www.tcl-lang.org/man/tcl8.6/TclLib/SetResult.htm
newlist : '{a 30 c 40}'
listObj already holds these braces; appending quotes is _not_ the issue..
How I can remove my curly braces from my 'listObj' ?
To obtain this result : newlist : 'a 30 c 40'
Besides looking elsewhere in your code (as stated above), maybe you should reconsider why you are mixing C and script level Tcl code. I cannot guess the real-world use case here.
You are right , without code you can't see my problem.
I’ll try to follow your advice...

I can’t reproduce my problem with this simple code :
critcl::cproc newlist {Tcl_Interp* interp} ok {

Tcl_Obj *listObj = Tcl_NewListObj (0,NULL);

Tcl_ListObjAppendElement (interp, listObj, Tcl_NewStringObj("a", 1));
Tcl_ListObjAppendElement (interp, listObj, Tcl_NewIntObj(30));
Tcl_ListObjAppendElement (interp, listObj, Tcl_NewStringObj("c", 1));
Tcl_ListObjAppendElement (interp, listObj, Tcl_NewIntObj(40));
Tcl_Obj* newlist = Tcl_NewObj();
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_AppendObjToObj(newlist, listObj);
Tcl_AppendObjToObj(newlist, Tcl_NewStringObj("'", 1));
Tcl_SetObjResult(interp, newlist);

return TCL_OK;
}

puts [newlist] ; # 'a 30 c 40'

I'll continue

I finally found , my problem was that my input list was not of this form {a 30 c 40} but like this {{a 30 c 40}}.
problem solved with Tcl_ListObjIndex(...)

Nicolas


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Wed, 11 May 2022 17:25 UTC
References: 1 2 3 4 5 6 7
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
Date: Wed, 11 May 2022 19:25:39 +0200
Lines: 26
Message-ID: <ygak0asugks.fsf@akutech.de>
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com>
<2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
<a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com>
<824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net rvFTnCnTZ8i18DbRBkXeWApQrE3BkNOyvMe9d+UWw4hljPxJY=
Cancel-Lock: sha1:FquHHzBu0REmxJkhxFKA1t6leIg= sha1:t5iTiJg0KfDrQXxfAwkmf4Pp8dc=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
View all headers
* Nicolas Robert <nicolasrobert.19000@gmail.com>
| I finally found , my problem was that my input list was not of this
| form {a 30 c 40} but like this {{a 30 c 40}}.  problem solved with
| Tcl_ListObjIndex(...)

Note that if any of the list elements themselves are (sub-)lists or
have spaces or other special chars in the value, the "{}" might come
back again.

    % set list  [list a 30 b 40]
    a 30 b 40
    % lappend list c "10 20"
    a 30 b 40 c {10 20}

Note the last element.

    % lappend list d \{
    a 30 b 40 c {10 20} d \{

Again...

If it is *really* important that there is no {} (or \ for the same
reason) in the printed string, you would need to check for that and take
appropriate action if there is.

R'


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Wed, 11 May 2022 17:57 UTC
References: 1 2 3 4 5 6 7 8
X-Received: by 2002:a37:68ca:0:b0:6a0:4bd:6098 with SMTP id d193-20020a3768ca000000b006a004bd6098mr20215750qkc.605.1652291860903;
Wed, 11 May 2022 10:57:40 -0700 (PDT)
X-Received: by 2002:a9d:5d0e:0:b0:605:dca7:832a with SMTP id
b14-20020a9d5d0e000000b00605dca7832amr10078732oti.136.1652291860539; Wed, 11
May 2022 10:57:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 11 May 2022 10:57:40 -0700 (PDT)
In-Reply-To: <ygak0asugks.fsf@akutech.de>
Injection-Info: google-groups.googlegroups.com; posting-host=93.2.241.29; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 93.2.241.29
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com> <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com> <824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
<ygak0asugks.fsf@akutech.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <09242ec3-ea8c-48b1-96ed-a66344443b1en@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Wed, 11 May 2022 17:57:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2728
View all headers
Le mercredi 11 mai 2022 à 19:25:45 UTC+2, Ralf Fassel a écrit :
* Nicolas Robert <nicolasro...@gmail.com>
| I finally found , my problem was that my input list was not of this
| form {a 30 c 40} but like this {{a 30 c 40}}. problem solved with
| Tcl_ListObjIndex(...)
Note that if any of the list elements themselves are (sub-)lists or
have spaces or other special chars in the value, the "{}" might come
back again.

% set list [list a 30 b 40]
a 30 b 40
% lappend list c "10 20"
a 30 b 40 c {10 20}

Note the last element.

% lappend list d \{
a 30 b 40 c {10 20} d \{

Again...

If it is *really* important that there is no {} (or \ for the same
reason) in the printed string, you would need to check for that and take
appropriate action if there is.

R'

I would be surprised if I had this kind of case, since I work with structured lists. (huddle list).
If that were the case, I don’t think I can find a solution, as my knowledge of the C language is limited...

Nicolas


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Wed, 25 May 2022 16:03 UTC
References: 1 2 3 4 5 6 7 8 9
X-Received: by 2002:a0c:ec0d:0:b0:461:dedb:fc5c with SMTP id y13-20020a0cec0d000000b00461dedbfc5cmr27205630qvo.52.1653494611193;
Wed, 25 May 2022 09:03:31 -0700 (PDT)
X-Received: by 2002:a05:6830:44a4:b0:60b:39e7:ab22 with SMTP id
r36-20020a05683044a400b0060b39e7ab22mr478230otv.148.1653494610903; Wed, 25
May 2022 09:03:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 25 May 2022 09:03:30 -0700 (PDT)
In-Reply-To: <09242ec3-ea8c-48b1-96ed-a66344443b1en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.2.241.29; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 93.2.241.29
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com> <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com> <824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
<ygak0asugks.fsf@akutech.de> <09242ec3-ea8c-48b1-96ed-a66344443b1en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d18eceb6-5e8b-48d5-9226-b1edec171edcn@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Wed, 25 May 2022 16:03:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3712
View all headers
Le mercredi 11 mai 2022 à 19:57:42 UTC+2, Nicolas Robert a écrit :
Le mercredi 11 mai 2022 à 19:25:45 UTC+2, Ralf Fassel a écrit :
* Nicolas Robert
| I finally found , my problem was that my input list was not of this
| form {a 30 c 40} but like this {{a 30 c 40}}. problem solved with
| Tcl_ListObjIndex(...)
Note that if any of the list elements themselves are (sub-)lists or
have spaces or other special chars in the value, the "{}" might come
back again.

% set list [list a 30 b 40]
a 30 b 40
% lappend list c "10 20"
a 30 b 40 c {10 20}

Note the last element.

% lappend list d \{
a 30 b 40 c {10 20} d \{

Again...

If it is *really* important that there is no {} (or \ for the same
reason) in the printed string, you would need to check for that and take
appropriate action if there is.

R'
I would be surprised if I had this kind of case, since I work with structured lists. (huddle list).
If that were the case, I don’t think I can find a solution, as my knowledge of the C language is limited...

Nicolas

Hello ,
I have 2 questions
I need this result : > s {Hello World}

I encountered problems when my string contained spaces as in the above result ,
to avoid this, I added my string obj in a list.

Tcl_Obj* defaultTag = Tcl_NewObj();

Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("s ", 2));
if (Tcl_DStringLength(srcObj) == 0) {
    Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("{}", 2));
} else {
    Tcl_Obj *listStringObj  = Tcl_NewListObj (0,NULL);
    Tcl_ListObjAppendElement(interp, listStringObj, srcObj);
    Tcl_AppendObjToObj(defaultTag, listStringObj);
}

Is that a correct solution? Or I’ll do it another way

2nd question :
'srcObj' can be empty... Checking its length is a correct solution ?

Nicolas


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: briang
Newsgroups: comp.lang.tcl
Date: Wed, 25 May 2022 16:17 UTC
References: 1 2 3 4 5 6 7 8 9 10
X-Received: by 2002:ac8:59c7:0:b0:2f9:3b5c:342b with SMTP id f7-20020ac859c7000000b002f93b5c342bmr10409320qtf.58.1653495445816;
Wed, 25 May 2022 09:17:25 -0700 (PDT)
X-Received: by 2002:a05:6808:1244:b0:322:6925:3f4f with SMTP id
o4-20020a056808124400b0032269253f4fmr5670654oiv.39.1653495445510; Wed, 25 May
2022 09:17:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 25 May 2022 09:17:25 -0700 (PDT)
In-Reply-To: <d18eceb6-5e8b-48d5-9226-b1edec171edcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=50.53.75.154; posting-account=f4QznQoAAAAjupLEpV87s_G-96g1Io1w
NNTP-Posting-Host: 50.53.75.154
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com> <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com> <824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
<ygak0asugks.fsf@akutech.de> <09242ec3-ea8c-48b1-96ed-a66344443b1en@googlegroups.com>
<d18eceb6-5e8b-48d5-9226-b1edec171edcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ee646932-bd6d-43d1-b463-d8aba09d6958n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: bgriffin...@gmail.com (briang)
Injection-Date: Wed, 25 May 2022 16:17:25 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
On Wednesday, May 25, 2022 at 9:03:33 AM UTC-7, Nicolas Robert wrote:
Le mercredi 11 mai 2022 à 19:57:42 UTC+2, Nicolas Robert a écrit :
Le mercredi 11 mai 2022 à 19:25:45 UTC+2, Ralf Fassel a écrit :
* Nicolas Robert
| I finally found , my problem was that my input list was not of this
| form {a 30 c 40} but like this {{a 30 c 40}}. problem solved with
| Tcl_ListObjIndex(...)
Note that if any of the list elements themselves are (sub-)lists or
have spaces or other special chars in the value, the "{}" might come
back again.

% set list [list a 30 b 40]
a 30 b 40
% lappend list c "10 20"
a 30 b 40 c {10 20}

Note the last element.

% lappend list d \{
a 30 b 40 c {10 20} d \{

Again...

If it is *really* important that there is no {} (or \ for the same
reason) in the printed string, you would need to check for that and take
appropriate action if there is.

R'
I would be surprised if I had this kind of case, since I work with structured lists. (huddle list).
If that were the case, I don’t think I can find a solution, as my knowledge of the C language is limited...

Nicolas
Hello ,
I have 2 questions
I need this result : > s {Hello World}

I encountered problems when my string contained spaces as in the above result ,
to avoid this, I added my string obj in a list.

Tcl_Obj* defaultTag = Tcl_NewObj();

Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("s ", 2));
if (Tcl_DStringLength(srcObj) == 0) {
Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("{}", 2));
} else {
Tcl_Obj *listStringObj = Tcl_NewListObj (0,NULL);
Tcl_ListObjAppendElement(interp, listStringObj, srcObj);
Tcl_AppendObjToObj(defaultTag, listStringObj);
}

Is that a correct solution? Or I’ll do it another way

No, this is not the correct solution. The mistake made here is that the code is trying to guess the correct string form of a list.  This is re-inventing the code that already exists in Tcl to correctly manage a list. 
Just don't do this and let Tcl do it for you.

Assuming that "defaultTag" is intended to be a list, then only List operations should be used to modify this Tcl_Obj value.

Tcl_Obj* defaultTag = Tcl_NewObj();
Tcl_Obj* s = Tcl_NewStringObj("s", 1);

Tcl_ListObjAppendElement(interp, defaultTag, s);
Tcl_ListObjAppendElement(interp, defaultTag, srcObj);

Work smarter, not harder.


2nd question :
'srcObj' can be empty... Checking its length is a correct solution ?

Answered above.

-Brian


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Nicolas Robert
Newsgroups: comp.lang.tcl
Date: Thu, 26 May 2022 08:16 UTC
References: 1 2 3 4 5 6 7 8 9 10 11
X-Received: by 2002:a05:6214:c64:b0:462:483f:64ff with SMTP id t4-20020a0562140c6400b00462483f64ffmr13691008qvj.26.1653552967504;
Thu, 26 May 2022 01:16:07 -0700 (PDT)
X-Received: by 2002:a05:6808:14cc:b0:328:b183:c2cc with SMTP id
f12-20020a05680814cc00b00328b183c2ccmr452133oiw.150.1653552967184; Thu, 26
May 2022 01:16:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 26 May 2022 01:16:06 -0700 (PDT)
In-Reply-To: <ee646932-bd6d-43d1-b463-d8aba09d6958n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.2.241.29; posting-account=12Ku7QoAAABZfwpOT4Ksf001bDFF99F1
NNTP-Posting-Host: 93.2.241.29
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com> <2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com> <a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com> <824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
<ygak0asugks.fsf@akutech.de> <09242ec3-ea8c-48b1-96ed-a66344443b1en@googlegroups.com>
<d18eceb6-5e8b-48d5-9226-b1edec171edcn@googlegroups.com> <ee646932-bd6d-43d1-b463-d8aba09d6958n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d5546eb7-caca-4244-9bad-954c7c980358n@googlegroups.com>
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
From: nicolasr...@gmail.com (Nicolas Robert)
Injection-Date: Thu, 26 May 2022 08:16:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
Le mercredi 25 mai 2022 à 18:17:27 UTC+2, briang a écrit :
On Wednesday, May 25, 2022 at 9:03:33 AM UTC-7, Nicolas Robert wrote:
Le mercredi 11 mai 2022 à 19:57:42 UTC+2, Nicolas Robert a écrit :
Le mercredi 11 mai 2022 à 19:25:45 UTC+2, Ralf Fassel a écrit :
* Nicolas Robert
| I finally found , my problem was that my input list was not of this
| form {a 30 c 40} but like this {{a 30 c 40}}. problem solved with
| Tcl_ListObjIndex(...)
Note that if any of the list elements themselves are (sub-)lists or
have spaces or other special chars in the value, the "{}" might come
back again.

% set list [list a 30 b 40]
a 30 b 40
% lappend list c "10 20"
a 30 b 40 c {10 20}

Note the last element.

% lappend list d \{
a 30 b 40 c {10 20} d \{

Again...

If it is *really* important that there is no {} (or \ for the same
reason) in the printed string, you would need to check for that and take
appropriate action if there is.

R'
I would be surprised if I had this kind of case, since I work with structured lists. (huddle list).
If that were the case, I don’t think I can find a solution, as my knowledge of the C language is limited...

Nicolas
Hello ,
I have 2 questions
I need this result : > s {Hello World}

I encountered problems when my string contained spaces as in the above result ,
to avoid this, I added my string obj in a list.

Tcl_Obj* defaultTag = Tcl_NewObj();

Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("s ", 2));
if (Tcl_DStringLength(srcObj) == 0) {
Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("{}", 2));
} else {
Tcl_Obj *listStringObj = Tcl_NewListObj (0,NULL);
Tcl_ListObjAppendElement(interp, listStringObj, srcObj);
Tcl_AppendObjToObj(defaultTag, listStringObj);
}

Is that a correct solution? Or I’ll do it another way
No, this is not the correct solution. The mistake made here is that the code is trying to guess the correct string form of a list. This is re-inventing the code that already exists in Tcl to correctly manage a list.
Just don't do this and let Tcl do it for you.

Assuming that "defaultTag" is intended to be a list, then only List operations should be used to modify this Tcl_Obj value.

Tcl_Obj* defaultTag = Tcl_NewObj();
Tcl_Obj* s = Tcl_NewStringObj("s", 1);

Tcl_ListObjAppendElement(interp, defaultTag, s);
Tcl_ListObjAppendElement(interp, defaultTag, srcObj);

Work smarter, not harder.

2nd question :
'srcObj' can be empty... Checking its length is a correct solution ?
Answered above.

-Brian

Thanks for the advice, it’s much cleaner.

Nicolas


Subject: Re: Tcl_Obj : What is the recommended way to append a object to another object ?
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 26 May 2022 08:34 UTC
References: 1 2 3 4 5 6 7 8 9 10 11 12
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.de (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Tcl_Obj : What is the recommended way to append a object to
another object ?
Date: Thu, 26 May 2022 10:34:16 +0200
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <t6ne26$3nv$1@dont-email.me>
References: <3f00ffbc-d0ed-4a65-8ecb-34034f099f81n@googlegroups.com>
<722881c6-d31e-449f-bef7-82a56d1cf708n@googlegroups.com>
<2927b8ec-389e-4eee-8de9-da20c8ce55a5n@googlegroups.com>
<c2b6b4ec-fe93-4ca8-97fd-22e774f54fd4n@googlegroups.com>
<a718eda8-6929-452b-985e-84cbdebcc63fn@googlegroups.com>
<a97734fc-3cae-42c8-9ba8-c5160df502ffn@googlegroups.com>
<824db933-e4b0-46ce-bf6c-549403ae5066n@googlegroups.com>
<ygak0asugks.fsf@akutech.de>
<09242ec3-ea8c-48b1-96ed-a66344443b1en@googlegroups.com>
<d18eceb6-5e8b-48d5-9226-b1edec171edcn@googlegroups.com>
<ee646932-bd6d-43d1-b463-d8aba09d6958n@googlegroups.com>
<d5546eb7-caca-4244-9bad-954c7c980358n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 26 May 2022 08:34:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e0ab7154318d511afc24291b12e296a";
logging-data="3839"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IOJ9eb2x6ADTbrriQRasS"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:TE20LnaEkBAIbN6haZStdKUTlAU=
In-Reply-To: <d5546eb7-caca-4244-9bad-954c7c980358n@googlegroups.com>
Content-Language: en-GB
View all headers
Am 26.05.2022 um 10:16 schrieb Nicolas Robert:
Le mercredi 25 mai 2022 à 18:17:27 UTC+2, briang a écrit :
On Wednesday, May 25, 2022 at 9:03:33 AM UTC-7, Nicolas Robert wrote:
Le mercredi 11 mai 2022 à 19:57:42 UTC+2, Nicolas Robert a écrit :
Le mercredi 11 mai 2022 à 19:25:45 UTC+2, Ralf Fassel a écrit :
* Nicolas Robert
| I finally found , my problem was that my input list was not of this
| form {a 30 c 40} but like this {{a 30 c 40}}. problem solved with
| Tcl_ListObjIndex(...)
Note that if any of the list elements themselves are (sub-)lists or
have spaces or other special chars in the value, the "{}" might come
back again.

% set list [list a 30 b 40]
a 30 b 40
% lappend list c "10 20"
a 30 b 40 c {10 20}

Note the last element.

% lappend list d \{
a 30 b 40 c {10 20} d \{

Again...

If it is *really* important that there is no {} (or \ for the same
reason) in the printed string, you would need to check for that and take
appropriate action if there is.

R'
I would be surprised if I had this kind of case, since I work with structured lists. (huddle list).
If that were the case, I don’t think I can find a solution, as my knowledge of the C language is limited...

Nicolas
Hello ,
I have 2 questions
I need this result : > s {Hello World}

I encountered problems when my string contained spaces as in the above result ,
to avoid this, I added my string obj in a list.

Tcl_Obj* defaultTag = Tcl_NewObj();

Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("s ", 2));
if (Tcl_DStringLength(srcObj) == 0) {
Tcl_AppendObjToObj(defaultTag, Tcl_NewStringObj("{}", 2));
} else {
Tcl_Obj *listStringObj = Tcl_NewListObj (0,NULL);
Tcl_ListObjAppendElement(interp, listStringObj, srcObj);
Tcl_AppendObjToObj(defaultTag, listStringObj);
}

Is that a correct solution? Or I’ll do it another way
No, this is not the correct solution. The mistake made here is that the code is trying to guess the correct string form of a list. This is re-inventing the code that already exists in Tcl to correctly manage a list.
Just don't do this and let Tcl do it for you.

Assuming that "defaultTag" is intended to be a list, then only List operations should be used to modify this Tcl_Obj value.

Tcl_Obj* defaultTag = Tcl_NewObj();
Tcl_Obj* s = Tcl_NewStringObj("s", 1);

Tcl_ListObjAppendElement(interp, defaultTag, s);
Tcl_ListObjAppendElement(interp, defaultTag, srcObj);

Work smarter, not harder.

2nd question :
'srcObj' can be empty... Checking its length is a correct solution ?
Answered above.

-Brian

Thanks for the advice, it’s much cleaner.

Nicolas

I personally find it good practice to check eventual returned errors from Tcl_ListObjAppendElement.
This is hypotetical in this case, as there may not be any error.
The typical error would be, that "defaultTag" is not a list. This may not happen here.

Sorry, just noise,
Harald


1
rocksolid light 0.7.2
clearneti2ptor