Mark Gemmell <ug83mxg@cs.bham.ac.uk> writes:
> Date: Tue, 5 Feb 2002 13:18:12 +0000
> Organization: School of Computer Science, The University of Birmingham
>
> I'm doing a third yr AI project at birmingham, and am trying to do
> something very simple with strings, but can't find a simple solution.
>
> Basically all I want to do is convert: '1 2 a basic string <2 3>'
> into: [1 2 a basic string <2 3>]
>
> Sorry to be asking such a simple question, but attempts to find a simple
> way of doing this have failed thus far.
Mark, look at
HELP sysparse_string
HELP sys_parse_string
Grouping the <2 3> bit into a single item, if that's what you want
will be much harder than you think especially as it is not clear
what sort of item it should be: a string? A word? A pair?
A different approach is to derive a character repeater from a
string, using stringin, then derive an item repeater from the
character repeater, using incharitem, then use pdtolist to produce a
dynamic list from the item repeater, then use pop11_compile to
compile the dynamic list.
E.g.
vars string = '[1 2 \'a basic string\' [2 3]]';
datalength(string) =>
** 28
vars list = pop11_compile(pdtolist(incharitem(stringin(string))));
list =>
** [1 2 a basic string [2 3]]
length(list) =>
** 4
applist(list, npr);
1
2
a basic string
[2 3]
I hope that helps.
Instead of using pdotolist and pop11_compile you may be able to
parse the stream of items. That will be more efficient, but
typically much harder to get right.
All this assumes you can vary the format of your original string to
make it into a string of characters forming a pop11 list
expression of the required kind.
It may be MUCH easier to build the list directly!
Aaron
====
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 (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
|