4

Dartmouth BASIC seems to have gotten strings around 1968, and BASIC uses the $ on variable names to indicate that they're strings. This is a strategy for avoiding the need for explicit type declarations. I imagine that type declarations would have been considered an unwanted barrier to user-friendliness, and they would have also been a a poor fit because the language lacked any syntax at levels broader than the level of one statement (no begin-end, etc.). (Most implementations after Dartmouth BASIC were pure statement-by-statement interpreters.)

The first Unix shell came out in 1971. The Bourne shell uses a similar (but prefixed) $ syntax, although it has more to do with dereferencing and string interpolation. Perl, which is basically shell on steroids, uses the sigils $, @, and % in a manner similar to Dartmouth BASIC's, as an alternative to explicit typing (although the distinction being made is a different one, and they are also used for string interpolation).

Was the use of sigils as an alternative to type declarations an innovation of Dartmouth BASIC, or was it present in some earlier system such as the Multics shell (which I believe inspired the Bourne shell)?

17
  • 5
    BASIC was designed to allow lines of source to be processed without any semantic dependency upon any lines in the source code that have not been executed, nor any syntactic dependency upon other lines whether they have been executed or not. I don't know if it was the first such language, but those aspects somewhat force the design.
    – supercat
    Sep 28 at 19:12
  • 2
    What supercat said for sure, plus, compatability with earlier versions of BASIC. There just weren't that many types. In fact, for the first THREE VERSIONS of Dartmouth BASIC there was only ONE type: float. String variables weren't introduced until version 4 (according to wikipedia). So, when introducing string variables, in addition to wanting to minimize implementation effort, you also wanted all old programs of your students and professors to keep working. So it would have been hard to introduce types.
    – davidbak
    Sep 28 at 20:08
  • 2
    Finally, the era of the introduction of BASIC was the era of assembly languages, LISP, RPG, COBOL, and FORTRAN. You don't see any type declarations in any of those. (Well, COBOL. But that clearly wasn't going to influence any academically-designed language used for students.)
    – davidbak
    Sep 28 at 20:15
  • 1
    @supercat The lines have a dependency on the values of variables mentioned in them, though, and you could store the declared type in the same table. Or just have untyped variables and typed values, like Lisp. Maybe it just saves a bit of space to store variables of different types in separate linked lists.
    – benrg
    Sep 28 at 20:48
  • 1
    @benrg: The question of whether 150 IF X < Y THEN 200 should perform a numeric comparison or a string comparison should not require examining anything else in the code, and should not be affected by anything else the program has done.
    – supercat
    Sep 28 at 21:06
1

I imagine that type declarations would have been considered an unwanted barrier to user-friendliness

Not necessarily, as for example arrays do have a DIM.

Perl, which is basically shell on steroids, uses the sigils $, @, and % in a manner similar to Dartmouth BASIC's

Not really: In Perl, the prefixes and the context determine the usage. Example from the tutorial:

my %fruit_color = ("apple", "red", "banana", "yellow");
$fruit_color{"apple"};           # gives "red"

In BASIC, using different sigils means those are always different variables.

In Perl, can also evaluate the same variable in a string or list context:

my @animals = ("camel", "llama", "owl");
if (@animals < 5) { ... }

Which you cannot do in BASIC.

Which brings me to the main point:

Was the use of sigils as an alternative to type declarations an innovation

An important point that has not been brought up is that in quite a few early BASIC dialects (and unlike e.g. PERL), only the first letter and the following number counts. However, the sigil also counts. Which meant now you could have A for a number, A$ for a string, and A() for an array, and they would all be different. This made programming a lot easier.

And this approach is older than BASIC, and also used in other languages like MUMPS (where a following ^ distinguishes scalars and so called "globals" that are tree-structured).

The Bourne shell uses a similar (but prefixed) $ syntax, although it has more to do with dereferencing and string interpolation.

Exactly. So the way unix shells (and languages like Tcl) use a leading $ is quite different.

4
  • DIM is only actually needed for arrays whose largest index exceeds 10. I regard that as evidence of avoiding type declarations where possible, with a dollop of pragmatism on the side. Oct 2 at 12:25
  • 1
    This doesn't address the question. Oct 3 at 1:50
  • 1
    @BenCrowell your question is based on some assumptions that don't really apply, in particular that use of $ of BASIC in the one hand and shells or Perl on the other hand is somehow comparable. It does explain why BASIC uses $ and () as suffixes to create new kinds of variables, and that this is not a new idea, and has been used before.
    – dirkt
    Oct 3 at 4:46
  • Your facts about Perl are wrong, and you also got the name of the language wrong.
    – hobbs
    Nov 2 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.