Snobol Evaluation 11/14/2002 NOTE: Due to HTML Syntax conflicts, "#" is used in place of "<", the starting Tag. A. Strengths 1. Powerful Pattern Matching Features 2. Enhanced Expressivity 3. Simplicity 4. Good Tracing facilities B. Weaknesses 1. Lack of Structured Statements 2. Unreliability 3. Undesirable Side-Effects ---------------------------------------- 1. Poweful Pattern Matching Features. a. Recursive pattern structures (by use of Unevaluated Exp. Operator) b. Employment of Heuristics under QuickScan for Efficiency. (1) Continual comparison of number of characters remaining in the subject string against the number of characters required. (2) Repositioning of the cursor in the Unanchored mode only if sufficient characters remain. (3) Refusal to extend the substring matched by ARB or to reposition the cursor if failure is caused by too few characters. EX: pat = len(1) $ A ARB len(1) $ B ARB len(1) $ C *P(A,B,C) Fail "123456" pat (4) Refusal to extend substring matched by ARBNO(P) if the last match of P was the null string. c. Pattern matching with replacement EX: &Trim = 1 Pat = Pos(0) "(" Bal . Enclosed ")" Rpos(0) Again Exp Pat = Enclosed :S(Again) --------------------------------------------------------- 2. Enhanced Expressivity a. Predefined Primitive Pattern Functions/Variables Span() Break() Any() NotAny() Tab(N) RTab(N) Rem Pos(N) RPos(N) Fail Bal ARB ARBNO(P) Len(N) @X (Cursor Position) b. Enhanced Orthogonality (1) Incorporation of predicates into any statements. Cautions: N = LE(N,Max) N + 1 N LE(N,Max) = N + 1 N = (N + 1) N ;* Last two statements are the same when the predicate is true. (2) Many operators are used as both unary and binary operators: Unary Binary $ Indirect Referencing Immediate Value assignment . Name Conditional Value assignment * Unevaluated Expression Multiplication + Positive sign Addition - Negative sign Subtraction (3) Consistent success/failure of statements including function returns. (4) Functions returning variables (NRETURN) EX: define("NEXT(A)","NextEntry") :(Start) * A#0> shows the last array element already used. * That is, A#0>+1 is the next available array element. NextEntry A#0> = A#0> + 1 Next = .A#A#0>> :S(NReturn)F(FReturn) Start X = Array('0:100') Next(X) = "First" Next(X) = "Second" Next(X) = "Third" "FUNFUN" "UN" REM . Next(X) End ---- Above will result in X#0> = 4 X#1> = "First" X#2> = "Second" X#3> = "Third" X#4> = "FUN" (5) Many primitive functions are for both numbers and strings including Ident() and Differ() Cautions: S1 = "ABC" S2 = "AB" "C" S3 = A | B S4 = S3 S5 = 10 S6 = 2 * 5 S7 = 3.0 S8 = 3.0 ----Each pair of 4 above will have Ident() successful D1 = A | B D2 = A | B D3 = 5 D4 = "5" ----Each pair of 2 above will have Differ() successful c. Use of blank spaces (1) As binary concatenation operator of both strings and numbers (2) As a distinguisher between a binary operator and a unary operator. d. Structured Data types (1) User-defined types EX: Data("Node(Value,Left,Right)") (2) Arrays and Tables X = Array("3,4",10) ;* 2-dimensional (3-by-4) array with the ;* initial value of 10 for all elements. Y = Array(3,4) ;* 1-dimensional with initial value of 4 Y#1> = "University" Y#2> = 12345678 Y#3> = X ;* an array itself T = Table(20,10) ;* A table with initial size of 20 and ;* its size will be incerased by 10 each time when needed. T#"University"> = "Lamar" T#Index> = "Some Big" ;* A table's reference can be any type unlike that of ;* arrays which must be integers. ;* A table is, however, just one-dimensional ----------------------------------------------------- 3. Simplicity a. Relatively simple syntax, yet very powerful pattern definitions. b. Incorporation of branch operations (both unconditional and conditional) into many statements. c. The function definition body requires no header nor a trailer. d. Only one kind of functions returning a value or not. e. Operator Synosyms OPSYN(new,old,N) (1) when the third argument is omitted or zero. The other two arguments are to be taken as a function each. EX: OPSYN('Same','Ident') In the above case, SAME(X,Y) will behave just like Ident(X,Y). And, the synonym function, SAME(), may have arguments omitted. (2) when the third argument is 1. The other two arguments are to be taken as a unary operator respectively, if they are both defined as a unary operator. If just one of them is not, however, then it is to be taken as a function. If neither is defined as a unary operator, then they are both to be taken as a function, each. EX: OPSYN("F", '$', 1) ;* '$' is a defined unary operator but "F" is not. So it is to be taken as a function. F(X) will behave just like $X in this case. (3) when the third argument is 2. The other two arguments are to be taken as a binary operator each if they are defined as such. The results are similar to the case for unary operators. EX: OPSYN("+", "F", 2) In above case, the first argument is a defined binary operator but the second is not. So, it will be taken as a function name. Thus, "A + B" will be treated as "F(A,B)" f. Case-insensitive g. Very few types of statements ------------------------------------------------ B. Weaknesses 1. Lack of Structured Statements. a. No Structured selection ("IF") or loop ("FOR") statement. b. Danger of entering into an infinite loop. 2. Unreliability a. Due to lack of structured statements. Easy to make logical errors b. Danger of entering a function body without invoking it. c. Easy to make syntax errors like LE (One,Two) ;* Erroneous intermediate blank M+N ;* Missing intermediate blanks Not starting a label at column position-1. 3. Undesirable side-effects. a. Under Quickscan, ARB abd ARBNO(P) failing to exhaust all possible matchings when desired and treating an Unevaluated Expression as matching at least one character when desired otherwise. b. Under FullScan, failing to break infinite loops when using recursive patterns thereby generating "Stack OverFlow" error message.