Is there a way to determine the type of an element within a list in Prolog? I know that variables aren't explicitly typed in Prolog, but I need to check whether an element is a number, a specific character, etc. How can this be accomplished?
相关问题
- how to split a list into a given number of sub-lis
- C#: How do i get 2 lists into one 2-tuple list in
- F#: Storing and mapping a list of functions
- Creating a SPARQL parameterized query using append
- Select first row from multiple dataframe and bind
相关文章
- List可以存储接口类型的数据吗?
-
C# List
.FindAll 时 空指针异常 - What is the complexity of bisect algorithm?
- What are the problems associated to Best First Sea
- Given a list and a bitmask, how do I return the va
- How do I get from a type to the TryParse method?
- How can I fix this circular predicate in Prolog?
- Java Generics: How to specify a Class type for a g
You could try this code:
Hope it helps.
To check if a variable is bound to a list, you can use
is_list/1
.to check list you could try:
Prolog defines a group of built-in predicates for type testing purposes:
var/1
,atom/1
,integer/1
,float/1
,atomic/1
,compound/1
,nonvar/1
,number/1
, all of them with quite a self-explanatory meaning if you know the data types of the language. For specific characters, you may exploit unification with that character, after checking that the element is not a free variable (otherwise unification is always successful).number/1
See also http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%27F.1%27,swi%28%27/doc/Manual/predsummary.html%27%29%29