[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Sun, 14 Mar 2004 22:01:05 +0000 (UTC) 
Subject:Re: for in vectors 
From:A . Sloman 
Volume-ID: 

Luc Beaudoin wrote:

> I'm wondering why no for...endfor syntax is provided for vectors.

There is a rather ugly extension of 'for' involving the keyword
'using_subscriptor', explained and illustrated in HELP FOR

But there is a nicer syntax that was introduced in the late 1980s

It uses a meta-linguistic extension originally inspired by the
define_form construct, which makes it possible to extend the 'define'
syntax as in

    define :class ...

    define :method

    define :ved_runtime_action
        see REF vedprocs

    define :ruleset
        See help poprulebase

etc.

The general facility which makes those syntactic extensions possible
is explained in
    HELP define_form

This construct is used to introduce what we called 'sub_syntax' words.
Syntax words define a syntactic construct which they introduce.
Sub_syntax words introduce variants of that syntactic construct. e.g.
'define' is a syntax word, and 'class', 'method' etc. are sub_syntax
words illustrated above.

Various analogous meta-linguistic constructs (using sub_syntax words)
were introduced to extend the 'for' syntax by providing a number of
autoloadable syntactic extensions.

The sub_syntax word "in_vectorclass" does what you want, I think:

    for var1, var2 ... in_vectorclass vector1, vector2, ... do

It is explained in

    HELP for_form

Example:

    ;;; A vector of bytes (a string) and a vector of integers
    vars
        v1 = 'abcde',
        v2 = {1 2 3 4 5} ;

Loop over both vectors to create a vector of words "a1", "b2"
etc.

    vars a,b;
    {%
        for a, b in_vectorclass v1, v2 do
            consword(#| a, `0`+b |#)
        endfor
    %} =>

    ** {a1 b2 c3 d4 e5}

> But I was curious why it
> was left out in the first place.

In the first place the POP language was designed for machines that by
our standards were minute!

In 1972-3 POP2 ran on an Eliot 4130 with 64 KBytes of memory.

Pop11 ran on a PDP11 computer around 1976 with 256Kbytes of memory, if I
remember correctly. It used 16 bit addresses, and each process was
restricted to at most 32Kwords if I remember correctly.

In those days we did not have many looping constructs. As we moved onto
a Vax with a much larger address space, and more and more memory became
available, we could add more useful features to the language. Even then,
many of them are not built in to the core system but are optional
autoloadable extensions. Many of them are defined in:
    $usepop/pop/lib/auto/

But you have hit on a point on which Steve Leach has often commented.
There are many ways in which Pop11 is extraordinarily general, but not
quite as general as one would expect given what's already there.

That's because the ontology used by the designers was growing through
experience: hindsight is different.

E.g. '<>' can be used to concatenate many things: words, strings, lists,
vectors, procedures. ....

So why  not properties? and why not repeaters?

Part of the answer is that properties and repeaters are already
procedures, so there would be a tension between two interpretations of
'<>' if used with them.

But the main answer is simply that originally it was just introduced as
an infix short-hand for a list append procedure. Then someone (Steve
Hardy) suggested that it could be used for vectors too. Then it got
extended for other data-types.

The interpretation of "<>" for procedures as function composition seemed
a nice idea at the time, but maybe it was a mistake, because that
prevented other things, as illustrated above.

Aaron