MoleculeName ( )

Function stats

Average user rating
34
162
9999
Support
FileMaker 8.0 +
Date posted
23 December 2008
Last updated
26 December 2008
Version
Recursive function
Yes

Author Info
 The Shadow

22 functions

Average Rating 4.3

author_avatar



 

Function overview

Prototype

MoleculeName  ( inputName )


Parameters

inputName  The molecule description


Description

Tags:  Format   Chemistry  

Reformats a string of letters as numbers to attempt to make it look like a chemical.

Examples

Sample input

MoleculeName( “C11 H13 O4N2”; “” )


Sample output

C11H13O4N2 (but subscripted properly)

 

Function code

If ( IsEmpty(inputName); "";
   Let( [ letter = Left( inputName; 1 );
            remain = Right( inputName; Length(inputName) - 1 )
          ];

          Case ( letter = " ";  "";
                    letter = "0" or GetAsNumber(letter) <> 0;
                    TextStyleAdd ( letter; Subscript );
letter )
          & MoleculeName( remain )
   )
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/162

    Prototype: MoleculeName( inputName )
    Function Author: The Shadow (http://www.fmfunctions.com/mid/34)
    Last updated: 26 December 2008
    Version: 2.0

*/
// ===================================

 

Comments

Daniele Raybaudi
25 December 2008



Hi Shawn

I do not see the need of the second parameter.

Also I had some difficulty to understand your way to obtain some things ( like your IsNumber verification ).

I would write the same function in this way:

MoleculeName ( inputName )

Let([
adj = Substitute ( inputName ; " " ; "" ) ;
char = Left ( adj ; 1 ) ;
rest = Right ( adj ; Length ( adj ) - 1 )
];
Case(
Length ( adj ) ; If ( GetAsNumber ( char ) ≠ "" ; TextStyleAdd ( char ; Subscript ) ; char ) & MoleculeName ( rest )
)
)
(Edited by Daniele Raybaudi on 25/12/08 )
  General comment
Daniele Raybaudi
26 December 2008



Hi Shawn

didn't you like to have a discussion with me ?

I only said you my point of view and you could kindly say me that your molecula is a very big one !

So big to justify a tail recursion. ;)

Changing your code without an answer or a new comment from you seems inappropriate to the focus of this site: exchange ideas and knowledge.

Anyway I'm still waiting for your way to test if the "letter" is a number: why it's better:

letter = "0" or GetAsNumber(letter) <> 0

vs

GetAsNumber ( letter ) ≠ ""
  General comment
The Shadow
26 December 2008



Daniele, Sorry I didn't reply. I originally wrote this function soon after FM7 had come out, and I was pushing the concept of writing functions as tail-recursive. It wasn't appropriate for this function, as you point out, the input is likely quite small.

You are probably quite correct about the other change as well, it seems like an improvement, but I had to run to a Xmas party with the family and so wasn't willing to test it out.
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (31)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (12)
Layout Objects  (11)
Filter  (11)
Design  (10)
Array  (7)