Subject: Re: [SWIPL] Input numbers

From: "Richard A. O'Keefe" <[email-masked]>
Date: Mon, 18 Dec 2000 12:11:18 +1300 (NZDT)

Rastei Amelia Viorela  <[email-masked]> writes:
(edited)
	I want to read integers from the standard input.	
	I tried

	?-readln(X).
	|: 2 3
	X=[2,3].
	
I prefer library(read_constant) in the Quintus library, but since I wrote
it, that's no surprise.

	How can I use the values 2,3  separately?

You have a list X = [2,3].
You extract values from *this* list the same way you extract values
from *any* list, namely by unification.  So

    ?- readln([A,B]).
    |: 2 3
    A = 2
    B = 3 

Or	?- readln(X), X = [A,B|_].
    |: 31 41 59
    X = [31,41,59]
    A = 31
    B = 41

	Is X a list of numbers?
	So I can use the functions nth1 or nth0??? 
	
It is a possibly empty list of tokens.
    ?- readln(X).
    |: 'Twas brillig and the slithey toves did gyre and gimble in the wabe.

    X = ['\'', 'Twas', brillig, and, the, slithey, toves, did, gyre, and|...] 

A token is a number, a stretch of letters, or a punctuation mark.
	 
You can use {nth0,nth1}/3 on this list, but why would you?
Why not just write down a list with variable names for the responses
you do want and underscores for the ones you don't?