Did you know ... Search Documentation:
readln.pl -- Read line as list of tokens
PublicShow source

Read a sentence from the current input stream and convert it into a list of atoms and numbers:

  • Letters(A-Z, a-z) are converted to atoms
  • Digits (0-9) (and a '.' if a real number) are converted to numbers Some obscure 'rounding' is done, so you have most of the times only 6 significant digits with an exponent part. (This is caused by the system predicate 'name'. If you want looonnnggg numbers then define digits as parts of words). (N.B. reals work only if '.' is not defined as 'stop-char' but 'escape' will work in this case)

    The reader is flexible, you can define yourself:

    • the character on which reading will stop (this character is escapable with \ to read a \ type this character twice!!)
    • the character(s) that make up a word (execpt the characters A-Z, a-z that always make up words!! and (real)-numbers that always are grouped together!!)
    • whether you want conversion of uppercase letters to lowercase letters.

    readln/1 The default setting for readln/1 is

    • read up till newline
    • see underscore('_') and numbers 0-9 as part of words
    • make lowercase
    • If nothing is read readln/1 succeeds with []
    • If an end_of_file is read readln/1 succeeds with [..|end_of_file]
    readln/5 This predicate gives you the flexibility. It succeeds with arg1 = list of word&atoms arg2 = Ascii code of last character (but '-1' in case of ^D). To change one or more of the defaults you have to instantiate argument3 and/or argument4 and/or argument5. !! Uninstantiated arguments are defaulted !!
    • stop character(s): instantiate argument 3 with the list of ASCII code's of the desired stop characters (Note: you can also say: ".!?", what is equivalent to [46,33,63]).
    • word character(s): instantiate argument 4 with the list of ASCII code's of the desired word-part characters (Note: wou can also say: "", what is equivalent to [] ; i.e. no extra characters).
    • lowercase conversion: instantiate argument 5 with lowercase

Main predicates provided:

readln(P)           - Read a sentence up till NewLine and
                      unify <P> with the list of atoms/numbers
                      (identical to:
                             readln(P, [10],"_01213456789",uppercase).)
readln(P, LastCh)   - idem as above but the second argument is unified
                      with the last character read (the ascii-code for
                      the stop-character or -1)
readln(P, LastCh, Arg1, Arg2, Arg3)
                    - idem as above but the default setting is changed
                      for the instantiated args:
                      Arg1: List of stop characters
                      Arg2: List of word_part characters
                      Arg3: uppercase/lowercase conversion
Examples: read_sentence(P,Case) :- readln(P,_,".!?","_0123456789",Case).
read_in(P) :- % with numbers as separate readln(P,Eof,_,"", _). % entities.
read_atom(A) :- % stop on newline, readln(A,_,_," ",_). % space is part of word
See also
- library(readutil), nlp package.
deprecated
- Old code. Not maintained and probably not at the right level of abstraction. Not locale support.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source readln(Arg1, Arg2, Arg3, Arg4, Arg5)
Source readln(Arg1)
Source readln(Arg1, Arg2)