Look Ma no File // Data Viewer as a programmable calculator

Now with While (fm18) and fixed SetRecursion (fm19) a new world might open up:

not only for the 5th grader try prime number factoring in the data viewer:

SetRecursion (
While ( [ //initialVariable

// YOUR POSITIVE INTEGER CANDIDATE HERE:
~zahl = 123123123 ;

~sep = " * " ; // TIMES with spaces

~liste = "" ;
~primefact = 2 // first prime to test
] ; // guarding condition:
~primefact^2 ≀ ~zahl ;

[ //logic -- naΓ―ve

~teilt = Mod ( ~zahl ; ~primefact ) = 0 ;
~zahl = if ( ~teilt ; div ( ~zahl ; ~primefact ) ; ~zahl ) ;
~liste = if ( ~teilt ; list ( ~liste ; ~primefact ) ; ~liste ) ;

~primefact = case ( ~teilt ; ~primefact ; ~primefact = 2 ; 3 ; ~primefact + 2 ) // naΓ―vely step over every odd number

] ; // result:

// Evaluate ( Substitute ( list ( ~liste ; ~zahl ) ; ΒΆ ; ~sep )) // VERIFICATOIN
Substitute ( list ( ~liste ; ~zahl ) ; ΒΆ ; ~sep )
) ; // end while

10^6 ) // end set recursion

5 Likes

Nice example, but for a little more of a challenge, you should implement "The sieve of Eratosthenes". :wink:

Sieve of Eratosthenes - GeeksforGeeks


Being still on FMP 16, I'm a little confused by your code. Since looping and recursion are often seen as equal (but separate) ways of solving a problem, and you're using a while statement, then where is the recursion (and need for "Set Recursion")?

It's hard to understand why a "while" loop would be limited in iterations and you'd need an extra Set Recursion to go beyond 50,000 iterations. Having that extra step is unheard of in traditional programming.

Just curious ... How fast is your code example? I'd like to benchmark it here also.

Maybe this code is similar: Prime factors in java. I would modify this code to remove the System.out.println() until the very end for performance and just add the found prime factors to a StringBuilder or List or something.


I wish my German wasn't so rusty from all those years ago when I could actually speak it (I Know what "zahl" means, at least!).

2 Likes

Does your example run without a file :wink: ?

1 Like

Sorry, just trying to clarify...what do you mean by "file"?

I meant you open the application called FileMaker then without even opening a file you open the data viewer and there on the second tab you can program functionally and thanks to the while (and let) function you have a Turing complete (kind of) language.

My example is just demoing a little naΓ―ve prime factorization not even on the level of a fifth grader but fun to watch and super fast and proof of the point to test a looping calculation in the data viewer where recursion would require a file to provide custom function editor...

2 Likes

Nothing wrong here: while is a recursion under the hood:

Pseudo Custom function WHILE ( condition , logic ) :=

If ( condition ; WHILE ( condition , logic ) , result )

That's what I was afraid of....Another FMI internal hack (like ExecuteSQL being mapped to a "Find").

And, that FMI implementation may explain why the While is so fricken slow relative to Java using the benchmark I did with another developer (FMP's WHILE was about 1/400th the speed of Java). Even JavaScript blows FMP's while away.

Thanks, man. :slight_smile:

It's a nice example. I love code examples like that. :slight_smile:

And, your CF looks really cool and useful.

1 Like

Many languages implement the while as recursion. There is nothing wrong with it. (It s only my conclusion that it is this way BTW - only CII ( Claris international inc.) would tell and maybe they can’t even tell it might come down to the compiler. (Some compilers translate while into recursion then recursion translates into GoTo ...

2 Likes

Thank you @anon45965781 I adore your Java and webservices advocacy BUT my point was not using a custom function. Just opening data viewers second tab no file required. Sorry I didn’t state that. Get a free trial of 19 and edit live the Zahl argument in the data viewer and see how in β€˜real time’ the result displays. Super fast IMHO

1 Like

Gotcha. I thought your posting was really good!

Since FMP19 supports JavaScript, I just found some code and modified it a bit to get the primes for the first 1,000 integers. The JavaScript code ran in one millisecond. WOW!

I may end up getting FMP19, but so far it's been really hard to justify. The main reason I'd get it would be to run forum code (like yours) so I don't have to ask questions... :slight_smile:


For completeness, here's the JavaScript code I ran. This should run in the FMP 19 web viewer also.

Output;

Code took: 1 millisecond(s).
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ Values β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0 β”‚ 2 β”‚
β”‚ 1 β”‚ 3 β”‚
β”‚ 2 β”‚ 5 β”‚
β”‚ 3 β”‚ 7 β”‚
β”‚ 4 β”‚ 11 β”‚
β”‚ 5 β”‚ 13 β”‚
β”‚ 6 β”‚ 17 β”‚
β”‚ 7 β”‚ 19 β”‚
β”‚ 8 β”‚ 23 β”‚
β”‚ 9 β”‚ 29 β”‚
β”‚ 10 β”‚ 31 β”‚
β”‚ 11 β”‚ 37 β”‚
β”‚ 12 β”‚ 41 β”‚
β”‚ 13 β”‚ 43 β”‚
β”‚ 14 β”‚ 47 β”‚
β”‚ 15 β”‚ 53 β”‚
β”‚ 16 β”‚ 59 β”‚
β”‚ 17 β”‚ 61 β”‚
β”‚ 18 β”‚ 67 β”‚
β”‚ 19 β”‚ 71 β”‚
β”‚ 20 β”‚ 73 β”‚
β”‚ 21 β”‚ 79 β”‚
β”‚ 22 β”‚ 83 β”‚
β”‚ 23 β”‚ 89 β”‚
β”‚ 24 β”‚ 97 β”‚
β”‚ 25 β”‚ 101 β”‚
β”‚ 26 β”‚ 103 β”‚
β”‚ 27 β”‚ 107 β”‚
β”‚ 28 β”‚ 109 β”‚
β”‚ 29 β”‚ 113 β”‚
β”‚ 30 β”‚ 127 β”‚
β”‚ 31 β”‚ 131 β”‚
β”‚ 32 β”‚ 137 β”‚
β”‚ 33 β”‚ 139 β”‚
β”‚ 34 β”‚ 149 β”‚
β”‚ 35 β”‚ 151 β”‚
β”‚ 36 β”‚ 157 β”‚
β”‚ 37 β”‚ 163 β”‚
β”‚ 38 β”‚ 167 β”‚
β”‚ 39 β”‚ 173 β”‚
β”‚ 40 β”‚ 179 β”‚
β”‚ 41 β”‚ 181 β”‚
β”‚ 42 β”‚ 191 β”‚
β”‚ 43 β”‚ 193 β”‚
β”‚ 44 β”‚ 197 β”‚
β”‚ 45 β”‚ 199 β”‚
β”‚ 46 β”‚ 211 β”‚
β”‚ 47 β”‚ 223 β”‚
β”‚ 48 β”‚ 227 β”‚
β”‚ 49 β”‚ 229 β”‚
β”‚ 50 β”‚ 233 β”‚
β”‚ 51 β”‚ 239 β”‚
β”‚ 52 β”‚ 241 β”‚
β”‚ 53 β”‚ 251 β”‚
β”‚ 54 β”‚ 257 β”‚
β”‚ 55 β”‚ 263 β”‚
β”‚ 56 β”‚ 269 β”‚
β”‚ 57 β”‚ 271 β”‚
β”‚ 58 β”‚ 277 β”‚
β”‚ 59 β”‚ 281 β”‚
β”‚ 60 β”‚ 283 β”‚
β”‚ 61 β”‚ 293 β”‚
β”‚ 62 β”‚ 307 β”‚
β”‚ 63 β”‚ 311 β”‚
β”‚ 64 β”‚ 313 β”‚
β”‚ 65 β”‚ 317 β”‚
β”‚ 66 β”‚ 331 β”‚
β”‚ 67 β”‚ 337 β”‚
β”‚ 68 β”‚ 347 β”‚
β”‚ 69 β”‚ 349 β”‚
β”‚ 70 β”‚ 353 β”‚
β”‚ 71 β”‚ 359 β”‚
β”‚ 72 β”‚ 367 β”‚
β”‚ 73 β”‚ 373 β”‚
β”‚ 74 β”‚ 379 β”‚
β”‚ 75 β”‚ 383 β”‚
β”‚ 76 β”‚ 389 β”‚
β”‚ 77 β”‚ 397 β”‚
β”‚ 78 β”‚ 401 β”‚
β”‚ 79 β”‚ 409 β”‚
β”‚ 80 β”‚ 419 β”‚
β”‚ 81 β”‚ 421 β”‚
β”‚ 82 β”‚ 431 β”‚
β”‚ 83 β”‚ 433 β”‚
β”‚ 84 β”‚ 439 β”‚
β”‚ 85 β”‚ 443 β”‚
β”‚ 86 β”‚ 449 β”‚
β”‚ 87 β”‚ 457 β”‚
β”‚ 88 β”‚ 461 β”‚
β”‚ 89 β”‚ 463 β”‚
β”‚ 90 β”‚ 467 β”‚
β”‚ 91 β”‚ 479 β”‚
β”‚ 92 β”‚ 487 β”‚
β”‚ 93 β”‚ 491 β”‚
β”‚ 94 β”‚ 499 β”‚
β”‚ 95 β”‚ 503 β”‚
β”‚ 96 β”‚ 509 β”‚
β”‚ 97 β”‚ 521 β”‚
β”‚ 98 β”‚ 523 β”‚
β”‚ 99 β”‚ 541 β”‚
β”‚ 100 β”‚ 547 β”‚
β”‚ 101 β”‚ 557 β”‚
β”‚ 102 β”‚ 563 β”‚
β”‚ 103 β”‚ 569 β”‚
β”‚ 104 β”‚ 571 β”‚
β”‚ 105 β”‚ 577 β”‚
β”‚ 106 β”‚ 587 β”‚
β”‚ 107 β”‚ 593 β”‚
β”‚ 108 β”‚ 599 β”‚
β”‚ 109 β”‚ 601 β”‚
β”‚ 110 β”‚ 607 β”‚
β”‚ 111 β”‚ 613 β”‚
β”‚ 112 β”‚ 617 β”‚
β”‚ 113 β”‚ 619 β”‚
β”‚ 114 β”‚ 631 β”‚
β”‚ 115 β”‚ 641 β”‚
β”‚ 116 β”‚ 643 β”‚
β”‚ 117 β”‚ 647 β”‚
β”‚ 118 β”‚ 653 β”‚
β”‚ 119 β”‚ 659 β”‚
β”‚ 120 β”‚ 661 β”‚
β”‚ 121 β”‚ 673 β”‚
β”‚ 122 β”‚ 677 β”‚
β”‚ 123 β”‚ 683 β”‚
β”‚ 124 β”‚ 691 β”‚
β”‚ 125 β”‚ 701 β”‚
β”‚ 126 β”‚ 709 β”‚
β”‚ 127 β”‚ 719 β”‚
β”‚ 128 β”‚ 727 β”‚
β”‚ 129 β”‚ 733 β”‚
β”‚ 130 β”‚ 739 β”‚
β”‚ 131 β”‚ 743 β”‚
β”‚ 132 β”‚ 751 β”‚
β”‚ 133 β”‚ 757 β”‚
β”‚ 134 β”‚ 761 β”‚
β”‚ 135 β”‚ 769 β”‚
β”‚ 136 β”‚ 773 β”‚
β”‚ 137 β”‚ 787 β”‚
β”‚ 138 β”‚ 797 β”‚
β”‚ 139 β”‚ 809 β”‚
β”‚ 140 β”‚ 811 β”‚
β”‚ 141 β”‚ 821 β”‚
β”‚ 142 β”‚ 823 β”‚
β”‚ 143 β”‚ 827 β”‚
β”‚ 144 β”‚ 829 β”‚
β”‚ 145 β”‚ 839 β”‚
β”‚ 146 β”‚ 853 β”‚
β”‚ 147 β”‚ 857 β”‚
β”‚ 148 β”‚ 859 β”‚
β”‚ 149 β”‚ 863 β”‚
β”‚ 150 β”‚ 877 β”‚
β”‚ 151 β”‚ 881 β”‚
β”‚ 152 β”‚ 883 β”‚
β”‚ 153 β”‚ 887 β”‚
β”‚ 154 β”‚ 907 β”‚
β”‚ 155 β”‚ 911 β”‚
β”‚ 156 β”‚ 919 β”‚
β”‚ 157 β”‚ 929 β”‚
β”‚ 158 β”‚ 937 β”‚
β”‚ 159 β”‚ 941 β”‚
β”‚ 160 β”‚ 947 β”‚
β”‚ 161 β”‚ 953 β”‚
β”‚ 162 β”‚ 967 β”‚
β”‚ 163 β”‚ 971 β”‚
β”‚ 164 β”‚ 977 β”‚
β”‚ 165 β”‚ 983 β”‚
β”‚ 166 β”‚ 991 β”‚
β”‚ 167 β”‚ 997 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜strong text

AFAIK you need a webviewer to run JS in FM19 (sans plugin/service), so that still wouldn't work in the data viewer like @FileKraft was talking about. 1 ms ain't bad though, it's almost worth creating the fmp12 file! :wink:

2 Likes

If someone needs JavaScript without Webviewer, we have some JavaScript functions in MBS FileMaker Plugin to do so.

e.g. see blog entries Using libPhoneNumber for phone number formatting and CRC function in FileMaker using JavaScript

2 Likes

Right, agreed, though the code I ran in 1 millisecond was not in the web viewer (I don't have FMP 19), but rather right in the JS IDE. From what I've heard, the FMP 19 web viewer is pretty fast.


In my replies above, I was posting something related but not meant as a substitute for, or to take anything away from, @FileKraft's cool posting. :slight_smile:

1 Like

Just a small clarification... You don't need 19 to do use JavaScript in the WebViewer. It became much easier to do once we got to 16. But it's been there for a while. 19 was just another step forward in ease of use.

1 Like

Sure, WebView.RunJavaScript is there for over 10 years now.

I've also been able to run JavaScript in a field, using a simple free micro-service and free API since FMP version 12 (8 years).

However, that capability wasn't the point in any of my postings.

Thanks,

FWIW, I did two small programs in both Java and in JavaScript to get the prime number factors of 123123123 per the posting above. In both programs I used a "Set" type to automatically remove duplicates. Thus, there could be a small internal performance penalty for using that data type.

In any case, both programs, using 123123123, ran in 4 ms (rounded). I'm amazed how fast JavaScript programs using Node are!

From what I've heard, FileMaker 19's Data Viewer is also fast.

I don't have 19, so I can't run @FileKraft's example for a benchmark comparison.

Thanks!

My point here was of different nature and not about web viewer java or JavaScript. I don’t want to advocate what has been stated before or sell. Sorry to be frank. Hoped to start a discussion about a new way to program minimally not lowly as in low code. The data viewer to try mini algorithms out is possible. Not ideal in general but ideal to create portable handy Snippet fm code .. thanks everyone!.

2 Likes

Yea I’m with you there. The data viewer is an excellent playground/sketch pad , especially now that we have While(). I keep FM open a lot of the time just for the data viewer, even without an open fmp12 as you’ve said. (Sorry the convo got a bit derailed.)

2 Likes