ArticleslgStudy

science

Sam (text editor)

Sam (text editor) 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 Sam (text editor) rather than just read about it. In short: Sam is a multi-file text editor based on structural regular expressions. It was originally designed in the early 1980s at Bell Labs by Rob Pike with the help of Ken Thompson and other Unix developers for the Blit windowing terminal running on v9 Unix; it was later ported to other systems.

Sam (text editor) — main illustration
Sam (text editor) — illustration

Key takeaways

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

Reference excerpt

Sam is a multi-file text editor based on structural regular expressions. It was originally designed in the early 1980s at Bell Labs by Rob Pike with the help of Ken Thompson and other Unix developers for the Blit windowing terminal running on v9 Unix; it was later ported to other systems. Sam follows a classical modular Unix aesthetic. It is internally simple, its power leveraged by the composability of a small command language and extensibility through shell integration.

Design and features Sam is designed as two synchronous programs: a command interpreter and a mouse-oriented bitmap windowing interface. The interpreter's command set is modeled after the UNIX editor ed and may be used to operate the editor from a standard text terminal. By default, however, Sam presents its own graphical user interface (GUI) window, samterm, which additionally allows point-and-click operations through pop-up context menus. This two-process structure allowed sam to access files on networked host systems through remote execution of the file-access process while running the windowing interface locally, thereby bypassing latency over slow connections. Samterm presents windows to files being edited and to a persistent command window which accepts input as sam commands. Most common editing operations are quickly and naturally accomplished with the point-and-click interface, which also functions inside the command window. This latter fact allows commands to be edited (and resubmitted) just as any other text, a function inherited from the DMD 5620 terminal interface.

Command syntax Sam's command syntax is formally similar to ed's or ex's, containing (structural-) regular expression based conditional and loop functions and scope addressing, even sharing some of ed's syntax for such functions. But while ed's commands are line-oriented, sam's are selection-oriented. Selections are contiguous strings of text (which may span multiple lines), and are specified either with the mouse (by sweeping it over a region of text) or by a pattern match. Sam's commands take such selections as basic—more or less as other Unix tools treat lines; thus, multi-line and sub-line patterns are as naturally handled by Sam as whole-line patterns are by ed, vi, AWK, Perl, etc. This is implemented through a model called structural regular expressions, which can recursively apply regular-expression matching to obtain other (sub)selections within a given selection. In this way, sam's command set can be applied to substrings that are identified by arbitrarily complex context. Sam extends its basic text-editing command set to handling of multiple files, providing similar pattern-based conditional and loop commands for filename specification. Any sequence of text-editing commands may be applied as a unit to each such specification.

Infinite undos Sam was one of the first text editors to support "infinite" undo to revert any number of editing errors. This feature, combined with Sam's facility to easily edit its own commands and, fundamentally, its small, orthogonal command set (containing only 33 commands), represent the program's bias toward a low learning threshold over other more expressive "power editors."

Endorsers Sam is the preferred text editor of several eminent programmers. It was the first full screen editor Ken Thompson liked. Sam is the text editor used by Bjarne Stroustrup, Brian Kernighan, Douglas McIlroy and Tom Duff. Others, like Dennis Ritchie, Rob Pike and Russ Cox, have transitioned to acme, an editor with the same command language as sam, but with an assortment of additional features, including mouse chording and automatic tiling of opened files. The latest version of sam was written as part of the Plan 9 operating system, but there are Microsoft Windows, macOS and X Window System ports available.

See also

acme (text editor) — Rob Pike's other popular text editor and successor of sam. ed (text editor) — The original Unix text editor by Ken Thompson Plan 9 from Bell Labs List of Unix commands

Notes

References Pike, Rob (October 1987). "The Text Editor sam". Software: Practice and Experience. 17 (11): 813–845. doi:10.1002/spe.4380171105. S2CID 36076160. Retrieved 2008-11-01. Pike, Rob. "A tutorial for the sam command language". Retrieved 2008-11-01.

External links ssam(1): stream interface to sam Sam Resources sam(1): screen editor with structural regular expressions A new Unix version of sam as part of Plan 9 from User Space A sam quick reference card

Illustrations

Sam (text editor) illustration

Worked examples

Example 1 — a first encounter with Sam (text editor)

Start with the simplest possible case. Write down what Sam (text editor) 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 Sam (text editor) 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 Sam (text editor) 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 Sam (text editor)

In research
Sam (text editor) 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 Sam (text editor) 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
Sam (text editor) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free text editors, Inferno (operating system), MacOS text editors, so understanding it makes those chapters shorter.
In everyday life
Look for Sam (text editor) 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 “Sam (text editor)” →

How to study Sam (text editor) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Sam (text editor) 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 Sam (text editor) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Sam (text editor) in simple terms?

Sam is a multi-file text editor based on structural regular expressions. It was originally designed in the early 1980s at Bell Labs by Rob Pike with the help of Ken Thompson and other Unix developers for the Blit windowing terminal running on v9 Unix; it was later ported to other systems.

Why does Sam (text editor) 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 Sam (text editor)?

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 Sam (text editor).

Tags

  • Free text editors
  • Inferno (operating system)
  • MacOS text editors
  • Plan 9 from Bell Labs
  • Unix text editors
  • Windows text editors

Keep exploring