Schemers - Parsers

Ready for the next lesson? We'll be writing our parser now, the Read in the REPL. We'll be using the nom library for parsing. It's what's known as a parser combinator library. By building small parsers that do one thing like parse a number or one that parses a string we can build them up into larger ones, for instance one that could parse a string or a number. It uses macros to build parsers. We'll start small and parse a procedure something like: (+ 3 4 5) Into a data structure we can use. By no means will our parser…

Read More

Russian Dolls and clean Rust code

Recently I started porting my website from Github pages to this domain. I wanted to make my own static site using Iron and code it all myself as a challenge rather then use a Jekyll template. The fact you're reading this means that succeeded! However, that's an article for another time. Today I wanted to talk a little about making your Rust code more readable as well as resources for better patterns and cleaner code. The Russian Doll Problem As part of the site I use a toml configuration file and I read certain values from it. Thing is with…

Read More

Schemers - Exercise 1

This post will be covering the exercises given in the first article. I'll be going over the answers and providing more idiomatic ways to do them. We'll evolve the answers to the one in the repo and cover some new concepts along the way. What we'll be covering The trim function from the String standard library module Rust use statements More match patterns Function Parameters Touching on &str Touching on enum Exercises Here's what I asked you to do in the prior post: Modify the Err line so that the program exits gracefully on an EOF or Interrupted, but…

Read More

Schemers - Input

In my CS undergrad right now I've been taking an interesting course on the Structure of Higher Level Languages. It's quite the eye opening class and one of the things we are doing there is implementing a Scheme interpreter in Scheme. I thought it would be fun to do something like a tutorial such as Write Yourself a Scheme in 48 Hours to teach others some Rust and create a Scheme interpreter. This series of blog posts is going to be aimed at people completely new to the language who have never touched it before. We'll be implementing the R5RS*…

Read More

Using Haskell in Rust

After my article on putting Rust in Haskell I set out on getting Haskell into Rust as part of my test suite for curryrs which is supposed to make this much easier. I was having some trouble getting this to work because Haskell FFI only supports exporting for C. I tried to get this to work directly with Rust but it didn't work at all. The main issue being that we need to initialize and end the Haskell runtime when we use our Haskell functions and closing it when we're done. Linking libraries also ended up being a problem to…

Read More

FFI with Haskell and Rust

I've had an idea percolating for a while. I love using Haskell for work. It's functional, expressive, and easy to reason about. It's also strongly typed and deals with immutable data (for the most part) which are big pluses for writing good code. However, it's garbage collected, and while it's not likely to run into performance issues for small projects, on larger ones it can get in the way. Commonly with Haskell, if one really needed speed, the FFI would be used with C code in order to get the performance needed. The only problem with that is that C…

Read More

Why you should be blogging about Rust

Let's jump right into it, I'm here to convince you to start blogging about Rust if you haven't and if you have to continue to do so, and possibly even more if you have the time for that. Why blog about it? What if I have nothing to contribute? Even if I did how would I even know what to write about? Fear not. All of these questions will be answered so let's start with the biggest one. Why we should blog more about Rust Well chances are if you're reading this article you like Rust right? Even if you…

Read More

Understanding where clauses and trait constraints

Lately I've been working on a crate functils to make Rust a little more functional and it's based off Stephen Diehl's Protolude crate. It has some very sensible defaults for Haskell after turning off the implicit Prelude that I enjoy using in my Haskell code. It includes some cool functions like the identity function: -- Given a type a return itself id :: a -> a id x = x I implemented that in Rust no problem with generics! pub fn identity<A>(x:A) -> A { x } Well how about this function uncons from protolude? If you…

Read More