[plt-scheme] Re: Text-contents to a function variable

From: Stephen Bloch (bloch at adelphi.edu)
Date: Thu Jan 14 18:56:55 EST 2010

On Jan 14, 2010, at 12:30 PM, Avi wrote:

> Goal: To balance a chemical compound
> I have GUI that when a user enters 2 elements in seperate text boxes,
> the element charges are plugged into a function that processes every
> combination of the charge multiplied by 1 2 and 3

How about this: forget about the GUI and the text boxes for a while, and get the other parts of the program to work.  Write a function that takes an element name (as a string) and returns its charge (presumably by some kind of table lookup).  Write a function that takes in two element names and generates all these combinations (presumably by calling the first function), looking for combinations that will make the equation balance.  Once you have all these things tested and debugged, THEN start worrying about a GUI.

Yet another case of starting a program by thinking about I/O first, rather than last....

I guess I can understand this impulse in a development environment that doesn't come with an interactive REPL: you CAN'T test your functions until you have a way to input the arguments, and a way to print the results.  (Even this isn't technically true -- you can write test cases that call the function on known arguments and compare the results with known right answers, printing out "success" or "failure" for each test case.)  But if you have DrScheme (or, for Java, BlueJ), this is unnecessary: you can concentrate on solving the real problem first, and come back to the I/O details later.


Stephen Bloch
sbloch at adelphi.edu





Posted on the users mailing list.