Question: I have this question in a homework assignment for my Computer Languages class. I'm trying to figure out what each one means, but I'm getting stuck.

> 
> Errors in a computer program can be
>  classified according to when they are
>  detected and, if they are detected at
>  compile time, what part of the
>  compiler detects them. Using your
>  favorite programming language, give an
>  example of:
> 
> 
> (a) A lexical error, detected by the
>  scanner.
> 
> 
> (b) A syntax error, detected by the
>  parser.
> 
> 
> (c) A static semantic error, detected
>  (at compile-time) by semantic
>  analysis.
> 
> 
> (d) A dynamic semantic error, detected
>  (at run-time) by code generated by the
>  compiler.
> 
> 
> 

For (a), I think this is would be correct: `int char foo;`

For (b), `int foo` (no semicolon)

For (c) and (d), I'm not sure what is being asked.

Thanks for the help.

Answer: 
I think the simplest solution is to test "boolean" parameters against their String representation.

```
@show_all = params[:show_all]
if @show_all.to_s == "true"
   # do stuff
end

```

Regardless of whether Rails delivers the parameter as the String "true" or "false" or an actual TrueClass or FalseClass, this test will always work.
Another approach is to pass only the key without a value. Although using `ActiveRecord::Type::Boolean.new.type_cast_from_user(value)` is pretty neat, there might be a situation when assigning a value to the param key is redundant.

Consider the following:
On my products index view by default I want to show only scoped collection of products (e.g. those that are in the stock). That is if I want to return all the products, I may send `myapp.com/products?show_all=true` and typecast the `show_all` parameter for a boolean value.

However the opposite option - `myapp.com/products?show_all=false` just makes no sense since it will return the same product collection as `myapp.com/products` would have returned.

An alternative: 

if I want to return the whole unscoped collection, then I send `myapp.com/products?all` and in my controller define 

```
private

def show_all?
  params.key?(:all)
end

```

If the key is present in params, then regardless of its value, I will know that I need to return all products, no need to typecast value.