Question

I have condition that uses the member function:

(cond ((member '1' (some-function)) (display #t)) (else (display #f)))

it works fine but i still couldn't find the answers to:

1)what is the type of '1'?

2)i have the next expression

(lambda(x)(= x 1))

how can I convert to the same type of '1'?

Was it helpful?

Solution

Notice that the cond expression is not doing what you think. What's really happening is this:

(cond ((member '1 '(some-function))
       (display #t))
      (else
       (display #f)))

In other words: the number 1 is being quoted and the expression '(some-function) is being interpreted as a single-element list with the symbol some-function as its only member. Regarding the first question, this expression:

'1'

… is invalid in Scheme - try typing it in the evaluation window, nothing will happen: the first quote applies to the number 1, and the second quote is expecting further input, so anything that's written after it will get quoted. FYI double quotes mean a string, as in many other languages: "1". But a single quote indicates a quoted expression, that evaluates to itself:

'1
=> 1

And it's just shorthand for this:

(quote 1)
=> 1

Which in the above expression is unnecessary, a number already evaluates to itself:

1
=> 1

Now, about the second question, it doesn't make sense because '1' is not a type, as explained above.

OTHER TIPS

'x is the same as (quote x). Scheme won't evaluate the argument so it's basically how you do constant values. It's not a single quote around rather you have two elements in the list quoted in your example like this:

(cond ((member '1 '(some-function)) (display #t)) (else (display #f)))

You never need to quote a number since it's always evaluated to itself. '1 is the same as just 1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top