{"id":33,"date":"2008-04-23T16:28:49","date_gmt":"2008-04-23T20:28:49","guid":{"rendered":"http:\/\/hoolihan.net\/blog-tim\/?p=33"},"modified":"2010-04-09T11:48:30","modified_gmt":"2010-04-09T16:48:30","slug":"curry-in-ruby","status":"publish","type":"post","link":"http:\/\/hoolihan.net\/blog-tim\/2008\/04\/23\/curry-in-ruby\/","title":{"rendered":"Curry in Ruby"},"content":{"rendered":"<p>Inspired by some currying examples in scheme, I wanted to try them in Ruby&#8230;<\/p>\n<pre>\r\n<code>def seq(oldfirst, keepold)\r\n  lambda do |new, old, item, list|\r\n    list.push(new) if old==item and\u00a0 !oldfirst\r\n    list.push(item) if keepold or old != item\r\n    list.push(new) if oldfirst and old==item\r\n  end\r\nend\r\n\r\ndef insertF(new, old, list, func)\r\n  temp = []\r\n  list.each do |item|\r\n    func.call new, old, item, temp\r\n  end\r\n  return temp\r\nend\r\n\r\ndef insertR(new,old,list)\r\n  insertF(new,old,list, seq(true,true))\r\nend\r\n\r\ndef insertL(new,old,list)\r\n  insertF(new,old,list,seq(false,true))\r\nend\r\n\r\ndef subst(new,old,list)\r\n  insertF(new,old,list,seq(false,false))\r\nend\r\n\r\n#examples\r\ninsertL(\"z\",\"b\",[\"a\",\"b\",\"c\"])\r\ninsertR(\"z\",\"b\",[\"a\",\"b\",\"c\"])\r\nsubst(\"z\",\"b\",[\"a\",\"b\",\"c\"])<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Inspired by some currying examples in scheme, I wanted to try them in Ruby&#8230; def seq(oldfirst, keepold) lambda do |new, old, item, list| list.push(new) if old==item and\u00a0 !oldfirst list.push(item) if keepold or old != item list.push(new) if oldfirst and old==item end end def insertF(new, old, list, func) temp = [] list.each do |item| func.call new, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,16],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-programming","category-ruby"],"_links":{"self":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}