REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: also

also  value1  value2

Returns the first value, but also evaluates the second.


value1 [any-type!]

value2 [any-type!]

See also:

if   either   any   all  


The also function lets you evaluate two expressions, but return the first, rather than the second. This function may seem a bit odd at first, but in many cases it can save you from needing another temporary variable.

Consider the case where you want to evaluate a block and return its result, but before returning the result, you want to change directories.

You could write:

result: do block
change-dir old-dir
return result

Or, you could write

return also do block change-dir old-dir

In fact, that's actually what happens in the in-dir function.

Another case might be an I/O port used by a function that wants to return the port's data but also close it:

return also port/locals/buffer close port

If you close the port first, the buffer cannot be accessed.

  TOC < Back Next > - WIP Wiki Feedback Admin