0

I'm new to Prolog and trying to do a program to check if some values can be a date, but I don't know what can I do with the language. I don't know the commands.

As example, I want to get the length of a string, but I don't know if this is possible.

Someone can show me a list of Prolog commands? I'm using tuProlog for Java.

By the way, the program I want to do is this: receive two or three parameters and check if is some type of date (eg.: 10/2000, 2011/09, 11/03/1191, etc.).

manlio
  • 18,345
  • 14
  • 76
  • 126
Renato Dinhani
  • 35,057
  • 55
  • 139
  • 199

3 Answers3

2

You can check out the User guide for tuProlog at this location Section 4.4 addresses builtin predicates.

This link might also be of help. Working with strings in Prolog

And for parsing, given that one of the libraries in tuProlog is for DCGs: Prolog DCG presentation

You can also search Stackoverflow for Prolog and dcg to see others' questions and answers.

Roman
  • 1,179
  • 6
  • 7
1

The documentation for SICStus Prolog describes its standard library. I'm not entirely sure what parts of it are or aren't standard for a Prolog implementation, but it might help you.

Vlad
  • 18,195
  • 4
  • 41
  • 71
1

tuProlog's user guide is easy to find: Documentation. Chapter 5 contains the Prolog commands at your disposal.

From your question, I infer that you receive the date as a string and you're not sure in which format the date string arrives.

I would look at text_term/2 to transform the string into a term (I'm not 100% sure, the Prolog system I use has a differently named predicate for that). Then you can test whether it contains one or two slashes (or is in another format or is not a date at all), by unifying Term with a Term of the desired structure:

Term = D/M/Y

and testing if this is a valid date:

text_term(Text,Term),
( Term = D/M/Y, valid_date(D,M,Y) ->
  true
; Term = M/D/Y, valid_date(D,M,Y) ->
  true
; ...

The -> is "if-then", the ; is "else". You'll need to write a predicate that test for valid dates, which I called valid_date/3 above.

twinterer
  • 2,416
  • 1
  • 15
  • 13