By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,719 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,719 IT Pros & Developers. It's quick & easy.

PHP and LISPPA technology

P: n/a
Let me to introduce myself. I'm author of the paxScript scripting
engine: www.paxscript.com.

My recent invention is the LISPPA technology (List Processing based on
the Polymorphic Arrays):

http://www.virtlabs.com.ua/paxscript/lisppa.htm

which allows to operate with dynamic data structures without using
pointers.

I think the LISPPA can be easily implemented in PHP. Benefits seems to
be obvious. You might create libraries provided the working with
lists, trees and other dynamic data structures directly in PHP. LISPPA
site also contains more complex examples related to the Artificial
Intelligence such as symbolic differentiation and mechanical theorem
proving.

I'm not an expert in PHP. However I would like to attract your
attention to the new technology as it can allow to extend
applicability server-side applications in PHP in the "Lisp data
domain"..

Thank you.

Alexander Baranovsky
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Alexander,

A friend of mine has recently built a simple LISP interpreter in
Smalltalk and showed me how it works. It was all pritty simple, i see no
reason why you couldn't do the same in php. OTOH, it has taken him quite
some time to learn enough about the details of LISP to write it
properly, but OK, he was using an article about writing LISP
interpreters in LISP, this may have complicated things quite a bit.

Of course your interpreter will not be blistering fast becuase php is
itself interpreted. And i am quite confident that i can find elegant OOP
equivalents directly in php for many AI examples. However, from what i
have seen from it so far i guess LISP can be great fun, because of its
radically different aproach to computing and the striking elegance of
solutions that can be created in it. But sorry, calling LISP "new
technology" that sounds to me like horrific neglect of history.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.
Alexander Baranovsky wrote:
Let me to introduce myself. I'm author of the paxScript scripting
engine: www.paxscript.com.

My recent invention is the LISPPA technology (List Processing based on
the Polymorphic Arrays):

http://www.virtlabs.com.ua/paxscript/lisppa.htm

which allows to operate with dynamic data structures without using
pointers.

I think the LISPPA can be easily implemented in PHP. Benefits seems to
be obvious. You might create libraries provided the working with
lists, trees and other dynamic data structures directly in PHP. LISPPA
site also contains more complex examples related to the Artificial
Intelligence such as symbolic differentiation and mechanical theorem
proving.

I'm not an expert in PHP. However I would like to attract your
attention to the new technology as it can allow to extend
applicability server-side applications in PHP in the "Lisp data
domain"..

Thank you.

Alexander Baranovsky


Jul 17 '05 #2

P: n/a
Hi Henk,
But sorry, calling LISP "new
technology" that sounds to me like horrific neglect of history.
But I never told it :-)

LISSPA is using arrays (random access structures) for the data
representation, not linked lists. This is big difference. And I do not
think that implementation LISP in PHP is a good idea because nested
interpreters will slow down total performance considerably.

A.

Henk Verhoeven <ne**@phppeanutsREMOVE-THIS.org> wrote in message news:<c5**********@news4.tilbu1.nb.home.nl>... Hi Alexander,

A friend of mine has recently built a simple LISP interpreter in
Smalltalk and showed me how it works. It was all pritty simple, i see no
reason why you couldn't do the same in php. OTOH, it has taken him quite
some time to learn enough about the details of LISP to write it
properly, but OK, he was using an article about writing LISP
interpreters in LISP, this may have complicated things quite a bit.

Of course your interpreter will not be blistering fast becuase php is
itself interpreted. And i am quite confident that i can find elegant OOP
equivalents directly in php for many AI examples. However, from what i
have seen from it so far i guess LISP can be great fun, because of its
radically different aproach to computing and the striking elegance of
solutions that can be created in it. But sorry, calling LISP "new
technology" that sounds to me like horrific neglect of history.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.
Alexander Baranovsky wrote:
Let me to introduce myself. I'm author of the paxScript scripting
engine: www.paxscript.com.

My recent invention is the LISPPA technology (List Processing based on
the Polymorphic Arrays):

http://www.virtlabs.com.ua/paxscript/lisppa.htm

which allows to operate with dynamic data structures without using
pointers.

I think the LISPPA can be easily implemented in PHP. Benefits seems to
be obvious. You might create libraries provided the working with
lists, trees and other dynamic data structures directly in PHP. LISPPA
site also contains more complex examples related to the Artificial
Intelligence such as symbolic differentiation and mechanical theorem
proving.

I'm not an expert in PHP. However I would like to attract your
attention to the new technology as it can allow to extend
applicability server-side applications in PHP in the "Lisp data
domain"..

Thank you.

Alexander Baranovsky

Jul 17 '05 #3

P: n/a
In paxBasic:

Dim L = [100, [200, [300, NULL]]]

P = AddressOf L 'Create alias of L
Do Until P = NULL 'Find tail of L
P = AddressOf P(1)
Loop
P = [400, P] 'Add new item at the tail of L

in PHP:

$l = array(100, array(200, array(300, null)));
//imho this IS a linked list

$p =& $l;
do {
$p =& $p[1];
} while ($p!==null);
$p = array(400, $p);

Mmm, would'nt this be simpeler?:
$l = array(100, 200, 300);
$l[] = 400;

another example:
P = AddressOf L(1)
P = AddressOf P(1) 'insert before 200
P = [150, P]

literally translates to:
$p =& $l[1];
$p =& $p[1];
$p = array(150, $p);

but it results in array(100, array(200, array(150, array(300, null)))) :-(

on $l = array(100, 200, 300, 400);
it woud be: array_splice($l,1,0, 150);
ant this correctly gives: array(100, 150, 200, 300, 400);

then they have this reduced statement:
reduced L = L(1)
in php we don't need it:
$l =& $l[1];
is no problem, php will collect the garbage when the script is finished.

I can go on like this, but i do not see much of a point. To me array
seems fine as it is, and if i really want a linked list i rather
implement it with objects:
$list =& new List(100, new List(200, new List(300)));

$current =& $list;
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar(new List(400));

would then become:

function addAtTail(&$car)
{
$current =& $this
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar($car);
}

function addCdrAtTail($cdr)
{
$this->addAtTail(new List($cdr));
}

OK, the method names may not correctly reflect common LISP terminology,
but at least they raise the question about what are the correct terms!

Greetings,

Henk Verhoeven,
www.phpPeanuts.org
Alexander Baranovsky wrote:
Hi Henk,

But sorry, calling LISP "new
technology" that sounds to me like horrific neglect of history.

But I never told it :-)


Jul 17 '05 #4

P: n/a
I'll use paxC because its syntax more similar to PHP, so readers will
able to better understand our discussion.
$l = array(100, array(200, array(300, null)));
//imho this IS a linked list

$p =& $l;
do {
$p =& $p[1];
} while ($p!==null);
$p = array(400, $p);
In paxC I do the same with

variant L, P;
L = [100, [200, [300, null]]];
P = & L; // Create alias of L
while (P != null) {P = & P[1]; }; // Find last item
P = [400, null]; // Add new item

So, PHP syntax a bit cumbersome, but I can accept it. It really allows
to create a list by means of arrays.

More important is another question: effectivity. In paxC I insert new
item at the head of L list by

L = [50, L];

Let's consider semantics of the statement. It means

variant temp = paxArray(2);
temp[0] = 50;
temp[1] = L;
L = temp;

The last 2 lines are key. The L and temp variables are references in
paxC. So, the statement of insertion of new item will be processed
effectively (i.e. without copying of actual array and new chip of
garbage).

But the assignment statement in PHP creates duplicate of array: In
paxC I use unary "+" operator to create a duplicate of variable.
Mmm, would'nt this be simpeler?:
$l = array(100, 200, 300);
$l[] = 400;
Let's do not discuss it. The article devoted to linked lists. Besides,
I guess, you are using reallocation of memory in implementation, so I
cannot consider the solution as quite elegant.
then they have this reduced statement:
reduced L = L(1)
in php we don't need it:
$l =& $l[1];
is no problem, php will collect the garbage when the script is finished.
Suppose, you have placed your statement $l = & $l[1] in the body of a
long loop. Are you sure that you will see termination of your program
before than resources will be exhausted ?
another example:
P = AddressOf L(1)
P = AddressOf P(1) 'insert before 200
P = [150, P]

literally translates to:
$p =& $l[1];
$p =& $p[1];
$p = array(150, $p);

but it results in array(100, array(200, array(150, array(300, null)))) :-(
Your sign of grief is not necessary :-) In my example the list already
contain 50 before 100, so result is correct.
I can go on like this, but i do not see much of a point. To me array
seems fine as it is, and if i really want a linked list i rather
implement it with objects:
$list =& new List(100, new List(200, new List(300)));

$current =& $list;
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar(new List(400));
Oh, let's do not discuss it as well. :-) We are discussing features of
language ad hoc, not build-in classes. For example, paxScript allows
to import any Delphi classes, but I cannot consider it as a essential
feature.

And the last. I did not found an analogue of TerminalOf operator in
PHP. The use of aliases jointly with terminals allows to simplify data
representation and algorithmes in AI, so I consider it as an important
concept.

A.

Henk Verhoeven <ne**@phppeanutsREMOVE-THIS.org> wrote in message news:<c5**********@news2.tilbu1.nb.home.nl>... In paxBasic:

Dim L = [100, [200, [300, NULL]]]

P = AddressOf L 'Create alias of L
Do Until P = NULL 'Find tail of L
P = AddressOf P(1)
Loop
P = [400, P] 'Add new item at the tail of L

in PHP:

$l = array(100, array(200, array(300, null)));
//imho this IS a linked list

$p =& $l;
do {
$p =& $p[1];
} while ($p!==null);
$p = array(400, $p);

Mmm, would'nt this be simpeler?:
$l = array(100, 200, 300);
$l[] = 400;

another example:
P = AddressOf L(1)
P = AddressOf P(1) 'insert before 200
P = [150, P]

literally translates to:
$p =& $l[1];
$p =& $p[1];
$p = array(150, $p);

but it results in array(100, array(200, array(150, array(300, null)))) :-(

on $l = array(100, 200, 300, 400);
it woud be: array_splice($l,1,0, 150);
ant this correctly gives: array(100, 150, 200, 300, 400);

then they have this reduced statement:
reduced L = L(1)
in php we don't need it:
$l =& $l[1];
is no problem, php will collect the garbage when the script is finished.

I can go on like this, but i do not see much of a point. To me array
seems fine as it is, and if i really want a linked list i rather
implement it with objects:
$list =& new List(100, new List(200, new List(300)));

$current =& $list;
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar(new List(400));

would then become:

function addAtTail(&$car)
{
$current =& $this
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar($car);
}

function addCdrAtTail($cdr)
{
$this->addAtTail(new List($cdr));
}

OK, the method names may not correctly reflect common LISP terminology,
but at least they raise the question about what are the correct terms!

Greetings,

Henk Verhoeven,
www.phpPeanuts.org
Alexander Baranovsky wrote:
Hi Henk,

But sorry, calling LISP "new
technology" that sounds to me like horrific neglect of history.

But I never told it :-)

Jul 17 '05 #5

P: n/a
Hi Alexander,
Are you sure that you will see termination of your program
before than resources will be exhausted ?
No, but if i would worry about that, i would not be using php.
In practice it simply has never happened to me. (i make web
applications with loads of objects, i allways use references with
objects and non-literal arrays, and i avoid them if their life
expectancy is only a single method call, but not becuase of having no
garbage collection during a http request: i consider that descent
practice in Java and Smalltalk too)
I did not found an analogue of TerminalOf operator in PHP. true, but to be honest i find the entire varibale reference business
tricky, it breaches encapsulation. That's why i make made the
getTerminal function in the class below return the last list, not a
reference to its cdr.
We are discussing features of language ad hoc, not build-in classes.
php4 has no built-in classes. I just thought the following to be too
obvious to write down (exept for getTerminal and lit):

class List {

var $car;
var $cdr;

//constructor
function List(&$car, &$cdr)
{
$this->setCar($car);
$this->setCdr($cdr);
}

//static convenience function for creating new from literal for $car
function &lit($car, &$cdr)
{
return new List($car, $cdr);
}

function &getCar()
{
return $this->car;
}

function setCar(&$car)
{
$this->car =& $car;
}

function &getCdr()
{
return $this->cdr;
}

function setCdr(&$cdr)
{
$this->cdr =& $cdr;
}

function hasCdr()
{
return $this->getCdr() !== null;
}

function &getTerminal()
{
$current =& $this;
do {
$current =& $current->getCdr();
} while ($current->hasCdr());
return $current;
}

} //end class List

I now see that i need the `lit` function, and that i should have written:
$null = null; //to pass by reference
$list =& List::lit(100, List::lit(200, List::lit(300, $null)));

$current =& $list;
do {
$current =& $current->getCdr();
} while ($current->hasCdr());
$current->setCdr(List::lit(400, $null));
The use of aliases jointly with terminals allows to simplify data
representation and algorithmes in AI, so I consider it as an important
concept.
The use of meaningfull method/function/class names, objects,
encapsulation, late binding, polymorphism, delegation, classes,
inheritance, garbage collection, exceptions, blocks, hashed associative,
indexable and sortable collections of variable size, iterators, events,
directed graphs with named roles (inlcudes n-ary trees), metaobjects,
dynamic invocation, wrappers and filters allow to simplify data
representation and algorithms in allmost any area of application, so i
consider those as important concepts ;-). As far as they need to be part
of the language, php4 has most but is missing some of them, but it's
hosting costs, installed base on webservers and lbnl its mindshare with
young programmers is worth a litle inconvenience. (IMHO).

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

BTW, most array-based growable collections will overallocate so that
there is room for insertions without producing garbage every time. This
may be hidden in php, but that does not mean it's not there.

Alexander Baranovsky wrote: I'll use paxC because its syntax more similar to PHP, so readers will
able to better understand our discussion.

$l = array(100, array(200, array(300, null)));
//imho this IS a linked list

$p =& $l;
do {
$p =& $p[1];
} while ($p!==null);
$p = array(400, $p);

In paxC I do the same with

variant L, P;
L = [100, [200, [300, null]]];
P = & L; // Create alias of L
while (P != null) {P = & P[1]; }; // Find last item
P = [400, null]; // Add new item

So, PHP syntax a bit cumbersome, but I can accept it. It really allows
to create a list by means of arrays.

More important is another question: effectivity. In paxC I insert new
item at the head of L list by

L = [50, L];

Let's consider semantics of the statement. It means

variant temp = paxArray(2);
temp[0] = 50;
temp[1] = L;
L = temp;

The last 2 lines are key. The L and temp variables are references in
paxC. So, the statement of insertion of new item will be processed
effectively (i.e. without copying of actual array and new chip of
garbage).

But the assignment statement in PHP creates duplicate of array: In
paxC I use unary "+" operator to create a duplicate of variable.

Mmm, would'nt this be simpeler?:
$l = array(100, 200, 300);
$l[] = 400;

Let's do not discuss it. The article devoted to linked lists. Besides,
I guess, you are using reallocation of memory in implementation, so I
cannot consider the solution as quite elegant.

then they have this reduced statement:
reduced L = L(1)
in php we don't need it:
$l =& $l[1];
is no problem, php will collect the garbage when the script is finished.

Suppose, you have placed your statement $l = & $l[1] in the body of a
long loop. Are you sure that you will see termination of your program
before than resources will be exhausted ?

another example:
P = AddressOf L(1)
P = AddressOf P(1) 'insert before 200
P = [150, P]

literally translates to:
$p =& $l[1];
$p =& $p[1];
$p = array(150, $p);

but it results in array(100, array(200, array(150, array(300, null)))) :-(

Your sign of grief is not necessary :-) In my example the list already
contain 50 before 100, so result is correct.

I can go on like this, but i do not see much of a point. To me array
seems fine as it is, and if i really want a linked list i rather
implement it with objects:
$list =& new List(100, new List(200, new List(300)));

$current =& $list;
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar(new List(400));

Oh, let's do not discuss it as well. :-) We are discussing features of
language ad hoc, not build-in classes. For example, paxScript allows
to import any Delphi classes, but I cannot consider it as a essential
feature.

And the last. I did not found an analogue of TerminalOf operator in
PHP. The use of aliases jointly with terminals allows to simplify data
representation and algorithmes in AI, so I consider it as an important
concept.

A.

Henk Verhoeven <ne**@phppeanutsREMOVE-THIS.org> wrote in message news:<c5**********@news2.tilbu1.nb.home.nl>...
In paxBasic:

Dim L = [100, [200, [300, NULL]]]

P = AddressOf L 'Create alias of L
Do Until P = NULL 'Find tail of L
P = AddressOf P(1)
Loop
P = [400, P] 'Add new item at the tail of L

in PHP:

$l = array(100, array(200, array(300, null)));
//imho this IS a linked list

$p =& $l;
do {
$p =& $p[1];
} while ($p!==null);
$p = array(400, $p);

Mmm, would'nt this be simpeler?:
$l = array(100, 200, 300);
$l[] = 400;

another example:
P = AddressOf L(1)
P = AddressOf P(1) 'insert before 200
P = [150, P]

literally translates to:
$p =& $l[1];
$p =& $p[1];
$p = array(150, $p);

but it results in array(100, array(200, array(150, array(300, null)))) :-(

on $l = array(100, 200, 300, 400);
it woud be: array_splice($l,1,0, 150);
ant this correctly gives: array(100, 150, 200, 300, 400);

then they have this reduced statement:
reduced L = L(1)
in php we don't need it:
$l =& $l[1];
is no problem, php will collect the garbage when the script is finished.

I can go on like this, but i do not see much of a point. To me array
seems fine as it is, and if i really want a linked list i rather
implement it with objects:
$list =& new List(100, new List(200, new List(300)));

$current =& $list;
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar(new List(400));

would then become:

function addAtTail(&$car)
{
$current =& $this
do {
$current =& $current->getCar();
} while ($current->hasCar());
$current->setCar($car);
}

function addCdrAtTail($cdr)
{
$this->addAtTail(new List($cdr));
}

OK, the method names may not correctly reflect common LISP terminology,
but at least they raise the question about what are the correct terms!

Greetings,

Henk Verhoeven,
www.phpPeanuts.org
Alexander Baranovsky wrote:
Hi Henk,

But sorry, calling LISP "new
technology" that sounds to me like horrific neglect of history.
But I never told it :-)


Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.