Visualize a tree: Difference between revisions

m
m (syntax highlighting fixup automation)
 
(3 intermediate revisions by 2 users not shown)
Line 1,671:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Visualize_a_tree}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
Fōrmulæ is a homoiconic language using expression trees as its fundamental structure, so managing trees is very natural.
In '''[https://formulae.org/?example=Visualize_a_tree this]''' page you can see the program(s) related to this task and their results.
 
'''Creating trees from expressions'''
 
The ToTree expression creates a tree from a given expression. see the following examples:
 
[[File:Fōrmulæ - Visualize a tree 01.png]]
 
[[File:Fōrmulæ - Visualize a tree 02.png]]
 
Be aware the the expression will be first reduced, like the following:
 
[[File:Fōrmulæ - Visualize a tree 03.png]]
 
[[File:Fōrmulæ - Visualize a tree 04.png]]
 
It order to avoid the reduction, the use of the Protect expression is recommended:
 
[[File:Fōrmulæ - Visualize a tree 05.png]]
 
[[File:Fōrmulæ - Visualize a tree 06.png]]
 
In the following example, it is shown that a matrix is a list containing (same cardinality) sublists:
 
[[File:Fōrmulæ - Visualize a tree 07.png]]
 
[[File:Fōrmulæ - Visualize a tree 08.png]]
 
'''Creating trees programatically'''
 
The tree, like any other expression in Fōrmulæ is a first-class citizen of the language. Fōrmulæ also supports high-order functions, so trees can be set as parameters of functions, or retrieved from functions.
 
The following example shows a function that produces a Fibonacci tree, a tree that shows the calls of a function that recursively calculates Fibonacci numbers:
 
[[File:Fōrmulæ - Fibonacci sequence 03.png]]
 
[[File:Fōrmulæ - Fibonacci sequence 04.png]]
 
[[File:Fōrmulæ - Fibonacci sequence 05.png]]
 
=={{header|FreeBASIC}}==
Line 4,573 ⟶ 4,610:
{{trans|C}}
{{libheader|Wren-dynamic}}
<syntaxhighlight lang="ecmascriptwren">import "./dynamic" for Struct
import "random" for Random
 
2,120

edits