title: How to convert a string from a text input into a function in a Scala
body: <p>I am creating a GUI using Scala which should play a signal dependent on the algorithm but into the textField, eg. sin(2*Pi*400*t). The playing function works perfectly, however the issue is the input for the GUI. The textField takes the function and converts it to a string, now I was wondering is there a simple way to convert the string back into a function. I was considering matching the input to various valid functions, however I don't want to restrict the possible functions, as I want the user to be more create </p>
  
  <p>I am still relatively new to Scala, hopefully one of you have a better idea. Here is the code I have so far, its a basic setup focusing on functionality.</p>
  
  <pre><code>object PlayApp extends SimpleGUIApplication {
    def top = new MainFrame {
      title = "Play Function App"
      val label = new Label("Type in function to be played")
  
      object Function extends TextField ( columns = 10)
      val label2 = new Label("Type in length of time to play")
      object Time extends TextField { columns = 10}  
      val button = new Button("Play")
  
      contents = new BoxPanel(Orientation.Vertical) {
        contents += label
        contents += Function
        contents += label2
        contents += Time
        contents += button
        border = Swing.EmptyBorder(50, 50, 20, 50)
      }
  
      var f = "sin(t)"
      var x = 0
  
      listenTo(Function, Time, button) 
      reactions += {
        case EditDone(Function) =&gt;
          f = Function.text.toString
        case EditDone(Time)     =&gt;
          x = Time.text.toInt
        case ButtonClicked(b)   =&gt;
          play(t =&gt; f.toDouble,0,x)
      }
    }
  }
  </code></pre>