Question: There are a lot of retro-computers with BASIC as an integral part of the operating system. The IBM 5100 was one of the first computers with a separate memory space for BASIC, followed by the Commodore PET, Apple II and TRS-80.

But why was BASIC built into their operating systems, using memory? From [this memory map](http://sta.c64.org/cbm64mem.html), the Commodore 64 had memory completely reserved for BASIC. There were computers, like the Altair 8800, that provided BASIC as software that could be loaded into memory when necessary, and these computers both worked and sold well.

So why was BASIC built into so many computers' operating systems?

Answer: 
As far as I know it was included because it was essentially the operating system interface. When you installed MS-DOS on a PC it provided you with commands and allowed you to run programs that executed machine code on the machine. 

BASIC back then was similar. It provided you with a command prompt, operating system-level commands like reading/writing data to disk, a printer, tape, do simple things like print to the screen, and read in user input.

This way you had a general set of commands with an interpreter that could be ported to other CPUs and memory configurations with minimal changes. You just needed to setup which commands were available and what machine specific code was run for those command.

Essentially a portable, programmable, operating system.
Once upon a time, 16 kilobytes of DRAM was expensive. The original 8080 Altair came with up to 4 kbytes of memory on a single memory board.

The only programming languages (higher than ASM) that could fit in that small a memory were Tiny BASIC (Palo Alto Tiny BASIC, Altair BASIC (Gates and Allen) and Woz's Integer BASIC, et.al.) and Forth. The only alternatives were hand coding assembly language, or cross-compiling on a larger minicomputer. Basic was more well known and far more commercially viable than entering programs in binary via front panel switches. Later personal computers continued with what the market was familiar with (from the books and magazine articles at that time), and came with BASIC loaded into ROM. 

So the answer is:

BASIC (with a very simple OS for I/O) came in ROM on many early personal computers because mass-produced masked ROM was cheaper than RAM, on a per byte basis. 64k address space was considered huge at the time, so dedicating a portion of it to ROM was not considered wasteful. And BASIC in ROM allowed the computer to be usable on power-up, instead of after loading software via paper-tape, cassette tape, or some other media.