Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is apostrophe type in scheme

Tags:

lisp

scheme

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'?

like image 855
user3453625 Avatar asked Jan 10 '23 22:01

user3453625


1 Answers

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.

like image 187
Óscar López Avatar answered Jan 18 '23 05:01

Óscar López