enlarging structures 
Author Message
 enlarging structures

Quote:


> > Is it possible to have an automatically-enlarging structure
> > in which to store objects/object references?

> Well, you could have a look at using dynamic lists. There are a couple of HELP
> files, HELP PDTOLIST which is quite helpful and HELP LISTS which isn't that
> helpful at all! Essentially you would create a dynamic list of objects by
> calling 'pdtolist' which takes a procedure as an argument. That procedure -
> call it, say, build_bot - would generate (and return) an object, so you'd
> have something like:

> vars bot_list;
> pdtolist(build_bot) -> bot_list;

> At first bot_list will be empty, but as soon as you attempt to index an
> element of the list (e.g. bot_list(n) =>) it will create n objects in the
> list. The list is essentially infinitely big. There's a better explanation in
> the book 'Programming in POP-11' by Jonathan Lavanthol, page 107. Any
> problems, find or mail me.

Having problems finding the one copy the library has of this out of print boot,
so hope you don't mind me asking a further question regarding pdtolist: I'm
getting an error when I supply pdtolist with a procedure that has an argument:

        ;;; MISHAP - enp: EXECUTING NON-PROCEDURE (AS UPDATER)
        ;;; INVOLVING:  <undef this_line>

I'm hoping this is nothing to do with an unmentioned attribute of pdtolist -
but even if it does take a procedure with args, could you please let me know
how those arguments are processed dynamically?  Like, does pdtolist retain in
their place the value they held at the initial assignment of pdtolist(p(a,b))->x,
or on calling x, will p(a,b) by accessed with the current values of a,b ?

Or -- do you know of a POP detailed reference book that's still in print?
Although I've been programming for some years, I'm finding some of the HELP files
are less than they claim to be.... maybe there's a gap in the market?

TIA,
Lee

______________________________________________________________________



______________________________________________________________________
"Post-modernism...the Grande Narrative that denies Grande Narrative."
                         - Cedric Watts (personal correspondence, 1997)



Sun, 05 May 2002 03:00:00 GMT  
 enlarging structures
It looks as if nobody has replied to this.

Quote:

> Date: Wed, 17 Nov 1999 10:12:47 +0000
> Organization: C: must try harder.



> > > Is it possible to have an automatically-enlarging structure
> > > in which to store objects/object references?

Depends what you mean by "automatically-enlarging".

Lists are often used in AI languages in part because they can be
extended as needed, including splicing things into the middle.
(See TEACH DATABASE, for instance.) Properties grow as needed to
store the information given to them. See HELP NEWPROPERTY
HELP NEWMAPPING, and REF PROPS (badly named).

If you give an example of what you want, it is usually easier to
know what the appropriate answer is.

[SD]

Quote:
> > Well, you could have a look at using dynamic lists. There are a couple of HELP
> > files, HELP PDTOLIST which is quite helpful and HELP LISTS which isn't that
> > helpful at all! Essentially you would create a dynamic list of objects by
> > calling 'pdtolist' which takes a procedure as an argument.

More precisely: it takes a procedure which requires NO arguments,
and every time it calls produces one result. Those are often called
"generator" procedures. Examples are itemread, readline, charin,
closures of random, e.g. random(%100%) (See HELP CLOSURES)
and more complex procedures, e.g. this

    random(%100%) <> sqrt

which produces a procedure which returns the square root of a random
integer between 1 and 100.

vars gen = random(%100%) <> sqrt;

Then you can test it:

repeat 8 times gen() endrepeat =>
** 6.40312 8.24621 2.64575 2.44949 9.94987 6.245 7.54984 9.69536

Quote:
> > That procedure -
> > call it, say, build_bot - would generate (and return) an object, so you'd
> > have something like:

> > vars bot_list;
> > pdtolist(build_bot) -> bot_list;

E.g., using the generator gen, defined above:

    vars num_list = pdtolist(gen);

num_list is now an unexpanded dynamic list:

    num_list =>
    ** [...]

Force the list to expand four links, by asking for its fourth
element.

    num_list(4) =>
    ** 9.21954

Now it prints out the expanded items, and some dots:

    num_list =>
    ** [4.0 8.66026 7.0 9.21954 ...]

    num_list(6) =>
    ** 8.0

    num_list =>
    ** [4.0 8.66026 7.0 9.21954 7.68115 8.0 ...]

Quote:
> > At first bot_list will be empty, but as soon as you attempt to index an
> > element of the list (e.g. bot_list(n) =>) it will create n objects in the
> > list. The list is essentially infinitely big. There's a better explanation in
> > the book 'Programming in POP-11' by Jonathan Lavanthol, page 107. Any
> > problems, find or mail me.

You can also look at Chapter 6 of the Pop-11 primer, which you may
have available as TEACH PRIMER, or look at the html version

    http://www.*-*-*.com/

There are more examples there (search for dynamic) and also in
HELP PDTOLIST

Quote:

> Having problems finding the one copy the library has of this out of print boot,
> so hope you don't mind me asking a further question regarding pdtolist: I'm
> getting an error when I supply pdtolist with a procedure that has an argument:

A procedure that takes an argument cannot be used as a generator, as
defined above.

Quote:

>    ;;; MISHAP - enp: EXECUTING NON-PROCEDURE (AS UPDATER)
>    ;;; INVOLVING:  <undef this_line>

> I'm hoping this is nothing to do with an unmentioned attribute of pdtolist -
> but even if it does take a procedure with args, could you please let me know
> how those arguments are processed dynamically?

It is not at all clear what you would want a procedure that takes
an argument to do with them in creating a dynamic list. See the
random example above.

Quote:
> Like, does pdtolist retain in
> their place the value they held at the initial assignment of pdtolist(p(a,b))->x,

That would make sense only if p(a,b) returned a generator that could
then be used by pdtolist.  If you want p always to be used with the
same arguments, use partial application, i.e. partially apply p to
the two arguments, using this syntax

    p(%a, b%)

That creates a procedure which is a generator, provided that p
always returns exactly one result.

Quote:
> or on calling x, will p(a,b) by accessed with the current values of a,b ?

> Or -- do you know of a POP detailed reference book that's still in print?

The primer is available in postscript and{*filter*}from the freepoplog
site. This version prints two pages to a sheet of A4.

    http://www.*-*-*.com/

It is slightly out of date because it still mentions ISL as the
distributor of poplog.

Robin Popplestone has just made his book available too.
    http://www.*-*-*.com/

It is more substantial than the primer. There is also a huge amount
of very accurate and up to date information in the REF files, but
they are often not easy for beginners to read.
E.g. REF LISTS REF PROCEDURE

The Barrett,Ramsay&Sloman book on Pop-11 (around 1985) also has
a section on dynamic lists. However, like the Laventhol book it
is somewhat out of date as they use "vars" rather than "lvars"
for local variables.

Quote:
> Although I've been programming for some years, I'm finding some of the HELP files
> are less than they claim to be.... maybe there's a gap in the market?

The help and teach files have not been kept well up to date. The REF
files are more complete.

However, any explanation will be at the wrong level for some users:
too terse for some and too long winded for others. Often experienced
programmers find learning an AI language difficult because they try
to map what they are learning on to what they have previously
learnt, which leads to erroneous interpretations. Beginners are
sometimes at an advantage!

Quote:
> ...


> ______________________________________________________________________                  

I hope that helps.

Aaron
PS
Newsgroup etiquette: If you post using a linewidth of no more
than about 65 columns that makes stuff remain readable after
it has been indented a couple of times, even in relatively narrow
windows (many people read with just an 80 column window or less,
as long lines can be hard to read.).
--
Aaron Sloman, ( http://www.*-*-*.com/ ~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk   (NB: Anti Spam address)
PAPERS: http://www.*-*-*.com/



Thu, 09 May 2002 03:00:00 GMT  
 enlarging structures

Quote:
> [...]
> More precisely: it takes a procedure which requires NO
> arguments, and every time it calls produces one result. Those
> are often called "generator" procedures. Examples are itemread,
> readline, charin, closures of random, e.g. random(%100%)  ....

readline - that makes it clear.

[Further comprehensive & appreciated explanation cut for space]

Quote:
> It is not at all clear what you would want a procedure that
> takes an argument to do with them in creating a dynamic list.
> See the random example above.

Hm. I'm not at all sure a dynamic list would help. I simply wish to
have a structure indexable - by integer or string - of unspecified

%hash would do the job. It seems - and I'm hoping for correction
here! - that in POP, 'array procedures mishap if any of their
subscript arguments is not in the appropriate range'.  Is this a
hang-up from non-AI scripting languages, or a result of not having
a grep routine in Win32 to scan the HELP/REF/TEACH files?

Cheers,
Lee
<L Goddard at Sussex>



Fri, 10 May 2002 03:00:00 GMT  
 enlarging structures
Hi Lee,

Quote:
>Hm. I'm not at all sure a dynamic list would help. I simply wish to
>have a structure indexable - by integer or string - of unspecified
>size, so that it can be added to when needed.

Pop11's datastructures are mainly geared up for a functional style,
primarily for efficiency but also as a matter of style.

Of all of Pop11's built in datastructures, the one that is likely
to meet your needs without change is the property.  See * NEWPROPERTY,
* NEWANYPROPERTY, * NEWASSOC, and * NEWMAPPING for the pre-built
constructors.  The most general and complex is -newanyproperty-.

If what you really want is an extensible 1D array, then Pop11 does
not have exactly what you want.  The best thing to do is implement
it.  It is pretty easy ... (I do not have a Poplog to hand so forgive
me if I make some errors.)

defclass lconstant exvector {
     in_use   : pint,
     capacity : pint,
     data

Quote:
};

define new_exvector();
     consexvector( 0, 0, nullvector )
enddefine;

define lconstant ensure_capacity( n, ex );
     lvars ( i, c, d ) = ex.destexvector;
     if c < n then
         {% d.explode, dupnum( undef, n - c ) %} -> ex.data;
         n -> ex.capacity;
     endif
enddefine;

define add_exvector( x, ex );
     lvars ( i, c, d ) = ex.destexvector;
     if ex.capacity == ex.in_use then
         ensure_capacity( d.datalength * 2 + 8 );
     endif;
     x -> subscrv( i + 1 ->> ex.in_use, d )
enddefine;

define index_exvector( n, ex );
     lvars ( i, _, d ) = ex.destexvector;
     subscrv( fi_check( n, 1, i ), d )
enddefine;

define updaterof index_exvector( v, n, ex );
     lvars ( i, c, d ) = ex.destexvector;
     unless n <= i do
         ensure_capacity( n, ex );
     endunless;
     v -> subscrv( n, ex )
enddefine;

And so on and on ....

However, the fact that Pop11 does not have extensible vectors
built-in should be a big clue that this is not the usual programming
style used.  Perhaps Lee could post a reply indicating the overall
context that this came up.  I think it would be interesting to
compare and contrast the styles of programming.  My 50p says that
what Lee "should" be using is the stack and lists.

Actually, I think not having built-in extensible vectors is a pity.
I have argued in that past that one of Pop11's great strengths is
the ability to mimic the programming styles from other languages.
However, the omission of extensible vectorclass objects is a bit of
a killer for people coming from a Perl (or Basic) background.

Perhaps we should add extensible vectorclass objects to our list of
things to add to Poplog now it is Open Source?  After all, one would
like it to behave properly with regard to things like -length-,
-copy-, and the garbage collector and so on ...

Steve



Fri, 10 May 2002 03:00:00 GMT  
 enlarging structures

Quote:

> Hi Lee,

> >Hm. I'm not at all sure a dynamic list would help. I simply wish to
> >have a structure indexable - by integer or string - of unspecified
> >size, so that it can be added to when needed.

[Much appreciated explanations snipped for space]

Quote:
> ... However, the fact that Pop11 does not have extensible vectors
> built-in should be a big clue that this is not the usual programming
> style used.  Perhaps Lee could post a reply indicating the overall
> context that this came up.  I think it would be interesting to
> compare and contrast the styles of programming.  My 50p says that
> what Lee "should" be using is the stack and lists.

I'm creating what I'm assured are 'intelligent' agents to explore a
network to discover a 'least cost' route. These I'd like to index,
which I thought to do by simply pushing references onto a stack -
at least, that's what I've done in Perl with no ugly results (it's
hard to get ugly results in Perl, easy to get ugly code).

Quote:
> Actually, I think not having built-in extensible vectors is a pity.
> I have argued in that past that one of Pop11's great strengths is
> the ability to mimic the programming styles from other languages.

Had the same thought, but presume - as you note above and as Aaron
noted earlier in the thread - that perhaps it's a matter of AI
technique.

Thanks for asking,
Lee



Sat, 11 May 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. enlarge scope of an awk-declared variable ?

2. how to enlarge code cache

3. Indicators and controls will not enlarge or move.

4. Enlarging Get Panel Image

5. Enlarge XY Graph for printing

6. Enlarging Get Panel Image

7. Q : Enlarge Image maintain It's Quality...

8. Enlarging Cursor area

9. How to enlarge an defined array?

10. enlarge tk_getOpenFile dialog

11. How to enlarge size of Expect_out(buffer) ?

12. Structures within Structures

 

 
Powered by phpBB® Forum Software