<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged pure</title>
<link>https://coderlegion.com/tag/pure</link>
<description>Powered by Question2Answer</description>
<item>
<title>DevLog 20250724: C# Scripting, Pure 2, Updated + Some Recap</title>
<link>https://coderlegion.com/4264/devlog-20250724-c-scripting-pure-2-updated-some-recap</link>
<description>&lt;h3 id=&quot;intro&quot;&gt;Intro&lt;/h3&gt;
&lt;p&gt;Pure has been our in-house C# scripting solution for a few years now.&lt;br&gt;
After experimenting with the well-known &lt;a rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/CS-Script&quot;&gt;CS-Script&lt;/a&gt; and some other solutions I can no longer recall, I began experimenting with &lt;a rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/Roslyn_(compiler)&quot;&gt;Roslyn&lt;/a&gt; in .NET around 2022/2023, and it's been working well ever since.&lt;/p&gt;
&lt;h4 id=&quot;usage&quot;&gt;Usage&lt;/h4&gt;
&lt;p&gt;Below is a basic Pure script and its execution:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c#&quot;&gt;using static System.Console;

var sum = File.ReadLines(&quot;Data.csv&quot;)
    .Skip(1)
    .Select(l =&amp;gt; l.Split(','))
    .Sum(parts =&amp;gt; double.Parse(parts[1]));
WriteLine(sum);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://publication.tor1.cdn.digitaloceanspaces.com/Websites/MethodoxWiki/Images/Utilities-CLI-Pure-Basic_Example.png&quot; alt=&quot;Result&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;recap&quot;&gt;Recap&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Version 0.0.3&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1g0yfd5tu0wiq9natttt.png&quot; alt=&quot;v0.0.3&quot;&gt;&lt;/p&gt;
&lt;p&gt;The first version of Pure was just a simple wrapper around Roslyn. Later, we expanded it to support syntax like &lt;code&gt;Import(MathNet.Numerics)&lt;/code&gt;. It wasn't until we added native libraries like &lt;code&gt;CSV&lt;/code&gt;, &lt;code&gt;ODBC&lt;/code&gt;, and &lt;code&gt;CentralSnippets&lt;/code&gt; that things started to get interesting.&lt;/p&gt;
&lt;h3 id=&quot;motivation&quot;&gt;Motivation&lt;/h3&gt;
&lt;p&gt;Below is an old table I compiled when first drafting the design document for Pure (1), with some updates to mention newer solutions:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=292194321662759487&quot; alt=&quot;Table 1&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;what-s-special&quot;&gt;What's Special&lt;/h3&gt;
&lt;p&gt;Pure 2 is a lightweight C# scripting platform with modern C# 12 syntax and easy NuGet import support. Pure is based on Roslyn. In addition to the base .NET runtime, Pure offers additional libraries for handling common tasks, along with a handy scripting interface (REPL and Notebook) and a place where people can share their &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Pure-the-Language/CentralSnippets&quot;&gt;snippets&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;Pure 2 is conceptually similar to &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Pure-the-Language/Pure&quot;&gt;Pure&lt;/a&gt; but architecturally very different - it directly builds upon Parcel NExT's Ama runtime (the same runtime used by Divooka). Pure is designed for very short snippets and getting everyday tasks done faster.&lt;/p&gt;
&lt;p&gt;Pure 2 uses C# 12 and is similar to &lt;a rel=&quot;nofollow&quot; href=&quot;https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements&quot;&gt;top-level statements&lt;/a&gt; in C#, with the following features:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You can define types and functions anywhere in the middle of the script.&lt;/li&gt;
&lt;li&gt;Pure has its own package import behavior (default namespace usage and package lookup rules).&lt;/li&gt;
&lt;li&gt;Default global scope math functions, and default &lt;code&gt;using&lt;/code&gt; for &lt;code&gt;System.IO&lt;/code&gt; and &lt;code&gt;System.Linq&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Top-level function and variable definitions, alongside classes and other common C# constructs.&lt;/li&gt;
&lt;li&gt;Simplifies common tasks even further.&lt;/li&gt;
&lt;li&gt;Macros to support text-based parsing, file inclusion, and module imports.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;features&quot;&gt;Features&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Single-word standard package names. One-command NuGet package import and on-the-fly package invocation (through &lt;code&gt;Import&lt;/code&gt;).  &lt;/li&gt;
&lt;li&gt;Full compatibility with Divooka packages and Divooka graphs.&lt;/li&gt;
&lt;li&gt;Pure uses &lt;code&gt;PUREPATH&lt;/code&gt; to search for scripts when using &lt;code&gt;Include&lt;/code&gt; and when executing script files directly from the command line as the first argument.  &lt;/li&gt;
&lt;li&gt;Pure is very lightweight and will always be a thin layer on top of Roslyn/.NET runtime.  &lt;/li&gt;
&lt;li&gt;CLI REPL; GUI Notebook.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;basic-syntax&quot;&gt;Basic Syntax&lt;/h4&gt;
&lt;p&gt;Certain macros/syntax are provided to implement language-level scripting constructs:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8123867204314969076&quot; alt=&quot;Table 2&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;Be aware that adopting a scripting system - any scripting system - comes with significant risks. It's wise to plan carefully and pick the best tools for the task at hand.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Download page for Pure 2 on &lt;a rel=&quot;nofollow&quot; href=&quot;https://methodox.itch.io/pure-2&quot;&gt;Methodox Itch.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Official Page for Pure 2 on &lt;a rel=&quot;nofollow&quot; href=&quot;https://wiki.methodox.io/en/Utilities/CLI/Pure&quot;&gt;Methodox Wiki&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/4264/devlog-20250724-c-scripting-pure-2-updated-some-recap</guid>
<pubDate>Fri, 25 Jul 2025 01:39:40 +0000</pubDate>
</item>
</channel>
</rss>