I'm trying to make a truth-table generator for a digital electronics course because that's how I have fun in my spare time and don't judge me.
Anywho, I figured I'd have a hash with the string equivalent of operators as keys, and the Scheme procedures that correspond to those operators as values.
E.g.
(define operator-table #hash(("+" . or) ("*" . and)))
So I could do something like
(lambda (a b) ((hash-ref operator-table (string-ref input-str i)) a b))
Now I realize the above probably won't work right, but as it is I can't even tinker with it until I get it right, because apparently and
and or
are special in Scheme. At the REPL, if I type in not
it replies #<procedure:not>
. But if I give it and
or or
, it says and: bad syntax in: and
. Is there a procedure version of and
I can use? Or do I have to make one with lambda
? Or am I missing something entirely?
The only reason I didn't just go with lambda from the get-go is that I don't want to lose the variable-arity abilities of the builtin and
[I can do (and #t #f)
as well as (and #t #f #f #t #f #t)
].