set timeout -1

proc bc_init { {init_string "scale=6\r"} } {
    
    spawn bc
    set I $spawn_id
    send -i $I $init_string
    expect -re "(.*)\r\n" 

    return $I

}

proc bc_eval {spawn_id math_expr} {

    send -i $spawn_id "$math_expr\r"

    expect -re "(.*)\r\n(.*)\r\n" {return $expect_out(2,string)}

}


proc bc_test {} {

    set math_string {2.3 * 4.6666 * 1.1 + 500}
    set j [bc_init]
    set result [bc_eval $j $math_string]

    puts "The evaluation of $math_string is: $result"

}
