Search code examples
terminalttycaretbasiccursor-position

What is the purpose of the dummy argument that's passed to BASIC's POS function?


Not long ago I read that the Commodore 64's BASIC interpreter contains a POS function which returns the current horizontal position of the cursor. Since then, I've noticed this idiosyncrasy in some other BASIC dialects, including Microsoft QBASIC, and even Roku's BrightScript, which is much more recent.

What I'm wondering is, why is this a thing? If the value of the argument isn't used, why even require it? My guess is that maybe really early on BASIC didn't support functions without arguments, and it's stuck around for whatever reason, probably compatibility. But that wouldn't explain why it's still a required argument.

Worth mentioning is QBASIC also includes CSRLEN, which returns the vertical position of the cursor, but it doesn't require/accept any arguments. This supports my idea that it came from "ancient times"—POS would have been a well-defined operation on the earliest terminals (teletypes), but CSRLEN wouldn't have made sense until later hardware.


Solution

  • I seem to recall (very vaguely) that the lookup table in which pos was placed was one where all functions had an argument (like sin or fre). To that end, pos used common code to ensure it had an argument, even though it was ignored.

    The BASIC interpreter in the C64, being based on the (rather limited) 6502 CPU had to all sorts of wondrous tricks to allow all its functionality.


    Now keep in mind that required reaching down in to my gray matter through 30-odd years of detritus. I suspect you'll get a more accurate(a) answer over at the retro-computing sister site.


    (a) And probably more complete, to an almost painful degree :-)