by Darius Bacon
A programming argot

Cant, a message-oriented language

This is a hobby project: a programming language descended mainly from E and Scheme. Nowadays there are at least two more direct and more interesting and useful E descendants: Secure EcmaScript and Monte.

;; SICP exercise 2.29
;; (I renamed 'total-weight' to just 'weight'.)

;; OO version

(to (mobile<- left right)
  (make _
    (to ~.weight    (+ left.weight right.weight))
    (to ~.balanced? (and left.balanced?
                         (= left.torque right.torque)))))

(to (branch<- length submobile)
  (let structure (if (number? submobile) (weight<- submobile) submobile))
  (make _
    (to ~.torque    (* length structure.weight))
    (to msg         (call structure msg))))

(to (weight<- value)
  (make _
    (to ~.weight    value)
    (to ~.balanced? #yes)))

(let test-mobile
  (mobile<- (branch<- 1 10)
            (branch<- 2 (mobile<- (branch<- 3 20)
                                  (branch<- 4 30)))))

(let test-balanced-mobile
  (mobile<- (branch<- 7 10)
            (branch<- 1 (mobile<- (branch<- 3 40)
                                  (branch<- 4 30)))))

(out .print test-mobile.balanced?)
(out .print test-balanced-mobile.balanced?)
Information updated 01/03/20
Note: This entry has not yet been moderated.
View Comments