;; -------------------------------------------------------------------------
;;  File:    fizzle.lsp
;;  Created: Sat Apr 30 14:06:22 2016
;;  Comment: Library of Physics Constants and Functions.
;; -------------------------------------------------------------------------

(defpackage :fizzle

  ( :use :common-lisp :slip :moth )

  ( :export 
   ; constants
   :speed-of-light
   :gravity
   :feet-in-meter
   ; physics
   :time-dilation
   :free-fall
   :disp-free-fall
  ))

(in-package fizzle)

; constants

(defconstant speed-of-light 299792458) ; speed of light m/s
(defconstant gravity 9.8) ; m/s^2
(defconstant feet-in-meter 3.28084) ; ft in a meter

; testing with:
;
; 86% speed of light
; 3 hour trip
; ~6 hours elapse for people on earth

(defun time-dilation (pct_c t_hrs)
  "Computes the time in t_hrs that have elapsed on Earth if someone is 
   moving close to the speed of light (pct_c) for time in hours (t_hrs)."
  (let* ( (c_2 (expt speed-of-light 2))
         (v (* pct_c speed-of-light))
          (v_2 (expt v 2)))
    (/ t_hrs (sqrt (- 1 (/ v_2 c_2))))))

(defun free-fall (s)
  "Computes free fall in meters after seconds (s)."
  (* 0.5 gravity (expt s 2)))
  
(defun disp-free-fall (s)
  (format t "~% An object falls ~a meters after ~a seconds." (fizzle:free-fall s) s))