tretje srecanje

main
Lio Novelli 2024-05-16 22:33:30 +02:00
parent 8b6aca4982
commit 4da40fc948
2 changed files with 289 additions and 67 deletions

View File

@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head> <head>
<!-- 2024-04-30 Tue 19:31 --> <!-- 2024-05-16 Thu 22:32 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Structure and Interpretation of Computer Programs</title> <title>Structure and Interpretation of Computer Programs</title>
@ -201,36 +201,46 @@
<h2>Table of Contents</h2> <h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc"> <div id="text-table-of-contents" role="doc-toc">
<ul> <ul>
<li><a href="#orgfa6dfd2">1. Foreword and Preface</a></li> <li><a href="#org65e2102">1. Foreword and Preface</a></li>
<li><a href="#org7c75cdc">2. 1. Grajenje abstrakcij s procedurami</a> <li><a href="#orgd844a85">2. 1. Grajenje abstrakcij s procedurami</a>
<ul> <ul>
<li><a href="#org5fd76f1">2.1. Elementi programiranja</a></li> <li><a href="#org9cc9e23">2.1. Elementi programiranja</a></li>
<li><a href="#orgdd9a89f">2.2. Izvajanje kombinacij(e)</a></li> <li><a href="#orgc38e99e">2.2. Izvajanje kombinacij(e)</a></li>
<li><a href="#orgc00fe8a">2.3. 1.1.4 Sestavljene procedure</a></li> <li><a href="#org4561884">2.3. 1.1.4 Sestavljene procedure</a></li>
<li><a href="#org880c70f">2.4. 1.1.5 Substitucijski model za izvajanje procedur</a></li> <li><a href="#org5a7e4a4">2.4. 1.1.5 Substitucijski model za izvajanje procedur</a></li>
<li><a href="#orgc3d2732">2.5. meta</a> <li><a href="#org4f92eb8">2.5. meta</a>
<ul> <ul>
<li><a href="#org4f46a86">2.5.1. video lekcije</a></li> <li><a href="#org0b39e3d">2.5.1. video lekcije</a></li>
</ul> </ul>
</li> </li>
<li><a href="#org9170e9c">2.6. vaje</a> <li><a href="#org56f8627">2.6. vaje</a>
<ul> <ul>
<li><a href="#org33d53b7">2.6.1. 1.3</a></li> <li><a href="#org26ed807">2.6.1. 1.3</a></li>
<li><a href="#orgaece15c">2.6.2. 1.5</a></li> <li><a href="#org5917931">2.6.2. 1.5</a></li>
<li><a href="#orgfcdfec0">2.6.3. 1.6</a></li> <li><a href="#org46d6002">2.6.3. 1.6</a></li>
<li><a href="#org6d81d53">2.6.4. 1.7</a></li> <li><a href="#org752ea5e">2.6.4. 1.7</a></li>
<li><a href="#orgec5d243">2.6.5. 1.8</a></li> <li><a href="#org5fba44a">2.6.5. 1.8</a></li>
</ul> </ul>
</li> </li>
<li><a href="#org8d4a90a">2.7. 1.1.8 Procedure kot crne skatle abstrakcij</a></li> <li><a href="#orgdf856c9">2.7. 1.1.8 Procedure kot crne skatle abstrakcij</a></li>
<li><a href="#orgc1bedf1">2.8. 1.2.2 Drevesna rekurzija</a></li>
<li><a href="#orga7e8396">2.9. 1.2.3 Redi rasti</a></li>
<li><a href="#orgf79e38f">2.10. 1.2.4 Eksponentna funkcija</a></li>
<li><a href="#org8125de0">2.11. 1.2.5 Najvecji skupni deljitel</a></li>
<li><a href="#orge8e49b3">2.12. 1.2.6 Primer: Iskanje prastevil</a></li>
<li><a href="#org6c46b7b">2.13. 1.3 Sestavljanje abstrakcij s procedurami visjega reda</a></li>
<li><a href="#orga8cba41">2.14. 1.3.1 Procedure kot argumenti</a></li>
<li><a href="#orgb6993b9">2.15. 1.3.2 Sestavljanje procedur z Lambda</a></li>
<li><a href="#org5ea790c">2.16. 1.3.3 Procedure kot splosne metode</a></li>
<li><a href="#org0a1c5a7">2.17. 1.3.4 Procedure kot vrnjene vrednosti</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
<div id="outline-container-orgfa6dfd2" class="outline-2"> <div id="outline-container-org65e2102" class="outline-2">
<h2 id="orgfa6dfd2"><span class="section-number-2">1.</span> Foreword and Preface</h2> <h2 id="org65e2102"><span class="section-number-2">1.</span> Foreword and Preface</h2>
<div class="outline-text-2" id="text-1"> <div class="outline-text-2" id="text-1">
<blockquote> <blockquote>
<p> <p>
@ -272,12 +282,12 @@ ukvarjanje s pojmovanjem "kako".
</div> </div>
</div> </div>
<div id="outline-container-org7c75cdc" class="outline-2"> <div id="outline-container-orgd844a85" class="outline-2">
<h2 id="org7c75cdc"><span class="section-number-2">2.</span> 1. Grajenje abstrakcij s procedurami</h2> <h2 id="orgd844a85"><span class="section-number-2">2.</span> 1. Grajenje abstrakcij s procedurami</h2>
<div class="outline-text-2" id="text-2"> <div class="outline-text-2" id="text-2">
</div> </div>
<div id="outline-container-org5fd76f1" class="outline-3"> <div id="outline-container-org9cc9e23" class="outline-3">
<h3 id="org5fd76f1"><span class="section-number-3">2.1.</span> Elementi programiranja</h3> <h3 id="org9cc9e23"><span class="section-number-3">2.1.</span> Elementi programiranja</h3>
<div class="outline-text-3" id="text-2-1"> <div class="outline-text-3" id="text-2-1">
<dl class="org-dl"> <dl class="org-dl">
<dt>Primitivni izrazi</dt><dd>predstavtljajo najpreprostejše gradnike (entitete) <dt>Primitivni izrazi</dt><dd>predstavtljajo najpreprostejše gradnike (entitete)
@ -290,8 +300,8 @@ omogočajo upravljanje z njimii kot enotami</dd>
</div> </div>
</div> </div>
<div id="outline-container-orgdd9a89f" class="outline-3"> <div id="outline-container-orgc38e99e" class="outline-3">
<h3 id="orgdd9a89f"><span class="section-number-3">2.2.</span> Izvajanje kombinacij(e)</h3> <h3 id="orgc38e99e"><span class="section-number-3">2.2.</span> Izvajanje kombinacij(e)</h3>
<div class="outline-text-3" id="text-2-2"> <div class="outline-text-3" id="text-2-2">
<p> <p>
Postopek za izvajanje kombinacij: Postopek za izvajanje kombinacij:
@ -333,8 +343,8 @@ oblika.
</div> </div>
<div id="outline-container-orgc00fe8a" class="outline-3"> <div id="outline-container-org4561884" class="outline-3">
<h3 id="orgc00fe8a"><span class="section-number-3">2.3.</span> 1.1.4 Sestavljene procedure</h3> <h3 id="org4561884"><span class="section-number-3">2.3.</span> 1.1.4 Sestavljene procedure</h3>
<div class="outline-text-3" id="text-2-3"> <div class="outline-text-3" id="text-2-3">
<ul class="org-ul"> <ul class="org-ul">
<li>Številke in aritmetične operacije so primitivni podatki in procedure.</li> <li>Številke in aritmetične operacije so primitivni podatki in procedure.</li>
@ -353,8 +363,8 @@ abstrakcije.</li>
</div> </div>
</div> </div>
<div id="outline-container-org880c70f" class="outline-3"> <div id="outline-container-org5a7e4a4" class="outline-3">
<h3 id="org880c70f"><span class="section-number-3">2.4.</span> 1.1.5 Substitucijski model za izvajanje procedur</h3> <h3 id="org5a7e4a4"><span class="section-number-3">2.4.</span> 1.1.5 Substitucijski model za izvajanje procedur</h3>
<div class="outline-text-3" id="text-2-4"> <div class="outline-text-3" id="text-2-4">
<p> <p>
Za izvajanje sestavljenih procedur z argumenti, izvedeš telo procedure z vsakim Za izvajanje sestavljenih procedur z argumenti, izvedeš telo procedure z vsakim
@ -383,8 +393,8 @@ izraza, ki vsebuje zgolj primitivne izraze in potem izvedi (vso) evalvacijo.</dd
</div> </div>
<div id="outline-container-orgc3d2732" class="outline-3"> <div id="outline-container-org4f92eb8" class="outline-3">
<h3 id="orgc3d2732"><span class="section-number-3">2.5.</span> meta</h3> <h3 id="org4f92eb8"><span class="section-number-3">2.5.</span> meta</h3>
<div class="outline-text-3" id="text-2-5"> <div class="outline-text-3" id="text-2-5">
<p> <p>
Linki: Linki:
@ -400,8 +410,8 @@ Kako nastavit spacemacs, in malo o guile-u.
</div> </div>
<div id="outline-container-org4f46a86" class="outline-4"> <div id="outline-container-org0b39e3d" class="outline-4">
<h4 id="org4f46a86"><span class="section-number-4">2.5.1.</span> video lekcije</h4> <h4 id="org0b39e3d"><span class="section-number-4">2.5.1.</span> video lekcije</h4>
<div class="outline-text-4" id="text-2-5-1"> <div class="outline-text-4" id="text-2-5-1">
<p> <p>
<a href="https://yewtu.be/channel/UCEBb1b_L6zDS3xTUrIALZOw">https://yewtu.be/channel/UCEBb1b_L6zDS3xTUrIALZOw</a> (6.001 SICP: Structure and Interpretation of Computer Programs (2004)) <a href="https://yewtu.be/channel/UCEBb1b_L6zDS3xTUrIALZOw">https://yewtu.be/channel/UCEBb1b_L6zDS3xTUrIALZOw</a> (6.001 SICP: Structure and Interpretation of Computer Programs (2004))
@ -411,16 +421,16 @@ Kako nastavit spacemacs, in malo o guile-u.
</div> </div>
</div> </div>
<div id="outline-container-org9170e9c" class="outline-3"> <div id="outline-container-org56f8627" class="outline-3">
<h3 id="org9170e9c"><span class="section-number-3">2.6.</span> vaje</h3> <h3 id="org56f8627"><span class="section-number-3">2.6.</span> vaje</h3>
<div class="outline-text-3" id="text-2-6"> <div class="outline-text-3" id="text-2-6">
</div> </div>
<div id="outline-container-org33d53b7" class="outline-4"> <div id="outline-container-org26ed807" class="outline-4">
<h4 id="org33d53b7"><span class="section-number-4">2.6.1.</span> 1.3</h4> <h4 id="org26ed807"><span class="section-number-4">2.6.1.</span> 1.3</h4>
<div class="outline-text-4" id="text-2-6-1"> <div class="outline-text-4" id="text-2-6-1">
</div> </div>
<ol class="org-ol"> <ol class="org-ol">
<li><a id="orge132dac"></a>najprej narobe<br /> <li><a id="orgffab77a"></a>najprej narobe<br />
<div class="outline-text-5" id="text-2-6-1-1"> <div class="outline-text-5" id="text-2-6-1-1">
<p> <p>
Define a procedure that takes three numbers as arguments and returns the sum of Define a procedure that takes three numbers as arguments and returns the sum of
@ -428,45 +438,45 @@ the squares of the two larger numbers.
</p> </p>
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-scheme"><span style="color: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">sum-of-large</span> x y z<span style="color: #bc6ec5;">)</span> <pre class="src src-scheme"><span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">sum-of-large</span> x y z<span style="color: #6c3163;">)</span>
<span style="color: #bc6ec5;">(</span>+ <span style="color: #6c3163;">(</span>+
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; x y<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* x x<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* y y<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; x y<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* x x<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* y y<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; y z<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* y y<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* z z<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; y z<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* y y<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* z z<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
<span style="color: #bc6ec5;">)</span> <span style="color: #6c3163;">)</span>
<span style="color: #4f97d7;">)</span> <span style="color: #3a81c3;">)</span>
<span style="color: #4f97d7;">(</span>sum-of-large <span style="color: #a45bad;">3</span> <span style="color: #a45bad;">8</span> <span style="color: #a45bad;">5</span><span style="color: #4f97d7;">)</span> <span style="color: #3a81c3;">(</span>sum-of-large <span style="color: #4e3163;">3</span> <span style="color: #4e3163;">8</span> <span style="color: #4e3163;">5</span><span style="color: #3a81c3;">)</span>
</pre> </pre>
</div> </div>
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-scheme"><span style="color: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">sum-of-larger</span> x y z<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">let*</span> <pre class="src src-scheme"><span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">sum-of-larger</span> x y z<span style="color: #6c3163;">)</span> <span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">let*</span>
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>s <span style="color: #b1951d;">(</span><span style="color: #4f97d7; font-weight: bold;">lambda</span> <span style="color: #4f97d7;">(</span>a<span style="color: #4f97d7;">)</span> <span style="color: #4f97d7;">(</span>* a a<span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> <span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>s <span style="color: #b1951d;">(</span><span style="color: #3a81c3; font-weight: bold;">lambda</span> <span style="color: #3a81c3;">(</span>a<span style="color: #3a81c3;">)</span> <span style="color: #3a81c3;">(</span>* a a<span style="color: #3a81c3;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>sl <span style="color: #b1951d;">(</span><span style="color: #4f97d7; font-weight: bold;">lambda</span> <span style="color: #4f97d7;">(</span>b c<span style="color: #4f97d7;">)</span> <span style="color: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #bc6ec5;">(</span>&gt; b c<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>s b<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>s c<span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>sl <span style="color: #b1951d;">(</span><span style="color: #3a81c3; font-weight: bold;">lambda</span> <span style="color: #3a81c3;">(</span>b c<span style="color: #3a81c3;">)</span> <span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #6c3163;">(</span>&gt; b c<span style="color: #6c3163;">)</span> <span style="color: #6c3163;">(</span>s b<span style="color: #6c3163;">)</span> <span style="color: #6c3163;">(</span>s c<span style="color: #6c3163;">)</span><span style="color: #3a81c3;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">)</span>
<span style="color: #2d9574;">(</span>+ <span style="color: #67b11d;">(</span>sl x y<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>sl y z<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>+ <span style="color: #67b11d;">(</span>sl x y<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>sl y z<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
<span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span> <span style="color: #6c3163;">)</span><span style="color: #3a81c3;">)</span>
<span style="color: #4f97d7;">(</span>sum-of-larger <span style="color: #a45bad;">3</span> <span style="color: #a45bad;">8</span> <span style="color: #a45bad;">5</span><span style="color: #4f97d7;">)</span> <span style="color: #3a81c3;">(</span>sum-of-larger <span style="color: #4e3163;">3</span> <span style="color: #4e3163;">8</span> <span style="color: #4e3163;">5</span><span style="color: #3a81c3;">)</span>
</pre> </pre>
</div> </div>
</div> </div>
</li> </li>
<li><a id="org8da2665"></a>pravilno<br /> <li><a id="orgb84d327"></a>pravilno<br />
<div class="outline-text-5" id="text-2-6-1-2"> <div class="outline-text-5" id="text-2-6-1-2">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-scheme"><span style="color: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">sum-squares-of-larger</span> x y z<span style="color: #bc6ec5;">)</span> <pre class="src src-scheme"><span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">sum-squares-of-larger</span> x y z<span style="color: #6c3163;">)</span>
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>&gt; x y<span style="color: #2d9574;">)</span> <span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>&gt; x y<span style="color: #2d9574;">)</span>
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; y z<span style="color: #67b11d;">)</span> <span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; y z<span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* x x<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* y y<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* x x<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* y y<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* x x<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* z z<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* x x<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* z z<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">)</span>
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; x z<span style="color: #67b11d;">)</span> <span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; x z<span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* y y<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* x x<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* y y<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* x x<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* y y<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* z z<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ <span style="color: #b1951d;">(</span>* y y<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* z z<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">)</span>
<span style="color: #bc6ec5;">)</span> <span style="color: #6c3163;">)</span>
<span style="color: #4f97d7;">)</span> <span style="color: #3a81c3;">)</span>
<span style="color: #4f97d7;">(</span>sum-squares-of-larger <span style="color: #a45bad;">9</span> <span style="color: #a45bad;">10</span> <span style="color: #a45bad;">8</span><span style="color: #4f97d7;">)</span> <span style="color: #3a81c3;">(</span>sum-squares-of-larger <span style="color: #4e3163;">9</span> <span style="color: #4e3163;">10</span> <span style="color: #4e3163;">8</span><span style="color: #3a81c3;">)</span>
</pre> </pre>
</div> </div>
</div> </div>
@ -474,8 +484,8 @@ the squares of the two larger numbers.
</ol> </ol>
</div> </div>
<div id="outline-container-orgaece15c" class="outline-4"> <div id="outline-container-org5917931" class="outline-4">
<h4 id="orgaece15c"><span class="section-number-4">2.6.2.</span> 1.5</h4> <h4 id="org5917931"><span class="section-number-4">2.6.2.</span> 1.5</h4>
<div class="outline-text-4" id="text-2-6-2"> <div class="outline-text-4" id="text-2-6-2">
<p> <p>
Aplikativni vrstni red: pade takoj v neskoncno zanko. Aplikativni vrstni red: pade takoj v neskoncno zanko.
@ -484,8 +494,8 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
</div> </div>
</div> </div>
<div id="outline-container-orgfcdfec0" class="outline-4"> <div id="outline-container-org46d6002" class="outline-4">
<h4 id="orgfcdfec0"><span class="section-number-4">2.6.3.</span> 1.6</h4> <h4 id="org46d6002"><span class="section-number-4">2.6.3.</span> 1.6</h4>
<div class="outline-text-4" id="text-2-6-3"> <div class="outline-text-4" id="text-2-6-3">
<p> <p>
<a href="sqrt-newton.scm">sqrt-newton.scm</a> <a href="sqrt-newton.scm">sqrt-newton.scm</a>
@ -493,8 +503,8 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
</div> </div>
</div> </div>
<div id="outline-container-org6d81d53" class="outline-4"> <div id="outline-container-org752ea5e" class="outline-4">
<h4 id="org6d81d53"><span class="section-number-4">2.6.4.</span> 1.7</h4> <h4 id="org752ea5e"><span class="section-number-4">2.6.4.</span> 1.7</h4>
<div class="outline-text-4" id="text-2-6-4"> <div class="outline-text-4" id="text-2-6-4">
<ul class="org-ul"> <ul class="org-ul">
<li><code>good-enough?</code> ni vredu za iskanje korenov majhnih stevil.</li> <li><code>good-enough?</code> ni vredu za iskanje korenov majhnih stevil.</li>
@ -509,8 +519,8 @@ dovolj majhne in takrat prekini funkcijo.</li>
</div> </div>
</div> </div>
<div id="outline-container-orgec5d243" class="outline-4"> <div id="outline-container-org5fba44a" class="outline-4">
<h4 id="orgec5d243"><span class="section-number-4">2.6.5.</span> 1.8</h4> <h4 id="org5fba44a"><span class="section-number-4">2.6.5.</span> 1.8</h4>
<div class="outline-text-4" id="text-2-6-5"> <div class="outline-text-4" id="text-2-6-5">
<p> <p>
// Glej v sqrt-newton.sqm // Glej v sqrt-newton.sqm
@ -519,8 +529,8 @@ dovolj majhne in takrat prekini funkcijo.</li>
</div> </div>
</div> </div>
<div id="outline-container-org8d4a90a" class="outline-3"> <div id="outline-container-orgdf856c9" class="outline-3">
<h3 id="org8d4a90a"><span class="section-number-3">2.7.</span> 1.1.8 Procedure kot crne skatle abstrakcij</h3> <h3 id="orgdf856c9"><span class="section-number-3">2.7.</span> 1.1.8 Procedure kot crne skatle abstrakcij</h3>
<div class="outline-text-3" id="text-2-7"> <div class="outline-text-3" id="text-2-7">
<ul class="org-ul"> <ul class="org-ul">
<li>block structure</li> <li>block structure</li>
@ -528,6 +538,124 @@ dovolj majhne in takrat prekini funkcijo.</li>
</ul> </ul>
</div> </div>
</div> </div>
<div id="outline-container-orgc1bedf1" class="outline-3">
<h3 id="orgc1bedf1"><span class="section-number-3">2.8.</span> 1.2.2 Drevesna rekurzija</h3>
</div>
<div id="outline-container-orga7e8396" class="outline-3">
<h3 id="orga7e8396"><span class="section-number-3">2.9.</span> 1.2.3 Redi rasti</h3>
</div>
<div id="outline-container-orgf79e38f" class="outline-3">
<h3 id="orgf79e38f"><span class="section-number-3">2.10.</span> 1.2.4 Eksponentna funkcija</h3>
</div>
<div id="outline-container-org8125de0" class="outline-3">
<h3 id="org8125de0"><span class="section-number-3">2.11.</span> 1.2.5 Najvecji skupni deljitel</h3>
</div>
<div id="outline-container-orge8e49b3" class="outline-3">
<h3 id="orge8e49b3"><span class="section-number-3">2.12.</span> 1.2.6 Primer: Iskanje prastevil</h3>
</div>
<div id="outline-container-org6c46b7b" class="outline-3">
<h3 id="org6c46b7b"><span class="section-number-3">2.13.</span> 1.3 Sestavljanje abstrakcij s procedurami visjega reda</h3>
</div>
<div id="outline-container-orga8cba41" class="outline-3">
<h3 id="orga8cba41"><span class="section-number-3">2.14.</span> 1.3.1 Procedure kot argumenti</h3>
<div class="outline-text-3" id="text-2-14">
<p>
//exercise 1.29
#name: simpson
</p>
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">sum</span> term a next b<span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>&gt; a b<span style="color: #2d9574;">)</span>
<span style="color: #4e3163;">0</span>
<span style="color: #2d9574;">(</span>+ <span style="color: #67b11d;">(</span>term a<span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>sum term <span style="color: #b1951d;">(</span>next a<span style="color: #b1951d;">)</span> next b<span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span>
<span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
<span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">integral</span> f a b dx<span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #6c3163; font-weight: bold;">add-dx</span> x<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>+ x dx<span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>* <span style="color: #2d9574;">(</span>sum f <span style="color: #67b11d;">(</span>+ a <span style="color: #b1951d;">(</span>/ dx <span style="color: #4e3163;">2.0</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span> add-dx b<span style="color: #2d9574;">)</span> dx<span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
<span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">sum-s</span> term a next b fact<span style="color: #6c3163;">)</span>
<span style="color: #2aa1ae; background-color: #ecf3ec;">;; </span><span style="color: #2aa1ae; background-color: #ecf3ec;">fact is altering between 4 and 2</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #6c3163; font-weight: bold;">check-fact</span> fact<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>= fact <span style="color: #4e3163;">4</span><span style="color: #67b11d;">)</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">4</span><span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>&gt; a b<span style="color: #2d9574;">)</span>
<span style="color: #4e3163;">0</span>
<span style="color: #2d9574;">(</span>+ <span style="color: #67b11d;">(</span>* fact <span style="color: #b1951d;">(</span>term a<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>sum-s term <span style="color: #b1951d;">(</span>next a<span style="color: #b1951d;">)</span> next b <span style="color: #b1951d;">(</span>check-fact fact<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span>
<span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
<span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">simpson</span> f a b dx<span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #6c3163; font-weight: bold;">add-dx</span> x<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>+ x dx<span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>* <span style="color: #2d9574;">(</span>+ <span style="color: #67b11d;">(</span>f a<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>f b<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>sum-s f <span style="color: #b1951d;">(</span>add-dx a<span style="color: #b1951d;">)</span> add-dx <span style="color: #b1951d;">(</span>- b dx<span style="color: #b1951d;">)</span> <span style="color: #4e3163;">4</span><span style="color: #67b11d;">)</span> <span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>/ dx <span style="color: #4e3163;">3.0</span><span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
<span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">simpson-gizmo</span> f a b dx<span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #6c3163; font-weight: bold;">add-dxdx</span> x<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>+ x dx dx<span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>* <span style="color: #2d9574;">(</span>+
<span style="color: #67b11d;">(</span>* <span style="color: #4e3163;">4</span> <span style="color: #b1951d;">(</span>sum f <span style="color: #3a81c3;">(</span>+ a dx<span style="color: #3a81c3;">)</span> add-dxdx b<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>* <span style="color: #4e3163;">2</span> <span style="color: #b1951d;">(</span>sum f a add-dxdx b<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>- <span style="color: #b1951d;">(</span>f a<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #67b11d;">(</span>- <span style="color: #b1951d;">(</span>f b<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>/ dx <span style="color: #4e3163;">3.0</span><span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
<span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">cube</span> x<span style="color: #6c3163;">)</span> <span style="color: #6c3163;">(</span>* x x x<span style="color: #6c3163;">)</span><span style="color: #3a81c3;">)</span>
<span style="color: #3a81c3;">(</span>list
<span style="color: #6c3163;">(</span>integral cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">0.01</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>integral cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">0.001</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>simpson cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">0.01</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>simpson cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">0.001</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>simpson cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #2d9574;">(</span>/ <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">1000</span><span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>simpson-gizmo cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">0.01</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>simpson-gizmo cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #2d9574;">(</span>/ <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">10000</span><span style="color: #2d9574;">)</span><span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>simpson-gizmo cube <span style="color: #4e3163;">1</span> <span style="color: #4e3163;">2</span> <span style="color: #4e3163;">0.00001</span><span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
</pre>
</div>
<p>
// exercise 1.30
</p>
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #3a81c3;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #6c3163;">(</span><span style="color: #6c3163; font-weight: bold;">sum-i</span> term a next b<span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #6c3163; font-weight: bold;">iter</span> a result<span style="color: #2d9574;">)</span>
<span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>&gt; a b<span style="color: #67b11d;">)</span>
result
<span style="color: #67b11d;">(</span>iter <span style="color: #b1951d;">(</span>next a<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>+ result <span style="color: #3a81c3;">(</span>term a<span style="color: #3a81c3;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
<span style="color: #2d9574;">)</span>
<span style="color: #6c3163;">)</span>
<span style="color: #6c3163;">(</span>iter a <span style="color: #4e3163;">0</span><span style="color: #6c3163;">)</span>
<span style="color: #3a81c3;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb6993b9" class="outline-3">
<h3 id="orgb6993b9"><span class="section-number-3">2.15.</span> 1.3.2 Sestavljanje procedur z Lambda</h3>
</div>
<div id="outline-container-org5ea790c" class="outline-3">
<h3 id="org5ea790c"><span class="section-number-3">2.16.</span> 1.3.3 Procedure kot splosne metode</h3>
</div>
<div id="outline-container-org0a1c5a7" class="outline-3">
<h3 id="org0a1c5a7"><span class="section-number-3">2.17.</span> 1.3.4 Procedure kot vrnjene vrednosti</h3>
</div>
</div> </div>
</div> </div>
</body> </body>

View File

@ -195,3 +195,97 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
- block structure - block structure
- lexical scoping - lexical scoping
** 1.2.2 Drevesna rekurzija
** 1.2.3 Redi rasti
** 1.2.4 Eksponentna funkcija
** 1.2.5 Najvecji skupni deljitel
** 1.2.6 Primer: Iskanje prastevil
** 1.3 Sestavljanje abstrakcij s procedurami visjega reda
** 1.3.1 Procedure kot argumenti
//exercise 1.29
#name: simpson
#+begin_src scheme
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b)
)
)
)
(define (integral f a b dx)
(define (add-dx x) (+ x dx))
(* (sum f (+ a (/ dx 2.0)) add-dx b) dx)
)
(define (sum-s term a next b fact)
;; fact is altering between 4 and 2
(define (check-fact fact) (if (= fact 4) 2 4))
(if (> a b)
0
(+ (* fact (term a))
(sum-s term (next a) next b (check-fact fact))
)
)
)
(define (simpson f a b dx)
(define (add-dx x) (+ x dx))
(* (+ (f a) (f b) (sum-s f (add-dx a) add-dx (- b dx) 4) ) (/ dx 3.0))
)
(define (simpson-gizmo f a b dx)
(define (add-dxdx x) (+ x dx dx))
(* (+
(* 4 (sum f (+ a dx) add-dxdx b))
(* 2 (sum f a add-dxdx b))
(- (f a))
(- (f b))
) (/ dx 3.0))
)
(define (cube x) (* x x x))
(list
(integral cube 1 2 0.01)
(integral cube 1 2 0.001)
(simpson cube 1 2 0.01)
(simpson cube 1 2 0.001)
(simpson cube 1 2 (/ 1 1000))
(simpson-gizmo cube 1 2 0.01)
(simpson-gizmo cube 1 2 (/ 1 10000))
(simpson-gizmo cube 1 2 0.00001)
)
#+end_src
#+RESULTS:
| 3.7499625000000045 | 3.7499996249995324 | 3.644925346666673 | 3.7499999999995324 | 3.749893334961112 |
// exercise 1.30
#+begin_src scheme
(define (sum-i term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ result (term a)))
)
)
(iter a 0)
)
#+end_src
** 1.3.2 Sestavljanje procedur z Lambda
** 1.3.3 Procedure kot splosne metode
** 1.3.4 Procedure kot vrnjene vrednosti