linked list for string class

L

larry_wallet

How would I go about creating a linked list in Perl? I would like to
dynamically generate structures or objects and link one to the next so
that I may traverse the list back and forth.

I would then like to have each object in the list contain as a member
a single text character. By stringing together an arbitrary number of
these objects, this larger structure, which could be a class
containing the linked list, could be used as a "string" class,
literally a string of characters, not bound by the limitations of
simple common strings.

I appreciate any thoughts on how I might implement this structure in
Perl, which seems uniquely well suited to the task.


****
*lw*
****

Director of Generic Programming and Abstractions,
Integrated Distributed Systems, Inc.
 
A

Ala Qumsieh

I would then like to have each object in the list contain as a member
a single text character. By stringing together an arbitrary number of
these objects, this larger structure, which could be a class
containing the linked list, could be used as a "string" class,
literally a string of characters, not bound by the limitations of
simple common strings.

I'm curious to know what the limitations of common strings are and how
your string class overcomes them.

--Ala
 
U

Uri Guttman

AQ> I'm curious to know what the limitations of common strings are and
AQ> how your string class overcomes them.

they are just classier!

<and i ask the same question>

uri
 
J

Joe Smith

could be used as a "string" class,
literally a string of characters, not bound by the limitations of
simple common strings.

Perl handles UTF-8, which included characters that are not bound by
the limitation of being held in a single byte. Is that what you're
talking about?

Using 5 or 9 bytes to hold a single character is mighty wasteful.
-Joe
 
P

Paul Lalli

How would I go about creating a linked list in Perl? I would like to
dynamically generate structures or objects and link one to the next so
that I may traverse the list back and forth.

Have you read
perldoc -q "linked list"
? Please check the Perl FAQ before posting.
I would then like to have each object in the list contain as a member
a single text character. By stringing together an arbitrary number of
these objects, this larger structure, which could be a class
containing the linked list, could be used as a "string" class,
literally a string of characters, not bound by the limitations of
simple common strings.

Exactly what limitations do you believe Perl's native strings have, and
how do you believe your class will overcome them?

Perhaps you should ask us for help with your *actual* goal is, rather
than with how you believe you should achieve that goal.
I appreciate any thoughts on how I might implement this structure in
Perl, which seems uniquely well suited to the task.

I'm sure I somewhere read something like "Just because There's More Than
One Way To Do It, that doesn't mean all ways are equally good."

Paul Lalli
 
L

larry_wallet

I'm curious to know what the limitations of common strings are and how
your string class overcomes them.

--Ala

You are right, I did not explain clearly the benefits. Strings as
they are are made up of dead characters. Characters with no life, no
awareness, no sense of purpose, no knowledge of where they are and who
surrounds them.

Imagine a string of characters in which each character is of a
different class, derived from the same class of course, and each knows
its place in the string yet cooperates with its fellow characters in
ways that we can only dream of. This leads to technology like
self-correcting strings, intelligent documents, and even interactive,
multitasking text. The benefits are basically issues of encapsulation
and extensibility.

****
*lw*
****

Director of Generic Programming and Abstractions,
Integrated Distributed Systems, Inc.
 
T

Tad McClellan

How would I go about creating a linked list in Perl?


By reading the Perl FAQ *before* posting to the Perl newsgroup.


perldoc -q linked

How do I handle linked lists?
 
A

Anno Siegel

How would I go about creating a linked list in Perl? I would like to
dynamically generate structures or objects and link one to the next so
that I may traverse the list back and forth.

I would then like to have each object in the list contain as a member
a single text character. By stringing together an arbitrary number of
these objects, this larger structure, which could be a class
containing the linked list, could be used as a "string" class,
literally a string of characters, not bound by the limitations of
simple common strings.

I'm not happy with your terminology here. How can "this ... structure"
(a linked list) be a class? How can it "contain the linked list"
which would be itself? It doesn't make sense.
I appreciate any thoughts on how I might implement this structure in
Perl, which seems uniquely well suited to the task.

What you want is trivial to implement in Perl (see below), but
the advantages over plain arrays or strings escape me. There
isn't much you can do with a liked list that can't be done with
the more traditional structures. If you want characters who know
which string they are part of (inherently true for list nodes),
that could be implemented in other ways too.

Anyway, below is the skeleton of a node class that could be embellished
to base linked list on. The pay load of each node can be any scalar,
not just characters.

Anno

#!/usr/local/bin/perl
use strict; use warnings; $| = 1;

my $n;
$n = Node->new( $_, $n) for qw( alpha beta gamma delta);
print "$_\n" for $n->list;

###################################################################

package Node;

# create new node. if $tail is given, append it to the new node
sub new {
my ( $class, $data, $tail) = @_;
bless [ $data, $tail], $class;
}

# return a list of the data contents of all nodes
sub list {
my $node = shift;
return ( $node->[ 0]) unless $node->[ 1];
( $node->[ 0], $node->[ 1]->list);
}
 
C

ctcgag

You are right, I did not explain clearly the benefits. Strings as
they are are made up of dead characters. Characters with no life, no
awareness, no sense of purpose, no knowledge of where they are and who
surrounds them.

Do you give motivational seminars for ASCII characters?

Imagine a string of characters in which each character is of a
different class, derived from the same class of course, and each knows
its place in the string yet cooperates with its fellow characters in
ways that we can only dream of.

OK, I'm thinking of a godawful mess. When I'm typing up my thesis, the
last thing I want is for all the "the"s to make a coalition with all the
"adenosine"s and then jointly declare war upon any word ending with "-gen"
or "-ome".

If the characters are no longer characters but now fully sentient beings,
then I would say you no longer have a string, becuase that is not what
"string" means when programmers use that word.

Xho
 
M

Michele Dondi

Imagine a string of characters in which each character is of a
different class, derived from the same class of course, and each knows
its place in the string yet cooperates with its fellow characters in
ways that we can only dream of. This leads to technology like
self-correcting strings, intelligent documents, and even interactive,
multitasking text. The benefits are basically issues of encapsulation
and extensibility.

Are you sure you want to do this in *Perl*?


Michele
 
A

Anno Siegel

Michele Dondi said:
Are you sure you want to do this in *Perl*?

I think we have been trolled, though not very effectively. I mean,
larry_wallet@yahoo...

Anno
 
D

David K. Wall

Anno Siegel said:
I think we have been trolled, though not very effectively. I
mean, larry_wallet@yahoo...

Possibly, but Xho's response was worth it. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top