Note that there are some explanatory texts on larger screens.

plurals
  1. POPractical Scheme Programming
    primarykey
    data
    text
    <p>It's been a few months since I've touched Scheme and decided to implement a command line income partitioner using Scheme.</p> <p>My initial implementation used plain recursion over the continuation, but I figured a continuation would be more appropriate to this type of program. I would appreciate it if anyone (more skilled with Scheme than I) could take a look at this and suggest improvements. I'm that the multiple <code>(display...</code> lines is an ideal opportunity to use a macro as well (I just haven't gotten to macros yet).</p> <pre><code>(define (ab-income) (call/cc (lambda (cc) (let ((out (display "Income: ")) (income (string-&gt;number (read-line)))) (cond ((&lt;= income 600) (display (format "Please enter an amount greater than $600.00~n~n")) (cc (ab-income))) (else (let ((bills (* (/ 30 100) income)) (taxes (* (/ 20 100) income)) (savings (* (/ 10 100) income)) (checking (* (/ 40 100) income))) (display (format "~nDeduct for bills:---------------------- $~a~n" (real-&gt;decimal-string bills 2))) (display (format "Deduct for taxes:---------------------- $~a~n" (real-&gt;decimal-string taxes 2))) (display (format "Deduct for savings:-------------------- $~a~n" (real-&gt;decimal-string savings 2))) (display (format "Remainder for checking:---------------- $~a~n" (real-&gt;decimal-string checking 2)))))))))) </code></pre> <p>Invoking <code>(ab-income)</code> asks for input and if anything below 600 is provided it (from my understanding) returns <code>(ab-income)</code> at the <code>current-continuation</code>. My first implementation (as I said earlier) used plain-jane recursion. It wasn't bad at all either but I figured every return call to <code>(ab-income)</code> if the value was below 600 kept expanding the function.</p> <p>(please correct me if that apprehension is incorrect!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload