% A Guide to Rust Syntax
A very brief guide to Rust syntax. It assumes you are already familiar with programming concepts.
The assert!
macro ends the program if the condition passed to it is not true:
fn main() {
(defun ! (n) | |
(if (= n 0) 1 | |
(* n (! (- n 1))))) |
;; The following definition for amb, assert and other operators are from Teach Yourself Scheme in Fixnum Days by Dorai Sitaram. | |
(define amb-fail '()) | |
(define initialize-amb-fail | |
(lambda () | |
(set! amb-fail | |
(lambda () | |
(error "amb tree exhausted"))))) |
(define bool-to-binary (lambda (n) (map (lambda (x) (if (equal? x #t) 1 0)) n))) | |
(define binary-to-bool (lambda (n) (map (lambda (x) (if (= x 1) #t #f)) n))) | |
(define binary | |
(lambda (number bits) | |
(if (= bits 0) '() | |
(begin | |
(let* | |
((b (if (>= number (expt 2 (- bits 1))) 1 0)) | |
(v (if (= b 1) (- number (expt 2 (- bits 1))) number))) |