Need Help in understanding Pointer exercise Please

blov · · 537 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi Everybody. </p> <p><strong>UPDATE</strong> First of all, thanks for the helps you guys provided. I realize that this was a MASSIVE problem, and I couldn&#39;t quite put a finger on it, but finally I succeeded. I think I&#39;ve got a good understanding now what is happening and what needs to go where. There is still a lot to improve on the code, but I removed all of the duplications mostly. <a href="https://github.com/Skarlso/goprojects/blob/master/exercism/react.go">https://github.com/Skarlso/goprojects/blob/master/exercism/react.go</a>. What I still want to do is to create a proxy on the CreateCompute1-2 because it largely does the same thing. And now because the computeFunction is an interface{} it can be anything. But is later cast though. So maybe I change it to func(...int) instead. </p> <p>Cheers everyone!</p> <p>I would like to request help in understanding a golang exercise. </p> <p>It is an exercise which is described in exercism.go. Unfortunately there have been very few solutions on this, because I&#39;ve got quite far ahead. And to be fair and honest, I don&#39;t quite get the three which are there and I can&#39;t learn from them. </p> <p>I understand what I should do, for the exercise, please read the readme, on my github page here =&gt; <a href="https://github.com/Skarlso/goprojects/tree/master/exercism">https://github.com/Skarlso/goprojects/tree/master/exercism</a></p> <p>It&#39;s basic. You have a couple of cells. If one changes, those who are registered to that Cell, also change their values based on a compute Function which they have. </p> <p>Easy enough in theory. I got as far as what you see. I understand that I need a pointer reference in the input cell so that when it calls its listeners, those listeners are able to change their respective values. I just can&#39;t get it done. I got completely confused where and what to point at. </p> <p>I&#39;ve got so far that I have a connection with MyReact which holds the listeners for an Input Cell. Got so far, that I can call the compute function which computes the new value.</p> <p>Also, a computed cell can have callbacks but that&#39;s something which should be relatively easy. </p> <p>Thanks, any help is much appreciated. I want to learn this stuff, but at this point, I&#39;m just lost. :( </p> <p><strong>EDIT</strong> Fixed my typos, huh quite a lot of them... :)</p> <p><strong>EDIT2</strong> I appreciate ANY help. I do NOT would like to have a complete solution of this exercise, sorry if that wasn&#39;t clear. I just would like to have some kind of nudge into some direction as I&#39;m lost where and how to continue. Don&#39;t bother to try and solve the whole thing. Though I know that it would be difficult to give advice without it. Well this is only for the not faint of heart people. :) </p> <p>THANK YOU! Gergely.</p> <hr/>**评论:**<br/><br/>dilap: <pre><p>I think it&#39;s too big an ask to have people go out and read an entire exercise and solve it for you.</p> <p>Suggestion: Try to find the exact point of confusion where you&#39;re getting stuck, and distill that into a self-contained example that, if it were solved, would help you get unstuck.</p> <p>Then post that as a question.</p></pre>skarlso: <pre><p>I understand that. Sorry if that wasn&#39;t very clear. :) I don&#39;t want them to solve the entire exercise!! Just give me a couple of &#34;pointers&#34; (pun intended). </p> <p>I&#39;m lost where to put what. I don&#39;t want a complete solution. Just a nudge into <em>some</em> direction. </p> <p>My problem is, that I don&#39;t know exactly what my problem is, and where it is. :) </p></pre>dilap: <pre><p>Well, speaking for myself personally, even reading and understanding that whole exercise was too much effort!</p> <p>But if you have a question that can be put in the form of a self-contained comment, I&#39;ll take a crack at answering it. :)</p></pre>skarlso: <pre><p>Thanks man. :) I&#39;ll try and formulate it better. Let me work something out for ya. :) </p></pre>dilap: <pre><p>looks like <a href="/u/sethammons" rel="nofollow">/u/sethammons</a> beat me to it!</p></pre>skarlso: <pre><p>Okay, so here is one. </p> <p>How do I make this guy =&gt; connections map[Cell][]*Cell</p> <p>Receive a bunch of pointers to a Cell? </p> <p>If I do this =&gt; connections := append(r.connections[cell.(InputCell)], *myComputeCell1)</p> <p>It says invalid redirect. I need Pointers to Cells here because I need them to CHANGE based on the change of another cell.</p> <p>So if I need it to change it needs to be a pointer. Using &amp; here is pointless since that gives back the address, right? </p> <p>Input cell is the key, which will have a bunch of depending cells in this map which it will cycle through and notify of a value change.</p></pre>sethammons: <pre><p>Are you trying to do something like the following? <a href="http://play.golang.org/p/DeAmSco_8o">http://play.golang.org/p/DeAmSco_8o</a></p></pre>skarlso: <pre><blockquote> <p><a href="http://play.golang.org/p/DeAmSco_8o" rel="nofollow">http://play.golang.org/p/DeAmSco_8o</a></p> </blockquote> <p>Exactly!! </p> <p>I was doing the same thing, though I had several other problems. :) </p> <p>Like, I was trying to reference an interface, rather than an struct. Also, I had a wrong linking of pointers somewhere in my code. </p> <p>I&#39;m sorry guys, I know this is too complex to be a simple problem. But than again, rarely anything is simple in the world of software development. :) </p> <p>Thanks for the effort of helping though!!! Much appreciated!</p></pre>

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

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