steven@boring.uucp (Steven Pemberton) (01/29/86)
(This B is unrelated to the predecessor of C: B is a working title. The language will get its final name, ABC, when the language is frozen.) Summary There is now a first implementation of B available for the IBM PC and compatibles under MS-DOS, alongside the existing implementation for Unix. It is available for the cost of the media: $35 US, or Dfl. 100. Details of the implementation and an order form are at the end of this article. What is B? B is a new interactive programming language and environment that is as simple as Basic to learn, offers the structure of C and Pascal, but thanks to its high-level data-types is very powerful and convenient to use. DATA-TYPES It has 2 basic data-types: numbers and texts (=strings), and 3 composite data-types: compounds, lists and tables. o Numbers are unbounded, like all data-types in B, and are kept exact if possible (even with division); o Texts can be joined, repeated, trimmed; o Compounds are like records, or structures, but without field-names; o Lists are sorted sequences of values of any one type (numbers, texts, lists...); o Tables are generalised arrays: both indexes and elements may be of any type. COMMANDS The usual structured commands are available: IF, WHILE, etc. You can define your own commands and functions. Functions can return values of any type. ENVIRONMENT B is both a language and an environment. There is a structured editor that knows about B which you use the whole time that you are using B. It suggests possible command completions, so for instance, if you type a W, it suggests the command WRITE, which you can accept by typing a tab. It also supplies such things as closing brackets automatically. EXAMPLES The best way to appreciate the power and simplicity of B is to see some examples, and 2 are given below. For more details see "An Overview of the B programming Language" by Leo Geurts, in SIGPLAN December 1982, and "Description of B" by Lambert Meertens and Steven Pemberton, SIGPLAN February 1985.) Imagine you want to maintain a list of phone numbers. You start off with an empty list (>>> is the prompt from B): >>> PUT {} IN tel and add a few numbers >>> PUT 4138 IN tel["Frank"] >>> PUT 4071 IN tel["Leo"] >>> PUT 4141 IN tel["Lambert"] Now you can look up individual numbers: >>> WRITE tel["Leo"] 4071 or even write the whole table: >>> WRITE tel {["Frank"]: 4138; ["Lambert"]: 4141; ["Leo"]: 4071} (note they're sorted on the names). You can access the list of 'keys' (the indexes): >>> WRITE keys tel {"Frank"; "Lambert"; "Leo"} and so you can write the table neatly: >>> FOR name IN keys tel: WRITE name, ":", tel[name] / Frank: 4138 Lambert: 4141 Leo: 4071 It is easy to discover who has a particular number: >>> IF SOME name IN keys tel HAS tel[name]=4141: WRITE name Lambert But if you do this often it is easier to create the inverse table: >>> PUT {} IN let >>> FOR name IN keys tel: PUT name IN let[tel[name]] >>> WRITE let[4141] Lambert >>> WRITE let {[4071]: "Leo"; [4138]: "Frank"; [4141]: "Lambert} Example 2: a cross reference generator. (This example would need more than 100 lines of Pascal or C.) HOW'TO INDEX text: PUT {} IN xtab FOR line'no IN keys text: TREAT'LINE OUTPUT TREAT'LINE: PUT text[line'no] IN line WHILE line>"": TREAT'WORD TREAT'WORD: GET'WORD IF word>"": SAVE'WORD GET'WORD: PUT "" IN word WHILE line>"" AND NOT alpha: PUT line@2 IN line WHILE line>"" AND alpha: PUT word^line|1, line@2 IN word, line alpha: REPORT line|1 in {"a".."z"} OR line|1 in {"A".."Z"} SAVE'WORD: IF word not'in keys xtab: PUT {} IN xtab[word] INSERT line'no IN xtab[word] OUTPUT: FOR word IN keys xtab: WRITE word<<10 FOR line IN xtab[word]: WRITE line>>4, " " WRITE / THE IMPLEMENTATION o Requires at least 384K bytes to run, though there is a restricted version without the built-in editor that runs in 256K. o Runs under MS-DOS 2.0 or higher. o Configurable for different size screens, or to use the ANSI screen driver, for compatibles with incompatible BIOS. o Editing operations can be bound to the keys of your choice. o Comes on a single 5.25" or 3.5" diskette. Apricot format also available. o It is not copy protected. But: o It is not a production version: it is not fast, but it is fun! WHAT YOU GET Apart from the floppy, you get a book introducing B, how to use the system, and giving a complete description of the language, and a quick reference guide. HOW TO ORDER Fill in the details below, and send them with a cheque or money order for $35 US or Dfl. 100 (to cover cost of media, postage, etc.) payable to Stichting Mathematisch Centrum, Amsterdam to: B Group, PC Distribution Informatics/AA CWI POB 4079 1009 AB Amsterdam The Netherlands Name: Organisation: Address: Country: Telephone: Network address: Type of machine(s): Required media [ ] 5.25" double-sided, double density floppy [ ] 3.5" double-sided floppy Required version [ ] Full implementation (at least 384K bytes) [ ] Small version (256K bytes) Signature and date: