For a while now, I’ve been working on a variant/subset of LaTeX which I call MiniLaTeX. The idea is to be able write MiniLaTeX documents in the browser and also to have them rendered there … indeed, to have them rendered in real-time as the user types. Good for writing class notes, problem sets, etc. You can see MiniLaTeX in action
Both apps are written in Elm, with the second also using Lamdera, a technology which enables one to write both the front- and backend in Elm, with the two communicating via websockets (read that last word as fast). …
I’ve used the app a good deal myself, but now, to make it fulfill its purpose, I need feedback from real users. The app has a chat feature (Chat button, lower right, see screen shot at end). You can use the chat to report bugs, make suggestions, and ask questions. And yes, you can write equations in LaTeX in the chat!
As a fun exercise, I decided to try to make a Lisp using Elm … not the whole deal, of course, but just a little piece to see what is possible and how one would do it. The result, which I will describe here, is a skeleton of a very small typed Lisp. Of course Lisp itself doesn’t have types, so this is a different beast. In any case, one needs to construct two functions,
eval. Here is how the parser works:
> parse "(+ 1 2)"
Just (LIST [Str "+",Num 1,Num 2])
: Maybe AST
And here is…
In a previous post, I discussed an Elm implementation of the mini-language Arith discussed in Benjamin Peirce’s book Types and Programming Languages (TAPL). The implementation provides a parser and an eval function, so we can do things like this:
> parse "succ succ 0"
Ok (Succ (Succ Zero))> parse "succ succ 0" |> evalResult
Just (Numeric 2)
As it stands now, the expression
succ succ false is perfectly “grammatical” and is accepted by the parser:
> parse "succ succ false"
Ok (Succ (Succ F))
But of course, this expression makes no sense, and when we evaluate it, we get an…
The Elm programming language is best known for building web apps. Turns out, however, that one can also build something quite different: command-line programs like the one you see on the left. It is a simple stack-based calculator. The first command computes 2 + 3 and leaves 5 on the stack. The next command adds 1 to whatever is on top of the stack. Each command takes its arguments, either from the command line or the stack, and leaves the result on top of the stack. There are some useful variants like
\sub x y = sub y x that does subtraction in the opposite of the usual order. Thus, if 5 is on top of the stack, and you say
\sub 1, then 4 will be on top. And if you subsequently say
\div 4, then 1.333… will be on top. In addition, there are more exotic commands, such as
push 1 2 3 4, which push a sequence of numbers onto the stack. Then the command
sum will add them up, leaving 10 on top. The sister command
av will compute their average, leaving 2.5 …
Get the physics right, then the code!
In this article, we will design a little light meter, making sure that we get the whole pipeline right: the physics, the math, the code, and the wiring.
First off, the sensor. This is a light-dependent resistor, or LDR aka photoresistor: a little gadget whose resistance R1 varies with the intensity L of the light to which it is exposed.
What do bacteria, human populations, and the Coronavirus epidemic have in common? Short answer: exponential growth. We often use this term as a synonym for growing really fast. But in fact it has a precise, mathematical meaning, one that is vital in understanding and responding to epidemics like Coronavirus. But before the math, a parable:
In a far away land, there is a magical pond. One the first day of Spring, at precisely 7 am, there appears one lily pad, fully formed. On the second day, again at 7 am, there are two lily pads, also fully formed. On day three, there are four. And so on. …
Adventures in Programming
In this article, we are going to look at how loops are used, first in an imperative language, like Python, then in a pure functional language, like Elm. While the particular languages used are not as important as the ideas, these are languages that I have used a lot, and which I like a lot, though for different purposes. The first few examples will be mathematical, but involve nothing more exotic that adding numbers. The very last example is about text processing.
The article is organized as follows:
Microbial I is a simulation of the life of a fake micro-organism, Mono, which is lives in a very flat world — not Flatland, but thin, like the layer of water between a microscope slide and the coverslip. Mono has a diameter, an area, a lifespan, and a growth rate. When it grows to a sufficient size, it undergoes (at random) the process of cell-division, giving rise to two daughter cells. The daughters begin life anew, with the minimum area and age zero. As cells age, they change color. Babies are green, young cells are yellow, mature ones are blue, and the old are red. Cell death, like cell-division, is a random process. Once a cell reaches 95% of the nominal life-span of Mono, the grim-reaper comes to remove cells at random. This, of course, implies that cells can survive well beyond the nominal life-span, just as humans do. There are endless variations of such simulations. …