Add more examples

This commit is contained in:
Timothy Warren 2019-03-15 15:15:07 -04:00
parent 5d17aa3655
commit 9ded988259
2 changed files with 130 additions and 34 deletions

104
.gitignore vendored
View File

@ -1,51 +1,52 @@
# ---> VisualStudioCode # Created by https://www.gitignore.io/api/macos,scheme,jetbrains+all,visualstudiocode
.vscode/* # Edit at https://www.gitignore.io/?templates=macos,scheme,jetbrains+all,visualstudiocode
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# ---> Scheme ### JetBrains+all ###
*.ss~ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
*.ss#*
.#*.ss
*.scm~
*.scm#*
.#*.scm
# ---> JetBrains
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff: # User-specific stuff
.idea/**/workspace.xml .idea/**/workspace.xml
.idea/**/tasks.xml .idea/**/tasks.xml
.idea/dictionaries .idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Sensitive or high-churn files: # Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/ .idea/**/dataSources/
.idea/**/dataSources.ids .idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml .idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml .idea/**/sqlDataSources.xml
.idea/**/dynamic.xml .idea/**/dynamic.xml
.idea/**/uiDesigner.xml .idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle: # Gradle
.idea/**/gradle.xml .idea/**/gradle.xml
.idea/**/libraries .idea/**/libraries
# Mongo Explorer plugin: # Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml .idea/**/mongoSettings.xml
## File-based project format: # File-based project format
*.iws *.iws
## Plugin-specific files:
# IntelliJ # IntelliJ
/out/ out/
# mpeltonen/sbt-idea plugin # mpeltonen/sbt-idea plugin
.idea_modules/ .idea_modules/
@ -62,15 +63,37 @@ crashlytics.properties
crashlytics-build.properties crashlytics-build.properties
fabric.properties fabric.properties
# ---> macOS # Editor-based Rest Client
*.DS_Store .idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### JetBrains+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
# Sonarlint plugin
.idea/sonarlint
### macOS ###
# General
.DS_Store
.AppleDouble .AppleDouble
.LSOverride .LSOverride
# Icon must end with two \r # Icon must end with two \r
Icon Icon
# Thumbnails # Thumbnails
._* ._*
@ -90,3 +113,24 @@ Network Trash Folder
Temporary Items Temporary Items
.apdisk .apdisk
### Scheme ###
*.ss~
*.ss#*
.#*.ss
*.scm~
*.scm#*
.#*.scm
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
# End of https://www.gitignore.io/api/macos,scheme,jetbrains+all,visualstudiocode

58
lib.scm
View File

@ -1,6 +1,11 @@
(define (sqrt x) #lang sicp
(define (average x y) (/ (+ x y) 2)) (define (average x y) (/ (+ x y) 2))
(define (square x) (* x x)) (define (square x) (* x x))
(define (cube x) (* x x x))
(define (% a b)
(remainder a b))
(define (sqrt x)
(define (good-enough? guess) (define (good-enough? guess)
(< (abs (- (square guess) x)) 0.00001)) (< (abs (- (square guess) x)) 0.00001))
(define (improve guess) (define (improve guess)
@ -21,7 +26,6 @@
(fact-iter (* counter product) (fact-iter (* counter product)
(+ counter 1) (+ counter 1)
max-count))) max-count)))
(fact-iter 1 1 n)) (fact-iter 1 1 n))
@ -64,7 +68,6 @@
(+ (cc amount (- kinds-of-coins 1)) (+ (cc amount (- kinds-of-coins 1))
(cc (- amount (first-denomination kinds-of-coins)) (cc (- amount (first-denomination kinds-of-coins))
kinds-of-coins))))) kinds-of-coins)))))
(cc amount 5)) (cc amount 5))
@ -74,3 +77,52 @@
(ptri (- n 1)) (ptri (- n 1))
(+ (* (ptri (- n 2)) 2) (+ (* (ptri (- n 2)) 2)
(* (ptri (- n 3)) 3))))) (* (ptri (- n 3)) 3)))))
(define (p x) (- (* 3 x) (* 4 (cube x))))
(define (sine angle)
(if (not (> (abs angle) 0.1))
angle
(p (sine (/ angle 3.0)))))
;(define (expt b n)
; (if (= n 0) 1 (* b (expt b (- n 1)))))
(define (expt b n) (expt-iter b n 1))
(define (expt-iter b counter product)
(if (= counter 0)
product
(expt-iter b
(- counter 1)
(* b product))))
(define (fast-exp b n)
(cond ((= n 0)
1)
((even? n)
(square (fast-exp b (/ n 2))))
(else
(* b (fast-exp b (- n 1))))))
(define (gcd a b)
(if (= b 0)
a
(gcd b (% a b))))
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n)
n)
((divides? test-divisor n)
test-divisor)
(else (find-divisor
n
(+ test-divisor 1)))))
(define (divides? a b)
(= (% b a) 0))
(define (prime? n)
(= n (smallest-divisor n)))