Hi, I need to write a function in Scheme that takes a literal as an argument and returns a complementary literal. For example, if the function were name litcom, then:
(litcom 'a) = (not a)
(litcom '(not a)) = a
This confuses me right off the back, as it seems to me like I would have to define the literal a to be a boolean value of true first.
The function I've written so far is this:
(define litcom(lambda (lit)
(cond ((equal? lit #t) (not lit))
((equal? lit #f) (not lit))
)))
If I define a literal as either true or false, then this function will return the complementary value. For example:
(define a #t)
(litcom a) returns #f
But this isn't what I'm trying to do. What I need to be returned is what like the example at the beginning. I don't understand how:
For any literal _, to return (not _)
And for any literal (not _) return _
Any help will be greatly appreciated, thanks.
3 replies to this topic
#1
Posted 26 March 2011 - 02:51 PM
|
|
|
#2
Posted 27 March 2011 - 04:36 AM
First you have to remember that not, in most programming language, is boolean operator. No wonder that from the basic point of view it must work with boolean value. However not usually able to work with bits (usually represented by integers). So I believe (depends on the actual language and dialect you are using) that you still can get "not not a = a" if you cast a into bits/integers.
For example:
If a = 01010101(b), then not a = 10101010(b). then not not a = not 10101010(b) = 01010101(b). There you get that "not not a=a" with a does not have to be boolean values only.
For example:
If a = 01010101(b), then not a = 10101010(b). then not not a = not 10101010(b) = 01010101(b). There you get that "not not a=a" with a does not have to be boolean values only.
#3
Posted 28 March 2011 - 06:38 PM
Hi, thanks for the response. I understand now that all the variables I'm using have a boolean value of #t.
What I essentially need to do is traverse a list of boolean values in scheme and make sure that a boolean and its complement don't occur in the list. So if a occurs in a list, then I want to create a function that returns #t if (not a) doesn't occur in the list and #f if it does.
I'm having difficulty doing this because I have to compare the variable name (memory location?) as opposed to the variable value.
For example, if the function litcom returns (not a), and (not a) is a part of my list, I need to be able to compare the two by checking if they are the same variable. This isn't the same as comparing their values. (not a) and (not b) both have the same value of #f, but they aren't both the complementary literal of a.
What I essentially need to do is traverse a list of boolean values in scheme and make sure that a boolean and its complement don't occur in the list. So if a occurs in a list, then I want to create a function that returns #t if (not a) doesn't occur in the list and #f if it does.
I'm having difficulty doing this because I have to compare the variable name (memory location?) as opposed to the variable value.
For example, if the function litcom returns (not a), and (not a) is a part of my list, I need to be able to compare the two by checking if they are the same variable. This isn't the same as comparing their values. (not a) and (not b) both have the same value of #f, but they aren't both the complementary literal of a.
#4
Posted 01 April 2011 - 04:35 AM
Sorry for late reply, but you confused me here. Perhaps some code sample would clear your intention?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









