tag:blogger.com,1999:blog-2441850399540300710.post5122762696422636093..comments2024-02-17T03:47:06.818-08:00Comments on CraigBlog: Implementations of Slideshow in C# and ClojureCraig Anderahttp://www.blogger.com/profile/17084199593129216563noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-2441850399540300710.post-20252367355007942402010-03-18T04:39:46.000-07:002010-03-18T04:39:46.000-07:00@Lau: ha, yes, I now remember seeing your ASCII ar...@Lau: ha, yes, I now remember seeing your ASCII art post last month. Good stuff!craig-anderanoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-74166499673538643992010-03-18T03:53:21.000-07:002010-03-18T03:53:21.000-07:00Interesting Finds: March 18, 2010Interesting Finds: March 18, 2010Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-17405131475905975602010-03-17T11:24:20.000-07:002010-03-17T11:24:20.000-07:00Hey Craig,
Np - Fun task.
Regarding gensym then ...Hey Craig,<br /><br />Np - Fun task.<br /><br />Regarding gensym then you can simply try changing to the # format and run (macroexpand-1 '(props img .getHeight .getWidth)) to see the results. You'll notice that a different gensym is generated for each iteration of the for-loop. This is intentional, though not optimal for a job such as this.<br /><br />If you're interested in how the macro came to be, you can check out this thread, as a Microsoft guy I suppose you'll like it :)<br /><br />http://www.bestinclass.dk/index.php/2010/02/my-tribute-to-steve-ballmer/Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-74773440992359105202010-03-17T11:10:40.000-07:002010-03-17T11:10:40.000-07:00One question that springs to mind is whether Cloju...One question that springs to mind is whether Clojure's gensym support (the # suffix) wouldn't make the macro a little easier to read. But perhaps I'm missing something.craig-anderanoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-87773711019991771332010-03-17T11:06:03.000-07:002010-03-17T11:06:03.000-07:00Very cool, Lau. Thanks for taking the time to have...Very cool, Lau. Thanks for taking the time to have a look. I really like the props macro, and the rest of the cleanup you did makes sense to me, too. The idea of using a future with sleep is also nice - as you say, the timer introduces unnecessary complexity. <br /><br />Your use of when-let is an obvious "duh" now that I see it - I suppose I should always be on the lookout for an "if" where one of the clauses evaluates to nil. As you say, my C# background is showing here - like others I've found that it's not the switch to Clojure so much as the switch to functional that's difficult. <br /><br />An interesting experiment for me would be to see if some of these changes would survive the translation to C#. <br /><br />The named variables were generally there as leftovers from debugging - pasted in from intermediate steps in the REPL. Along the same lines, the C# version actually squishes compute-bounds and fit-to together, as I've got a repeated calculation in there. That would make it even shorter and (hopefully) clearer. <br /><br />All in all, it has been an interesting experiment. Thanks again for helping out with it!craig-anderanoreply@blogger.comtag:blogger.com,1999:blog-2441850399540300710.post-47239474090274120662010-03-17T10:11:03.000-07:002010-03-17T10:11:03.000-07:00Hey,
First of all I think you did a very very job...Hey,<br /><br />First of all I think you did a very very job stepping into Clojure. Though in a few places it shows that you're used to C#.<br /><br />For instance do you define the sequence using a loop with side-effects, it takes an extra line to implement it in a purely functional lazy sequence, but I think its worth it. Secondly I see you add a lot of named variables which in more than a few cases isn't necessary or helpful. <br /><br />I rewrote your code to address those two issues, which brought the code-size down to about 95 lines. Then it dawned on me, that you don't need another mutable construct to determine a 'currentimage', since all you need is a randomly selected index. In addition I don't see why exactly you'd want a timer, since a future would have the exact same effect. <br /><br />So with the above in mind I added a macro to simplify some of the repetive Java interop and that brought the code down to 85 lines without loosing anything (I hope), so we're coming up on 50% of the C# code. You can read the code here:<br /><br />http://gist.github.com/335511<br /><br />Hope to see more from you in the near future,<br />Lau JensenAnonymousnoreply@blogger.com