Re: accessing head of list




"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).


.



Relevant Pages

  • Re: Highly efficient string reversal code
    ... int len=strlen ... taking the "string length" of an integer. ... The head end now contains an array of 0x00 (up to ... results of the head end xor the tail end. ...
    (comp.lang.c)
  • Re: Linked List Library
    ... Append a new item at the end of the list. ... My append list function, returns the tail. ... tail = head = NULL; ... strcpy(node -> data, string); ...
    (comp.lang.c)
  • I would like to split easily a cell in two cells
    ... Suppose that A1 contains a string, ... I would like to edit A1, put my text cursor somewhere, and by an easy ... head tail ...
    (microsoft.public.excel.misc)
  • Re: Python Doc Problem Example: os.path.split
    ... I was working on a program where i needed to split a path into dirname, ... > Split the pathname path into a pair, (head, tail) where tail is the ... > last pathname component and head is everything leading up to that. ... > tail part will never contain a slash; if path ends in a slash, ...
    (comp.unix.programmer)
  • Re: Using a link list over an array.
    ... compile (p->data is a void *) so you have not shown us some key ... int cmp ... head = list_sort; ... list_type *tail; ...
    (comp.lang.c)