Tcl_ExprLong(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– Tcl_ExprLong β€” evaluate an expression πŸ’–

okay bestie, welcome to the Tcl_ExprLong page from the Tcl Library Procedures ✨ (it's a <pink>3tcl</pink> manual, iykyk). this is the little family of C functions that takes an expression and hands you back the answer β€” but in four different flavours πŸ“. come sit, we're doing this together.


✨ 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 whose context we're evaluating expr in, bestie. she's the one holding the vibe.
  • const char *expr (in) β€” the expression itself, the thing we're evaluating. main character fr.
  • long *longPtr (out) β€” a pointer to the spot where the integer value of the expression gets stored 🫢
  • int *doublePtr (out) β€” a pointer to the spot where the floating-point value of the expression gets stored 🌸
  • int *booleanPtr (out) β€” a pointer to the spot where the 0/1 boolean value of the expression gets stored ⭐

πŸ’… DESCRIPTION πŸ’…

so. these four procedures all evaluate the expression given by the expr argument and return the result in one of four different forms. periodt. the expression can have any of the forms accepted by the expr command β€” so like, all of them, no cap.

⚠️ okay important heads-up: these procedures have been largely replaced by the value-based procedures Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, and Tcl_ExprObj. those value-based girlies 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 πŸ‘‘

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. she does the heavy lifting AND the snitching, iconic.

for all of these procedures the return value is a standard Tcl result:

  • TCL_OK means the expression was successfully evaluated ✨
  • 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. like, the inner error bubbles right on up. no filter.

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 πŸ’€ (yes, truncated, don't come for me). 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 πŸŽ€

🌈 SEE ALSO 🌈

Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj


πŸ‘‘ KEYWORDS πŸ‘‘

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


and that's the whole page bestie πŸ¦‹ this one's from Tcl 7.0, and the manual page is literally called Tcl_ExprLong(3tcl). go evaluate something cute, ily, bye πŸ’œβœ¨

πŸ“¦ where this page comes from