{"id":171,"date":"2015-08-28T04:33:06","date_gmt":"2015-08-28T04:33:06","guid":{"rendered":"http:\/\/www.voidbred.com\/blog\/?p=171"},"modified":"2015-08-28T14:43:15","modified_gmt":"2015-08-28T14:43:15","slug":"adventures-with-ironscheme-pt-2","status":"publish","type":"post","link":"http:\/\/www.voidbred.com\/blog\/2015\/08\/adventures-with-ironscheme-pt-2\/","title":{"rendered":"Adventures with IronScheme pt. 2"},"content":{"rendered":"<p>So, I got a response on StackOverflow from the creator of IronScheme on how to combine enums. \u00a0It was very nice of him, IronScheme is obviously a labor of love for him. \u00a0Just as I wrote a conversion of the &#8220;hello world&#8221; program generator in F#, I now present it in IronScheme with no attempt to reduce the verbosity.<\/p>\n<pre class=\"toolbar:1 lang:default decode:true \" title=\"ironscheme reflection hello world\">(import\r\n (rnrs)\r\n (ironscheme)\r\n (ironscheme clr))\r\n\r\n(clr-using System)\r\n(clr-using System.Reflection.Emit)\r\n(clr-using System.Reflection)\r\n(clr-using System.Threading)\r\n\r\n(define (emit-hello-world)\r\n  (let ((assembly-name (clr-new AssemblyName)))\r\n    (clr-prop-set! AssemblyName Name assembly-name \"HelloWorld\")\r\n    (let* ((thread-domain (clr-static-call Thread GetDomain))\r\n           (assembly-builder\r\n            (clr-call AppDomain\r\n                      DefineDynamicAssembly\r\n                      thread-domain\r\n                      assembly-name\r\n                      (clr-static-field-get AssemblyBuilderAccess\r\n                                            RunAndSave)))\r\n           (module (clr-call AssemblyBuilder\r\n                             DefineDynamicModule\r\n                             assembly-builder\r\n                             \"HelloWorld.exe\"))\r\n           (type-builder (clr-call ModuleBuilder\r\n                                   DefineType\r\n                                   module\r\n                                   \"HelloWorldType\"\r\n                                   '(public class)))\r\n           (method-builder (clr-call TypeBuilder\r\n                                     DefineMethod\r\n                                     type-builder\r\n                                     \"Main\"\r\n                                     '(hidebysig static public)\r\n                                     (get-clr-type 'System.Void)\r\n                                     (vector (get-clr-type 'System.String))))\r\n           (ilgenerator (clr-call MethodBuilder\r\n                                  GetILGenerator\r\n                                  method-builder)))\r\n      (clr-call ILGenerator\r\n                EmitWriteLine\r\n                ilgenerator\r\n                \"Hello World\")\r\n      (clr-call ILGenerator\r\n                Emit\r\n                ilgenerator\r\n                (clr-static-field-get OpCodes Ret))\r\n      (let ((new-type (clr-call TypeBuilder\r\n                                CreateType\r\n                                type-builder)))\r\n        (clr-call AssemblyBuilder\r\n                  SetEntryPoint\r\n                  assembly-builder\r\n                  method-builder\r\n                  (clr-static-field-get PEFileKinds ConsoleApplication))\r\n        (clr-call AssemblyBuilder\r\n                  Save\r\n                  assembly-builder\r\n                  \"HelloWorld.exe\")\r\n        (display \"done\")\r\n        (newline)))))\r\n\r\n(emit-hello-world)\r\n\r\n<\/pre>\n<h6>References:<\/h6>\n<ul>\n<li><a href=\"http:\/\/blogs.msdn.com\/b\/joelpob\/archive\/2004\/01\/21\/61411.aspx\" target=\"_blank\">http:\/\/blogs.msdn.com\/b\/joelpob\/archive\/2004\/01\/21\/61411.aspx<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>So, I got a response on StackOverflow from the creator of IronScheme on how to combine enums. \u00a0It was very nice of him, IronScheme is obviously a labor of love for him. \u00a0Just as I wrote a conversion of the &#8220;hello world&#8221; program generator in F#, I now present it in IronScheme with no attempt&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[24,26],"_links":{"self":[{"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/posts\/171"}],"collection":[{"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":3,"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":175,"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions\/175"}],"wp:attachment":[{"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.voidbred.com\/blog\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}