Lio, srecanje #4
parent
7d579b9b12
commit
684c695994
65
index.html
65
index.html
|
@ -3,11 +3,11 @@
|
|||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2024-05-17 pet 12:43 -->
|
||||
<!-- 2024-05-29 Wed 21:51 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Kompotov programerski bralni krožek #1: SICP</title>
|
||||
<meta name="author" content="Yuri" />
|
||||
<meta name="author" content="Lio Novelli" />
|
||||
<meta name="generator" content="Org Mode" />
|
||||
<style>
|
||||
#content { max-width: 60em; margin: auto; }
|
||||
|
@ -198,7 +198,7 @@
|
|||
<body>
|
||||
<div id="content" class="content">
|
||||
<h1 class="title">Kompotov programerski bralni krožek #1: SICP</h1>
|
||||
<div class="footer" id="orgc1028a9">
|
||||
<div class="footer" id="org2c48c6f">
|
||||
<p>
|
||||
Izvorna koda se nahaja na <a href="https://git.kompot.si/programerski-bralni-krozek/sicp">git.kompot.si</a>.
|
||||
</p>
|
||||
|
@ -206,7 +206,7 @@ Izvorna koda se nahaja na <a href="https://git.kompot.si/programerski-bralni-kro
|
|||
</div>
|
||||
|
||||
<p>
|
||||
Beremo <a href="https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs">Structure and Interpretation of Computer Programs</a>.
|
||||
Beremo <a href="https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs">Structure and Interpretation of Computer Programs</a>. (<a href="https://web.mit.edu/6.001/6.037/sicp.pdf">prenesi pdf</a>)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
@ -214,18 +214,18 @@ Za bralni krožek se dogovarjamo prek (javne) mailing liste, na katero se lahko
|
|||
</p>
|
||||
|
||||
|
||||
<div id="org1569423" class="figure">
|
||||
<div id="orgda18b5b" class="figure">
|
||||
<p><img src="./tb.jpg" alt="tb.jpg" />
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org14c9c4c" class="outline-2">
|
||||
<h2 id="org14c9c4c">Srečanja</h2>
|
||||
<div class="outline-text-2" id="text-org14c9c4c">
|
||||
<div id="outline-container-org0e18dba" class="outline-2">
|
||||
<h2 id="org0e18dba">Srečanja</h2>
|
||||
<div class="outline-text-2" id="text-org0e18dba">
|
||||
</div>
|
||||
<div id="outline-container-org19a2e8a" class="outline-3">
|
||||
<h3 id="org19a2e8a">#4: sreda, 29. 5. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-org19a2e8a">
|
||||
<div id="outline-container-orge2c289f" class="outline-3">
|
||||
<h3 id="orge2c289f">#4: sreda, 29. 5. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-orge2c289f">
|
||||
<p>
|
||||
Dogodek je <a href="https://dogodki.kompot.si/events/0f3df86f-abc0-4725-bb4c-3587262a672c">tukaj</a>.
|
||||
Preglejujemo naloge iz prvega poglavja.
|
||||
|
@ -233,9 +233,9 @@ Preglejujemo naloge iz prvega poglavja.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org80c7d8b" class="outline-3">
|
||||
<h3 id="org80c7d8b">#3: četrtek, 16. 5. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-org80c7d8b">
|
||||
<div id="outline-container-orgda1ad5c" class="outline-3">
|
||||
<h3 id="orgda1ad5c">#3: četrtek, 16. 5. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-orgda1ad5c">
|
||||
<p>
|
||||
Kot ponavadi je dogodek na našem <a href="https://dogodki.kompot.si/events/8435c26d-4dbd-4e28-94c2-a237c837865d">mobilizonu</a>.
|
||||
</p>
|
||||
|
@ -247,9 +247,9 @@ Na srečanju smo skupaj reševali vajo 1.29.
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org2e21a8d" class="outline-4">
|
||||
<h4 id="org2e21a8d">zapiski</h4>
|
||||
<div class="outline-text-4" id="text-org2e21a8d">
|
||||
<div id="outline-container-org06e99f3" class="outline-4">
|
||||
<h4 id="org06e99f3">zapiski</h4>
|
||||
<div class="outline-text-4" id="text-org06e99f3">
|
||||
<ul class="org-ul">
|
||||
<li><a href="zapiski/sicp-lio.html#MissingReference">lio</a></li>
|
||||
<li><a href="./zapiski/3_g1smo.scm">g1smo</a></li>
|
||||
|
@ -258,9 +258,9 @@ Na srečanju smo skupaj reševali vajo 1.29.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org6a834f1" class="outline-3">
|
||||
<h3 id="org6a834f1">#2: torek, 30. 4. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-org6a834f1">
|
||||
<div id="outline-container-orgb085ad8" class="outline-3">
|
||||
<h3 id="orgb085ad8">#2: torek, 30. 4. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-orgb085ad8">
|
||||
<p>
|
||||
Dogodek je <a href="https://dogodki.kompot.si/events/8435c26d-4dbd-4e28-94c2-a237c837865d">tukaj</a>.
|
||||
</p>
|
||||
|
@ -270,9 +270,9 @@ Nadaljujemo z branjem poglavja 1.2, Procedures and the processes they generate.
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgb5dace1" class="outline-4">
|
||||
<h4 id="orgb5dace1">zapiski</h4>
|
||||
<div class="outline-text-4" id="text-orgb5dace1">
|
||||
<div id="outline-container-org54396aa" class="outline-4">
|
||||
<h4 id="org54396aa">zapiski</h4>
|
||||
<div class="outline-text-4" id="text-org54396aa">
|
||||
<ul class="org-ul">
|
||||
<li><a href="zapiski/sicp_1_2_tina.md">tina</a> (<a href="zapiski/sicp_1_2_tina.scm">vaje</a>, <a href="zapiski/sicp_sec_1_2.scm">druga varjanta</a>)</li>
|
||||
<li><a href="zapiski/sicp-lio.html#MissingReference">lio</a></li>
|
||||
|
@ -282,9 +282,9 @@ Nadaljujemo z branjem poglavja 1.2, Procedures and the processes they generate.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org34051e2" class="outline-3">
|
||||
<h3 id="org34051e2">#1: sreda, 17. 4. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-org34051e2">
|
||||
<div id="outline-container-org2afa1fb" class="outline-3">
|
||||
<h3 id="org2afa1fb">#1: sreda, 17. 4. 2024 18.45 v CTK</h3>
|
||||
<div class="outline-text-3" id="text-org2afa1fb">
|
||||
<p>
|
||||
Beremo uvod in do poglavja 1.2, približno 30 strani.
|
||||
</p>
|
||||
|
@ -294,9 +294,9 @@ Link do <a href="https://dogodki.kompot.si/events/76672075-1c6f-48f1-bc37-05dde9
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgaf97219" class="outline-4">
|
||||
<h4 id="orgaf97219">zapiski</h4>
|
||||
<div class="outline-text-4" id="text-orgaf97219">
|
||||
<div id="outline-container-org6b34977" class="outline-4">
|
||||
<h4 id="org6b34977">zapiski</h4>
|
||||
<div class="outline-text-4" id="text-org6b34977">
|
||||
<ul class="org-ul">
|
||||
<li><a href="zapiski/1_g1smo.html">g1smo</a></li>
|
||||
<li><a href="zapiski/sicp-lio.html">lio</a></li>
|
||||
|
@ -306,10 +306,5 @@ Link do <a href="https://dogodki.kompot.si/events/76672075-1c6f-48f1-bc37-05dde9
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: Yuri</p>
|
||||
<p class="date">Created: 2024-05-17 pet 12:43</p>
|
||||
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
|
@ -7,7 +7,7 @@
|
|||
Izvorna koda se nahaja na [[https://git.kompot.si/programerski-bralni-krozek/sicp][git.kompot.si]].
|
||||
#+END_footer
|
||||
|
||||
Beremo [[https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs][Structure and Interpretation of Computer Programs]].
|
||||
Beremo [[https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs][Structure and Interpretation of Computer Programs]]. ([[https://web.mit.edu/6.001/6.037/sicp.pdf][prenesi pdf]])
|
||||
|
||||
Za bralni krožek se dogovarjamo prek (javne) mailing liste, na katero se lahko prijavite na https://liste.kompot.si/postorius/lists/bralni.kompot.si/
|
||||
|
||||
|
|
|
@ -51,7 +51,9 @@
|
|||
)
|
||||
|
||||
(define (pascal globina seznam)
|
||||
(display (make-string globina #\ ))
|
||||
(display seznam)
|
||||
(display "\n")
|
||||
(if (= globina 0)
|
||||
seznam
|
||||
(pascal (- globina 1) (cons 1 (nov-seznam seznam)))
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2024-05-16 Thu 22:32 -->
|
||||
<!-- 2024-05-29 Wed 21:50 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Structure and Interpretation of Computer Programs</title>
|
||||
|
@ -201,46 +201,46 @@
|
|||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents" role="doc-toc">
|
||||
<ul>
|
||||
<li><a href="#org65e2102">1. Foreword and Preface</a></li>
|
||||
<li><a href="#orgd844a85">2. 1. Grajenje abstrakcij s procedurami</a>
|
||||
<li><a href="#orgc29ca22">1. Foreword and Preface</a></li>
|
||||
<li><a href="#org81536d5">2. 1. Grajenje abstrakcij s procedurami</a>
|
||||
<ul>
|
||||
<li><a href="#org9cc9e23">2.1. Elementi programiranja</a></li>
|
||||
<li><a href="#orgc38e99e">2.2. Izvajanje kombinacij(e)</a></li>
|
||||
<li><a href="#org4561884">2.3. 1.1.4 Sestavljene procedure</a></li>
|
||||
<li><a href="#org5a7e4a4">2.4. 1.1.5 Substitucijski model za izvajanje procedur</a></li>
|
||||
<li><a href="#org4f92eb8">2.5. meta</a>
|
||||
<li><a href="#org09ba581">2.1. Elementi programiranja</a></li>
|
||||
<li><a href="#org79ae90c">2.2. Izvajanje kombinacij(e)</a></li>
|
||||
<li><a href="#org4bf06e2">2.3. 1.1.4 Sestavljene procedure</a></li>
|
||||
<li><a href="#orgf96a231">2.4. 1.1.5 Substitucijski model za izvajanje procedur</a></li>
|
||||
<li><a href="#org2356eae">2.5. meta</a>
|
||||
<ul>
|
||||
<li><a href="#org0b39e3d">2.5.1. video lekcije</a></li>
|
||||
<li><a href="#org1a875a1">2.5.1. video lekcije</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#org56f8627">2.6. vaje</a>
|
||||
<li><a href="#orge24b089">2.6. vaje</a>
|
||||
<ul>
|
||||
<li><a href="#org26ed807">2.6.1. 1.3</a></li>
|
||||
<li><a href="#org5917931">2.6.2. 1.5</a></li>
|
||||
<li><a href="#org46d6002">2.6.3. 1.6</a></li>
|
||||
<li><a href="#org752ea5e">2.6.4. 1.7</a></li>
|
||||
<li><a href="#org5fba44a">2.6.5. 1.8</a></li>
|
||||
<li><a href="#org9124e61">2.6.1. 1.3</a></li>
|
||||
<li><a href="#orgfb06a20">2.6.2. 1.5</a></li>
|
||||
<li><a href="#orgb4abc50">2.6.3. 1.6</a></li>
|
||||
<li><a href="#org19c25b3">2.6.4. 1.7</a></li>
|
||||
<li><a href="#orgd223612">2.6.5. 1.8</a></li>
|
||||
</ul>
|
||||
</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>
|
||||
<li><a href="#org73c888b">2.7. 1.1.8 Procedure kot crne skatle abstrakcij</a></li>
|
||||
<li><a href="#org95ea2ee">2.8. 1.2.2 Drevesna rekurzija</a></li>
|
||||
<li><a href="#org1358990">2.9. 1.2.3 Redi rasti</a></li>
|
||||
<li><a href="#org18b4f25">2.10. 1.2.4 Eksponentna funkcija</a></li>
|
||||
<li><a href="#orga719e3c">2.11. 1.2.5 Najvecji skupni deljitel</a></li>
|
||||
<li><a href="#org303b7e7">2.12. 1.2.6 Primer: Iskanje prastevil</a></li>
|
||||
<li><a href="#org308cc01">2.13. 1.3 Sestavljanje abstrakcij s procedurami visjega reda</a></li>
|
||||
<li><a href="#orgc7ad7a4">2.14. 1.3.1 Procedure kot argumenti</a></li>
|
||||
<li><a href="#org920469a">2.15. 1.3.2 Sestavljanje procedur z <code>Lambda</code></a></li>
|
||||
<li><a href="#orgb365f70">2.16. 1.3.3 Procedure kot splosne metode</a></li>
|
||||
<li><a href="#orge72480c">2.17. 1.3.4 Procedure kot vrnjene vrednosti</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org65e2102" class="outline-2">
|
||||
<h2 id="org65e2102"><span class="section-number-2">1.</span> Foreword and Preface</h2>
|
||||
<div id="outline-container-orgc29ca22" class="outline-2">
|
||||
<h2 id="orgc29ca22"><span class="section-number-2">1.</span> Foreword and Preface</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
<blockquote>
|
||||
<p>
|
||||
|
@ -282,12 +282,12 @@ ukvarjanje s pojmovanjem "kako".
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgd844a85" class="outline-2">
|
||||
<h2 id="orgd844a85"><span class="section-number-2">2.</span> 1. Grajenje abstrakcij s procedurami</h2>
|
||||
<div id="outline-container-org81536d5" class="outline-2">
|
||||
<h2 id="org81536d5"><span class="section-number-2">2.</span> 1. Grajenje abstrakcij s procedurami</h2>
|
||||
<div class="outline-text-2" id="text-2">
|
||||
</div>
|
||||
<div id="outline-container-org9cc9e23" class="outline-3">
|
||||
<h3 id="org9cc9e23"><span class="section-number-3">2.1.</span> Elementi programiranja</h3>
|
||||
<div id="outline-container-org09ba581" class="outline-3">
|
||||
<h3 id="org09ba581"><span class="section-number-3">2.1.</span> Elementi programiranja</h3>
|
||||
<div class="outline-text-3" id="text-2-1">
|
||||
<dl class="org-dl">
|
||||
<dt>Primitivni izrazi</dt><dd>predstavtljajo najpreprostejše gradnike (entitete)
|
||||
|
@ -300,8 +300,8 @@ omogočajo upravljanje z njimii kot enotami</dd>
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgc38e99e" class="outline-3">
|
||||
<h3 id="orgc38e99e"><span class="section-number-3">2.2.</span> Izvajanje kombinacij(e)</h3>
|
||||
<div id="outline-container-org79ae90c" class="outline-3">
|
||||
<h3 id="org79ae90c"><span class="section-number-3">2.2.</span> Izvajanje kombinacij(e)</h3>
|
||||
<div class="outline-text-3" id="text-2-2">
|
||||
<p>
|
||||
Postopek za izvajanje kombinacij:
|
||||
|
@ -343,8 +343,8 @@ oblika.
|
|||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-org4561884" class="outline-3">
|
||||
<h3 id="org4561884"><span class="section-number-3">2.3.</span> 1.1.4 Sestavljene procedure</h3>
|
||||
<div id="outline-container-org4bf06e2" class="outline-3">
|
||||
<h3 id="org4bf06e2"><span class="section-number-3">2.3.</span> 1.1.4 Sestavljene procedure</h3>
|
||||
<div class="outline-text-3" id="text-2-3">
|
||||
<ul class="org-ul">
|
||||
<li>Številke in aritmetične operacije so primitivni podatki in procedure.</li>
|
||||
|
@ -363,8 +363,8 @@ abstrakcije.</li>
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org5a7e4a4" class="outline-3">
|
||||
<h3 id="org5a7e4a4"><span class="section-number-3">2.4.</span> 1.1.5 Substitucijski model za izvajanje procedur</h3>
|
||||
<div id="outline-container-orgf96a231" class="outline-3">
|
||||
<h3 id="orgf96a231"><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">
|
||||
<p>
|
||||
Za izvajanje sestavljenih procedur z argumenti, izvedeš telo procedure z vsakim
|
||||
|
@ -393,8 +393,8 @@ izraza, ki vsebuje zgolj primitivne izraze in potem izvedi (vso) evalvacijo.</dd
|
|||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-org4f92eb8" class="outline-3">
|
||||
<h3 id="org4f92eb8"><span class="section-number-3">2.5.</span> meta</h3>
|
||||
<div id="outline-container-org2356eae" class="outline-3">
|
||||
<h3 id="org2356eae"><span class="section-number-3">2.5.</span> meta</h3>
|
||||
<div class="outline-text-3" id="text-2-5">
|
||||
<p>
|
||||
Linki:
|
||||
|
@ -410,8 +410,8 @@ Kako nastavit spacemacs, in malo o guile-u.
|
|||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-org0b39e3d" class="outline-4">
|
||||
<h4 id="org0b39e3d"><span class="section-number-4">2.5.1.</span> video lekcije</h4>
|
||||
<div id="outline-container-org1a875a1" class="outline-4">
|
||||
<h4 id="org1a875a1"><span class="section-number-4">2.5.1.</span> video lekcije</h4>
|
||||
<div class="outline-text-4" id="text-2-5-1">
|
||||
<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))
|
||||
|
@ -421,16 +421,16 @@ Kako nastavit spacemacs, in malo o guile-u.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org56f8627" class="outline-3">
|
||||
<h3 id="org56f8627"><span class="section-number-3">2.6.</span> vaje</h3>
|
||||
<div id="outline-container-orge24b089" class="outline-3">
|
||||
<h3 id="orge24b089"><span class="section-number-3">2.6.</span> vaje</h3>
|
||||
<div class="outline-text-3" id="text-2-6">
|
||||
</div>
|
||||
<div id="outline-container-org26ed807" class="outline-4">
|
||||
<h4 id="org26ed807"><span class="section-number-4">2.6.1.</span> 1.3</h4>
|
||||
<div id="outline-container-org9124e61" class="outline-4">
|
||||
<h4 id="org9124e61"><span class="section-number-4">2.6.1.</span> 1.3</h4>
|
||||
<div class="outline-text-4" id="text-2-6-1">
|
||||
</div>
|
||||
<ol class="org-ol">
|
||||
<li><a id="orgffab77a"></a>najprej narobe<br />
|
||||
<li><a id="org101bff2"></a>najprej narobe<br />
|
||||
<div class="outline-text-5" id="text-2-6-1-1">
|
||||
<p>
|
||||
Define a procedure that takes three numbers as arguments and returns the sum of
|
||||
|
@ -438,45 +438,45 @@ the squares of the two larger numbers.
|
|||
</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-of-large</span> x y z<span style="color: #6c3163;">)</span>
|
||||
<span style="color: #6c3163;">(</span>+
|
||||
<span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> 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>> 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: #6c3163;">)</span>
|
||||
<span style="color: #3a81c3;">)</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 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>
|
||||
<span style="color: #bc6ec5;">(</span>+
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> 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>> 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: #4f97d7;">)</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>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<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-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: #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: #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>> 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>
|
||||
<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>
|
||||
<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: #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>> 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: #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: #6c3163;">)</span><span style="color: #3a81c3;">)</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>
|
||||
<span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</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>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li><a id="orgb84d327"></a>pravilno<br />
|
||||
<li><a id="orge6e316f"></a>pravilno<br />
|
||||
<div class="outline-text-5" id="text-2-6-1-2">
|
||||
<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-squares-of-larger</span> x y z<span style="color: #6c3163;">)</span>
|
||||
<span style="color: #6c3163;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>> x y<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> y z<span style="color: #67b11d;">)</span>
|
||||
<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>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>> 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>> 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>* 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: #3a81c3; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> x z<span style="color: #67b11d;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> 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>* z z<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>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>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</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>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -484,8 +484,8 @@ the squares of the two larger numbers.
|
|||
</ol>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org5917931" class="outline-4">
|
||||
<h4 id="org5917931"><span class="section-number-4">2.6.2.</span> 1.5</h4>
|
||||
<div id="outline-container-orgfb06a20" class="outline-4">
|
||||
<h4 id="orgfb06a20"><span class="section-number-4">2.6.2.</span> 1.5</h4>
|
||||
<div class="outline-text-4" id="text-2-6-2">
|
||||
<p>
|
||||
Aplikativni vrstni red: pade takoj v neskoncno zanko.
|
||||
|
@ -494,8 +494,8 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org46d6002" class="outline-4">
|
||||
<h4 id="org46d6002"><span class="section-number-4">2.6.3.</span> 1.6</h4>
|
||||
<div id="outline-container-orgb4abc50" class="outline-4">
|
||||
<h4 id="orgb4abc50"><span class="section-number-4">2.6.3.</span> 1.6</h4>
|
||||
<div class="outline-text-4" id="text-2-6-3">
|
||||
<p>
|
||||
<a href="sqrt-newton.scm">sqrt-newton.scm</a>
|
||||
|
@ -503,8 +503,8 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org752ea5e" class="outline-4">
|
||||
<h4 id="org752ea5e"><span class="section-number-4">2.6.4.</span> 1.7</h4>
|
||||
<div id="outline-container-org19c25b3" class="outline-4">
|
||||
<h4 id="org19c25b3"><span class="section-number-4">2.6.4.</span> 1.7</h4>
|
||||
<div class="outline-text-4" id="text-2-6-4">
|
||||
<ul class="org-ul">
|
||||
<li><code>good-enough?</code> ni vredu za iskanje korenov majhnih stevil.</li>
|
||||
|
@ -519,8 +519,8 @@ dovolj majhne in takrat prekini funkcijo.</li>
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-org5fba44a" class="outline-4">
|
||||
<h4 id="org5fba44a"><span class="section-number-4">2.6.5.</span> 1.8</h4>
|
||||
<div id="outline-container-orgd223612" class="outline-4">
|
||||
<h4 id="orgd223612"><span class="section-number-4">2.6.5.</span> 1.8</h4>
|
||||
<div class="outline-text-4" id="text-2-6-5">
|
||||
<p>
|
||||
// Glej v sqrt-newton.sqm
|
||||
|
@ -529,8 +529,8 @@ dovolj majhne in takrat prekini funkcijo.</li>
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-orgdf856c9" class="outline-3">
|
||||
<h3 id="orgdf856c9"><span class="section-number-3">2.7.</span> 1.1.8 Procedure kot crne skatle abstrakcij</h3>
|
||||
<div id="outline-container-org73c888b" class="outline-3">
|
||||
<h3 id="org73c888b"><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">
|
||||
<ul class="org-ul">
|
||||
<li>block structure</li>
|
||||
|
@ -539,91 +539,192 @@ dovolj majhne in takrat prekini funkcijo.</li>
|
|||
</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 id="outline-container-org95ea2ee" class="outline-3">
|
||||
<h3 id="org95ea2ee"><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 id="outline-container-org1358990" class="outline-3">
|
||||
<h3 id="org1358990"><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 id="outline-container-org18b4f25" class="outline-3">
|
||||
<h3 id="org18b4f25"><span class="section-number-3">2.10.</span> 1.2.4 Eksponentna funkcija</h3>
|
||||
<div class="outline-text-3" id="text-2-10">
|
||||
<p>
|
||||
#name: exponent
|
||||
</p>
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-scheme"><span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">O(n) korakov in O(n) prostora</span>
|
||||
<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;">expt</span> b n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>= n <span style="color: #a45bad;">0</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #a45bad;">1</span>
|
||||
<span style="color: #2d9574;">(</span>* b <span style="color: #67b11d;">(</span>expt b <span style="color: #b1951d;">(</span>- n <span style="color: #a45bad;">1</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
|
||||
<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;">expt-i</span> b n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>expt-iter b n <span style="color: #a45bad;">1</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">O(n) korakov O(1) prostor</span>
|
||||
<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;">expt-iter</span> b cnt prod<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>= cnt <span style="color: #a45bad;">0</span><span style="color: #2d9574;">)</span>
|
||||
prod
|
||||
<span style="color: #2d9574;">(</span>expt-iter b <span style="color: #67b11d;">(</span>- cnt <span style="color: #a45bad;">1</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>* b prod<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">fast-expt</span> b n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">cond</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>= n <span style="color: #a45bad;">0</span><span style="color: #67b11d;">)</span> <span style="color: #a45bad;">1</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>even? n<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>square <span style="color: #b1951d;">(</span>fast-expt b <span style="color: #4f97d7;">(</span>/ n <span style="color: #a45bad;">2</span><span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">else</span> <span style="color: #67b11d;">(</span>* b <span style="color: #b1951d;">(</span>fast-expt b <span style="color: #4f97d7;">(</span>- n <span style="color: #a45bad;">1</span><span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">even?</span> n<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>= <span style="color: #2d9574;">(</span>remainder n <span style="color: #a45bad;">2</span><span style="color: #2d9574;">)</span> <span style="color: #a45bad;">0</span><span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">square</span> x<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>* x x<span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span>
|
||||
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">1.16</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">successive squaring (fast-expt) but with iteration.</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">transformation (* a (expt b n)) constant</span>
|
||||
|
||||
<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;">fast-expt-i</span> b n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>fast-expt-iter b n <span style="color: #a45bad;">1</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">fast-expt-iter</span> b n a<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">cond</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>= n <span style="color: #a45bad;">0</span><span style="color: #67b11d;">)</span> a<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>even? n<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>fast-expt-iter <span style="color: #b1951d;">(</span>square b<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>/ n <span style="color: #a45bad;">2</span><span style="color: #b1951d;">)</span> a<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">else</span> <span style="color: #67b11d;">(</span>fast-expt-iter b <span style="color: #b1951d;">(</span>- n <span style="color: #a45bad;">1</span><span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* a b<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">I'm not sure why this works. I was just guessing.</span>
|
||||
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">excersize 1.17</span>
|
||||
<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;">slow-multi</span> a b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>= b <span style="color: #a45bad;">0</span><span style="color: #2d9574;">)</span> <span style="color: #a45bad;">0</span>
|
||||
<span style="color: #2d9574;">(</span>+ a <span style="color: #67b11d;">(</span>* a <span style="color: #b1951d;">(</span>- b <span style="color: #a45bad;">1</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
<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;">halve</span> x<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>/ x <span style="color: #a45bad;">2</span><span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span>
|
||||
<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;">double</span> x<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>* x <span style="color: #a45bad;">2</span><span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span>
|
||||
<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;">fast-multi</span> a b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">cond</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>= b <span style="color: #a45bad;">0</span><span style="color: #67b11d;">)</span> <span style="color: #a45bad;">0</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>even? b<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>double <span style="color: #b1951d;">(</span>fast-multi a <span style="color: #4f97d7;">(</span>halve b<span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">else</span> <span style="color: #67b11d;">(</span>+ a <span style="color: #b1951d;">(</span>fast-multi a <span style="color: #4f97d7;">(</span>- b <span style="color: #a45bad;">1</span><span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">excersize 1.18</span>
|
||||
<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;">fast-multi-i</span> a b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>fast-multi-iter a b <span style="color: #a45bad;">0</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
<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;">fast-multi-iter</span> a b s<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">cond</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>= b <span style="color: #a45bad;">0</span><span style="color: #67b11d;">)</span> s<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #67b11d;">(</span>even? b<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>fast-multi-iter <span style="color: #b1951d;">(</span>double a<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>halve b<span style="color: #b1951d;">)</span> s<span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">else</span> <span style="color: #67b11d;">(</span>fast-multi-iter a <span style="color: #b1951d;">(</span>- b <span style="color: #a45bad;">1</span><span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>+ s a<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</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 id="outline-container-orga719e3c" class="outline-3">
|
||||
<h3 id="orga719e3c"><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 id="outline-container-org303b7e7" class="outline-3">
|
||||
<h3 id="org303b7e7"><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 id="outline-container-org308cc01" class="outline-3">
|
||||
<h3 id="org308cc01"><span class="section-number-3">2.13.</span> 1.3 Sestavljanje abstrakcij s procedurami visjega reda</h3>
|
||||
<div class="outline-text-3" id="text-2-13">
|
||||
<p>
|
||||
Procedure, ki spreminjajo druge procedure se imenujejo <b>procedure višjega reda</b>.
|
||||
</p>
|
||||
</div>
|
||||
</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 id="outline-container-orgc7ad7a4" class="outline-3">
|
||||
<h3 id="orgc7ad7a4"><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>
|
||||
Primer vsote.
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-guile">
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<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>> a b<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #4e3163;">0</span>
|
||||
<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</span> term a next b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>> a b<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #a45bad;">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: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</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: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">integral</span> f a b dx<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #bc6ec5; 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: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>* <span style="color: #2d9574;">(</span>sum f <span style="color: #67b11d;">(</span>+ a <span style="color: #b1951d;">(</span>/ dx <span style="color: #a45bad;">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: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</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>> a b<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #4e3163;">0</span>
|
||||
<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-s</span> term a next b fact<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">fact is altering between 4 and 2</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #bc6ec5; font-weight: bold;">check-fact</span> fact<span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>= fact <span style="color: #a45bad;">4</span><span style="color: #67b11d;">)</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">4</span><span style="color: #2d9574;">)</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>> a b<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #a45bad;">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: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</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: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">simpson</span> f a b dx<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #bc6ec5; 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: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</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: #a45bad;">4</span><span style="color: #67b11d;">)</span> <span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>/ dx <span style="color: #a45bad;">3.0</span><span style="color: #2d9574;">)</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</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: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">simpson-gizmo</span> f a b dx<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #bc6ec5; 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: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>* <span style="color: #2d9574;">(</span>+
|
||||
<span style="color: #67b11d;">(</span>* <span style="color: #a45bad;">4</span> <span style="color: #b1951d;">(</span>sum f <span style="color: #4f97d7;">(</span>+ a dx<span style="color: #4f97d7;">)</span> add-dxdx b<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
|
||||
<span style="color: #67b11d;">(</span>* <span style="color: #a45bad;">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: #2d9574;">)</span> <span style="color: #2d9574;">(</span>/ dx <span style="color: #a45bad;">3.0</span><span style="color: #2d9574;">)</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</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: #4f97d7;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #bc6ec5;">(</span><span style="color: #bc6ec5; font-weight: bold;">cube</span> x<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>* x x x<span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</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: #4f97d7;">(</span>list
|
||||
<span style="color: #bc6ec5;">(</span>integral cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">0.01</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>integral cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">0.001</span><span style="color: #bc6ec5;">)</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>
|
||||
<span style="color: #bc6ec5;">(</span>simpson cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">0.01</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>simpson cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">0.001</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>simpson cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #2d9574;">(</span>/ <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">1000</span><span style="color: #2d9574;">)</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>simpson-gizmo cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">0.01</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>simpson-gizmo cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #2d9574;">(</span>/ <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">10000</span><span style="color: #2d9574;">)</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>simpson-gizmo cube <span style="color: #a45bad;">1</span> <span style="color: #a45bad;">2</span> <span style="color: #a45bad;">0.00001</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
@ -631,32 +732,145 @@ dovolj majhne in takrat prekini funkcijo.</li>
|
|||
// 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>> a b<span style="color: #67b11d;">)</span>
|
||||
<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-i</span> term a next b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #bc6ec5; font-weight: bold;">iter</span> a result<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> 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: #67b11d;">(</span>iter <span style="color: #b1951d;">(</span>next a<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>+ result <span style="color: #4f97d7;">(</span>term a<span style="color: #4f97d7;">)</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>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>iter a <span style="color: #a45bad;">0</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
// excercise 1.30, 1.31. 1.32
|
||||
</p>
|
||||
<div class="org-src-container">
|
||||
<pre class="src src-scheme"><span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">Analogno napisi produkt kot vsoto.</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">Pokazi kako izgleda fakulteta.</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">Aproksimacija pi/4 = 2/3*4/3*4/5*6/5*6/7*8/7...</span>
|
||||
|
||||
<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;">produkt-r</span> term a next b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">a, b sta spodnja in zgornja meja</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #2d9574;">(</span>> a b<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #a45bad;">1</span>
|
||||
<span style="color: #2d9574;">(</span>* <span style="color: #67b11d;">(</span>term a<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>produkt-r 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: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">fakulteta-p</span> n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>produkt-r <span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">lambda</span> <span style="color: #67b11d;">(</span>x<span style="color: #67b11d;">)</span> x<span style="color: #2d9574;">)</span> <span style="color: #a45bad;">1</span> <span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">lambda</span> <span style="color: #67b11d;">(</span>x<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ x <span style="color: #a45bad;">1</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span> n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">pribl-pi</span> n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>produkt-r <span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">lambda</span> <span style="color: #67b11d;">(</span>a<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>/ <span style="color: #b1951d;">(</span>* <span style="color: #4f97d7;">(</span>- a <span style="color: #a45bad;">1.0</span><span style="color: #4f97d7;">)</span> <span style="color: #4f97d7;">(</span>+ a <span style="color: #a45bad;">1.0</span><span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* a a<span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
<span style="color: #a45bad;">3.0</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">lambda</span> <span style="color: #67b11d;">(</span>x<span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ x <span style="color: #a45bad;">2.0</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span>
|
||||
n
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">gizmo se je spomnil resitve - dva produkta (zgornji in spodnji)</span>
|
||||
|
||||
<span style="color: #2aa1ae; background-color: #292e34;">;; </span><span style="color: #2aa1ae; background-color: #292e34;">iterativni produkt-i</span>
|
||||
<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;">produkt-i</span> term a next b<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span><span style="color: #4f97d7; font-weight: bold;">define</span> <span style="color: #2d9574;">(</span><span style="color: #bc6ec5; font-weight: bold;">iter-p</span> a result<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #2d9574;">(</span><span style="color: #4f97d7; font-weight: bold;">if</span> <span style="color: #67b11d;">(</span>> a b<span style="color: #67b11d;">)</span>
|
||||
result
|
||||
<span style="color: #67b11d;">(</span>iter-p <span style="color: #b1951d;">(</span>next a<span style="color: #b1951d;">)</span> <span style="color: #b1951d;">(</span>* result <span style="color: #4f97d7;">(</span>term a<span style="color: #4f97d7;">)</span><span style="color: #b1951d;">)</span><span style="color: #67b11d;">)</span>
|
||||
<span style="color: #2d9574;">)</span>
|
||||
<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>iter-p a <span style="color: #a45bad;">1</span><span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">pribl-pi-term</span> a<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>/ <span style="color: #2d9574;">(</span>* <span style="color: #67b11d;">(</span>- a <span style="color: #a45bad;">1.0</span><span style="color: #67b11d;">)</span> <span style="color: #67b11d;">(</span>+ a <span style="color: #a45bad;">1</span><span style="color: #67b11d;">)</span><span style="color: #2d9574;">)</span> <span style="color: #2d9574;">(</span>* a a<span style="color: #2d9574;">)</span><span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">pribl-pi-next</span> a<span style="color: #bc6ec5;">)</span> <span style="color: #bc6ec5;">(</span>+ a <span style="color: #a45bad;">2.0</span><span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</span>
|
||||
|
||||
<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;">pribl-pii</span> n<span style="color: #bc6ec5;">)</span>
|
||||
<span style="color: #bc6ec5;">(</span>produkt-i
|
||||
pribl-pi-term
|
||||
<span style="color: #a45bad;">3.0</span>
|
||||
pribl-pi-next
|
||||
n
|
||||
<span style="color: #bc6ec5;">)</span><span style="color: #4f97d7;">)</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 id="outline-container-org920469a" class="outline-3">
|
||||
<h3 id="org920469a"><span class="section-number-3">2.15.</span> 1.3.2 Sestavljanje procedur z <code>Lambda</code></h3>
|
||||
<div class="outline-text-3" id="text-2-15">
|
||||
<p>
|
||||
Splosna forma <code>let</code> izraza
|
||||
</p>
|
||||
|
||||
<pre class="example" id="orgc6db3ea">
|
||||
(let ((<var1> <exp1>)
|
||||
(<var2> <exp2>)
|
||||
...
|
||||
(<varn> <expn>))
|
||||
<body>)
|
||||
</pre>
|
||||
<p>
|
||||
To je okrajsava za
|
||||
</p>
|
||||
<pre class="example" id="org4ff7fd6">
|
||||
((lambda (<var1> ... <varn>)
|
||||
<body>)
|
||||
<exp1>
|
||||
...
|
||||
<exp2>
|
||||
)
|
||||
</pre>
|
||||
</div>
|
||||
</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 id="outline-container-orgb365f70" class="outline-3">
|
||||
<h3 id="orgb365f70"><span class="section-number-3">2.16.</span> 1.3.3 Procedure kot splosne metode</h3>
|
||||
<div class="outline-text-3" id="text-2-16">
|
||||
<p>
|
||||
Ce pogledamo proceduro za integral, vidimo mocnejse abstrakcije: procedure, ki
|
||||
izrazajo splosne racunske metode, neodvisne od posameznih vkljucenih funkcij.
|
||||
</p>
|
||||
</div>
|
||||
</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 id="outline-container-orge72480c" class="outline-3">
|
||||
<h3 id="orge72480c"><span class="section-number-3">2.17.</span> 1.3.4 Procedure kot vrnjene vrednosti</h3>
|
||||
<div class="outline-text-3" id="text-2-17">
|
||||
<p>
|
||||
V splošnem programski jeziki omejujo, kateri komputacijski elemente lahko (koda)
|
||||
spreminja. Elementi z najmanj omejitvami imajo <i>prvorazredni</i> status. Pravice in
|
||||
privilegiji prvorazrednih elementov so:
|
||||
</p>
|
||||
<ul class="org-ul">
|
||||
<li>lahko so poimenovani s spremenljivkami</li>
|
||||
<li>lahko so podani kot argumenti procedur</li>
|
||||
<li>lahko so vrnjeni kot rezultati procedur</li>
|
||||
<li>lahko so vključeni v podatkovne strukture</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
V Lispu imajo, za razliko od drugih programskih jezikov, procedure prvorazredni
|
||||
status. To predstavlja težave za implementacijo, ampak nudi višjo ekspresivno
|
||||
moč programskega jezika. Najvišja cena pri implementaciji procedur s
|
||||
prvorazrednim statusom je, da je potrebno rezervirati prostor za procedurine
|
||||
proste spremenljivke tudi, ko se procedura ne izvaja. V scheme-u so te
|
||||
spremenljivke shranjene v procedurino okolje (poglavje 4.1).
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<p class="author">Author: Lio Novelli</p>
|
||||
<p class="date">Created: 2024-05-29 Wed 21:50</p>
|
||||
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -202,14 +202,105 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
|
|||
|
||||
** 1.2.4 Eksponentna funkcija
|
||||
|
||||
#name: exponent
|
||||
#+begin_src scheme
|
||||
;; O(n) korakov in O(n) prostora
|
||||
(define (expt b n)
|
||||
(if (= n 0)
|
||||
1
|
||||
(* b (expt b (- n 1)))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(define (expt-i b n)
|
||||
(expt-iter b n 1)
|
||||
)
|
||||
|
||||
;; O(n) korakov O(1) prostor
|
||||
(define (expt-iter b cnt prod)
|
||||
(if (= cnt 0)
|
||||
prod
|
||||
(expt-iter b (- cnt 1) (* b prod))
|
||||
)
|
||||
)
|
||||
|
||||
(define (fast-expt b n)
|
||||
(cond
|
||||
((= n 0) 1)
|
||||
((even? n) (square (fast-expt b (/ n 2))))
|
||||
(else (* b (fast-expt b (- n 1))))
|
||||
)
|
||||
)
|
||||
|
||||
(define (even? n) (= (remainder n 2) 0))
|
||||
|
||||
(define (square x) (* x x))
|
||||
|
||||
;; 1.16
|
||||
;; successive squaring (fast-expt) but with iteration.
|
||||
;; transformation (* a (expt b n)) constant
|
||||
|
||||
(define (fast-expt-i b n)
|
||||
(fast-expt-iter b n 1)
|
||||
)
|
||||
|
||||
(define (fast-expt-iter b n a)
|
||||
(cond
|
||||
((= n 0) a)
|
||||
((even? n) (fast-expt-iter (square b) (/ n 2) a))
|
||||
(else (fast-expt-iter b (- n 1) (* a b)))
|
||||
)
|
||||
)
|
||||
|
||||
;; I'm not sure why this works. I was just guessing.
|
||||
|
||||
;; excersize 1.17
|
||||
(define (slow-multi a b)
|
||||
(if (= b 0) 0
|
||||
(+ a (* a (- b 1)))
|
||||
)
|
||||
|
||||
)
|
||||
(define (halve x) (/ x 2))
|
||||
(define (double x) (* x 2))
|
||||
(define (fast-multi a b)
|
||||
(cond
|
||||
((= b 0) 0)
|
||||
((even? b) (double (fast-multi a (halve b))))
|
||||
(else (+ a (fast-multi a (- b 1))))
|
||||
)
|
||||
)
|
||||
|
||||
;; excersize 1.18
|
||||
(define (fast-multi-i a b)
|
||||
(fast-multi-iter a b 0)
|
||||
)
|
||||
(define (fast-multi-iter a b s)
|
||||
(cond
|
||||
((= b 0) s)
|
||||
((even? b) (fast-multi-iter (double a) (halve b) s))
|
||||
(else (fast-multi-iter a (- b 1) (+ s a)))
|
||||
)
|
||||
)
|
||||
#+end_src
|
||||
|
||||
** 1.2.5 Najvecji skupni deljitel
|
||||
|
||||
** 1.2.6 Primer: Iskanje prastevil
|
||||
|
||||
** 1.3 Sestavljanje abstrakcij s procedurami visjega reda
|
||||
|
||||
Procedure, ki spreminjajo druge procedure se imenujejo *procedure višjega reda*.
|
||||
|
||||
** 1.3.1 Procedure kot argumenti
|
||||
|
||||
Primer vsote.
|
||||
|
||||
#+begin_src guile
|
||||
|
||||
#+end_src
|
||||
|
||||
//exercise 1.29
|
||||
#name: simpson
|
||||
#+begin_src scheme
|
||||
|
@ -284,8 +375,98 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.
|
|||
)
|
||||
#+end_src
|
||||
|
||||
** 1.3.2 Sestavljanje procedur z Lambda
|
||||
// excercise 1.30, 1.31. 1.32
|
||||
#+begin_src scheme
|
||||
;; Analogno napisi produkt kot vsoto.
|
||||
;; Pokazi kako izgleda fakulteta.
|
||||
;; Aproksimacija pi/4 = 2/3*4/3*4/5*6/5*6/7*8/7...
|
||||
|
||||
(define (produkt-r term a next b)
|
||||
;; a, b sta spodnja in zgornja meja
|
||||
(if (> a b)
|
||||
1
|
||||
(* (term a) (produkt-r term (next a) next b))
|
||||
)
|
||||
)
|
||||
|
||||
(define (fakulteta-p n)
|
||||
(produkt-r (lambda (x) x) 1 (lambda (x) (+ x 1)) n)
|
||||
)
|
||||
|
||||
(define (pribl-pi n)
|
||||
(produkt-r (lambda (a) (/ (* (- a 1.0) (+ a 1.0)) (* a a)))
|
||||
3.0
|
||||
(lambda (x) (+ x 2.0))
|
||||
n
|
||||
)
|
||||
)
|
||||
;; gizmo se je spomnil resitve - dva produkta (zgornji in spodnji)
|
||||
|
||||
;; iterativni produkt-i
|
||||
(define (produkt-i term a next b)
|
||||
(define (iter-p a result)
|
||||
(if (> a b)
|
||||
result
|
||||
(iter-p (next a) (* result (term a)))
|
||||
)
|
||||
)
|
||||
(iter-p a 1)
|
||||
)
|
||||
|
||||
(define (pribl-pi-term a)
|
||||
(/ (* (- a 1.0) (+ a 1)) (* a a)))
|
||||
|
||||
(define (pribl-pi-next a) (+ a 2.0))
|
||||
|
||||
(define (pribl-pii n)
|
||||
(produkt-i
|
||||
pribl-pi-term
|
||||
3.0
|
||||
pribl-pi-next
|
||||
n
|
||||
))
|
||||
#+end_src
|
||||
|
||||
** 1.3.2 Sestavljanje procedur z ~Lambda~
|
||||
|
||||
Splosna forma ~let~ izraza
|
||||
|
||||
#+begin_example scheme
|
||||
(let ((<var1> <exp1>)
|
||||
(<var2> <exp2>)
|
||||
...
|
||||
(<varn> <expn>))
|
||||
<body>)
|
||||
#+end_example
|
||||
To je okrajsava za
|
||||
#+begin_example scheme
|
||||
((lambda (<var1> ... <varn>)
|
||||
<body>)
|
||||
<exp1>
|
||||
...
|
||||
<exp2>
|
||||
)
|
||||
#+end_example
|
||||
|
||||
|
||||
** 1.3.3 Procedure kot splosne metode
|
||||
|
||||
Ce pogledamo proceduro za integral, vidimo mocnejse abstrakcije: procedure, ki
|
||||
izrazajo splosne racunske metode, neodvisne od posameznih vkljucenih funkcij.
|
||||
|
||||
** 1.3.4 Procedure kot vrnjene vrednosti
|
||||
|
||||
V splošnem programski jeziki omejujo, kateri komputacijski elemente lahko (koda)
|
||||
spreminja. Elementi z najmanj omejitvami imajo /prvorazredni/ status. Pravice in
|
||||
privilegiji prvorazrednih elementov so:
|
||||
- lahko so poimenovani s spremenljivkami
|
||||
- lahko so podani kot argumenti procedur
|
||||
- lahko so vrnjeni kot rezultati procedur
|
||||
- lahko so vključeni v podatkovne strukture
|
||||
|
||||
V Lispu imajo, za razliko od drugih programskih jezikov, procedure prvorazredni
|
||||
status. To predstavlja težave za implementacijo, ampak nudi višjo ekspresivno
|
||||
moč programskega jezika. Najvišja cena pri implementaciji procedur s
|
||||
prvorazrednim statusom je, da je potrebno rezervirati prostor za procedurine
|
||||
proste spremenljivke tudi, ko se procedura ne izvaja. V scheme-u so te
|
||||
spremenljivke shranjene v procedurino okolje (poglavje 4.1).
|
||||
|
|
Loading…
Reference in New Issue