3 ms·
Not having used sam, but having used Linux since the 90s, why is "lines" quoted? Do text files not consist of lines, in sam?
by unwind 3y ago
Not having used sam, but having used Linux since the 90s, why is "lines" quoted? Do text files not consist of lines, in sam?
- jodrellblank 3y agoIt was a surprise to me to really understand that text files don't consist of lines anywhere, they are byte arrays. Interpreting 97 98 99 13 97 98 99 as text with lines abc abc is just one way to view it, but only 'correct' as far as saying agrees with the author's intent, but not objectively 'more correct'. I now think that being able to interpret the same thing in many ways, and shift between them at will to use the most useful one or leverage a different tool, is a key skill in computing and programming which doesn't get discussed all that often. Vim uses it in letting you treat it as lines, words, sentences, paragraphs, blocks, screens. Regexes let you treat it as character sequences, arbitrary sequences of patterns, repeating patterns. Hex editors go for the byte level. Structure editors let you treat it as INI blocks, key=value pairs, XML trees. IDEs let you treat it as functions, methods, classes, headers. And the more of them you can see, the more tools you can use - e.g. treating CSVs as lines of text in one context, then comma separated text, then comma separated dates and numbers and text, then entries in a user database, that lets you do different kind of processing on the same data where someone who sees it only as "a CSV" is more restricted. (I suspect that's a part of general thinking; being able to see the same thing in different overlapping contexts which let you take it apart at different size boundaries; e.g. a dessert on a table, is also a trifle, which is part sponge cake, which is a flour/butter/egg/sugar mix which is a starch/fat/binding/sweetner and that lets you rebuild it either as swapping the trifle out at your dinner party, or swapping the sponge out for biscuits in the trifle, or swapping the butter for margarine in the sponge recipe. Someone stuck in the pattern "children's parties always have trifle" or "this is an Italian theme dinner party so it has to have an Italian dessert" is limited, someone who sees a trifle as something you buy from a shop and can't make one, is limited, someone who sees trifle as "made with sponge" is limited, someone who sees sponge as a single recipe is limited, someone who can swap any part at any level at their convenience is more flexible, less limited; someone who can do that on the fly for any of the foods on the table, would make a really good cook/host/organizer). See also: inside computers, it's all bytes, that's all there is. See also: Steve Yegge classic essay "The Emacs Problem" https://sites.google.com/site/steveyegge2/the-emacs-problem https://sites.google.com/site/steveyegge2/the-emacs-problem "How did I get so far off the original track of text processing? Well, that's the punch line of this shaggy-dog story: it's all text processing! Log files, configuration files, XML data, query strings, mini-languages, programming languages, transformers, web pages, word documents, everything... the vast majority of your programming work involves text processing somehow. What would you rather do? Learn 16 different languages and frameworks in order to do "simple" log-file and configuration-file processing? Or just buckle down, learn Lisp, and have all of these problems go away forever?"
- bediger4000 3y agoMy memory is slightly hazy, but... Sam certainly rendered text as lines, like you'd expect, respecting newlines as line breaks. But it had a different idea about lines of text when it came to regular expressions. There was a metacharacter that matched newlines as if they were just another character, so that regular expressions could match blocks of text spanning multiple lines. A separate metacharacter matched newlines the way vim does. This and other consequences of treating newline characters as just another character gave Sam a different feel, where lines weren't as important.
- casey2 3y agoI use sam -d. It's fairly similar to ed if you are familiar with it, the main differences are the expanded command language, better interface with *nix environments and allowing dot to include newlines, thus having commands work across lines. In windowed sam dot is the currently highlighted text and you have a snarf, cut and paste editor along with a separate window for commands.