{"id":7248,"date":"2018-06-02T12:23:11","date_gmt":"2018-06-02T16:23:11","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=7248"},"modified":"2018-06-02T12:23:11","modified_gmt":"2018-06-02T16:23:11","slug":"emacs-26-threads-and-generators","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=7248","title":{"rendered":"Emacs 26, Threads, and Generators"},"content":{"rendered":"<p> One of the things that a lot of people are exited about in Emacs 26 is the introduction of basic threading. Another, less mentioned, feature is generators. The excellent Chris Wellons has a must-read post that talks about both of these innovations. <\/p>\n<p> He first considers generators, which he describes as mostly modeled after Python generators and, to a lesser extent, JavaScript generators. Generators return an iterator object that performs a calculation but can stop in middle of the operation to return a value. When it&rsquo;s called again, it produces the next value and stops again. Python users will be familiar with the idea. <\/p>\n<p> In Elisp, the generators are implemented as closures. Wellons describes how they work and some of the gotchas involved but if you&rsquo;ve ever implemented a counter function that return the next sequential integer each time it&rsquo;s called, you&rsquo;ll be familiar with the concept. <\/p>\n<p> Next Wellons talks about the threading implementation. He says that they&rsquo;re basically pthreads and that they should be considered a first step in bringing threads to Emacs. Again, he discusses some of the things that can go wrong. <\/p>\n<p> Finally, being Wellons, he wrote an implementation of generators using threads. It was just a proof-of-concept implementation meant to give him some experience in using the new facilities. You can take a look at the <a href=\"https:\/\/github.com\/skeeto\/thriter\">code<\/a> on GitHub if you&rsquo;re interested. <\/p>\n<p> As always with Wellons&rsquo; posts, I learned some new things by reading it. If you do any Elisp at all, you should take a look. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the things that a lot of people are exited about in Emacs 26 is the introduction of basic threading. Another, less mentioned, feature is generators. The excellent Chris Wellons has a must-read post that talks about both of &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=7248\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[18],"class_list":["post-7248","post","type-post","status-publish","format-standard","hentry","category-programming","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7248"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7248\/revisions"}],"predecessor-version":[{"id":7249,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7248\/revisions\/7249"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}