Changeset 946

Show
Ignore:
Timestamp:
07/07/2008 06:15:04 (5 months ago)
Author:
james
Message:

tcl 8.5 supports **, so allow that, and work around it on < 8.5

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/en/complex_calculator.tcl

    r936 r946  
    1212 
    1313#                          name   regexp               chance  callback 
    14 bMotion_plugin_add_complex "calculator" {what('s| is) (\(*\s*[0-9.]+(\s*[+/*x%-]\s*\(*\s*[0-9.]+\s*\)*)+\s*\)*)} 100 "bMotion_plugin_complex_calculator" "en" 
     14bMotion_plugin_add_complex "calculator" {what('s| is) (\(*\s*[0-9.]+(\s*([+/*x%-]|\*\*)\s*\(*\s*[0-9.]+\s*\)*)+\s*\)*)} 100 "bMotion_plugin_complex_calculator" "en" 
    1515 
    1616bMotion_plugin_add_complex "calculator2" {what('s| is) the diff(erence)? between (.+ )?\d+,? and (.+ )?\d+} 100 "bMotion_plugin_complex_calculator2" "en" 
     
    2121proc bMotion_plugin_complex_calculator { nick host handle channel text } { 
    2222        if {[bMotionTalkingToMe $text] || [bMotion_interbot_me_next $channel]} { 
    23                 if [regexp -nocase {(\(*\s*[0-9.]+(\s*[+/*x%-]\s*\(*\s*[0-9.]+\s*\)*)+\s*\)*)} $text matches sum] { 
     23                if [regexp -nocase {(\(*\s*[0-9.]+(\s*([+/*x%-]|\*\*)\s*\(*\s*[0-9.]+\s*\)*)+\s*\)*)} $text matches sum] { 
    2424                        set sum [string map { x * } $sum] 
    2525                        set sum [string trim $sum] 
    2626                        set result "failed" 
     27 
     28                        # TCL < 8.5 doesn't know **, so we have to use pow() 
     29                        if {[info pa] < 8.5} { 
     30                                if [regexp {\*\*} $sum] { 
     31                                        bMotion_putloglev d * "calculator: rewriting $sum using pow()" 
     32                                        regsub -all {([0-9]+)\s*\*\*\s*([0-9]+)} $sum {pow(\1,\2)} sum 
     33                                        bMotion_putloglev d * "calculator: new expr is $sum" 
     34                                } 
     35                        } 
     36 
    2737                        catch { 
    2838                                set result [expr $sum] 
     
    5363 
    5464bMotion_abstract_register "calculation_output" { 
     65        "for this problem, i'll need to set my calculator to 'maths'%|%2" 
     66        "%2%|write that down in your copybooks now" 
    5567        "%% = %2" 
    5668        "%% is %2"