Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Josh Holbrook
Josh Holbrook

Posted on

Matanuska ADR 015 - String Concatenation Operator

This article is a repost of an ADR fromMatanuska BASIC, my attempt to write a BASIC interpreter in TypeScript.

Context

Atto

While researchingfantasy consoles, I learned about a BASIC implementation calledAtto. In its"from BASIC" doc, it mentions that it uses; as its string concatenation operator.

This seems like an odd decision. But it makes sense when you remember thatprint in traditional BASIC use; to separate expressions. As I understand it, this is ad-hoc syntax in those commands. What Atto does here is take this syntax andgeneralizes it. That makes it avery interesting and clever design choice.

Matanuska BASIC's Current Behavior

Currently, Matanuska BASIC treats+ as a concatenation operator. This isn't an unusual choice - BASIC8 goes this route, for example. It's also consistent with many modern languages, such as Python.

Traditional BASIC Behavior

TheECMA-55 Standard describes; assolely a mechanic withinprint statements. Other statements which similarly take multiple arguments use, to separate them. In fact,print will allow expressions to be separated by, as well, but treats, and; differently - put a pin in that.

The specification forPRINT is... interesting. It specifies fixed-width "zones" for print output within a fixed-width "margin". The specification ensures that numbers can be formatted in a way where they'll always fit within one of these zones. It then specifies that, while; is treated as a concatenation operator,, generates enough space to align the following value to the next zone.TAB(<n>) is treated asspecial syntax which "tabs over"n number of zones. If a print statementends in a; or,, a newline isnot generated and thefollowing print statement appends to the end of that line. Finally, if a print statement has enough values that it overflows the margin (or outputs a string which is long enough to do the same), it inserts newlines as-needed to avoid clipping.

Decision

Matanuska will continue to use the+ operator for general purpose string concatenation.

First,+ is common and well-understood in many modern languages, while; would be considered strange and unusual. Honestly, that's enough.

But second,; isn't treated as a concatenation operator in traditional print statements, as much as it is treated as special syntax for formatting print output - and it's odd syntax at that. Rather than implement; as a general purpose string concatenation operator, I'd rather leave print statements as a potential odd duck - or possibly avoid traditional semantics altogether, in favor of eitherecho-like behavior or shell-like string "templating".

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I'm an Alaskan software developer with expertise in data, distributed systems and site reliability.
  • Location
    Alaska
  • Education
    M.S. Mechanical Engineering
  • Work
    Staff Engineer
  • Joined

More fromJosh Holbrook

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp