ArticleslgStudy

science

Bs (programming language)

Bs (programming language) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Bs (programming language) rather than just read about it. In short: bs is a programming language and a compiler/interpreter for modest-sized programs on UNIX systems. The bs command can be invoked either for interactive programming or with a file containing a program, optionally taking arguments, via a Unix shell, e.g., using a Shebang (Unix) #!/usr/bin/bs.

Key takeaways

  • Bs (programming language) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Bs (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Bs (programming language) from memory before moving on to harder problems.

Reference excerpt

bs is a programming language and a compiler/interpreter for modest-sized programs on UNIX systems. The bs command can be invoked either for interactive programming or with a file containing a program, optionally taking arguments, via a Unix shell, e.g., using a Shebang (Unix) #!/usr/bin/bs. An early man page states, "[bs] is a remote descendant of Basic [sic] and SNOBOL4, with a little C thrown in."

History The bs command appears in UNIX System III Release 3.0 (1980), first released outside of Bell Labs in 1982. It was written by Dick Haight (Richard C. Haight) circa 1978, who recounts it as follows:

I wrote bs at the time Unix (V 3?) and all of the commands were being converted from assembler to C. So [ Ken Thompson’s ] bas became my bs — sort of. The Release 3.0 manual mentions bs prominently on page 9 (emphasis added):

Writing a program. To enter the text of a source program into a UNIX file, use ed(1). The four principal languages available under UNIX are C (see cc(1)), Fortran (see f77(1)), bs (a compiler/interpreter in the spirit of Basic, see bs(1)), and assembly language (see as(1)). While not released outside prior to System III, the bs command was present internally in UNIX/TS 1.0 (November 1978), PWB/UNIX 2.0 (June 1979), and CB UNIX editions 2.1 (November 1979) and 2.3 (1981). The bs command does not appear in some earlier internal releases, e.g., the UNIX Support Group’s March 1977 release, nor the PWB/UNIX manual dated May, 1977, suggesting its creation circa 1978. It does not appear in any version of Research Unix nor the Berkeley Software Distribution. Subsequently and into the 1990s, bs was included in a variety of System III-derived or System V-derived commercial operating systems including, but not limited to: PC/IX; UNIX System V Releases 2 & 3: SVR2, SVR3, SVR3.2 (1986); HP-UX; AIX; and A/UX. (The User's Manual for the AT&T UNIX PC (3B1) specifically mentions that the bs command is not available, but that it is available on SVR3.2.) Occasionally, bs was touted as one of the primary programming languages for development under UNIX. However, bs is not included in the POSIX.1 commands and utilities (the standard List of Unix commands) nor in the Single UNIX Specification and is not provided with most contemporary operating systems. For example in Linux, similar syntax and functionality is provided by bc, Perl, and POSIX shell. In the 21st century, bs is present in, at least, HP-UX Release 11i (2000), as well as AIX versions 6.1 (2007) and 7.2 (2018), likely due to their UNIX System V heritage.

Design and features The bs man page, ostensibly the programming language's only specification, characterizes it as follows:

Bs is designed for programming tasks where program development time is as important as the resulting speed of execution. Formalities of data declaration and file/process manipulation are minimized. Line-at-a-time debugging, the trace and dump statements, and useful run-time error messages all simplify program testing. Furthermore, incomplete programs can be debugged; inner functions can be tested before outer functions have been written and vice versa. A bs program is compiled and executed differently from programs written in the other principal Unix programming languages of the time: C, FORTRAN, and assembly language, whose respective commands compile program source code to executable assembler output (a.out). Instead, a bs program is, first, converted by the bs command to an internal reverse Polish (RPN) intermediate representation and then executed by the command's internal virtual stack machine. The bs language, thus, is a hybrid interpreter and compiler and a divergence in Unix programming from Ancient Unix. The bs language shares some features and syntax with BASIC, SNOBOL, and C, the two former presumably inspiring its name. Like BASIC, it can be used interactively, either executing statements immediately or collecting them into a program to be executed subsequently. Like in SNOBOL4, the assignment operator (=) is used for I/O and bs can execute code in strings, using its eval function. It also includes SNOBOL's interrogation operator (?) used to test whether an expression evaluation succeeds or not. The built-in format function, limited to one argument, supports a subset of C's printf format conversion specifiers, e.g., "%f". The language has some conspicuous elements. For instance, its program functions are defined using the fun ... nuf syntax and its functions can have local variables. Also, bs can operate in two modes, either interpreting (and executing) statements and programs or compiling them, and switching between the two using compile and stop. Otherwise, its functionality is unique only collectively (in one language), since individual features are redundant with those of coexisting tools, such as the Unix Shell, e.g., file I/O and loops, and AWK, e.g., associative arrays and Regular expression matching. The bs language was meant for convenient development and debugging of small, modular programs. It has a collection of syntax and features from prior, popular languages but it is internally compiled, unlike a Shell script. As such, in purpose, design, and function, bs is a largely unknown, modest predecessor of hybrid interpreted/compiled languages such as Perl and Python.

Syntax Examples The following examples are derived from an A/UX bs(1) man page. This example uses bs as a calculator:

This example is the outline of a typical bs program:

This example demonstrates I/O:

Sample Program The following is a sample bs program that emits the words to the song 99 Bottles of Beer using /usr/bin/bs.

See also dc bc

References

Worked examples

Example 1 — a first encounter with Bs (programming language)

Start with the simplest possible case. Write down what Bs (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Bs (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Bs (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Bs (programming language)

In research
Bs (programming language) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Bs (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Bs (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programming languages, Unix programming tools, so understanding it makes those chapters shorter.
In everyday life
Look for Bs (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Bs (programming language)” →

How to study Bs (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Bs (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Bs (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Bs (programming language) in simple terms?

bs is a programming language and a compiler/interpreter for modest-sized programs on UNIX systems. The bs command can be invoked either for interactive programming or with a file containing a program, optionally taking arguments, via a Unix shell, e.g., using a Shebang (Unix) #!/usr/bin/bs.

Why does Bs (programming language) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Bs (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Bs (programming language).

Tags

  • Programming languages
  • Unix programming tools

Keep exploring