<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/15537" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2008-03-16T17:14:53-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/15537</id>

		<entry>
		<author><name><![CDATA[strikelight]]></name></author>
		<updated>2008-03-16T17:14:53-04:00</updated>

		<published>2008-03-16T17:14:53-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=81828#p81828</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=81828#p81828"/>
		<title type="html"><![CDATA[Creating a New Math Function?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=81828#p81828"><![CDATA[
Well, if you want to modify an existing command... you'd have to first rename the original command, and write a proc that is named after the command you are modifying... and within that proc scan for what you are looking for, and remember to call the renamed command for things you aren't looking for.....<br><br>eg.<div class="codebox"><p>Code: </p><pre><code># rename the expr command to oexprrename expr oexpr#write our new expr commandproc expr {args} {  set newargs [list]# let's create a new function that computes the sum between 1..N# sum(N)  foreach item $args {    if {[regexp {sum\((.*)\)} $item - num]} {      set sres 0      for {set i 1} {$i &lt;= $num} {incr i} {        incr sres $i      }# add our result to the new arguments that we'll call the original# expr command with      lappend newargs $sres    } else {# not interested in this.. just add it to the arguments to call original# expr command with      lappend newargs $item    }  }  if {([llength $newargs] == 1) &amp;&amp; [info exists sres]} {# only our command was found in the expression, so just return the result    return [lindex $newargs 0]  } else {# call the original expr command    return [oexpr [join $newargs]]  }}</code></pre></div>example usage:<div class="codebox"><p>Code: </p><pre><code>% expr sum(10)55% expr 5 + sum(10)60</code></pre></div>Hope this helps...<br><br>Edit:<br>After some investigating,<br>In more modern Tcl versions,<br>you can define a math function in the tcl::mathfunc namespace, making things alot easier and nicer....<br><br>eg.<div class="codebox"><p>Code: </p><pre><code>proc tcl::mathfunc::sum {num} {   set sres 0  for {set i 1} {$i &lt;= $num} {incr i} {     incr sres $i   }  return $sres }</code></pre></div>And you would just use it the same way as above...<div class="codebox"><p>Code: </p><pre><code>% expr sum(10)55</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2005">strikelight</a> — Sun Mar 16, 2008 5:14 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dokueki]]></name></author>
		<updated>2008-03-16T16:14:00-04:00</updated>

		<published>2008-03-16T16:14:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=81826#p81826</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=81826#p81826"/>
		<title type="html"><![CDATA[Creating a New Math Function?]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=81826#p81826"><![CDATA[
I Googled it, but all I got was weird instructions I couldn't really understand. It'd be lovely if anyone could give me an example of how to make a new math function for expr that takes one argument, and show how to take more. Thanks in advance :)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8949">dokueki</a> — Sun Mar 16, 2008 4:14 pm</p><hr />
]]></content>
	</entry>
	</feed>
