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


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. The indentation length is the Scinotes one. It can be tuned through Scinotes preferences.
%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:
Thu Oct 24 11:13:15 CEST 2024