mirror of
https://gitee.com/XmacsLabs/planet.git
synced 2025-09-06 14:43:52 +00:00
SICP 05/07: use S7 Scheme session
This commit is contained in:
parent
a8150764c3
commit
5fb52afc54
2 changed files with 162 additions and 58 deletions
|
@ -1,12 +1,14 @@
|
|||
<TeXmacs|2.1.2>
|
||||
|
||||
<style|<tuple|generic|no-page-numbers|british|reduced-margins>>
|
||||
<style|<tuple|generic|no-page-numbers|british|reduced-margins|s7>>
|
||||
|
||||
<\body>
|
||||
<section*|Orders of Growth>
|
||||
|
||||
<\session|scheme|default>
|
||||
<\unfolded-io|Scheme] >
|
||||
<\session|s7|default>
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(define (expt-1 b n)
|
||||
|
||||
\ \ (if (= n 0)
|
||||
|
@ -18,19 +20,25 @@
|
|||
expt-1
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(expt-1 1 0)
|
||||
<|unfolded-io>
|
||||
1
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(expt-1 2 3)
|
||||
<|unfolded-io>
|
||||
8
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(define (expt-2 b n)
|
||||
|
||||
\ \ (define (expt-iter b counter product)
|
||||
|
@ -52,21 +60,27 @@
|
|||
expt-2
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(expt-2 3 3)
|
||||
<|unfolded-io>
|
||||
27
|
||||
</unfolded-io>
|
||||
|
||||
<\input|Scheme] >
|
||||
<\input>
|
||||
\<gtr\>\
|
||||
<|input>
|
||||
\;
|
||||
</input>
|
||||
</session>
|
||||
|
||||
<section*|Exponentiation>
|
||||
|
||||
<\session|scheme|default>
|
||||
<\unfolded-io|Scheme] >
|
||||
<\session|s7|default>
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(define (fast-expt b n)
|
||||
|
||||
\ \ (define (even? n)
|
||||
|
@ -86,17 +100,27 @@
|
|||
fast-expt
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(fast-expt 3 3)
|
||||
<|unfolded-io>
|
||||
27
|
||||
</unfolded-io>
|
||||
|
||||
<\input>
|
||||
\<gtr\>\
|
||||
<|input>
|
||||
\;
|
||||
</input>
|
||||
</session>
|
||||
|
||||
<section*|Greatest Common Divisors>
|
||||
|
||||
<\session|scheme|default>
|
||||
<\unfolded-io|Scheme] >
|
||||
<\session|s7|default>
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(define (gcd a b)
|
||||
|
||||
\ \ (if (= b 0)
|
||||
|
@ -108,11 +132,19 @@
|
|||
gcd
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
<\unfolded-io>
|
||||
\<gtr\>\
|
||||
<|unfolded-io>
|
||||
(gcd 10 20)
|
||||
<|unfolded-io>
|
||||
10
|
||||
</unfolded-io>
|
||||
|
||||
<\input>
|
||||
\<gtr\>\
|
||||
<|input>
|
||||
\;
|
||||
</input>
|
||||
</session>
|
||||
</body>
|
||||
|
||||
|
@ -128,4 +160,22 @@
|
|||
<associate|auto-2|<tuple|?|?>>
|
||||
<associate|auto-3|<tuple|?|?>>
|
||||
</collection>
|
||||
</references>
|
||||
</references>
|
||||
|
||||
<\auxiliary>
|
||||
<\collection>
|
||||
<\associate|toc>
|
||||
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|Orders
|
||||
of Growth> <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
|
||||
<no-break><pageref|auto-1><vspace|0.5fn>
|
||||
|
||||
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|Exponentiation>
|
||||
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
|
||||
<no-break><pageref|auto-2><vspace|0.5fn>
|
||||
|
||||
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|Greatest
|
||||
Common Divisors> <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
|
||||
<no-break><pageref|auto-3><vspace|0.5fn>
|
||||
</associate>
|
||||
</collection>
|
||||
</auxiliary>
|
Loading…
Add table
Add a link
Reference in a new issue