HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Delete all instances of "b" or "ac" from a string

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
instancesdeleteallfromstring

Problem

A recent question, inspired me to think about how far we've come, and how much easier tasks are in current, modern languages like C# and Java, compared to the low-level languages we were stuck with years ago.

Based on that, I decided to post some code for doing the same task, but in a language that (at least in most people's estimation) has been obsolete for decades. In this case, I chose an ancient language named SNOBOL 4 for the implementation.

Warning: this really is an old language (this year is its 50th anniversary), so try not to be terribly surprised at the length and complexity of the code compared to modern languages like C# and Java.

* read a string from standard input
    input_string = input

* find "b" or "ac" in s, replace with nothing, and repeat if successful:
del_loop input_string ("b" | "ac") =     : s(del_loop)

    * write out resulting string
    output = input_string


I don't think anybody's posted any SNOBOL 4 here before, so please be gentle...

Solution

As best I can tell (with the limited info available on the language), it looks like you're violating just a couple language concerns.

First: all example SNOBOL4 code I've seen has the lines without labels indented past the horizontal extent of the longest label by at least 2 spaces. That is:

input_string = input
del_loop input_string ("b" | "ac") =     : s(del_loop)
    output = input_string


Seems to be expected to be:

input_string = input
del_loop  input_string ("b" | "ac") =     : s(del_loop)
          output = input_string


It also looks like SNOBOL4 labels are expected to be SHOUTYLABELS:

input_string = input
DELLOOP  input_string ("b" | "ac") =     : s(DELLOOP)
         output = input_string


The next thing I seem to have seen is that output, input, and s are supposed to be SHOUTY.

input_string = INPUT
DELLOOP  input_string ("b" | "ac") =     : S(DELLOOP)
         OUTPUT = input_string


The next comment is that it looks like SNOBOL4 code uses PascalCase subject (variable) names.

InputString = INPUT
DELLOOP  InputString ("b" | "ac") =     : S(DELLOOP)
         OUTPUT = InputString


Next, it looks like the colons should line up vertically and be past the last horizontal character on any line. This doesn't apply to you, unless we include your comments:

* read a string from standard input
         InputString = INPUT

* find "b" or "ac" in s, replace with nothing, and repeat if successful:
DELLOOP  InputString ("b" | "ac") =                                       : S(DELLOOP)

         * write out resulting string
         OUTPUT = InputString


Lastly, it looks like the transfer is supposed to directly follow the colon. (No spaces.)

InputString = INPUT
DELLOOP  InputString ("b" | "ac") =     :S(DELLOOP)
         OUTPUT = InputString


Now, that looks like SNOBOL4. :) All-in-all, it looks quite good. Very nice to see an application of a very old language, that shows that sometimes the new ones just aren't the best suited for the task. (In fact, SNOBOL4 was designed to fulfill programmes with this in mind, it was designed to handle pattern-matching and string-processing very well.)

Code Snippets

input_string = input
del_loop input_string ("b" | "ac") =     : s(del_loop)
    output = input_string
input_string = input
del_loop  input_string ("b" | "ac") =     : s(del_loop)
          output = input_string
input_string = input
DELLOOP  input_string ("b" | "ac") =     : s(DELLOOP)
         output = input_string
input_string = INPUT
DELLOOP  input_string ("b" | "ac") =     : S(DELLOOP)
         OUTPUT = input_string
InputString = INPUT
DELLOOP  InputString ("b" | "ac") =     : S(DELLOOP)
         OUTPUT = InputString

Context

StackExchange Code Review Q#126602, answer score: 6

Revisions (0)

No revisions yet.