{
    "componentChunkName": "component---src-templates-index-template-js",
    "path": "/page/22",
    "result": {"data":{"site":{"siteMetadata":{"title":"Viksit Gaur Online","description":"Viksit's home on the WWW. Estd 1997 :)","url":"https://www.viksit.org"}},"allMarkdownRemark":{"nodes":[{"id":"71d54363-da9c-5cf1-a4f1-b474e2d542ee","html":"<p>I was experimenting with some sequences today, and ran into a stumbling block: Using immutable data structures, how do you execute multiple transformations in series on an object, and return the final value?</p>\n<p>For instance, consider a sequence of numbers,</p>\n<deckgo-highlight-code   >\n          <code slot=\"code\">\nuser&gt; (range 90 100)\n(90 91 92 93 94 95 96 97 98 99)</code>\n        </deckgo-highlight-code>\n<p>How do you transform them such that you increment each number by 1, and then get their text representation,</p>\n<deckgo-highlight-code   >\n          <code slot=\"code\">\n&quot;^_`abcd&quot;</code>\n        </deckgo-highlight-code>\n<p>Imperatively speaking, you would run a loop on each word, and transform the sequence data structure in place, and the last operation would achieve the desired result. Something like,</p>\n<deckgo-highlight-code   >\n          <code slot=\"code\">\n&gt;&gt;&gt; s = &quot;&quot;\n&gt;&gt;&gt; a = \n&gt;&gt;&gt; a\n\n&gt;&gt;&gt; for i in range(0,len(a)):\n...   s += chr(a+1)\n... \n&gt;&gt;&gt; s\n&#39;^_`abcd&#39;\n</code>\n        </deckgo-highlight-code>\n<p>If you knew about maps in python, this could be achieved with something like,</p>\n<deckgo-highlight-code   >\n          <code slot=\"code\">\n&gt;&gt;&gt; &#39;&#39;.join()\n&#39;^_`abcd&#39;</code>\n        </deckgo-highlight-code>\n<p>The easiest way to do this in Clojure is using the excellently named (<a href=\"http://debasishg.blogspot.com/2010/04/thrush-in-clojure.html)(-\">http://debasishg.blogspot.com/2010/04/thrush-in-clojure.html)(-</a>> and ->>). According the doc,</p>\n<blockquote>\n<p>Threads the expr through the forms. Inserts x as the<br>\nsecond item in the first form, making a list of it if it is not a<br>\nlist already. If there are more forms, inserts the first form as the<br>\nsecond item in second form, etc.</p>\n</blockquote>\n<p>It is used like this,</p>\n<deckgo-highlight-code   >\n          <code slot=\"code\">\nuser&gt; (-&gt;&gt; (range 90 100) (map inc) (map char) (apply str))\n&quot;^_`abcd&quot;</code>\n        </deckgo-highlight-code>\n<p>Basically, the line, (-> 7 (- 3) (- 6)) implies that 7 be substituted as the first argument to -, to become (- 7 3). This result is then substituted as the first argument to the second -, to get (- 4 6), which returns -2.</p>\n<deckgo-highlight-code   >\n          <code slot=\"code\">\nuser&gt; (-&gt; 7 (- 3) (- 6))\n-2</code>\n        </deckgo-highlight-code>\n<p>Voila!</p>\n<p>--</p>\n<p><em>If you have any questions or thoughts, don't hesitate to reach out. You can find me as <a href=\"http://twitter.com/viksit\">@viksit</a> on Twitter.</em></p>","excerpt":"I was experimenting with some sequences today, and ran into a stumbling block: Using immutable data structures, how do you execute multiple transformations in series on an object, and return the final value? For instance, consider a sequence of…","frontmatter":{"title":"Thrush Operators in Clojure (->, ->>)","date":"May 08, 2010","slug":"/blog/thrush-operators-in-clojure","tags":null}},{"id":"1d46437a-6643-5d0a-b381-28b2f77b6b6a","html":"<center>!(http://nikonizer.yfrog.com/Himg265/scaled.php?tn=0&server=265&filename=po7.png&xsize=640&ysize=640)</center>This is what the stock market looked like at 2pm today.\n<p>From the (<a href=\"http://www.reuters.com/article/idUSTRE6341EA20100506)\">http://www.reuters.com/article/idUSTRE6341EA20100506)</a><a></a>,</p>\n<blockquote>\n<p>The Dow suffered its biggest ever intraday point drop, which may have been caused by an erroneous trade entered by a person at a big Wall Street bank, multiple market sources said.</p>\n</blockquote>\n<p>and the suspected cause? A UI Glitch!</p>\n<blockquote>\n<p>In one of the most dizzying half-hours in stock market history, the Dow plunged nearly 1,000 points before paring those losses—all apparently due to a trader error.</p>\n<p>According to multiple sources, a trader entered a “b” for billion instead of an “m” for million in a trade possibly involving Procter &#x26; Gamble , a component in the Dow. (CNBC’s Jim Cramer noted suspicious price movement in P&#x26;G stock on air during the height of the market selloff. Watch.)</p>\n<p>Sources tell CNBC the erroneous trade may have been made at Citigroup .</p>\n<p>“We, along with the rest of the financial industry, are investigating to find the source of today’s market volatility,” Citigroup said in a statement. “At this point we have no evidence that Citi was involved in any erroneous transaction.”</p>\n<p>According to a person familiar with the probe, one focus is on futures contracts tied to the Standard &#x26; Poor’s 500 stock index, known as E-mini S&#x26;P 500 futures, and in particular a two-minute window in which 16 billion of the futures were sold.</p>\n<p>Citigroup’s total E-mini volume for the entire day was only 9 billion, suggesting that the origin of the trades was elsewhere, according to someone close to Citigroup’s own probe of the situation. The E-minis trade on the CME.</p>\n</blockquote>\n<p>--</p>\n<p><em>If you have any questions or thoughts, don't hesitate to reach out. You can find me as <a href=\"http://twitter.com/viksit\">@viksit</a> on Twitter.</em></p>","excerpt":"From the (http://www.reuters.com/article/idUSTRE6341EA20100506), The Dow suffered its biggest ever intraday point drop, which may have been caused by an erroneous trade entered by a person at a big Wall Street bank, multiple market sources said. and…","frontmatter":{"title":"Stock Crash","date":"May 06, 2010","slug":"/blog/stock-crash","tags":null}},{"id":"47c2dceb-c537-5b9e-ad81-ff076e20f0c9","html":"<p>Its surprising that the modulus (%) operator in C++ works upwards, but not downwards. When working on some code, I expected,</p>\n<p><cpp></cpp></p>\n<p>-1 % 3 = 2<br>\n0 % 3 = 0<br>\n1 % 3 = 1<br>\n2 % 3 = 2</p>\n<p>but ended up with,</p>\n<p><cpp></cpp></p>\n<p>-1 % 3 = -1<br>\n0 % 3 = 0<br>\n1 % 3 = 1<br>\n2 % 3 = 2</p>\n<p>As a result, you’d need to ensure that either you check that your result is</p>\n<p>result = n % 3;<br>\nif( result</p>\n<p>Or, a better solution might be to change the expression such that the negative case never arises,</p>\n<cpp>  \n{ int n = 0; int inc = -1; cout </cpp>\n<p>Hope this helps someone out there!</p>\n<p>--</p>\n<p><em>If you have any questions or thoughts, don't hesitate to reach out. You can find me as <a href=\"http://twitter.com/viksit\">@viksit</a> on Twitter.</em></p>","excerpt":"Its surprising that the modulus (%) operator in C++ works upwards, but not downwards. When working on some code, I expected,  -1 % 3 = 2 0 % 3 = 0 1 % 3 = 1 2 % 3 = 2 but ended up with,  -1 % 3 = -1 0 % 3 = 0 1 % 3 = 1 2 % 3 = 2 As a result, you’d…","frontmatter":{"title":"C++ Modulus Operator weirdness","date":"May 01, 2010","slug":"/blog/c-modulus-operator-weirdness","tags":null}},{"id":"3309c064-8dde-5dcc-94cc-55dcd221e271","html":"<p>I was trying to implement a simple binary search using a purely functional approach, and after much hacking, googling and wikibooking, came up with this in Clojure.</p>\n<clojure>  \n(defn binarysearch  \n ( \\  \n (binarysearch lst 0 (dec (count lst)) n))  \n ( \\  \n (if (&gt; lb ub) -1 ; this is the case where no element is found  \n (let [mid (quot (+ lb ub) 2)  \n mth (nth lst mid)]  \n (cond  \n ; mid &gt; n, so search lower  \n (&gt; mth n) (recur lst lb (dec mid) n)  \n ; mid </clojure>\n<p>--</p>\n<p><em>If you have any questions or thoughts, don't hesitate to reach out. You can find me as <a href=\"http://twitter.com/viksit\">@viksit</a> on Twitter.</em></p>","excerpt":"I was trying to implement a simple binary search using a purely functional approach, and after much hacking, googling and wikibooking, came up with this in Clojure. -- If you have any questions or thoughts, don't hesitate to reach out. You can find…","frontmatter":{"title":"Implementing Binary Search with Clojure","date":"April 20, 2010","slug":"/blog/implementing-binary-search-with-clojure","tags":null}},{"id":"250294a9-0eaf-51d2-9395-dc71ae319c50","html":"<p>I was recently looking for a method to create an application with Clojure that would allow specification of command line arguments.</p>\n<p>I came across an excellent (<a href=\"http://stackoverflow.com/questions/1341154/building-a-clojure-app-with-a-command-line-interface\">http://stackoverflow.com/questions/1341154/building-a-clojure-app-with-a-command-line-interface</a>) on Stack Overflow by (<a href=\"http://stackoverflow.com/users/128927/alanlcode\">http://stackoverflow.com/users/128927/alanlcode</a>), that provides a spectacular example. I’ve (<a href=\"http://gist.github.com/367681\">http://gist.github.com/367681</a>) it for reference.</p>\n<script src=\"http://gist.github.com/367681.js\"></script>\n<p>--</p>\n<p><em>If you have any questions or thoughts, don't hesitate to reach out. You can find me as <a href=\"http://twitter.com/viksit\">@viksit</a> on Twitter.</em></p>","excerpt":"I was recently looking for a method to create an application with Clojure that would allow specification of command line arguments. I came across an excellent (http://stackoverflow.com/questions/1341154/building-a-clojure-app-with-a-command-line…","frontmatter":{"title":"Clojure Application with Command Line Arguments","date":"April 15, 2010","slug":"/blog/clojure-application-with-command-line-arguments","tags":null}}]}},"pageContext":{"limit":5,"skip":105,"numPages":27,"currentPage":22}},
    "staticQueryHashes": ["4202924991","512065377"]}