Tcl and Javascript and PHP Calculator Tutorial

Tcl and Javascript and PHP Calculator Tutorial

Tcl and Javascript and PHP Calculator Tutorial

It’s a “blown mind” that has led me to involve Javascript to make the incarnation of our calculator of Tcl and PHP Calculator Tutorial allow for some round bracket functionality around the TCL (expr) “kernel” (sorry, Unix … my apologies LinusLinux). The nexus between what a user may enter, versus the hierarchy needs of TCL’s expr command just blew my mind, manperson!

So what did we turn to? Modernizing one’s thinking? We’re onto it? But we digress. Well, well.

We turned to Javascript’s eval function, not PHP’s eval, nor TCL’s eval version, thanks, but no thanks. Nevertheless … and didn’t you just know that “but” would be insulted by the paragraph above?! … use of Javascript eval (for round bracketing scenarios or operator hierarchy scenarios) is not the “cakewalk” that you may imagine. That is because …


6 ** 2 // in TCL "to the power of" operator syntax (which remains our web application display choice for the user) has ...
Math.pow(6, 2) // Javascript equivalent (behind the scenes)

… so we need to cater for that possibility. The Javascript logic is called at the document.body onload event.

As we often do here, the “progression” of logic was to convert some “hardcoded” HTML text (specifically “First Number:” and “:Second Number”) into HTML select (dropdown) elements to the left and to the right (respectively) of the “TCL kernel”, with additional options for the round bracketing the user may want. These dropdowns move out to the edges of the webpage as they make room for user entered additions to the calculation complexity of what they want to calculate. The “Math.pow()” logic needed benefits from the event timing thoughts on the dropdown’s onchange event logic, otherwise you’d be doing that dreaded of all dreadeds, in many programmers’ worlds methinks, tracking back through entered “calculator equation” texts to discover when a numerical value becomes an operator, a horrible job when a minus sign can be either, for example. These same “horrible” programming tasks would have been at the fore to making a “TCL only backend solution” come to pass, we are sure, too.

Can you see from all this how well (clientside) Javascript works with (serverside) PHP? They are a very potent duo, because it is like two bites at the cherry, every time, with their different timings of the application of their logics.

The downloadable PHP source code calculator.php changed this way to achieve this extension of functionality still supervising an unchanged calculator.tcl TCL source code script, and here is a live run link for you to try this calculator for yourself.


Previous relevant Tcl and PHP Calculator Tutorial is shown below.

Tcl and PHP Calculator Tutorial

Tcl and PHP Calculator Tutorial

The Tcl and PHP Primer Tutorial was a foretaste to today’s calculator web application that …

  • uses PHP as a frontend and (HTML) form navigation destination …
  • connects to backend via PHP exec
  • uses TCL as backend … via …

    exec("tclsh calculator.tcl < calculator.txt | tail -1 > calculator.out");

Crucial to the TCL’s backend role is TCL’s expr command, as a determinant regarding what today’s calculator is capable of.

Here is a link to some downloadable PHP source code calculator.php supervising calculator.tcl TCL source code, and here is a live run link.


Previous relevant Tcl and PHP Primer Tutorial … http://www.tcl.tk/software/tcltk/ is shown below.

Tcl and PHP Primer Tutorial ... http://www.tcl.tk/software/tcltk/

Tcl and PHP Primer Tutorial ... http://www.tcl.tk/software/tcltk/

Have you heard of Tcl/Tk? Think maybe you could introduce yourself to it with Tcl/Tk So Brilliant (but where do you start?) Primer Tutorial as shown below.

The Tcl in Tcl/Tk refers to the scripting side of things, while the Tk is a GUI framework. On some (maybe lots) of Linux or unix web servers, such as the one for this domain here at www.rjmprogramming.com.au Tcl scripting is available and that means Tcl could be used by PHP, as a server side language to use the exec method to ask something of Tcl and get something back, half of which is the arrangement we’d like to have when feeding our babies.

Today we write a webpage for finding the Country of Origin of a designated URL where PHP supervises Tcl:

  1. ask for a URL in PHP,
  2. send that to the same PHP with a different call …
  3. and use PHP exec method to send a Tcl commend line command to Tclsh and output this to a file known by the PHP,
  4. get the PHP to read the file of step 3. and send that information in a modified call of this same PHP,
  5. write out the Tcl based findings to the webpage in PHP,
  6. ask for a URL in PHP

Here is a link to some downloadable PHP source code domain.php supervising domain.tcl TCL source code, and here is a live run link.

Thanks to:


Previous relevant Tcl/Tk So Brilliant (but where do you start?) Primer Tutorial is shown below.

Tcl/Tk So Brilliant (but where do you start?) Primer Tutorial ... http://www.tcl.tk/software/tcltk/Tcl/Tk So Brilliant (but where do you start?) Primer Tutorial ... http://www.tcl.tk/software/tcltk/

Tcl/Tk So Brilliant (but where do you start?) Primer Tutorial ... http://www.tcl.tk/software/tcltk/

Have you heard of Tcl/Tk?

Tcl/Tk is open source (based on a BSD-style license), so you can use it and modify it virtually any way you want, including for commercial uses.

With Tcl/Tk have used in conjunction with C++ and Python (look out for Tkinter).

Use it for Games Programming (it makes pretty cute GUIs … you may disagree?!) and it used to work back at Mac OS X 10.5.8/XCode 3.0 (am going to try Mac OS X 10.7.5 … any advice anywhere?) and had it going on Windows XP with Visual Studio Express as well. It has a lot of cross-platform strengths.

Think Tcl/Tk is really really good.

In this primer tutorial you can see a Draw Poker game as an XCode project, see it Build and in action, then see how to arrange for *.dmg Package Distribution via Package Manager.

Link to Tcl/Tk website … Home of Tcl/Tk … where quote up the top resides
Link to Tcl/Tk jobs done … Tcl/Tk jobs done … personal experience

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Software, Tutorials and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>