<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Luis&#x27; Blog</title>
    <link href="https://luisvgs.github.io/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://luisvgs.github.io"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2023-08-11T00:00:00+00:00</updated>
    <id>https://luisvgs.github.io/atom.xml</id>
    <entry xml:lang="en">
        <title>Jules: my own Lisp flavor</title>
        <published>2023-08-11T00:00:00+00:00</published>
        <updated>2023-08-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://luisvgs.github.io/jules/" type="text/html"/>
        <id>https://luisvgs.github.io/jules/</id>
        
        <content type="html">&lt;p&gt;Soon I will blog about the current state of Jules, a work-in-progress Lisp flavor with type annotation. You can follow
the development at: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;luisvgs&#x2F;jules&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;luisvgs&#x2F;jules&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Writing Marta: an overview</title>
        <published>2020-07-07T00:00:00+00:00</published>
        <updated>2020-07-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://luisvgs.github.io/pl-design-0/" type="text/html"/>
        <id>https://luisvgs.github.io/pl-design-0/</id>
        
        <content type="html">&lt;p&gt;The past few months I&#x27;ve been working on my own programming language, called Marta. This is one of my many iterations of
implementing a working PL, and so far I&#x27;m happy enough to share with you my progress. With this post I expect to share
briefly some of my design decisions whilst working on the language, as well as what the future holds for my project.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-syntax&quot;&gt;The syntax&lt;&#x2F;h2&gt;
&lt;p&gt;If you are familiar with Scala or Rust, Marta&#x27;s syntax will be no stranger for you. Take the following snippet as an
example:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;let baz: Int = 20;
&lt;&#x2F;span&gt;&lt;span&gt;let foo: Int = |a| =&amp;gt; { a + baz };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;println(foo(10)) &#x2F;&#x2F; 30
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As you may intuitively deduce, the code above assigns baz of type int, a value of 20. Followed by a declaration of
lambda foo, which receives a as a parameter and sums them both. Finally, it prints the result.&lt;&#x2F;p&gt;
&lt;p&gt;Pretty simple, isn&#x27;t it?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;parsing&quot;&gt;Parsing&lt;&#x2F;h2&gt;
&lt;p&gt;In initial stages, I opted for writing my own parser and lexer however, I intended Marta&#x27;s syntax to be strictly typed
for now. That is, one should indicate the type of an expression (also known as ascription in the literature) during its initialization. This implied the lexing
process to be troublesome when writing more complex expressions. I opted for &lt;code&gt;lalrpop&lt;&#x2F;code&gt; as my main tool to generate the parser.&lt;&#x2F;p&gt;
&lt;p&gt;The AST is generated from the following grammar:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span&gt; Stmt: Stmt = {
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;expr:Expr&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;;&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;? =&amp;gt; Stmt::Expr(expr),
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;name:Ident&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;t:Ascription&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;rhs:Expr&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;;&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;?
&lt;&#x2F;span&gt;&lt;span&gt;    =&amp;gt; Stmt::Assign(name, rhs, t),
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;variable:Ident&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;rhs:Expr&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;;&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    =&amp;gt; Stmt::ReAssign(variable, rhs),
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;i:Ident&amp;gt; &amp;lt;args:ParamList&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;=&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;return_type:Ascription&amp;gt; &amp;lt;stmts:Block&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    =&amp;gt; Stmt::Func(i, args, stmts, return_type),
&lt;&#x2F;span&gt;&lt;span&gt;    ...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span&gt; Ascription: Ascription = {
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; =&amp;gt; Ascription::Int,
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;bool&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; =&amp;gt; Ascription::Bool,
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;string&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; =&amp;gt; Ascription::Str,
&lt;&#x2F;span&gt;&lt;span&gt;    ...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span&gt; Expr_: Expr = {
&lt;&#x2F;span&gt;&lt;span&gt;    ...
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;f:Ident&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;args:ExprList&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    =&amp;gt; Expr::Call(Call::Function(Function {func: f, args: args})),
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;i:&amp;#39;reduce&amp;#39;&amp;gt; &amp;lt;list:Expr_&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    =&amp;gt; Expr::Call(Call::Function(Function {func: i.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(), args: vec![ list ]})),
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;args:ParamList&amp;gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;=&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot; &amp;lt;stmts:Block&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    =&amp;gt; Expr::Function(args, stmts),
&lt;&#x2F;span&gt;&lt;span&gt;    ...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Definitely some improvements can be made.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;type-checking&quot;&gt;Type checking&lt;&#x2F;h1&gt;
&lt;p&gt;As of today, Marta implements basic type checking in which the evaluation
of primitives such as int, bool and string is trivial. If by any chance an incorrect operation is performed, the program
will panic.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s within my plans to implement a Hindley-Milner type system for the language, this way explicit type annotation will not
always be necessary and the language would feel more natural and expressive.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;conclusions&quot;&gt;Conclusions&lt;&#x2F;h1&gt;
&lt;p&gt;Writing my own programming language has been a beast of a task. I&#x27;m glad how this project is coming along. Learning about type systems has been a complete
joyful experience, although beginner friendly material is hard to find, one can make its own way to grasp the basics little
by little. I&#x27;m still not convinced with some design decisions I made, for example: error handling lacks of some edge
cases; the way the AST is being interpreted is perhaps not the most efficient way. I&#x27;ll be doing some research to
improve these funcionalities in the meantime. With that being said, Marta is so far the project I&#x27;m mostly proud of. As next steps you can expect some nice features in the
short-mid term: a hindley
milner type system, expand the standard library with some built-in methods, a backend compiler.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;hr data-content=&quot;references&quot; \&gt;
&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;: &lt;a href=&quot;https:&#x2F;&#x2F;www.cis.upenn.edu&#x2F;~bcpierce&#x2F;tapl&#x2F;&quot;&gt;Types and Programming Languages by Benjamin Pierce&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;&quot;&gt;&lt;&#x2F;h1&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;2&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;2&lt;&#x2F;sup&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;craftinginterpreters.com&#x2F;&quot;&gt;Crafting Interpreters by Robert Nystrom&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
</content>
        
    </entry>
</feed>
