What happens to your input - inside Prolog


next up previous contents
Next: Who are you talking to?
Up: Operating systems
Previous: What happens to your input - inside the operating
Back: to main list of student notes

What happens to your input - inside Prolog

When the input reaches Prolog, there are more complications caused by the fact that Prolog commands need not be exactly one line long. If they were, it would be easy to tell where they ended. But Prolog is designed to be free format, so that spaces and newlines between words have no significance. Thus you can write either

eps(psbug2,psworld2).
or
eps( psbug2,
     psworld2
   ).
or even
eps
(
psbug2
,
psworld2
)
.

When typing commands, you normally won't want this freedom, and will use as few spaces as possible. However, when writing programs (such as sets of production rules), it's very useful to have it. Indentation and spacing form valuable psychological cues to a program's structure. Hence, although the older card-based languages did not allow free-format input, all the newer ones do.

This means that the only way Prolog can tell where a command ends is by looking for the dot at the end. And it uses its own buffer to do this. As soon as it receives a character from the operating system, it adds it to the buffer. It keeps doing so, until it sees a dot. It then takes the entire contents of the buffer to be the next command, and processes that.

The upshot of this is that even if you hit RETURN, if you forget the dot at the end of the command, Prolog will again just keep waiting.

Incidentally, the operating system does not need dots at the end of its commands. It assumes that all commands are one line long unless you tell it otherwise. If you type a dot, it will be treated as an error. You may also have tried the Eliza program. This assumes that all sentences are one line long, and hence doesn't need a terminator either. However, the operating system and Eliza both require you to hit RETURN after a line.


next up previous contents
Next: Who are you talking to?
Up: Operating systems
Previous: What happens to your input - inside the operating
Back: to main list of student notes



Jocelyn Paine
Thu Feb 15 00:11:40 GMT 1996