Author Topic: Formal parameter substitution  (Read 102 times)

Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Formal parameter substitution
« on: October 28, 2011, 04:47:36 am »
The SNOBOL/regular expressions thread brought back to my mind a little tool I built in the 1990s for manipulating text strings.  The idea was to combine a template and a data list.

The template consisted of plain text with embedded formal parameters.  The data list consisted of a series of lines of text, where each line contained actual parameters.  The expansion tool would read each line of the data list and, for that line, produce an expansion of the template, with actual parameters substituted for formal parameters.  It's a little like the mail-merge facility in a word processor.

The tool I built was not terribly efficient, but I could use it in an amazing variety of ways.  One way was to use a query on the metadata of a relational database to generate a list of a few hundred user table names.  Then generate a template with some SQL DDL to be done on each table, with the table name as a formal parameter.  The expansion was ready to feed into the SQL interpreter.  As long as I kept the number of entries in the data list down to a few hundred, the inefficiency never bothered me. 

Why did I bother to build my own tool, instead of using available tools?  Well, you have to understand "production machines" of that era.  They often did not have any compilers on them.  Intentionally, so as to prevent any development work.  The machines I worked on were all VAXen.  But they all had SQL, in order to be able to manage the database.  And they all had DCL, in order to be able to command VMS.  So I wrote it in DCL.

Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Re: Formal parameter substitution
« Reply #1 on: October 29, 2011, 10:56:48 am »
There's a certain amount of humor in the idea of me writing a useful tool in DCL.

At the time, I was quite taken with structured programming, PASCAL, and Nicklaus Wirth.  You know,
"there's no excuse for sytanx errors or logic errors".  I was really trying to live up to that credo, and doing a halfway decent job of it. 

For those of you who never touched DCL it was the command language for VMS.  It was intended to be for some other operating systems as well, but VMS is the only one I know of.  The batch language of DOS reminds me a tiny bit of DCL.  But DCL was both cleaner and more powerful than DOS batch.  It was sort of halfway between DOS Batch and BASIC.  I imagine some of the scripting languages that have come along to be in the same vein as DCL. 



Still, the idea of writing anything non trivial in DCL was kinda funny to me.  Not strong typing.  Not terribly structured.  Not modular enough.  Then I stumbled across the following:

Code: [Select]
current_line $= "''current_line'"

or something close to that.  It caused DCL to perform actual parameter substitution, using the current context, for any formal parameters detected in the text contained in current_line.  Wow.  The rest of the tool was very, very straightforward. 




The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 14182
  • Gornix user
    • View Profile
Re: Formal parameter substitution
« Reply #2 on: October 29, 2011, 11:07:40 am »
I hacked around in DCL a bit in my VAX years (1982-87.) A great system and command language.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Re: Formal parameter substitution
« Reply #3 on: October 29, 2011, 11:43:54 am »
For those of you who don't relate to parameter substitution, the term MACRO may jog your memory. 

The assembly language of my youth had a prominent Macro facility built in.  So much so, that the language was called MACRO.  Extensive use of Macros could make assembly code take on the look and feel of a higher level language.  But it was easy to go astray.  It might have been nice if there was a preprocessor that just expanded the Macros and showed you what it looked like in expanded form.

I have even heard tell of Macros being used in the context of JCL.  That's outside my world.  A quick search on "Macro JCL" turned up a Q&A where the expert was saying that JCL had no macro facility.  But that doesn't mean you couldn't have used some kind of external macro facility to automatically generate JCL. 






Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Re: Formal parameter substitution
« Reply #4 on: October 29, 2011, 11:45:17 am »
Ahhh, it does my heart good to see the word "hacked" used in the way I have traditionally used it.  The word has evolved so much that I'm afraid of using it in the traditional way, for fear of being misunderstood. 


The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 14182
  • Gornix user
    • View Profile
Re: Formal parameter substitution
« Reply #5 on: October 29, 2011, 12:00:45 pm »
I experimentally programmed with DCL as a very ancillary part of my work. I automated some things that were tedious to do manually. What I call "hacking around".

As part of the YCombinator seed money machine for technology startups, there is a discussion board called "Hacker News". It really means "programmer news". And it's dominated by lots and lots of programmers who have (real) Walter Mitty dreams of making it big.

I personally think the phrase "Hacker News" is seriously wrong for that site. That site is for small scale tech entrepreneurs who happen to code. A "real" hacker is interested in the subject matter without a lot of regard for the commercial purpose of it.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Re: Formal parameter substitution
« Reply #6 on: October 31, 2011, 11:53:13 pm »
Unless I'm reading you wrong (always a possibility) what you call "hacking around" and what I call "hacking around" are the same thing. 

And automating things that are tedious to do manually...  That's the whole reason I got into computers!  Making a living was a side benefit.


The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 14182
  • Gornix user
    • View Profile
Re: Formal parameter substitution
« Reply #7 on: November 01, 2011, 12:04:50 am »
Yes, our definitions match. The computer used as an interesting tool to solve non computer based problems.

For me it stopped being "hacking around" when someone was paying me specifically to write software, not solve circuit equations however, computer or not.  When I had to deliver actual code to someone else it stopped being hacking around.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


Walter Mitty

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 1025
    • View Profile
Re: Formal parameter substitution
« Reply #8 on: November 01, 2011, 06:13:33 am »
Fair enough.  When they pay you, it isn't hacking anymore.

I only remember one contract where DCL procedures were part of the deliverables for the project.  However, in this case, the DCL was just a thin wrapper for some SQL and RMU commands that did the actual work. 

For things like the formal parameter substitution tool,  they never became the property of my clients.  In that case, I developed the germ of the idea on a contract, but the one I developed on my own was a much more generic fully blown idea.   It remained my own property until I posted it on some shareware site and effectively made it part of the public domain.

I don't think I gave away very much money.



Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf