Bra和KET:AmigaDOS中的字符串插值
Bra and KET: String Interpolation in AmigaDOS

原始链接: https://www.datagubbe.se/braket/

本文探讨了AmigaDOS脚本插值令人惊讶的灵活性,重点关注用于分隔变量的字符。默认情况下,使用`<`和`>`,但可以使用`.BRA`和`.KET`指令更改这些字符。 Datagubbe Labs的作者研究了哪些字符是有效的。他们创建了一个名为`makescript`的ARexx程序来生成带有自定义分隔符的脚本,并测试了各种场景。标准的卷曲括号(`{`和`}`)按预期工作,同时还有不匹配的括号对,例如`[`和`}`,甚至标准字母也能正常工作。 调查进一步深入,探索了不可打印的ASCII字符。换出(SO)和换入(SI)字符按预期工作,而使用BEL字符(ASCII 7)作为起始字符和NAK字符(ASCII 21)作为结束字符也同样有效,尽管BEL字符通常会使屏幕闪烁。 文章总结道,AmigaDOS脚本插值功能强大,并为分隔符提供了广泛的字符选择,这证明了其弹性和适应性。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Bra 和 KET:AmigaDOS 中的字符串插值 (datagubbe.se) ingve 1小时前 7 分 | 隐藏 | 过去 | 收藏 | 讨论 加入我们,参加 6 月 16-17 日在旧金山举办的 AI 初创公司学校! 指导原则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系我们 搜索:
相关文章
  • (评论) 2024-07-24
  • 动态规划不是黑魔法 2024-01-15
  • Tcl 教程 2025-03-17
  • 周末项目:用 C 变得愚蠢 2024-07-01
  • (评论) 2024-04-28

  • 原文

    Exploring the unnecessary, part 3735928559

    Spring 2025

    A Short Word on AmigaDOS Scripts

    Without getting caught up in semantics, AmigaDOS in this text refers to the command line portion of the Amiga computers' operating system. AmigaDOS is based on TRIPOS, but was expanded and added to by both the original Amiga team and then Commodore. One thing that remains basically the same is the parser for shell scripts, or sequence files as they're called in TRIPOS. The script parser is reasonably competent for a 1980:s home computer OS and can be used for solving real world made up programming problems.

    The parser accepts a few special directives, such as .KEY, which is used to describe the template for arguments passed to the script file. For example, .KEY FILENAME/A tells the parser that the script accepts a string argument called FILENAME. These directives are placed at the start of the script file.

    By default, the parser does string interpolation using the characters < (less than) and > (greater than). The cleverness of this is debatable: these characters are also used for I/O redirection, which can quickly make things confusing. Luckily, the parser also accepts the directives .BRA and .KET, each followed by a single character, which lets the programmer override the default interpolation characters. The terms BRA and KET are most likely borrowed from Dirac notation.

    A Simple Example

    Usually, AmigaDOS scripts using interpolation replace the default characters with curly braces, { and }, respectively. This trend may have originated at Commodore. Consider the following script:

    .BRA {
    .KET }
    .KEY var
    Echo Hello {var}!
    

    Here, < and > have been substituted with { and }. The script takes a single argument, var, and the string interpolation then replaces {var} with the supplied argument. If saved as the file myscript and executed, the following AmigaShell session can be achieved:

    AmigaShell> myscript datagubbe
    Hello datagubbe!
    AmigaShell> _
    

    Interpolate This!

    This of course begs the question: What characters can be used for string interpolation in shell scripts? Thanks to the tireless efforts of talented researchers at Datagubbe Labs, an answer can be presented - and programmers worldwide can finally get a good night's sleep. Without further ado, let's get down to brass tacks!

    Test Tooling

    There are text editors on the Amiga that'll happily insert any ASCII character into a text file, but why use an existing solution when you can build your own? An ARexx program - makescript - was quickly hacked together meticulously constructed for the purpose. This program generates an AmigaDOS script file with arbitrary characters for .BRA and .KET, supplied either as plain text or ASCII char codes. The source code for makescript is available here.

    Bread and Butter

    The defaults and the standard curly substitutes both work very well, as expected. Datagubbe Labs has taken the liberty of preparing screenshots, to further emphasize the validity and rigor of this important research. The scripts can also be downloaded, for transparency and reproducibility. Witness:

    A screenshot of an Amiga shell window running the scripts using default and curly bra-kets.

    Odds and Alphas

    What about non-matching character pairs, such as [ and }? That works, too, which was expected. As does standard letters, such as A and B.

    A screenshot of an Amiga shell window running the scripts using odd and alphabetic bra-kets.

    Bells and Whistles

    Finally, non-printable characters were introduced. First, shift out (SO, decimal char code 14) and shift in (SI, decimal char code 15) were tested. These worked, too. Then, upping the ante, our relentless researchers decided to try the ASCII BEL character (decimal char code 7). AmigaDOS handles the BEL character by flashing the screen when it's encountered in a text. How would this fare in script execution? For closing the interpolation, negative acknowledgement (NAK, decimal char code 21), was chosen. This too, proved to work flawlessly - and no screen flashing was encountered when executing the script.

    A screenshot of 
an Amiga shell window running the scripts using SO/SI and BEL/NAK
bra-kets.

    Another Job Well Done

    Naturally, when printing the script file contents to the shell window using the AmigaDOS command Type, these characters cause a bit of commotion. BEL, for example, results in a screen flash as expected. In order to verify that the characters are indeed present in the script files, feel free to download them above - or study this screenshot of MicroEMACS, displaying the non-printable characters as control sequences.

    In conclusion, AmigaDOS string interpolation offers both resilience and a wide variety of choice - a cause for celebration as good as any. Thanks for your attention, and happy hacking!

    联系我们 contact @ memedata.com