First go project - String to number calculator

xuanbao · · 338 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I made my first go project. It&#39;s a string to number calculator. I would love to get some feedback on this. <a href="https://github.com/relnod/calcgo" rel="nofollow">https://github.com/relnod/calcgo</a></p> <hr/>**评论:**<br/><br/>Killing_Spark: <pre><p>Would be nice to have variables in there too. You cant evaluate these asts until the user provides an instantiation of the variable, but it would probably be useful if someone builds an app around your library. </p></pre>relnod: <pre><p>Variables are a great idea! I tried implemeting them here <a href="https://github.com/relnod/calcgo/pull/4" rel="nofollow">https://github.com/relnod/calcgo/pull/4</a>. Currently I can only have integer variables, because I&#39;m not sure, whats the best way to pass both integer and float variables to my interpreter. Currently I pass my variables to the Interpreter like this: <code>result, errors := calcgo.Interpret(&#34;a&#34;, map[string]int{&#34;a&#34;: 1, &#34;b&#34;: 2})</code></p> <p>The Interpret function now looks like this: <code>func Interpret(str string, variables ...map[string]int) (float64, []error) {</code></p> <p>Is there a good way to support both integers and floats like this?</p></pre>Killing_Spark: <pre><p>I dont know any unfortunatly. You could make the input floats and require the user to cast ints to floats but that is a bit ugly too :/</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

338 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传