Live data from Hacker News

Running Advent of Code on a $2 microcontroller

medium.com

1–10 of 14 posts

Re: Running Advent of Code on a $2 microcontroller

#2
Two different Smalltalk-on-embedded articles on the front page of Hacker news right now: This one (by me) and https://news.ycombinator.com/item?id=34208753

Yes, Toit is pretty much a Smalltalk dialect.

Similarities

Blocks (closures passed to functions as a foundation of control flow)

Blocks have non-local return (you can return from the syntactically enclosing fn in a block).

Block arguments introduced with | | delimiters

Single inheritance object orientation

Dynamic typing but type safe

Named arguments

Uses virtual machine to run, including garbage collector.

Differences

Toit's syntax is more like a cleaned up Python than Smalltalk.

Toit also has positional arguments.

Toit's blocks are more lightweight than Smalltalk closures (no allocation)

Development is with source files and compiler, not image-based.

Toit has optional types, and if you use them they are checked. (Types are non-nullable by default.)

Toit has interfaces

Toit can build standalone executables, VM included

Toit has top level functions not attached as methods to some class.

Array (List) indexing is 0-based, not 1-based.

Quick intro here: https://docs.toit.io/language

Re: Running Advent of Code on a $2 microcontroller

#4
post #3

> special CoordSet that wraps a regular Set, encoding objects into integers... we don’t need to implement decoding the integers and reifying the Coord objects Wouldn't it be much simpler to just keep a set of hashes? That's basically what this is.

Not sure what you mean by this. Hashes have collisions, so how would that work?

The attraction of the CoordSet is that it behaves as if it is storing actual objects, but is actually saving memory. So the abstraction hides the optimization, which makes it easier to reason about the rest of the program.

Re: Running Advent of Code on a $2 microcontroller

#5
post #3

> special CoordSet that wraps a regular Set, encoding objects into integers... we don’t need to implement decoding the integers and reifying the Coord objects Wouldn't it be much simpler to just keep a set of hashes? That's basically what this is.

Not sure what you mean by this. Hashes have collisions, so how would that work? The attraction of the CoordSet is that it behaves as if it is storing actual objects, but is actually saving memory. So the abstraction hides the optimization, which makes it easier to reason about the rest of the program.

Collisions are extremely unlikely. You will know if a collision occurred if the answer is rejected. If that happens you can tweak the hash algorithm and try again. This would allow saving coordinates outside of the [-1000, 30000] range.

I think it would be easier to reason about because,

1. KISS: You don't need to verify the encoding code is correct.

2. YAGNI: The program doesn't require reading the coordinates back out, so the program should not store the coordinates in a format that can do that.

Re: Running Advent of Code on a $2 microcontroller

#7

Two different Smalltalk-on-embedded articles on the front page of Hacker news right now: This one (by me) and https://news.ycombinator.com/item?id=34208753 Yes, Toit is pretty much a Smalltalk dialect. Similarities Blocks (closures passed to functions as a foundation of control flow) Blocks have non-local return (you can return from the syntactically enclosing fn in a block). Block arguments introduced with | | delim…

[deleted]

Re: Running Advent of Code on a $2 microcontroller

#9
post #8

What a wonderful little language! Can I use it on PC?

Sure.

The easiest way is probably to install Jaguar https://github.com/toitlang/jaguar

I would very much recommend the Visual Studio Code extension when you are starting out with the language. Will give you a lot of help and hints around the syntax. But you can use any editor.

Run a program on the desktop with `jag run -d host myprogram.toit`

Install the `host` package for non-embedded things like files, pipes and subprocesses:

# Make this directory into a Toit project.

touch package.yaml

# Install the host package

jag pkg install host

Other packages like http or mqtt can be found at https://pkg.toit.io/

Re: Running Advent of Code on a $2 microcontroller

#10
post #8

What a wonderful little language! Can I use it on PC?

Sure. The easiest way is probably to install Jaguar https://github.com/toitlang/jaguar I would very much recommend the Visual Studio Code extension when you are starting out with the language. Will give you a lot of help and hints around the syntax. But you can use any editor. Run a program on the desktop with `jag run -d host myprogram.toit` Install the `host` package for non-embedded things like files, pipes and su…

Thank you very much for the instruction. It went smoothly. I just had to additionally run

jag setup

which I was clearly told by jag run ...

Very nice experience so far.

One issue I have is that when I use UTF-8 characters in strings they don't show up correctly when the program outputs them to console which also uses UTF-8.

Not sure if I should configure jag somehow to make it work?

With exactly the same setup (editor/console) I have no encoding issues with javascript or python.

What's weirder, console in MINGW64 git bash window (directly, but not through Visual Studio Code) works just fine, even if I launch cmd or powershell in this gitbash window it still works fine.

Switching windows to UTF-8 systemwide through intl.cpl seems to help.

Still weird that other environments don't require this.

Post reply on HN