{"id":1324,"date":"2018-01-20T11:34:56","date_gmt":"2018-01-20T11:34:56","guid":{"rendered":"http:\/\/dlang.org\/blog\/?p=1324"},"modified":"2021-10-08T11:06:38","modified_gmt":"2021-10-08T11:06:38","slug":"project-highlight-bsdscheme","status":"publish","type":"post","link":"https:\/\/dlang.org\/blog\/2018\/01\/20\/project-highlight-bsdscheme\/","title":{"rendered":"Project Highlight: BSDScheme"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"alignleft wp-image-1326 size-thumbnail\" src=\"http:\/\/dlang.org\/blog\/wp-content\/uploads\/2018\/01\/Lambda_lc-200x200.png\" alt=\"\" width=\"200\" height=\"200\" srcset=\"https:\/\/dlang.org\/blog\/wp-content\/uploads\/2018\/01\/Lambda_lc-200x200.png 200w, https:\/\/dlang.org\/blog\/wp-content\/uploads\/2018\/01\/Lambda_lc-300x300.png 300w, https:\/\/dlang.org\/blog\/wp-content\/uploads\/2018\/01\/Lambda_lc.png 375w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/>Last year, Phil Eaton started working on <a href=\"https:\/\/github.com\/eatonphil\/bsdscheme\">BSDScheme<\/a>, a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Scheme_(programming_language)\">Scheme<\/a> interpreter that he ultimately intends to support <a href=\"https:\/\/bitbucket.org\/cowan\/r7rs-wg1-infra\/src\/default\/R7RSHomePage.md?fileviewer=file-view-default\">Scheme R7RS<\/a>. In college, he had completed two compiler projects in C++ for two different courses. One was a Scheme to Forth compiler, the other an implementation of the Tiger language from Andrew Appel\u2019s <a href=\"https:\/\/www.cs.princeton.edu\/~appel\/modern\/\">\u2018Modern Compiler Implementation\u2019 books<\/a>.<\/p>\n<blockquote><p>I hadn\u2019t really written a complete interpreter or compiler since then, but I\u2019d been trying to get back into language implementation. I planned to write a Scheme interpreter that was at least bootstrapped from a compiled language so I could go through the traditional steps of lexing, parsing, optimizing, compiling, etc., and not just build a language of the meta-circular interpreter variety. I was spurred to action when my co-worker at Linode, <a href=\"https:\/\/github.com\/briansteffens\">Brian Steffens<\/a>, wrote <a href=\"https:\/\/github.com\/briansteffens\/bshift\">bshift<\/a>, a compiler for a C-like language.<\/p><\/blockquote>\n<p>For his new project, he wanted to use something other than C++. Though he knows the language and likes some of the features, he overall finds it a \u201ccomplicated mess\u201d. So he started on BSDScheme using C, building generic ADTs via macros.<\/p>\n<p>As he worked on the project, he referred to Brian\u2019s bshift for inspiration. As it happens, bshift is implemented in D. Over time, he discovered that he \u201creally liked the power and simplicity of D\u201d. That eventually led him to drop C for D.<\/p>\n<blockquote><p>It was clear it would save me a ton of time implementing all the same data structures and flows one implements in almost every new C project. The combination of compile-time type checking, GC, generic ADT support, and great C interoperability was appealing.<\/p><\/blockquote>\n<p>He\u2019s been developing the project on Mac and FreeBSD, using LDC, <a href=\"https:\/\/github.com\/ldc-developers\/ldc\">the LLVM-based D compiler<\/a>. In that time, he has found a number of D features beneficial, but two stand out for him above the rest. The first is <a href=\"https:\/\/dlang.org\/spec\/function.html#nested\">nested functions<\/a>.<\/p>\n<blockquote><p>They\u2019re a good step up from C, where nested functions are not part of the standard and only unofficially supported (in different ways) by different compilers. C++ has lambdas, but that\u2019s not really the same thing. It is a helpful syntactic sugar used in BSDScheme for defining new functions with external context (the names of the parameters to bind).<\/p><\/blockquote>\n<p>As for the second, hold on to your seats: it\u2019s the GC.<\/p>\n<blockquote><p>The existence of a standard GC is a big benefit of D over C and C++. Sure, you could use the Boehm GC, but how that works with threads is up to you to discover. It is not fun to do prototyping in a GC-less language because the amount of boilerplate distracts from the goals. People often say this when they\u2019re referring to Python, Ruby, or Node, but D is not at all comparable for (among) a few reasons: 1) compile-time type-checking, 2) dead-simple C interop, 3) multi-processing support.<\/p><\/blockquote>\n<p>Spend some time in <a href=\"http:\/\/forum.dlang.org\">the D forums<\/a> and you\u2019ll often find newcomers from C and C++ who, unlike Phil, have a strong aversion to garbage collection and are actively seeking to avoid it. You\u2019ll also find replies from long-time D coders who started out the same way, but eventually came to embrace the GC completely and learned how to make it work for them. The D GC can certainly be problematic for certain types of software, but it is a net win for others. This point is reiterated frequently in <a href=\"https:\/\/dlang.org\/blog\/the-gc-series\/\">the GC series<\/a> on this blog, which shows how to get the most out of the GC, profile it, and mitigate its impact if it does become a performance problem.<\/p>\n<p>As Phil learned the language, he identified areas for improvement in the D documentation.<\/p>\n<blockquote><p>Certainly it is advantageous compared to the C preprocessor that there is not an entirely separate language for doing compile-time macros, but the behavior difference and transition guides are missing or poorly written. A comparison between D templates and C++ templates (in all their complexity) could also be a great source of explanation.<\/p><\/blockquote>\n<p>We\u2019re always looking to improve the documentation and make it more friendly to newcomers of all backgrounds. The docs are often written by people who are already well-versed in the language and its ecosystem, making blind spots somewhat inevitable. Anyone in the process of learning D is welcome and encouraged to help improve both the <a href=\"https:\/\/dlang.org\/spec\/spec.html\">Language<\/a> and <a href=\"https:\/\/dlang.org\/phobos\/index.html\">Library<\/a> docs. In the top right corner of each page are two links: \u201cReport a bug\u201d and \u201cImprove this page\u201d. The first takes you to <a href=\"https:\/\/issues.dlang.org\">D\u2019s bug tracker<\/a> to report a documentation bug, the second allows anyone with a logged-in GitHub account to quickly fork <a href=\"https:\/\/dlang.org\/\">dlang.org<\/a>, edit the page online, and submit a pull request.<\/p>\n<p>In addition to the ulitmate goal of supporting Scheme R7RS, Phil plans to add <a href=\"https:\/\/en.wikipedia.org\/wiki\/Foreign_function_interface\">FFI<\/a> support in order to allow BSDScheme to call D functions directly, as well as support for D threads and an LLVM-based backend.<\/p>\n<p>Overall, he seems satisfied with his decision to move to D for the implementation.<\/p>\n<blockquote><p>I think D has been a good time investment. It is a very practical language with a lot of the necessary high-level aspects and libraries for modern development. In the future, I plan to dig more into the libraries and ecosystem for backend web systems. Furthermore, unlike with C or C++, so far I\u2019d feel comfortable choosing D for projects where I am not the sole developer. This includes issues ranging from prospective ease of onboarding to long-term performance and maintainability.<\/p><\/blockquote>\n<p>A big thanks to Phil for taking the time to contribute to this post (be sure to check out <a href=\"http:\/\/notes.eatonphil.com\/first-few-hurdles-writing-a-scheme-interpreter.html\">his blog<\/a>, too). We\u2019re always happy to hear about new projects in D. <a href=\"https:\/\/github.com\/eatonphil\/bsdscheme\">BSDScheme<\/a> is released under <a href=\"https:\/\/github.com\/eatonphil\/bsdscheme\/blob\/master\/LICENSE.md\">the three-clause BSD license<\/a>, so it\u2019s a great place to start for anyone looking for an interesting open-source D project to contribute to or learn from. Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year, Phil Eaton started working on BSDScheme, a Scheme interpreter that he ultimately intends to support Scheme R7RS. In college, he had completed two compiler projects in C++ for two different courses. One was a Scheme to Forth compiler, the other an implementation of the Tiger language from Andrew Appel\u2019s \u2018Modern Compiler Implementation\u2019 books.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,13],"tags":[],"_links":{"self":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1324"}],"collection":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/comments?post=1324"}],"version-history":[{"count":9,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1324\/revisions"}],"predecessor-version":[{"id":1363,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1324\/revisions\/1363"}],"wp:attachment":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/media?parent=1324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/categories?post=1324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/tags?post=1324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}