Lacking Natural Simplicity (Posts about mmk)https://tkurtbond.github.io/categories/mmk.atom2024-01-23T18:49:43ZT. Kurt BondNikolaVMS Code from the Pasthttps://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/2003-05-08T00:00:00-05:002003-05-08T00:00:00-05:00T. Kurt Bond<p>Listening to: Hawkwind, <a class="reference external" href="http://www.freedb.org/freedb_search_fmt.php?cat=rock&id=d50ba50e">Chronicle of the Black Sword</a>.</p>
<p>I've been reading a lot of VMS BASIC <a class="footnote-reference brackets" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#footnote-1" id="footnote-reference-1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> source code from the early
1990s <a class="footnote-reference brackets" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#footnote-2" id="footnote-reference-2" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a> recently, and the one lesson it has taught me is that
refactoring source code is vital for maintainability. Much of this
source code originated in one program that was copied and edited
whenever a new program was needed, so each new program generally ended
up with a lot of rag-tag odds-and-ends code from the original program
that was not actually needed for the functionality of the new program.
Unfortunately, when one is trying to change some existing
functionality one has to look at each and every program <em>and figure
out if that functionality is actually implemented and used in that
program</em>, and to do this you have to mentally trace the execution of
the code! The moral? When you copy code, delete everything you don't
actually use! Refactor, refactor, refactor!</p>
<p>And why didn't we use <code class="docutils literal">%INCLUDE</code> more? There are hundress of lines of
external function declarations that are used time and again in several
programs; we should have put them in a couple of include files.</p>
<p>I really wish VMS Basic allowed <a class="reference external" href="http://groups.google.com/groups?q=tkb+group:comp.os.vms&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=a3db6b24.0305081211.6f867ad0%40posting.google.com&rnum=1">redimensioning array formal
parameters</a>, but I understand why it's not allowed. (Perhaps
there should have been a specific descriptor for arrays that can be
redimensioned?)</p>
<p>I was shocked to rediscover that there was no way of reliably building
the system from the source code. MMS was too expensive for us at the
time and if <a class="reference external" href="http://www.madgoat.com/mmk.html">MMK</a> existed we
didn't know about it. We used a bunch of ad-hoc DCL command
procecudures to compile whatever program we were working on (most of
them were all in one source file, and linked against one library of
utility routines) and these were never collected. So, you couldn't
easily tell if the current set of executables was actually built from
up-to-date source. Since I've been doing the odd bit of maintenance on
this system every six months or so I finally broke down and created
<code class="docutils literal">DESCRIP.MMS</code> files for use with MMK, and I'm much easier in my mind
now.</p>
<p>There were a number of things in this system that I think were well
done, though, so it hasn't been all pain looking at it again.</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="footnote-1" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#footnote-reference-1">1</a><span class="fn-bracket">]</span></span>
<p>I'm working with it on an Alpha so I can't call it VAX BASIC
anymore.</p>
</aside>
<aside class="footnote brackets" id="footnote-2" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#footnote-reference-2">2</a><span class="fn-bracket">]</span></span>
<p>The original version of this system ran on PDP-11 running RSTS/E.
I've been involved in two major conversions of systems running on
PDP-11 RSTS/E to VAX/VMS, both using the POISE DMS-Plus on both RSTS/E and
VMS, with extensive homegrown applications written in VMS BASIC and
using the POISE SPL API.</p>
</aside>
</aside>
<section id="section-1">
<h2>2014-11-03</h2>
<p>Here's the text of my post to comp.os.vms:</p>
<blockquote>
<p>The BASIC for OpenVMS Reference Manual says, in the fifth item of the
Remarks section:</p>
<blockquote>
<p>The executable DIM statement cannot be used to dimension virtual arrays,
arrays received as formal parameters, or arrays declared in COMMON, MAP,
or nonexecutable DIM statements.</p>
<p><a class="reference external" href="http://h71000.www7.hp.com/doc/73final/cobol/bas_ref_013.htm#noisn">http://h71000.www7.hp.com/doc/73final/cobol/bas_ref_013.htm#noisn</a></p>
</blockquote>
<p>The "no formal parameters" rule is inconvienent. It means that you
can't pass an array to a function, redimension it, fill it with values,
and then use LBOUND and UBOUND in the caller to find out its new size.</p>
<p>Presumably it is illegal because there is no way at compile time to
know if the function will be called with a dynamic array created with
the executable DIM statement or a static array created with a
non-executable DIM statement.</p>
<p>However, the programmer <em>can</em> know, so it ought to be safe to
redimension the array directly when the programmer knows it was
created by an executable DIM statement.</p>
<p>Using Alpha BASIC V1.4-000 under OpenVMS V7.2 and looking at the
listing of some code with some executable dimension statements
compiled with /LIST/MACHINE revealed the existance of DBASIC$RT_DIM
and after a little experimentation lead to a program that used
DBASIC$RT_DIM directly to redimension dynamically dimensioned arrays
in functions, included below.</p>
<p>DBASIC$RT_DIM is not documented for users (probably by design) and
could <em>theoretically</em> lead to flying monkeys and access violations,
and is probably bad style. However, are there any <em>practical</em>
reasons why this wouldn't work safely? Are there any
conditions under which this hack would fail to work?</p>
<p>Here is an example program:</p>
<div class="code"><pre class="code text"><a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-1" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-1" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-1"></a>program redim
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-2" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-2" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-2"></a> option type = explicit, constant type = integer, &
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-3" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-3" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-3"></a> size = integer long, size = real double
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-4" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-4" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-4"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-5" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-5" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-5"></a> external sub redim_in_sub (string dim())
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-6" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-6" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-6"></a> external long function my_redim (string dim(), long)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-7" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-7" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-7"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-8" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-8" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-8"></a> declare long i, r
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-9" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-9" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-9"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-10" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-10" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-10"></a> i = 10
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-11" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-11" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-11"></a> dim string vs(i) ! has to be a variable to make it an executable dim.
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-12" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-12" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-12"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-13" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-13" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-13"></a> r = my_redim (vs(), 30)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-14" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-14" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-14"></a> print "ubound(vs):"; ubound(vs)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-15" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-15" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-15"></a> for i = lbound(vs) to ubound(vs) \ vs(i) = "vs 30-" + num1$(i) \ next i
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-16" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-16" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-16"></a> gosub print_vs
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-17" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-17" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-17"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-18" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-18" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-18"></a> call redim_in_sub (vs())
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-19" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-19" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-19"></a> print "ubound(vs):"; ubound(vs)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-20" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-20" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-20"></a> gosub print_Vs
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-21" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-21" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-21"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-22" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-22" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-22"></a> exit program
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-23" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-23" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-23"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-24" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-24" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-24"></a>print_vs:
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-25" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-25" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-25"></a> for i = lbound(vs) to ubound(vs) \ print i; ": "; vs(i) \ next i
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-26" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-26" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-26"></a> return ! from print_vs
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-27" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-27" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-27"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-28" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-28" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-28"></a>end program ! redim
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-29" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-29" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-29"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-30" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-30" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-30"></a>function long my_redim (long s by value, long n)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-31" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-31" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-31"></a> option type = explicit, constant type = integer, &
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-32" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-32" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-32"></a> size = integer long, size = real double
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-33" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-33" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-33"></a> declare long r
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-34" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-34" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-34"></a> external long function dbasic$rt_dim (long by value, long by value)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-35" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-35" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-35"></a> r = dbasic$rt_dim (s, n)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-36" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-36" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-36"></a>end function r ! my_redim
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-37" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-37" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-37"></a>
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-38" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-38" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-38"></a>sub redim_in_sub (string s())
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-39" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-39" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-39"></a> option type = explicit, constant type = integer, &
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-40" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-40" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-40"></a> size = integer long, size = real double
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-41" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-41" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-41"></a> external sub set_strings (string dim(), string)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-42" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-42" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-42"></a> declare long i
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-43" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-43" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-43"></a> call my_redim (s(), 40)
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-44" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-44" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-44"></a> for i = 0 to 40 \ s(i) = "redim in sub " + num1$(i) \ next i
<a id="rest_code_1dccaa466f5d44998d920b0f1c8d218d-45" name="rest_code_1dccaa466f5d44998d920b0f1c8d218d-45" href="https://tkurtbond.github.io/posts/2003/05/08/vms-code-from-the-past/#rest_code_1dccaa466f5d44998d920b0f1c8d218d-45"></a>end sub ! redim_in_sub
</pre></div>
<p>(Interestingly, a slightly different approach was necessary using VAX
BASIC V3.5 under VMS V5.5-2: using BY VALUE in function
definition statements is not allowed by this version of VAX BASIC,
and BAS$RT_DIM had to be used instead of DBASIC$RT_DIM, of course.)</p>
</blockquote>
</section>