Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.0 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Advanced functions > tree2code

tree2code

generates the text definition of a Scilab function from its internal code

Syntax

txt = tree2code(tree, prettyprint)

Arguments

tree

a macro internal tree (coming from macr2tree).

prettyprint

an optional boolean value:

%T : The generated code is indented and beautified
%F : The generated code is not beautified (default)
txt

column of texts: Scilab instructions defining the function

Description

Given a loaded Scilab function "tree" (returned by macr2tree), tree2code allows to re-generate the code defining the function.

Examples

tree = macr2tree(log2);   // note that the input is log2 (the function handle), not "log2"
txt = tree2code(tree, %T);
printf("%s\n", txt);
--> printf("%s\n",c)
function [f,e] = log2(x)
  // x may be positive, negative, or complex
  [lhs,rhs] = argn(0)
  if rhs<>1 then
    msg = gettext("%s: Wrong number of input argument(s): %d expected.\n")
    error(msprintf(msg, "log2", 1))
  end;
  if argn(1)==1 then
    f = log(x)/log(2)
  else
    [f,e] = frexp(x)
  end
endfunction

See also

  • macr2tree — provides the internal code of a compiled Scilab function
  • macrovar — variables of function
  • string — conversion to string
Report an issue
<< overloading Advanced functions varargin >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:03:08 CET 2017