Plasma Programming LanguageThe Plasma programming language strikes a balance between functional and imperative programming, making it easier to write reliable and efficient software.
http://plasmalang.org/
Sat, 17 Mar 2018 16:29:25 +1100Sat, 17 Mar 2018 16:29:25 +1100Jekyll v3.6.0Two and a Half Years<div class="paragraph">
<p>It&#8217;s been two and a half years since I started work on Plasma.
With the end of 2017 I noticed that many other language projects were
publishing retrospectives of their last year.
Well with one developer progress is a lot slower, so rather than summarise
the last year,
I&#8217;ll write about the whole history!</p>
</div>
<div class="sect1">
<h2 id="expectations">Expectations</h2>
<div class="sectionbody">
<div class="paragraph">
<p>I can&#8217;t talk or think about progress without thinking about my expectations.
It&#8217;s fair to say that I did expect to get further with this project, but I
don&#8217;t think that I underestimated the amount of effort required or my
limited time.
I knew those well going in, nevertheless I did expect to get further in this
time.
The <a href="http://plasmalang.org/roadmap.html">roadmap</a> is organised by milestones,
each milestone is made up of multiple goals.
I hoped, but now that I have retrospect, to achieve about one milestone
every six months, at least for the first few 2&ndash;3 milestones.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="progress-psychology">Progress &amp; Psychology</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Initially progress seemed rapid, I was excited and had some close friends
excited about the project.
However in 2.5 years I am over half-way through the second milestone,
less than I expected.</p>
</div>
<div class="paragraph">
<p>I published the roadmap to provide a sense of what my goals are to anyone
reading along or wishing to get involved.
It also helps me maintain focus on what I want to accomplish now and later
(and I&#8217;ve recently been experimenting with a kanban board and github
issues).
However it has a side effect of making it clear what I have (and haven&#8217;t yet)
achieved.</p>
</div>
<div class="paragraph">
<p>While that side affect can sometimes be unfortunate, I think I&#8217;d feel like I
had less progress if I did not see the roadmap at all, I would have no
lovely green ticks to see at all!
While I don&#8217;t want to dwell on this &mdash;
since I don&#8217;t owe anyone Plasma, there&#8217;s no "deadline" &mdash;
a feeling of progress (and peer support) is just something I seem to need
sometimes.
Therefore I try to accept that I set myself lofty goals and
when I evaluate my progress I try to do so against more moderate goals.</p>
</div>
<div class="paragraph">
<p>If you think this all sounds quiet difficult to live with
then I&#8217;d like to point out that I wouldn&#8217;t have started Plasma if I was
already satisfied with my career progress and contributions in the last few
years.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="where-is-plasma-at-today">Where is Plasma at today?</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Plasma has:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>a token-based bytecode interpreter, it&#8217;ll be replaced by better
technology later;</p>
</li>
<li>
<p>enough builtin types and functions for testing;</p>
</li>
<li>
<p>a compiler that generates .pz bytecode format files;</p>
</li>
<li>
<p>basic functions, expressions, statements, if-then-else, pattern matching;</p>
</li>
<li>
<p>a type system with ADTs, higher-order values/calls and generics;</p>
</li>
<li>
<p>the basics of the <a href="http://plasmalang.org/docs/plasma_ref.html#_handling_effects_io_destructive_update">resource system</a>;</p>
</li>
<li>
<p>many features in a planning state!</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="looking-forward">Looking Forward</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Without calculating it, (although the git logs are available) it seems like
I&#8217;m closing off one goal every two or so months.
That&#8217;s actually not bad for something I do in my spare time.</p>
</div>
<div class="paragraph">
<p>Also quite a few of the recent goals: higher-order code, generics,
resources; allow Plasma to become more expressive.
The language itself is taking shape.
Now more than ever I can feel the implementation getting closer to my
vision.
Each time I complete a goal I feel excited about the expressibility that the
next goal will bring.
It won&#8217;t be long (relatively) and Plasma will be ready for some testing.</p>
</div>
<div class="paragraph">
<p>Next I&#8217;ll be adding some more test cases for higher order calls,
support for closures, lambdas etc. Then it&#8217;s time to implement the module
system and make design decisions about the Prelude/stdlib.
At that point milestone #2 will be almost complete and its time to encourage
some testing.</p>
</div>
</div>
</div>Wed, 03 Jan 2018 00:00:00 +1100http://plasmalang.org/2018/01/03/two-and-a-half-years.html
http://plasmalang.org/2018/01/03/two-and-a-half-years.htmlHigher order values<div class="paragraph">
<p>Another item ticked off the roadmap! Higher order values and higher order
calls. That&#8217;s two items!</p>
</div>
<div class="paragraph">
<p>Now it is possible to capture higher order values. Let&#8217;s say we have a
function such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>func hello_msg(name : String) -&gt; String {
return "Hello " ++ name ++ "\n"
}</pre>
</div>
</div>
<div class="paragraph">
<p>Now in another function&#8217;s body we can create a value pointing to the
function.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>f = hello_msg</pre>
</div>
</div>
<div class="paragraph">
<p>And even call it:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>s = f("World")</pre>
</div>
</div>
<div class="paragraph">
<p>This is pretty simple stuff, but necessary for any expressive programming
language.
Next we&#8217;ll be adding more tests to make sure these values work if we put
them inside other structures (like a list of functions). We also want to
make sure that statically created data can refer to functions (currently it
cannot).
Statically constructed data also cannot refer to data cyclically;
this may be a good thing.
After that we&#8217;ll add closures (including lambdas), partial application,
and allow data constructors to also serve as functions.</p>
</div>Sun, 19 Nov 2017 00:00:00 +1100http://plasmalang.org/2017/11/19/higher-order-values.html
http://plasmalang.org/2017/11/19/higher-order-values.htmlMulti-value functions<div class="paragraph">
<p>Woo, another goal ticked off on the
<a href="http://plasmalang.org/roadmap.html">roadmap</a>.
Plasma now supports functions that return any number of results.</p>
</div>
<div class="paragraph">
<p>Whenever you want to return more than one result from a function,
it&#8217;s always bothered me how doing this in C and many other languages is
pretty clumsy:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>int do_something(int input, int *second_output);</pre>
</div>
</div>
<div class="paragraph">
<p>Of course some languages you can use tupling to achieve the same affect,
such as Haskell.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>do_something :: Int -&gt; (Int, Int)</pre>
</div>
</div>
<div class="paragraph">
<p>But I&#8217;ve always felt that this doesn&#8217;t directly represent what the developer
is asking.
They want to actually return multiple things, and not have the accidental
complexity of saying "this returns a tuple".
This may be splitting hairs, maybe it is and so I&#8217;ll move on to my next
point.</p>
</div>
<div class="paragraph">
<p>I&#8217;d prefer a language implementation to support this directly in its native
calling convention (like Prolog or Mercury),
and not handle it as an optimisation that eliminates the memory allocation
of the tuple.
In other words, when there are multiple inputs that is handled directly by
the calling convention, which says where to place them in registers and the
stack.
I would like the same treatment of output arguments, they should likewise
just be left in registers and the stack as a sensible calling convention
would allow.
I&#8217;m not aware of a common C calling convention that does that, but I&#8217;m not
writing a C compiler so that&#8217;s only important when dealing with foreign
code.
Therefore I want a language that supports this <em>directly</em> rather than having
developers rely on <em>optimisations working as they expect</em>.</p>
</div>
<div class="paragraph">
<p>Plasma now supports functions that return any number of values (0 or more).
In this example pm() returns both the absolute value and negative absolute
value of its input.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>func pm(x : Int) -&gt; Int, Int {
if (x &lt; 0) {
x_abs = x * -1
} else {
x_abs = x
}
return x_abs, x_abs * -1
}</pre>
</div>
</div>
<div class="paragraph">
<p>Some examples of things that return multiple results like this are the
quadratic formula, and integer division (return the quotient and remainder).
Of course there are plenty of situations, particularly with functional
programming styles, where returning multiple results is common.</p>
</div>
<div class="paragraph">
<p>Functions can also return no results.
In a pure language such as Plasma
this only makes sense if they have some effect on the world.
Printing a result is a good example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>func do_pm(x : Int) using IO {
p, m = pm(x)
print!("p: " ++ int_to_string(p) ++ ", m: " ++ int_to_string(m) ++ "\n")
}</pre>
</div>
</div>
<div class="paragraph">
<p>In Plasma there is no void symbol like in languages like C.
Instead a function simply returns no results like do_pm() above..</p>
</div>
<div class="paragraph">
<p>Later when expression versions of if and match statements are added,
then those will also support multiple results.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>func pm2(x : Int) -&gt; Int, Int {
neg_x = x * -1
return if x &lt; 0 then neg_x, x else x, neg_x
}</pre>
</div>
</div>
<div class="paragraph">
<p>Plasma is beginning to really take shape.
I&#8217;m feeling rather excited; I think the time when people will want to try it
out for some small tasks is getting noticeably closer.</p>
</div>Tue, 08 Aug 2017 00:00:00 +1000http://plasmalang.org/2017/08/08/multi-value-functions.html
http://plasmalang.org/2017/08/08/multi-value-functions.htmlParametric Polymorphism<div class="paragraph">
<p>It&#8217;s been some time but we&#8217;ve finally ticked off another goal on the
<a href="http://plasmalang.org/roadmap.html">roadmap</a>.
The basics of parametric polymorphism work.
You can define a type, such as List(a), not that a syntax sugar for list
cells and lists does not exist yet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>type List(a) = Nil
| Cons ( head : a, tail : List(a) )</pre>
</div>
</div>
<div class="paragraph">
<p>Here a is a type variable. It can be substituted for any concrete type.</p>
</div>
<div class="paragraph">
<p>Write a polymorphic function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>func list_length(l : List(a)) -&gt; Int {
match (l) {
Nil -&gt; { return 0 }
Cons(_, rest) -&gt; { return 1 + list_length(rest) }
}
}</pre>
</div>
</div>
<div class="paragraph">
<p>And call it with a list of numbers, or strings, or any concrete type.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>List1 = Cons(1, Cons(2, Cons(3, Cons(4, Nil))))
print!(int_to_string(list_length(List1)) ++ "\n")
List2 = Cons("A", Cons("B", Cons("C", Nil)))
print!(int_to_string(list_length(List2)) ++ "\n")</pre>
</div>
</div>
<div class="paragraph">
<p>There are some rough edges to clean up, for example the compiler doesn&#8217;t
check whether the correct number of types or variables are listed when
referring to a type (such as writing List when one should write
List(a)).
And polymorphism will become much more useful once Plasma supports other
features such as higher order values/calls (next major goal) and interfaces.</p>
</div>Sun, 16 Jul 2017 00:00:00 +1000http://plasmalang.org/2017/07/16/parametric-polymorphism.html
http://plasmalang.org/2017/07/16/parametric-polymorphism.htmlMatch-case statements<div class="paragraph">
<p>We&#8217;ve reached another minor milestone. Match-case statements are now
supported including some rules for how variables are allowed to be used in
branching code. This also means that Plasma is now Turing complete,
although it is far from being <em>expressive</em>.</p>
</div>
<div class="paragraph">
<p>Match statements attempt to match an expression against a number of patterns.
Currently the only patterns that are supported are integers, variable names
and underscore (a wild-card pattern). Cases are tried in order. Later the
compiler may warn about cases that are never executed (because an earlier
case matches).</p>
</div>
<div class="listingblock">
<div class="content">
<pre> match (n) {
0 -&gt; {
beer = "There's no beer!"
}
1 -&gt; {
beer = "There's only one beer"
}
m -&gt; {
beer = "There are " ++ int_to_string(m) ++ " bottles of beer"
}
}
print!(beer)</pre>
</div>
</div>
<div class="paragraph">
<p>If a variable is produced by at least one case, and used outside the match
statement then it <strong>must</strong> be produced in all cases that <em>fall through</em>. If a
variable is produced on at least one case, and not used outside the match,
then it will be <em>named apart</em> by the compiler, allowing it to have a
different type from variables with the same name in other cases. These
rules have been implemented however the error messages will abort
compilation. Friendlier errors will be implemented later.</p>
</div>
<div class="paragraph">
<p>If it is possible that no case matches, and the other cases produce values
used after the match, then that is also an error. However until types are
properly implemented this cannot be implemented.</p>
</div>
<div class="paragraph">
<p>Cases may contain a return statement (or otherwise not <em>fall through</em>, if
that happens they do not need to produce any variables. Currently the
compiler only supports either all cases falling through, or none falling
through. I plan to implement this later, this will probably be implemented
by transforming the code after the match into a separate function which is
called in the cases that fall through. This will also have implications for
type-checking due to the order of compilation passes, so must wait until
then.</p>
</div>Fri, 30 Sep 2016 00:00:00 +1000http://plasmalang.org/2016/09/30/match-statements.html
http://plasmalang.org/2016/09/30/match-statements.htmlPresentation At Compose<!--
Copyright (C) 2016 Paul Bone
Licensed as CC BY-NC-ND 4.0
-->
<p>
On the 29th of August I gave a presentation at
<a href="http://www.composeconference.org/">Compose :: Melbourne</a>
about Plasma's goals and ideas, how it is different from many other
functional languages and the current status of the project.
Now that the video has been made available it is now easy to show other
people, people who couldn't make it to Melbourne, the presentation.
</p>
<iframe width="560" height="315"
src="https://www.youtube.com/embed/sIVzfYelaS4"
frameborder="0" allowfullscreen></iframe>
<p>
The bibliographic information for this presentation is:
<span class="author">P. Bone</span>
<span class="title">Plasma Programming Language</span>
<span class="conf">Compose :: Melbourne Conference</span>
<span class="when">Aug, 2016</span>
<span class="links">
<a href="/pub/pbone-2016-plasma.pdf" target-"_blank">Slides</a>
</span>
</p>
<p>
After the presentation I received plenty of positive feedback and some
questions and had quite a few interesting discussions with various people.
I still need to talk with
<a href="http://people.eng.unimelb.edu.au/lee">Lee naish</a> some more about
resources.
My favorite feedback however was someone calling out "Plasma Rocks!" in my
direction as our paths crossed at the after party.
I don't know who this was or what they liked about it in particular,
but I'm pleased that they liked it so much the felt the need to call out.
</p>
<p>
If you have any feedback about the presentation or Plasma itself
I'd love to <a href="/contact.html">hear from you</a>
</p>
Mon, 19 Sep 2016 00:00:00 +1000http://plasmalang.org/2016/09/19/presentation-at-compose.html
http://plasmalang.org/2016/09/19/presentation-at-compose.html