3 ms·
From Wikipedia entry on SNOBOL/SPITBOL 'SNOBOL4 stands apart from most programming languages by having patterns as a first-class data type (i.e. a data type wh
by Zuider 11y ago
From Wikipedia entry on SNOBOL/SPITBOL
'SNOBOL4 stands apart from most programming languages by having patterns as a first-class data type (i.e. a data type whose values can be manipulated in all ways permitted to any other data type in the programming language) and by providing operators for pattern concatenation and alternation. Strings generated during execution can be treated as programs and executed.'
By contrast, other languages such favor the use of regular expressions.
I am not so sure about the claim to uniquness. Ralph Griswald went on to develop the Icon language which included this feature. The Unicon language, a superset of Icon also has this distinction.
- raldi 11y agoI'm having a hard time understanding the parenthetical. If you grok it, and could take a moment to explain it in your own words -- or give an example of its use -- I'd very much appreciate it. Thanks!
- mindcrime 11y agoI think it's saying that "patterns" are themselves values that have operations you can perform on them. For example, adding to patterns, or subtracting from them, or concatenating them, etc. I don't know SNOBOL though, so I'm having a hard time picturing what the actual implications of that are, or exactly how it works. But I'm intrigued enough now that I want to go read this "Green Book" and see what it's all about.
- braythwayt 11y agoIf you have a pattern that matches FIRSTNAME and another that matches LASTNAME, roughly: FULLNAME = FIRSTNAME LASTNAME Whitespace is a catenation operator, and catenating two patterns gives you a new pattern that matches a string matching the first and the second pattern. Maybe you want to handle old-school people like raganwald: OLDSCHOOLNAME = LASTNAME ‘, ‘ FIRSTNAME Or both: ANYNAME = FULLNAME | OLDSCHOOLNAME The vertical bar is an alternate operator. Regular expressions work the same way, but in most languages, the regular expression language is really a DSL embedded in the syntax for a regular expression literal. Whereas in SNOBOL, all those operators are ordinary language operators and you can use them anywhere. So you can manipulate patterns programatically.
- raldi 11y agoOh, neat. Perl 6 appears to have assimilated that idea: http://doc.perl6.org/language/regexes#Subrules http://doc.perl6.org/language/regexes#Subrules
- kbenson 11y agoI don't think that's quite the same, as Perl 6 isolates the grammar DSL to grammar blocks, but it would be trivial to make something in Perl 6 that is equivalent, if there isn't already, by defining operators between tokens and grammars in Perl 6 to accomplish the same thing. IIUC grammars are also first class in Perl 6, but it isolates their DSL to grammar blocks. I'm not sure of the specifics of each to note whether one is capable of easily doing something the other can't or has a hard time with, but it looks to boil down to SPITBAL's implementation being slightly easier to access as there's no grammar block required, and Perl 6's being slightly more clear and self documenting, due to that same requirement. Note: I've yet to use either, so someone with more experience, possibly you, might be able to correct my misunderstandings.
- plorkyeran 11y agoHow does that differ from a parser combinator library beyond that it's baked into the language? It took a few decades for other languages to catch up, but patterns being first-class objects that can be combined in various ways isn't that unusual. For example, in Lua with LPeg those examples would be: full_name = first_name * last_name old_school_name = last_name * P', ' * first_name any_name = full_name + old_school_name (* is sequence, + is or, P is a function that converts a string to a pattern)
- pygy_ 11y agoIt is similar, but in Snobol, it is a core language feature.
- abecedarius 11y agoWhile I don't remember enough Snobol to say, in Icon every expression may participate in the pattern-matching search process. For example, `a < b` doesn't produce a boolean value, it either fails (cutting off the current branch of the search) or succeeds (producing b's value as its value, so you can write `a < b < c` with the conventional meaning without any special handling of that form of comparison). That's the kind of way that patterns are more deeply baked into these languages.