Re: accessing head of list
- From: "Andrew" <someone@xxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 05:38:11 GMT
"artheartscience" <steve@xxxxxxxxxxxxxxx> wrote in message
news:1145894448.958980.287980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hi, quick question...
if i read in a string with read(X), how could i then print out only the
first character?
I think this should work.
Assuming that X is a list, you need to print out the Head.
A list consists of a Head and a Tail (the tail is also a list).
So if X=Test it would look like
T,[est]
e,[st]
s,[t]
t,[]
Someone correct me if I am wrong!
So to implent this all you need is predicate to print out the Head.
go:-
%do all your stuff
read(X),
write_first_char(X).
write_first_char([H|T]):-write(H).
.
- References:
- accessing head of list
- From: artheartscience
- accessing head of list
- Prev by Date: Replace occurrence of a list with another?
- Next by Date: Create a List of Lists
- Previous by thread: accessing head of list
- Next by thread: Replace occurrence of a list with another?
- Index(es):
Relevant Pages
|
|