Podcast
Questions and Answers
Visual Prolog's string-handling predicates are categorized into basic string manipulation and advanced string manipulation.
Visual Prolog's string-handling predicates are categorized into basic string manipulation and advanced string manipulation.
False (B)
The frontchar
predicate can only be used to split a string into its first character and the remaining substring.
The frontchar
predicate can only be used to split a string into its first character and the remaining substring.
False (B)
The frontchar
predicate will always succeed, regardless of the input string.
The frontchar
predicate will always succeed, regardless of the input string.
False (B)
The fronttoken
predicate can only divide a string into lexical tokens.
The fronttoken
predicate can only divide a string into lexical tokens.
Given the goal fronttoken("Visual Prolog", T, R)
, T
will be bound to Visual
and R
will be bound to Prolog
.
Given the goal fronttoken("Visual Prolog", T, R)
, T
will be bound to Visual
and R
will be bound to Prolog
.
The frontstr
predicate requires the first and second parameters to be unbound when called.
The frontstr
predicate requires the first and second parameters to be unbound when called.
The concat
predicate is non-deterministic, meaning it can provide multiple solutions.
The concat
predicate is non-deterministic, meaning it can provide multiple solutions.
The predicate str_len
can only be used to verify the length of a string.
The predicate str_len
can only be used to verify the length of a string.
The isname
predicate checks if a string is a valid Visual Prolog variable name, allowing only digits and underscores.
The isname
predicate checks if a string is a valid Visual Prolog variable name, allowing only digits and underscores.
The subchar
predicate returns a character at a given position in a string and the positions are zero-indexed.
The subchar
predicate returns a character at a given position in a string and the positions are zero-indexed.
The substring
predicate will execute successfully even if the specified position and length result in accessing characters outside the string's boundaries.
The substring
predicate will execute successfully even if the specified position and length result in accessing characters outside the string's boundaries.
searchchar
will find all occurrences of a character in a given string through backtracking.
searchchar
will find all occurrences of a character in a given string through backtracking.
searchstring
can find multiple occurrences of a substring within a source string through backtracking.
searchstring
can find multiple occurrences of a substring within a source string through backtracking.
The predicates for type conversion in Visual Prolog include char_int
, str_char
, str_int
, str_real
, and upper_lower
.
The predicates for type conversion in Visual Prolog include char_int
, str_char
, str_int
, str_real
, and upper_lower
.
The char_int
predicate cannot be used to verify if a character corresponds to a specific integer value.
The char_int
predicate cannot be used to verify if a character corresponds to a specific integer value.
The str_char
predicate converts a string to its character representation.
The str_char
predicate converts a string to its character representation.
The str_int
predicate is used exclusively for converting strings to integers; it cannot perform the reverse conversion.
The str_int
predicate is used exclusively for converting strings to integers; it cannot perform the reverse conversion.
The str_real
predicate is used to convert strings to floating point numbers
The str_real
predicate is used to convert strings to floating point numbers
The upper_lower
predicate is designed to perform case conversions on strings or characters.
The upper_lower
predicate is designed to perform case conversions on strings or characters.
The upper_lower
predicate will always fail if the two strings are the same, even if they have differences in case.
The upper_lower
predicate will always fail if the two strings are the same, even if they have differences in case.
Flashcards
String Processing
String Processing
Standard predicates for powerful string manipulations in Visual Prolog.
Basic String-Handling Predicates
Basic String-Handling Predicates
Predicates that serve purposes such as dividing strings, building strings, verifying composition, returning substrings, finding length, creating blank strings and verifying Visual Prolog names.
frontchar/3
frontchar/3
Divides a string into its first character and the remaining substring.
fronttoken/3
fronttoken/3
Signup and view all the flashcards
frontstr/4
frontstr/4
Signup and view all the flashcards
concat/3
concat/3
Signup and view all the flashcards
str_len/2
str_len/2
Signup and view all the flashcards
isname/1
isname/1
Signup and view all the flashcards
subchar/3
subchar/3
Signup and view all the flashcards
substring/4
substring/4
Signup and view all the flashcards
searchchar/3
searchchar/3
Signup and view all the flashcards
searchstring/3
searchstring/3
Signup and view all the flashcards
char_int/2
char_int/2
Signup and view all the flashcards
str_char/2
str_char/2
Signup and view all the flashcards
str_int/2
str_int/2
Signup and view all the flashcards
str_real/2
str_real/2
Signup and view all the flashcards
upper_lower/2
upper_lower/2
Signup and view all the flashcards
Study Notes
- Visual Prolog offers standard predicates for string manipulations, divided into basic string-handling and type conversion.
- Strings can also be compared.
Basic String-Handling Predicates
- These predicates form the foundation for string handling in Visual Prolog.
- They divide a string into components/tokens.
- They build strings from specified strings/tokens.
- They verify a string's composition.
- They return a string, token, or list from a given string.
- They verify/return the string's length.
- They create blank strings of a specific length.
- They verify if a string is a valid Visual Prolog name.
frontchar/3
- It concatenates
Char
andString2
to equalString1
. - Format:
frontchar(String1, Char, String2)
. - Example goal:
frontchar("ahmed", H, R)
results inH = 'a'
andR = "hmed"
. - It takes three arguments: a string, a char (first char of the string), and the rest of the string.
frontchar
splits a string or creates one, and tests characters within.- It fails if
String1
is a zero-length string. - It is used to change a string to a list of characters.
- Example goal:
string_chlist("ABC", Z)
binds Z to['A', 'B', 'C']
.
fronttoken/3
fronttoken
has three functions based on the flow pattern used.- Format:
fronttoken(String1, Token, Rest)
. - With (i,o,o) flow, it finds the first token of String1, binds it to Token, and the remainder to Rest.
- The (i,i,o), (i,o,i), and (i,i,i) flow variants are tests.
- The (o,i,i) variant constructs a string by concatenating Token and Rest, binding String1 to the result.
- Tokens are grouped as names, numbers or non-space characters based on Visual Prolog Syntax.
- Suited for decomposing a string into lexical tokens.
- It divides a sentence into a list of names.
frontstr/4
frontstr
splitsString1
into two parts.- Format:
frontstr(NumberOfChars, String1, StartStr, EndStr)
. StartStr
contains the firstNumberOfChars
ofString1
, andEndStr
contains the rest.- When called, the first two parameters must be bound, and the last two must be free.
concat/3
concat
concatenatesString1
andString2
to equalString3
.- Format:
concat(String1, String2, String3)
. - At least two parameters must be bound.
- It gives only one solution.
- Example:
concat("ali", "hits", W)
results inW = "alihits"
.
str_len/2
str_len
returns or verifies string length, or returns a blank string of a given length.- Format:
str_len(StringArg, Length)
. - Example:
str_len("ali", L)
results inL = 3
. - It binds
Length
to the length ofStringArg
or tests ifStringArg
has the givenLength
. Length
is an unsigned integer.- It can return a string of spaces.
makebinary
is preferable for allocating buffers, especially for binary data.
isname/1
isname
verifies if the argument is a valid name according to Visual Prolog syntax.- Format:
isname(String)
. - A name starts with a letter or underscore, followed by letters, digits, and underscores.
- Spaces are ignored.
subchar/3
subchar
returns the character at a given position in a string.- Format:
subchar(String, Position, Char)
. - The first character is at position 1.
- It exits with an error if the position is beyond the string's end.
substring/4
substring
returns a part of another string.- Format:
substring(Str_in, Pos, Len, Str_out)
. Str_out
is bound to the string starting atPos
with lengthLen
fromStr_in
.- It exits with an error if
Pos
andLen
specify a string outside ofStr_in
. - It is not an error to ask for 0 bytes at the extreme end of the string.
searchchar/3
searchchar
returns the position of the first occurrence of a character in a string.- Format:
searchchar(String, Char, Position)
. - If the character isn't found, it fails and is not re-satisfiable.
searchstring/3
searchstring
returns the position of the first occurrence of a string in another string.- Format:
searchstring(SourceStr, SearchStr, Pos)
. - It fails if the search string isn't found or is longer than the source.
- It is not re-satisfiable.
Type Conversion Predicates
- Predicates in this category include:
char_int
,str_char
,str_int
,str_real
, andupper_lower
. - They facilitate conversions between different data types and strings.
char_int/2
char_int
converts a character to an integer or vice versa.- Format:
char_int(Char, Integer)
. - The arguments must correspond when both are bound. If one is bound, the other is converted and bound.
str_char/2
str_char
converts a string containing one character into a character or converts a single character into a string of one character.- Format:
str_char(String, Char)
. - In the (i,i) flow, it succeeds if String is bound to the single character string equivalent of Char, otherwise fails.
str_int/2
str_int
converts a string containing an integer into an integer, or converts an integer into its textual representation.- Format:
str_int(String, Integer)
. - With the (i,i) flow, it succeeds if
Integer
is bound to the integer equivalent of the string.
str_real/2
str_real
converts a string containing a real number to a real number, or vice versa.- Format:
str_real(String, Real)
. - With the (i,i) flow, it succeeds if Real is bound to the real equivalent of the real number represented by the string.
upper_lower/2
upper_lower
converts a string to all lower/upper case.- Format:
upper_lower(Upper, Lower)
. - It succeeds when both arguments, except for the case of letters, are identical.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.