0
votes

Suppose there is an expression that is essentially is simplified to the point: (true false), or any combination of true and false.

For example, [(predicate) false] or [(predicate) (predicate)]

I am trying to understand how such expressions are evaluated in Scheme - what is such a statement essentially saying?

1
Are the examples supposed to be terms in a cond special form? As they are written now it seems like predicate needs to return a procedure to take false as an argument. (square brackets can be used all places you have parentheses eg. [odd? 5] ; ==> #t ) - Sylwester
Yes they are supposed to be in terms of cond. And you are right, they would go through a procedure first to return true or false. @Sylwester - FΣynman

1 Answers

1
votes

As a term in a cond:

(cond 
  [(predicate) false]
  [else true])

Would be a conditional implementation of (not (predicate)) since the predicate needs to be a true value to get a false result.

(cond 
  [(predicate) (predicate)]
  [else false])

This is the same as (predicate) since it becomes itself for all true values and the default case I've added becomes it's false value.

In any of these if you have something else as the default case it would of course not map to those simple results but a slightly more complex ones:

(cond 
  [(predicate) (predicate)]
  [else 'something])

Would be the same as (and (predicate) 'something) since we have changed the false value to something.

(cond 
  [(predicate) false]
  [else 'something])

Would be the same as (and (not (predicate)) 'something)