{"id":17,"date":"2004-10-05T22:32:18","date_gmt":"2004-10-05T20:32:18","guid":{"rendered":"http:\/\/ken.friislarsen.net\/blog\/?p=17"},"modified":"2004-10-05T22:32:18","modified_gmt":"2004-10-05T20:32:18","slug":"callcc-for-moscow-ml","status":"publish","type":"post","link":"http:\/\/ken.friislarsen.net\/blog\/2004\/10\/05\/callcc-for-moscow-ml\/","title":{"rendered":"callcc for Moscow ML"},"content":{"rendered":"<p>The last few days I have tried to recreate my implementation of <code>callcc<\/code> for <a href=\"http:\/\/www.dina.kvl.dk\/~sestoft\/mosml.html\">Moscow ML<\/a>.  My original (incomplete) implementation was lost last fall when my old laptop was stolen (or it is still lurking somewhere in mess which is my old backup system).<\/p>\n<p>The code <em>almost<\/em> works. For example, the following code, which just ignores the continuation value <code>k<\/code>:<\/p>\n<pre>\n3 + callcc (fn k => 2 + 1);\n<\/pre>\n<p>Gives <code>6<\/code>, as it should.<\/p>\n<p>However, the following more interesting example, which actually uses the continuation value:<\/p>\n<pre>\n3 + callcc (fn k => 2 + throw (k, 1));\n<\/pre>\n<p>Gives <code>67299815<\/code> and not <code>4<\/code>. Ouch! <\/p>\n<p>Likewise, given the following declaration of <code>multiply<\/code>:<\/p>\n<pre>\nfun multiply ints =\n    callcc (fn ret =>\n    let\n        fun mult nil = 1\n          | mult (0::_) = throw (ret, 0)\n          | mult (n::ns) = n * mult ns\n    in\n\tmult ints\n    end)\n<\/pre>\n<p>The expression:<\/p>\n<pre>\nmultiply [1,2,3,4,0,5];\n<\/pre>\n<p>evaluates to <code>67299810<\/code> and not <code>0<\/code>. Double ouch!!<\/p>\n<p>My guess is that I somehow mess things up when I restore the stack, and some pointer ends up on top of the stack.  But I&#8217;m too tired to debug this futher tonight.<\/p>\n<p>One nifty feature of my code (if I can get it to work) is that it is implemented using the <code>Dynlib<\/code> library.  Which means that <strong>no<\/strong> changes are needed to the original Moscow ML code, it is all in a seperate library.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The last few days I have tried to recreate my implementation of callcc for Moscow ML. My original (incomplete) implementation was lost last fall when my old laptop was stolen (or it is still lurking somewhere in mess which is my old backup system). The code almost works. For example, the following code, which just <a class=\"read-more\" href=\"http:\/\/ken.friislarsen.net\/blog\/2004\/10\/05\/callcc-for-moscow-ml\/\">[&hellip;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-sml"],"_links":{"self":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":0,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"wp:attachment":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}