Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:30:47+00:00 2026-06-01T10:30:47+00:00

I was expecting if {[some_func $some_args]} { …. } to eval true and simply

  • 0

I was expecting

if {[some_func $some_args]} {
   ....
}

to eval true and simply work as soon as some_func returns some string. However there are errors.

Learning it the hard way, Tcl accepts only the

  • empty string -> False
  • 0 -> False
  • false -> False
  • true -> True
  • 1 -> True

To be precise:

% expr 1
1
% expr 0
0
% expr
wrong # args: should be "expr arg ?arg ...?"
% expr {{}}
% expr true
true
% expr false
false
% expr True
syntax error in expression "True": variable references require preceding $
% expr False
syntax error in expression "False": variable references require preceding $

It seems expr does not normalize it’s return value. Note especially the empty string result if an empty string is given.

So how do I easily convert strings into booleans?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:30:48+00:00Added an answer on June 1, 2026 at 10:30 am

    After thinking some more, and looking some more, the answer probably should be: “It depends”

    With my perl background I was expecting something similar to perl. My fault.

    In Tcl string is true seems to be the official cast function. Valid strings for casting are defined here:

    If string is any of 0, false, no, or off, then Tcl_GetBoolean stores a
    zero value at *boolPtr. If string is any of 1, true, yes, or on, then
    1 is stored at *boolPtr. Any of these values may be abbreviated, and
    upper-case spellings are also acceptable

    In my case, I don’t care about the string’s content so I can just

    if {[string length [some_func $some_args]] > 0} {
      ...
    }
    

    Another way to write this also is much simpler:

    if {[some_func $some_args] != {}} {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library (django-piston) which is expecting some parameters of the class as
How to create a true function pipeline using C#? I got some idea like
I have the following situation and I'm expecting some expert advise from SO folks.
I have a class template, expecting some other template as a parameter: template< class
I have a method expecting WCHAR**, i need to get some data back from
Exporting some data from mysql to a csv file using FasterCSV. I'd like the
I'm executing some complex queries in my app by hand via PDO, using $pdo
I would like to show loadingActivity while activity1 is executing some code (working), after
I'm reading The Art of Assembly: The MMX Instruction Set , After executing some
i have some files located in c:\MyApp\file.txt and current executing assenbly in in debud

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.