Review Advent of Code in Dialog, please

On your recommendation I have continued my Z-machine explorations with Dialog! The prose in the article is not finished, nor am I happy with the structure, but all the main pieces should be there.

I’m just less confident in my understanding of Dialog, so if someone could take the time to glance over the technical details and point out any big misunderstandings I seem to be harbouring, that would be amazing.

I hope to be able to publish for a wider audience next week, maybe.

(I also notice the syntax highlighting has a few oddities around queries – this is part of that Emacs mode I’m working on.)

7 Likes

Always love seeing more Dialog content!

It wouldn’t be hard to add some bitwise operators to Dialog, but I’ve refrained because I haven’t seen a lot of need for them, and adding more opcodes to the Å-machine is a bit of a pain. If there’s demand, though, it would be possible to add the basic set (& | ^ ~ >> <<) to operate on 14-bit numbers. (When I was playing around with writing a bignum library, I just converted everything to lists of base-100 digits via division and modulo, and used list operations instead.)

{ (cond) (result) (or) (otherwise) } isn’t actually exactly the same as (if) (cond) (then) (result) (else) (otherwise) (endif). They’re mostly the same, but (if) has the extra convenience of discarding all choice points after the condition is evaluated. This means that a failure farther down in the query will never backtrack to a leftover choice point from an earlier conditional.

The reason why #symbols are called “objects” is because Dialog originally always compiled to the Z-machine, and objects are a fundamental part of the Z-machine architecture. But in fact Dialog makes very little use of that architecture! It doesn’t use Z-machine property tables at all, for example.

But I also find myself wishing Dialog was a better general-purpose language, because it has been nice to work in. Then again, maybe this sharp focus on text adventures is what has kept it nice.

That was Linus’s original rationale for not including negative numbers or more math operations. Some of its limitations also come from the Z-machine, such as not being able to detect the case of its input (all input is converted to lowercase). But if there are features that would help it be useful in general, feel free to pitch them! I’m always looking for ways to make the language better for its users.

4 Likes

This is an excellent idea which I’m trying for the second day of this year’s AoC. I have the parser, constructor, and addition going. Once I’m out of this flu I’ll see if I can tie it together.

Yep, I realised this too. Anything else would be unexpected!

I’m afraid ultimately this would entail targeting something other than text adventure VMs, at which point just using Prolog might be easier… but I like the cohesiveness of Dialog.

2 Likes

Yeah, targetting something other than the Z-machine or Å-machine isn’t really on the table right now I’m afraid. There’s been some discussion of Glulx, but even that is a lot of work for minimal payoff.