# /return and /result

Usage:

/RETURN [expression]
/RESULT [expression]

/return stops execution of the macro body that called it, and causes the macro to return the string value of expression. If the expression is omitted, the return value of the macro is the empty string.

When a macro that calls /result was called as a function, /result is identical to /return. When a macro that calls /result was called as a command, /result has the additional effect of echoing the value of expression to the tfout stream. /Result thus allows the same macro to be called usefully as either a command or a function.

Note that /return and /result take the string value of expression. This is not a problem for integer- or float-valued expressions, since they convert freely to strings and back without loss of information. But if the expression is an enumerated special variable (e.g., `borg`), the value returned will be its string value (e.g., `"on"`), not its integer value (e.g., `1`). To force it to use the integer value, you can use the unary plus operator (e.g., `+borg`).

The return value of the last command (builtin or macro) is stored in %{?}. The return value of a function (builtin or macro) is just the value of the function.

These examples define several macros intended to be called as a functions:

      /def square = /return pow({1}, 2)

      /def hypot = /return sqrt(square({1}) + square({2}))

      /def strrev = \
          /let len=$[strlen({*})]%; \
          /return (len <= 1) ? {*} : \
              strcat(strrev(substr({*},len/2)), strrev(substr({*},0,len/2)))

If those examples had used /result instead of /return, they could also be used as commands when echoing is more convenient. For example,

        /eval say My name backwards is $(/strrev ${world_character}).

See: /if, /while, /test, /break, /exit, expressions, evaluation, variables

Back to index
Back to tf home page

Copyright © 1997, 1998, 1999, 2002, 2003, 2004 Ken Keys