Patrick the purple dragon

dragoncoder047’s blog

random thoughts about nonrandom things

ParTcl

← Previous: Lisp Practice Next: Scratching My Head Again
Posted
By dragoncoder047
Category: c

This post is part 2 of the arduino-scripting series:

  1. uLisp Thoughts
  2. ParTcl
  3. Scratching My Head Again
  4. Some Unrelated Ideas
  5. Segfaults
  6. LILduino

C headers are annoying. I was getting fed up with uLisp/Yisp and so I decided to run another Google search for “embeddable scripting language for Arduino”.

It turned up mruby-arduino – poorly documented, and a little too big for my needs.

It turned up eLua – which unfortunately is just a flashable firmware with no C interface for custom functions (just like with MicroPython).

And it turned up Serge Zaitsev’s ParTcl interpreter. It’s a bare-bones interpreter for the Tcl programming language which implements only 5 core functions (subst, set, while, if, and proc) as well as puts and some math functions.

Despite this minimalism, it is simple to understand as most things are abstracted away into functions and datatypes – and, leveraging the fact that “everything in Tcl is a string,” malloc and free can be used easily for dynamic memory management.

Additionally, from the Github readme:

…which is exactly what I need to use it as an Arduino library!

There are a few bugs – namely this one:

In the default implementation lists are implemented as raw strings that add some escaping (braces) around each iterm. It’s a simple solution that also reduces the code, but in some exotic cases the escaping can become wrong and invalid results will be returned.

Using my experience from Lisp lists, I saw that Tcl lists could be implemented as a linked list as well. I proposed it and we’ll see what Serge says. I could probably fork ParTcl and add it myself anyway.

This seems like the best solution so far, and what I’ll probably go with.

One last thing, with the regard to the name – do you think ParTcl would run on a Particle?