Calculate or Ask.

; I compared some monitors, and tried to calculate some data
; about size of pixels, area etc, using windows calculator, and
; it turned to be surprisingly slow and boring.
;
; Then I tried to write program in Newlisp, but then it turned
; that program itself had lot of redundancies, lot of sets,
; readlines etc.  
;
; I decided to write macro that might help me if I'll ever
; need to write such a trivial programs. Almost certainly I'll do.
;
; The macro is called with list of arguments.
; If argument is list of one element, its value is readed.
; If argument is list of two elements, the value of the second is.
; assigned to the first.

; Nothing really important, but it can be handy.

(set 'calculate-or-ask
     (lambda-macro()
        (dolist (i $args)
           (print (first i)
               (dup " " (- 20 (length (string (first i)))))
               " = ")
           (set (first i) (if (> (length i) 1)
                              (println (eval (nth 1 i)))
                              (float (read-line)))))))

(calculate-or-ask
     (Diagonal)
     (Width)
     (Height)
     (Price)
     (Pixels               (* Height Width))
     (Area                 (/ (* Diagonal Diagonal Width Height)
                              (+ (* Width Width)
                                 (* Height Height))))
     (Pixels/Unit-of-area  (/ Pixels Area))
     (Pixels/Unit-of-price (/ Pixels Price)))

(exit)



Program output.

No comments:

Post a Comment