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.
In addition to the answers above, something to keep in mind is that there wasn't a ton of commercial software available at the time compared to today and computers were not yet things that everyone needed or even found useful for their jobs. It's not like today where you could buy a computer, load it with Office and other software, use it to do your job, maybe even run your business and turn it into a multimillion dollar operation, and never touch a line of code. 

Meanwhile when I went to college in 1995 I had fellow freshmen who could barely get their PC turned on but they knew how to program in Pascal because the American school system at the time taught programming because they didn't know what else to do with these computer things everyone is buying, but they knew that it was going to be a "thing" in the future. 

So one of the reasons a lot of these old toy computers came with BASIC built in was because, compared to today, they didn't do much else. And they also tended to not run the software from the previous generation or any other computers (if you think about it, Apple's never completely shaken this mindset - they have few qualms about breaking backwards compatibility for machines more than a few years old and they sell a computer that can't run the software from the competition's platforms). Notice how it wasn't until the DOS/Windows cycle started happening that backwards compatibility became a big thing and then sales of computer took off. There were other factors too, like price, but it inspired a lot of consumer confidence when you could be reasonably certain your stuff could come along for the ride.