It looks as if nobody has replied to this.
Lee Goddard <lee.goddard@webslave.u-net.com> writes:
> Date: Wed, 17 Nov 1999 10:12:47 +0000
> Organization: C: must try harder.
>
> Stephen Drake wrote:
>
> > > Lee Goddard <leego@cogs.susx.ac.uk> wrote:
> > > 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]
> > 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
> > 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 ...]
> > 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.cs.bham.ac.uk/research/poplog/primer
There are more examples there (search for dynamic) and also in
HELP PDTOLIST
>
> 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.
>
> ;;; 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.
> 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.
> 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 latex from the freepoplog
site. This version prints two pages to a sheet of A4.
http://www.cs.bham.ac.uk/research/poplog/primer2.ps.gz
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.cs.bham.ac.uk/research/poplog/popbook.ps.gz
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.
> 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!
> ...
> Lee Goddard on IS MSc at Sussex: <leego@cogs.susx.ac.uk>
> Home: <lee.goddard@bigfoot.com> <http://www.webslave.u-net.com>
> ______________________________________________________________________
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.cs.bham.ac.uk/~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.cs.bham.ac.uk/research/cogaff/
|