Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters
Here is a pretty minimal command-line example:
$ echo 'proc test {args} {puts stdout $args}; test "Foo garp"' | tclsh
{Foo garp}
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters to me - my code has written a string delimited by quotes to a SQLite database. I'm trying to test the code and am passing strings to a proc that checks them against what is in the db. The comparison fails because the proc expects, say {Some string} but the database query is returning "Some string" so the proc is correctly detecting a difference.
I was very surprised by this because I was passing "Some string" to the proc.
Here is a pretty minimal command-line example:
$ echo 'proc test {args} {puts stdout $args}; test "Foo garp"' | tclsh
{Foo garp}
Also
$ echo 'proc test {args} {puts stdout $args}; test {Foo garp}' | tclsh
{Foo garp}
As far as I can see my options are
a) Ensure that the comparison proc in the test script sees a quote-
delimited string;
b) Within the comparision proc, convert the the brace-delimited
string to one that's delimited by quotes;
c) Work out how my code manages to write a quote-delimited string to
the database and get it to write one delimited by quotes instead; d) Give up on this particular test.
I have no idea how to do either a) or b), c) is going to be a lot of hard work (and is therefore unappealing :-) ) and d) really feels like the wrong thing to do.
Alan
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters
to me - my code has written a string delimited by quotes to a SQLite
On 9/9/2025 3:04 PM, Alan Grunwald wrote:
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it
matters to me - my code has written a string delimited by quotes to a
SQLite database. I'm trying to test the code and am passing strings to
a proc that checks them against what is in the db. The comparison
fails because the proc expects, say {Some string} but the database
query is returning "Some string" so the proc is correctly detecting a
difference.
I was very surprised by this because I was passing "Some string" to
the proc.
Here is a pretty minimal command-line example:
$ echo 'proc test {args} {puts stdout $args}; test "Foo garp"' | tclsh
{Foo garp}
Also
$ echo 'proc test {args} {puts stdout $args}; test {Foo garp}' | tclsh
{Foo garp}
As far as I can see my options are
a) Ensure that the comparison proc in the test script sees a quote- >> delimited string;
b) Within the comparision proc, convert the the brace-delimited
string to one that's delimited by quotes;
c) Work out how my code manages to write a quote-delimited string to >> the database and get it to write one delimited by quotes instead;
d) Give up on this particular test.
I have no idea how to do either a) or b), c) is going to be a lot of
hard work (and is therefore unappealing :-) ) and d) really feels like
the wrong thing to do.
Alan
Generally the rule is:
The quoting only exists at the SQL level:
Going in: Tcl → SQLite interface adds quotes → SQLite receives quoted SQL Coming out: SQLite → SQLite interface removes quotes → Tcl receives plain strings
Exception - if you explicitly store quote characters in your strings.
So, perhaps you can provide a smallish copy/paste example where you are having the problem.
In article <109q8c9$18m1k$[email protected]>,
Alan Grunwald <[email protected]> wrote:
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters
It doesn't.
Here is a pretty minimal command-line example:
$ echo 'proc test {args} {puts stdout $args}; test "Foo garp"' | tclsh
{Foo garp}
The name "args" is special and is a list.
Consider this little file and what it outputs:
==== CUT ===
#!/usr/bin/env tclsh8.6
proc test1 {args} {
puts stdout $args
}
proc test2 {x} {
puts stdout $x
}
test1 {foo bar}
test2 {foo bar}
==== END ===
On 09/09/2025 23:25, Ted Nolan <tednolan> wrote:
In article <109q8c9$18m1k$[email protected]>,
Alan Grunwald <[email protected]> wrote:
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters
It doesn't.
Here is a pretty minimal command-line example:
$ echo 'proc test {args} {puts stdout $args}; test "Foo garp"' | tclsh
{Foo garp}
The name "args" is special and is a list.
Consider this little file and what it outputs:
==== CUT ===
#!/usr/bin/env tclsh8.6
proc test1 {args} {
puts stdout $args
}
proc test2 {x} {
puts stdout $x
}
test1 {foo bar}
test2 {foo bar}
==== END ===
Thanks Ted.
I'm busy most of today but I will get back to you later on - probably
10-12 hours time.
Alan Grunwald <[email protected]> wrote:
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters
to me - my code has written a string delimited by quotes to a SQLite
Please be less ambigious. Is the string delimited by quotes (") or do
you actually mean it is delimited by braces ({) but you say "quotes"?
If what you got in the sqlite db was {a string with spaces} then the
most likely cause was you used a variable containing a list in a string context, in which case you'll get braces added (sometimes) when Tcl
converts the list to a "string representation".
I.e., you've likely mixed together strings and lists and are seeing the "stringified list" in the sqlite db.
$ rlwrap tclsh
% proc test {args} {puts $args}
'args' here inside the proc is actually a list. The "puts $args" is
using a "list" in a "string context", so Tcl outputs the string representation of the list. Which, as you see below, results in added
braces sometimes:
% test abc
abc
% test "abc def"
{abc def}
%
I have always thought it made no difference. All of a sudden it matters
to me - my code has written a string delimited by quotes to a SQLite database. I'm trying to test the code and am passing strings to a proc
that checks them against what is in the db.
On 10/09/2025 04:22, Rich wrote:
Alan Grunwald <[email protected]> wrote:
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters
to me - my code has written a string delimited by quotes to a SQLite
Please be less ambigious. Is the string delimited by quotes (") or do
you actually mean it is delimited by braces ({) but you say "quotes"?
If what you got in the sqlite db was {a string with spaces} then the
most likely cause was you used a variable containing a list in a string
context, in which case you'll get braces added (sometimes) when Tcl
converts the list to a "string representation".
I.e., you've likely mixed together strings and lists and are seeing the
"stringified list" in the sqlite db.
$ rlwrap tclsh
% proc test {args} {puts $args}
'args' here inside the proc is actually a list. The "puts $args" is
using a "list" in a "string context", so Tcl outputs the string
representation of the list. Which, as you see below, results in added
braces sometimes:
% test abc
abc
% test "abc def"
{abc def}
%
Thanks for the reply Rich. As I said on other messages, I can't give you
a proper response, but I'll get back to you properly later in the day.
I'm pretty sure that I've written a string to the database with real double-quotes ("). I should be able to produce a one-liner command-line
to extract it from the database, but had written that db to /tmp and
it's gone away after an overnight reboot, and I can reproduce the
database right now...
On 10/09/2025 08:49, Alan Grunwald wrote:
On 10/09/2025 04:22, Rich wrote:
Alan Grunwald <[email protected]> wrote:
Hi,
I admit that I'm fairly undisciplined about whether I write
set var "A string with spaces"
or
set var {A string with spaces}
I have always thought it made no difference. All of a sudden it matters >>>> to me - my code has written a string delimited by quotes to a SQLite
Please be less ambigious. Is the string delimited by quotes (") or do
you actually mean it is delimited by braces ({) but you say "quotes"?
If what you got in the sqlite db was {a string with spaces} then the
most likely cause was you used a variable containing a list in a string
context, in which case you'll get braces added (sometimes) when Tcl
converts the list to a "string representation".
I.e., you've likely mixed together strings and lists and are seeing the
"stringified list" in the sqlite db.
$ rlwrap tclsh
% proc test {args} {puts $args}
'args' here inside the proc is actually a list. The "puts $args" is
using a "list" in a "string context", so Tcl outputs the string
representation of the list. Which, as you see below, results in added
braces sometimes:
% test abc
abc
% test "abc def"
{abc def}
%
I definitely believe that I have written quotes (") to the database;
witness this command-line one-liner:
echo "SELECT cha_mods FROM changes" | sqlite3 /tmp/save3-1.0.db
variant "Testing testing" gender female
I want to determine whether my problem is in the 'real' code that writes
a quoted string to the database but shouldn't, or whether it lies in the test code that is comparing results incorrectly. All the while, sharing
only the minimal amount of code. Any suggestions?
$db save $d -default {variant "Testing testing" gender female}
Alan Grunwald <[email protected]> wrote:
$db save $d -default {variant "Testing testing" gender female}
This above *will* pass along a string that has the quotes (") literally present in the string. Curly brackets cause the Tcl parser to take the contents inside as a literal string (almost [1]) and in your example above, the quotes (") will remain in the string.
If you then insert that string, without further filtering, you'll get
literal quotes stored in the db.
[1] see rule [6] in the Tcl man page
set normalisedDict [dict create]
dict for {k v} inputDict {
dict set normalisedDict $k $v
}
On 11/09/2025 18:08, Alan Grunwald wrote:
set normalisedDict [dict create]
dict for {k v} inputDict {
dict set normalisedDict $k $v
}
There are several shorter ways to accomplish the same thing:
set normalisedDict [dict map {k v} $inputDict {set v}]
set normalisedDict [dict merge {} $inputDict]
set normalisedDict [dict remove $inputDict]
set normalisedDict [dict replace $inputDict]
Schelte
* Schelte <[email protected]>
| On 11/09/2025 18:08, Alan Grunwald wrote:
| > set normalisedDict [dict create]
| > dict for {k v} inputDict {
| > dict set normalisedDict $k $v
| > }
| There are several shorter ways to accomplish the same thing:
| set normalisedDict [dict map {k v} $inputDict {set v}]
I really don't understand what that accomplishes besides a copy of the
dict? Could you give an example where the src and dest dicts differ?
R'
Am 12.09.2025 um 15:42 schrieb Ralf Fassel:
* Schelte <[email protected]>
| On 11/09/2025 18:08, Alan Grunwald wrote:
| > set normalisedDict [dict create]
| > dict for {k v} inputDict {
| > dict set normalisedDict $k $v
| > }
| There are several shorter ways to accomplish the same thing:
| set normalisedDict [dict map {k v} $inputDict {set v}]
I really don't understand what that accomplishes besides a copy of the
dict? Could you give an example where the src and dest dicts differ?
R'
The string representation is vanished, which may have duplicated keys.
As this is later on saved to the data base as a string representation,
this is crucial.
set inputDict {a 1 a 2 b 3}
set normalizedDict [dict merge $inputDict {}]
sorry, the "dict merge" does not work.
On 12/09/2025 16:16, Harald Oehlmann wrote:
sorry, the "dict merge" does not work.
The dict merge does work the way I wrote it:
set normalizedDict [dict merge {} $inputDict]
Schelte
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,071 |
Nodes: | 10 (0 / 10) |
Uptime: | 69:04:06 |
Calls: | 13,754 |
Calls today: | 1 |
Files: | 186,984 |
D/L today: |
10,708 files (3,133M bytes) |
Messages: | 2,425,677 |