In: Computer Science
Meta Language(ML) has two commonly used data structures(Lists and tuples). Distinguish between two of them and rationalize your argument by the support of code snippet of each.
Lists |
Tuples |
How can we concatenate a string in Meta Language(ML)? Also write one coding example of string concatenation.
What is meant by right-associative ? Elaborate it using an example.
Write a condition in the given blank below using comparison operator to get the require output from this code.
Answer for first question
Lists
1. Lists are mutable.
2. You can change the items on the list and their ordering.
3. have different types of objects.
4. A list occupies more memory compared to tuples.
5. Lists have variable lengths.
6. Syntax : [ a,h,j ]
Tuples
1. They are immutable.
2. You cannot change the items of tuples and their ordering.
3. Tuple can also contain different types of objects.
4. Tuples occupy less memory.
5. Tuples have fixed lengths.
6. Syntax : ( a,h,j )
Answer for second question
Strings can be concatenated in Meta Language using the ^ operator
Example:
Answer for third question
The associativity is the property that determines how the
operator of the same precedence is executed if the parentheses are
missing in the expression.
The evaluation order of the expression is determined by precedence
and associativity if the parentheses are missing in the
expression.
The associativity can be:
Left to right
Right to left
For example:
The operator '=' is used as right-associative in most of the
programming languages.
a = b = c
First, the value of c is assigned to b and then assign to variable
a.
The operator '^' is right-associative.
x = 2^3^2
The above expression will be calculated as:
x = 2^(3^2)
x = 2^(9)
x = 512
Answer for fourth
question
given,
filter(P,nil) = nil
filter(P,x::xs) =
if P(x) then x::filter(P,xs)
else filter(P,xs) ;
The require output form is [1,8,5,3]
The input list elements is [1,10,23,8,5,16,3]
In the output, we see the list contains only elements that are less than 10 in the input list.
So, condition is given using comparison operator to require output below -:
fn x => (x < 10),[1,10,23,8,5,16,3] ;
#########PLEASE UPVOTE THE ANSWER########