Can anyone elaborate on this?
Can anyone elaborate on this?
'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.
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.
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)That's the kind of way that patterns are more deeply baked into these languages.
Perl 6 appears to have assimilated that idea: http://doc.perl6.org/language/regexes#Subrules
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.
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.