Sunday, December 13, 2015

MIT Scheme Console

$ ./mit-scheme console
MIT/GNU Scheme running under OS X
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116
;Warning: Invalid keyword: "console"
;Warning: Unhandled command line options: ("console")

1 ]=> 486

;Value: 486

1 ]=> (+ 137 349)

;Value: 486

1 ]=> (- 1000 334)

;Value: 666

1 ]=> (* 5 99)

;Value: 495

1 ]=> (/ 10 5)

;Value: 2

1 ]=> (+ 2.7 10)

;Value: 12.7

Combination = (operator operand1 operand2). The value of the combination is computed by applying the operator to the operands.

The prefix notation has the advantage of taking an arbitrary number of arguments. Making it easy to compute your tax deductions:

1 ]=> (+ 21 35 12 7)

;Value: 75

Calculate Mileage rate deduction:

1 ]=> (+ (* 57.5 200) (* 23 700))

;Value: 27600.

57.5 cents for each business mile driven and 23 cents for moving deduction. I drove 200 miles for business miles and 700 miles for moving. So I get a total deduction of $276 (since the answer is in cents).

This shows another advantage of prefix notation where we can have combinations of elements which are combinations.

Defining Variable

1 ]=> define size 2

;Syntactic keyword may not be used as an expression: #[keyword-value-item 13]
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error> 
;Unbound variable: size
;To continue, call RESTART with an option number:
; (RESTART 4) => Specify a value to use instead of size.
; (RESTART 3) => Define size to a given value.
; (RESTART 2) => Return to read-eval-print level 2.
; (RESTART 1) => Return to read-eval-print level 1.

3 error> 
;Value: 2

3 error> (define size 2)

;Value: size

3 error> size

;Value: 2

3 error> (* 5 size)

;Value: 10

3 error> (define pi 3.14159)

;Value: pi

3 error> (define radius 10)

;Value: radius

3 error> (* pi (* radius radius))

;Value: 314.159

3 error> (define circumference (* 2 pi radius))

;Value: circumference

3 error> circumference

;Value: 62.8318