All pastes #367393 Raw Edit

Untitled

public text v1 · immutable
#367393 ·published 2007-02-22 09:50 UTC
rendered paste body
;; (2 + 3) --> (+ 2 3)
;; (1 - 2 + 3 * 4 + 5) --> (- 1 (+ 2 (* 3 (+ 4 5))))

(define (rcalculate x)
  (let* ((p1 (car x))
	 (p2 (car (cdr x)))
	 (p3 (cdr (cdr x))))
    (cond
     ((= 1 (length p3)) (p2 p1 (car p3)))
     (else (p2 p1 (rcalculate p3))))))


; guile> (rcalculate '(2 + 3 + 4))
; Backtrace:
; In standard input:
;  247: 0* [rcalculate (2 + 3 + 4)]
;  240: 1  (let* ((p1 #) (p2 #) (p3 #)) (cond (# #) (#t #)))
;    ...
;  245: 2  [+ 2 ...
;  245: 3*  [rcalculate (3 + 4)]
;  240: 4   (let* ((p1 #) (p2 #) (p3 #)) (cond (# #) (#t #)))
;     ...
;  244: 5   [+ 3 4]

; standard input:244:25: In expression (p2 p1 (car p3)):
; standard input:244:25: Wrong type to apply: +
; ABORT: (misc-error)