Perfect Developer basic tutorial 3 This page last modified 2011-10-29 (JAC)

Expressions with Bound Variables Quiz

1. Given that variable x has type string, write an expression to test whether x contains any commas or semicolons.

exists c::x :- c = `,` | c = `;`
 

2. Given that variable s has type set of int:

  1. Write an expression stating that s contains at least one even number
  2. Write an expression stating that for a given integer x, each element in s is either not even or is not less than x
  3. Given that s contains at least one even number, write an expression to determine the lowest even number in s
  4. Write an expression that yields all the even numbers in s
  5. Write an expression that yields the squares of all the numbers in s
  6. Write an expression that yields the squares of all the even numbers in s

The following are not the only possible answers, because there are other ways of expressing them.

  1. exists x::s :- x % 2 = 0
  2. forall y::s :- y % 2 ~= 0 | y >= x
  3. that x::s :- x % 2 = 0 & (forall y::s :- y % 2 ~= 0 | y >= x)
  4. those x::s :- x % 2 = 0
  5. for x::s yield x * x
  6. for those x::s :- x % 2 = 0 yield x * x