Tcl_ExprLong(3)

πŸ“¦
version 9.0.3 Β· 2 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

✨ NAME ✨

Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString β€” bestie, these four literally evaluate an expression for you πŸ’…

This is the Tcl Library Procedures page, i.e. Tcl_ExprLong(3), so if you're writing C and you need to crunch a Tcl expression into a number, a float, a boolean, or a string, you're in exactly the right place. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <tcl.h>

int
Tcl_ExprLong(interp, expr, longPtr)

int
Tcl_ExprDouble(interp, expr, doublePtr)

int
Tcl_ExprBoolean(interp, expr, booleanPtr)

int
Tcl_ExprString(interp, expr)

🌸 ARGUMENTS 🌸

  • Tcl_Interp *interp (in) β€” the interpreter in whose context you're evaluating expr. Think of it as the little universe where your expression gets to exist and pop off. ✨
  • const char *expr (in) β€” the actual expression being evaluated. This is the main character right here. πŸ‘‘
  • long *longPtr (out) β€” pointer to the spot where the integer value of the expression gets stored. It's an out param, so it's holding your results, not your opinions. πŸ’–
  • int *doublePtr (out) β€” pointer to the spot where the floating-point value of the expression gets stored. Yes, it's declared int * in the synopsis and that's literally how the page prints it, so we're keeping it exactly like that, no cap. πŸ™ˆ
  • int *booleanPtr (out) β€” pointer to the spot where the 0/1 boolean value of the expression gets stored. Zero or one, that's it, that's the whole vibe. 🌈

πŸ’œ DESCRIPTION πŸ’œ

okay so, all four of these procedures do the same iconic thing: they evaluate the expression handed to them in the expr argument, and then they hand the result back to you in one of four different forms. Pick your fighter. 🫢

The expression can have any of the forms accepted by the expr command. Fr fr, anything expr can chew on.

but bestie, real talk: these procedures have been largely replaced by the value-based procedures Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, and Tcl_ExprObj. Those value-based ones evaluate an expression held in a Tcl value instead of a string, and the value argument can retain an internal representation that is more efficient to execute. So like… slay, but the Obj versions ate. 😭

The interp argument refers to an interpreter used to evaluate the expression (e.g. for variables and nested Tcl commands) and to return error information.

For all of these procedures the return value is a standard Tcl result: TCL_OK means the expression was successfully evaluated, and TCL_ERROR means that an error occurred while evaluating the expression. If TCL_ERROR is returned then the interpreter's result will hold a message describing the error. And if an error occurs while executing a Tcl command embedded in the expression, then that error will be returned. No cover-ups, we report what happened. πŸ’€

If the expression is successfully evaluated, then its value is returned in one of four forms, depending on which procedure is invoked:

  • Tcl_ExprLong β€” stores an integer value at *longPtr. If the expression's actual value is a floating-point number, then it is truncated to an integer (just chopped, don't cry about it). If the expression's actual value is a non-numeric string then an error is returned. πŸ“
  • Tcl_ExprDouble β€” stores a floating-point value at *doublePtr. If the expression's actual value is an integer, it is converted to floating-point. If the expression's actual value is a non-numeric string then an error is returned. ✨
  • Tcl_ExprBoolean β€” stores a 0/1 integer value at *booleanPtr. If the expression's actual value is an integer or floating-point number, then they store 0 at *booleanPtr if the value was zero and 1 otherwise. If the expression's actual value is a non-numeric string then it must be one of the values accepted by Tcl_GetBoolean such as yes or no, or else an error occurs. 🧚
  • Tcl_ExprString β€” returns the value of the expression as a string stored in the interpreter's result. The string one, the chill one, the low-effort-but-still-valid one. πŸ’…

🌟 SEE ALSO 🌟

  • Tcl_ExprLongObj
  • Tcl_ExprDoubleObj
  • Tcl_ExprBooleanObj
  • Tcl_ExprObj

(the glow-up squad, go check them out πŸ’–)


⭐ KEYWORDS ⭐

boolean, double, evaluate, expression, integer, value, string


and that's the whole page bestie!! πŸŽ€ this lil legend is from Tcl, version 7.0, page Tcl_ExprLong(3) β€” go forth and evaluate responsibly, mwah πŸ’œπŸ¦‹

πŸ“¦ where this page comes from