Chemical calculator: Difference between revisions

Added Fōrmulæ entry
(Added Fōrmulæ entry)
Line 1,756:
No assertion errors.
 
<!--
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Chemical_calculator}}
In [http://wiki.formulae.org/Chemical_Calculator this] page you can see the solution of this task.
 
'''Solution'''
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
Fōrmulæ has a module for chemistry. Notice that it is not a library, it effectively adds chemical elements as first class citizens to the language, and useful functions that operate with them, for example, to get their atomic masses.
 
There is an expression for a '''homonuclear compound''', a compound made from the union of several atoms of the same element, such as O<sub>2</sub>
 
There is also an expression for a '''heteronuclear compound''', a compound made from the union of several atoms of different elements, such as NaCl
 
[[File: Fōrmulæ - Chemical calculator 01.png]]
 
'''Notes'''
 
* The Tag(Expression) expression retrieves the tag of an expression. For example, when it is called on an homonuclear compound expression, it retrieves the string expression representing the string "Chemistry.HomonuclearCompound"
 
* The |Expression| retrieves the cardinality of the expression, this is, the number of subexpressions it has. If the expression is a heteronuclear compound it gives the number of elements being composed.
 
* If the expression given as parameter is a heteronuclear compound expression, the molar mass is the sum of the molar masses of each component. Note that this function is recursively called.
 
* If the expression given as parameter is a homonuclear compound expression, the molar mass is the product of the number of the group (the second component) and the molar mass of the expression (the first component). Note that this function is recursivelly called.
 
* Elsewhere, the result is the call of the GetAtomicMass(Expression) with the expression given as parameter.
 
'''Test cases'''
 
[[File: Fōrmulæ - Chemical calculator 02.png]]
 
[[File: Fōrmulæ - Chemical calculator 03.png]]
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
-->
=={{header|Go}}==
This doesn't use regular expressions, RPN or eval (which Go doesn't have). It's just a simple molar mass evaluator written from scratch.
2,120

edits