Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add `and*` and `or*`; non-* versions need a `bind-args`, though.

  • Loading branch information...
commit b376cd01048de4fdc3c52f7923e7a65bc021fef8 1 parent 1a15d51
@cpressey cpressey authored
View
29 README.markdown
@@ -189,20 +189,6 @@ Plans
final-result and unknown-tag reply messages, particularly during `call`
and `respond`.
-* Establish (and enforce) conventions listed in the Style document.
-
-* Write a `timer` module which exports a process which can be asked
- (via a message) to send back a message after a given time has passed.
- This could be used to build a version of `recv` which can time out.
-
-* Enhance the `console` module. Write a version of `robotfindskitten`
- using it.
-
-* In the `arith` module, possibly add `int-pow`.
-
-* In the `boolean` module, follow the style guidelines for associative
- binary operators.
-
* A macro for asserting that the correct number of arguments have been
given to a macro. (Right now the `small` macros don't complain if
given too many arguments.)
@@ -255,14 +241,23 @@ though.
file to which the problem can be traced. The purpose of all this is
to allow producing more complete error messages at the top level.
+* Support values, rather than simply presence of a value, in metadata.
+ This makes metadata more like a map of keys to values on a value,
+ than liks a set of keys on a value.
+
+### Devices ###
+
* Create the `device` module and use it instead of `crude-io` and
`console`. Perhaps make those two into "interface modules"? I
suppose an interface module would expose a predicate to check if a
device supports a given interface.
-* Support values, rather than simply presence of a value, in metadata.
- This makes metadata more like a map of keys to values on a value,
- than liks a set of keys on a value.
+* Write a `timer` device which can be asked (via a message) to send
+ back a message after a given time has passed. This could be used to
+ build a version of `recv` which can time out.
+
+* Enhance the `console` device. Write a version of `robotfindskitten`
+ using it.
### Possible Future Modules ###
View
4 doc/Style.markdown
@@ -109,8 +109,8 @@ Examples from the standard modules:
* `add`, `+`, and `sum`
* `multiply`, `*`, and `product`
-* `and`, `&`, and `conj`
-* `or`, `|`, and `disj`
+* `and`, `and*`, and `conj`
+* `or`, `or*`, and `disj`
* `gt?`, `>`, and `strictly-decreasing?`
* `gte?`, `>=`, and `decreasing?`
* `lt?`, `<`, and `strictly-increasing?`
View
102 doc/module/Boolean.markdown
@@ -5,8 +5,8 @@ Module `boolean`
### `and` ###
-`and` evaluates all of its arguments to booleans, and evaluates to the
-logical conjunction (boolean "and") of all of these values.
+`and` evaluates both of its arguments to booleans, and evaluates to the
+logical conjunction (boolean "and") of these two values.
| (robin (0 1) ((boolean (0 1) *))
| (and #t #t))
@@ -24,36 +24,66 @@ logical conjunction (boolean "and") of all of these values.
| (and #f #f))
= #f
-`and` can take any number of arguments.
+`and` expects exactly two arguments.
| (robin (0 1) ((boolean (0 1) *))
- | (and))
+ | (and #f))
+ ? uncaught exception: (illegal-arguments (#f))
+
+ | (robin (0 1) ((boolean (0 1) *))
+ | (and #t #f #f))
+ ? uncaught exception: (illegal-arguments (#t #f #f))
+
+`and` expects both of its arguments to be booleans.
+
+ | (robin (0 1) ((boolean (0 1)))
+ | (boolean:and 100 #t))
+ ? uncaught exception: (expected-boolean 100)
+
+ | (robin (0 1) ((boolean (0 1)))
+ | (boolean:and #t 99))
+ ? uncaught exception: (expected-boolean 99)
+
+`and` is short-circuiting in the sense that no arguments after the first
+`#f` argument will be evaluated. Fully testing this requires side-effects,
+but it can be demonstrated as follows.
+
+ | (robin (0 1) ((boolean (0 1)))
+ | (boolean:and #f 100))
+ = #f
+
+### `and*` ###
+
+`and*` is like `and`, but can take any number of arguments.
+
+ | (robin (0 1) ((boolean (0 1) *))
+ | (and*))
= #t
| (robin (0 1) ((boolean (0 1) *))
- | (and #f))
+ | (and* #f))
= #f
| (robin (0 1) ((boolean (0 1) *))
- | (and #t #t #t #t #t))
+ | (and* #t #t #t #t #t))
= #t
| (robin (0 1) ((boolean (0 1) *))
- | (and #t #t #t #f))
+ | (and* #t #t #t #f))
= #f
`and` expects its arguments to be booleans.
| (robin (0 1) ((boolean (0 1)))
- | (boolean:and 100))
+ | (boolean:and* 100))
? uncaught exception: (expected-boolean 100)
-`and` is short-circuiting in the sense that no arguments after the first
+`and*` is short-circuiting in the sense that no arguments after the first
`#f` argument will be evaluated. Fully testing this requires side-effects,
but it can be demonstrated as follows.
| (robin (0 1) ((boolean (0 1)))
- | (boolean:and #f 100))
+ | (boolean:and* #t #t #f 100))
= #f
### `conj` ###
@@ -104,8 +134,8 @@ to the logical conjunction of those booleans.
### `or` ###
-`or` evaluates all of its arguments to booleans, and evaluates to the
-logical disjunction (boolean "or") of all of these values.
+`or` evaluates both of its arguments to booleans, and evaluates to the
+logical disjunction (boolean "or") of these two values.
| (robin (0 1) ((boolean (0 1) *))
| (or #t #t))
@@ -123,36 +153,66 @@ logical disjunction (boolean "or") of all of these values.
| (or #f #f))
= #f
-`or` can take any number of arguments.
+`or` expects exactly two arguments.
+
+ | (robin (0 1) ((boolean (0 1) *))
+ | (or #f))
+ ? uncaught exception: (illegal-arguments (#f))
+
+ | (robin (0 1) ((boolean (0 1) *))
+ | (or #t #f #f))
+ ? uncaught exception: (illegal-arguments (#t #f #f))
+
+`or` expects both of its arguments to be booleans.
+
+ | (robin (0 1) ((boolean (0 1)))
+ | (boolean:or 100 #f))
+ ? uncaught exception: (expected-boolean 100)
+
+ | (robin (0 1) ((boolean (0 1)))
+ | (boolean:or #f 99))
+ ? uncaught exception: (expected-boolean 99)
+
+`or` is short-circuiting in the sense that no arguments after the first
+`#t` argument will be evaluated. Fully testing this requires side-effects,
+but it can be demonstrated as follows.
+
+ | (robin (0 1) ((boolean (0 1)))
+ | (boolean:or #t 100))
+ = #t
+
+### `or*` ###
+
+`or*` is like `or`, but can take any number of arguments.
| (robin (0 1) ((boolean (0 1) *))
- | (or))
+ | (or*))
= #f
| (robin (0 1) ((boolean (0 1) *))
- | (or #t))
+ | (or* #t))
= #t
| (robin (0 1) ((boolean (0 1) *))
- | (or #f #f #f #f #f))
+ | (or* #f #f #f #f #f))
= #f
| (robin (0 1) ((boolean (0 1) *))
- | (or #f #f #f #t))
+ | (or* #f #f #f #t))
= #t
-`or` expects its arguments to be booleans.
+`or*` expects its arguments to be booleans.
| (robin (0 1) ((boolean (0 1)))
- | (boolean:or 100))
+ | (boolean:or* 100))
? uncaught exception: (expected-boolean 100)
-`or` is short-circuiting in the sense that no arguments after the first
+`or*` is short-circuiting in the sense that no arguments after the first
`#t` argument will be evaluated. Fully testing this requires side-effects,
but it can be demonstrated as follows.
| (robin (0 1) ((boolean (0 1)))
- | (boolean:or #t 100))
+ | (boolean:or* #f #f #f #t 100))
= #t
### `disj` ###
View
8 doc/module/Miscellany.markdown
@@ -20,26 +20,26 @@ loop.
| (equal? literal-a literal-b))
? circular reference in module circular-a
-`and` is short-circuiting.
+`and*` is short-circuiting.
| (robin (0 1) ((small (0 1) *) (boolean (0 1) *) (concurrency (0 1) *) (crude-io (0 1) *))
| (let ((true
| (fun () (call! crude-output write (literal t) reply #t)))
| (false
| (fun () (call! crude-output write (literal f) reply #f))))
- | (and (true) (false) (false) (true))))
+ | (and* (true) (false) (false) (true))))
= t
= f
= #f
-`or` is short-circuiting.
+`or*` is short-circuiting.
| (robin (0 1) ((small (0 1) *) (boolean (0 1) *) (concurrency (0 1) *) (crude-io (0 1) *))
| (let ((true
| (fun () (call! crude-output write (literal t) reply #t)))
| (false
| (fun () (call! crude-output write (literal f) reply #f))))
- | (or (false) (true) (true) (false))))
+ | (or* (false) (true) (true) (false))))
= f
= t
= #t
View
26 module/boolean_0_1.robin
@@ -1,32 +1,40 @@
(robin (0 1) ((small (0 1) *) (env (0 1) *))
(let (
(and (macro (self args env)
+ (if (eval env (head args))
+ (if (eval env (head (tail args))) #t #f)
+ #f)))
+ (and* (macro (self args env)
(if (equal? args ())
#t
- (if (eval env (head args))
- (eval env (prepend self (tail args)))
- #f))))
+ (and (eval env (head args))
+ (eval env (prepend self (tail args)))))))
(conj-r (fun (self li)
(if (equal? li ())
#t
(and (head li)
(self self (tail li))))))
- (conj (fun (li) (conj-r conj-r li)))
+ (conj (fun (li)
+ (conj-r conj-r li)))
(or (macro (self args env)
+ (if (eval env (head args))
+ #t
+ (if (eval env (head (tail args))) #t #f))))
+ (or* (macro (self args env)
(if (equal? args ())
#f
- (if (eval env (head args))
- #t
- (eval env (prepend self (tail args)))))))
+ (or (eval env (head args))
+ (eval env (prepend self (tail args)))))))
(disj-r (fun (self li)
(if (equal? li ())
#f
(or (head li)
(self self (tail li))))))
- (disj (fun (li) (disj-r disj-r li)))
+ (disj (fun (li)
+ (disj-r disj-r li)))
(not (fun (a)
(if a #f #t)))
(xor (fun (a b)
(or (and a (not b)) (and (not a) b))))
)
- (export and conj or disj not xor)))
+ (export and and* conj or or* disj not xor)))
Please sign in to comment.
Something went wrong with that request. Please try again.