scam FILENAMEor
scam -r FILENAMEwhere
FILENAME
is replaced by the name of the program you wish to run.
The
-r
option will automatically run a no-argument function named
main
on startup.
(define (main) (println "AUTHOR: Rita Recursion rrita@crimson.ua.edu") )with the name and email replaced by your own name and email.
(scoping 'y ((define (zurp x) (define y (+ x 1)) this) 5))should return the symbol
bound
because y is
a locally
defined variable.
The call:
(scoping '* ((define (zarp x) this) 5))should return the symbol
free
because
*
is not locally
defined in the function zarp.
(scoping 'cs403sucks ((define (zirp x) this) 5))should return the symbol
undefined
because
who would define a variable like
that?
$ cat task1.args (println (scoping 'cs403sucks ((define (zirp x) this) 5))) $ scam -r task1.scm task1.args undefined $
(define (square x) (* x x)) (define body (get 'code square)) (inspect body)You can get the formal parameters by substituting
'parameters
for
'code
in the get expression.
The code inspection displays the list
(begin (* x x))
whose car is the symbol
begin
and
whose cadr is the list
(* x x)
.
(set 'code '(begin (+ x x)) square) (inspect (square 5))The inspection should display the value 10. Likewise, you can update the formal parameters.
(replace square (list '* + '+ *))This call would replace the times symbol with the adding built-in and the plus symbol with the multiplying built-in.
$ cat task2.args (define (abs n) (if (< n 0) (- n) n)) (replace abs (list '< < '- -)) (inspect (get 'code abs)) $ scam -r task2.scm task2.args (get (quote code) abs) is (begin (if (<builtin <(@)> n 0) (<builtin -(@)> n) n)) $You may use assignment for this task.
((dq'enqueueFront) value) ((dq'enqueueBack) value) ((dq'enqueueIndex) index value) ((dq'dequeueFront)) ((dq'dequeueBack)) ((dq'dequeueIndex) index) ((dq'display)) ((dq'peekFront)) ((dq'peekBack)) (dq'size)The enqueue methods should return the item enqueued while the dequeue methods should return the item dequeued. All methods should run in constant time except enqueueIndex and dequeueIndex. The enqueueIndex method runs in constant time when the index is a constant distance from the front and in linear time otherwise. Likewise, the dequeueIndex method runs in constant time when the index is a constant distance from the back and in linear time otherwise. The enqueueIndex function places the new value such that it occupies the given index, using zero-based counting. The dequeueIndex also uses zero-based counting and returns the item dequeued. The display function prints out the values in the dequeue, separated by commas with no added spaces.
$ cat task3.args (define dq (deque)) ((dq'enqueueFront) 3) ((dq'enqueueBack) 5) (inspect ((dq'dequeueFront))) (inspect ((dq'dequeueBack))) (inspect (dq'size)) (print "-") ((dq'display)) (println "-") $ scam -r task3.scm task3.args ((dq (quote dequeueFront))) is 3 ((dq (quote dequeueBack))) is 5 (dq (quote size)) is 0 -[]- $You may use assignment for this task.
wget beastie.cs.ua.edu/proglan/queue.scm wget beastie.cs.ua.edu/proglan/gates.scmUse your gates to build a half-adder and a full-adder, as in the text.
(include "queue.scm") (include "gates.scm") (include "nand.scm") (define the-agenda (make-agenda)) (define (main) ...) ...Example:
$ cat task4.args (define input-1 (make-wire)) (define input-2 (make-wire)) (define sum (make-wire)) (define carry (make-wire)) (probe 'sum sum) (probe 'carry carry) (half-adder input-1 input-2 sum carry) (set-signal! input-1 1) (propagate) (set-signal! input-2 1) (propagate) (println) $ scam -r task4.scm task4.args sum 0 New-value = 0 carry 0 New-value = 0 carry 6 New-value = 1 sum 6 New-value = 1 carry 12 New-value = 0 sum 12 New-value = 0 sum 18 New-value = 1 sum 24 New-value = 0 sum 30 New-value = 1 carry 42 New-value = 1 sum 60 New-value = 0 $The extra newline at the beginning is due to the way the text implements the probe function. You may use assignment for this task.
$ cat task5.args (define ones (cons-stream 1 ones)) (sdisplay 12 (smush ones +)) (println) $ scam -r task5.scm task5.args (0,1,1,1,1,2,2,1,3,3,1,4,...) $For every triplet, the first number, i, is the index of the second number in the original stream. The third number is the accumulation of the first zero through i elements. Use left associativity when combining.
(quad 1 3 -4 0.01)
would produce the stream representing the equation
$f={x}^{2}+3x-4$.
The step argument, s, gives the distance between evaluations
of the quadratic, starting at zero. The stream produced would
be equivalent to $\left(f\right(0),f(s),f(2s),f(3s),...)$.
f(0)
is given as the constant,
then
an integrated quadratic stream passed to derivate
should produce the original quadratic stream.
$ cat task6.args (define qs (quad 1 0 0 1)) (define is (integrate qs 1)) (define ds (derivate is 1 0)) (sdisplay 5 qs) (println) (sdisplay 5 is) (println) (sdisplay 5 ds) (println) (inspect (same-stream? qs ds 10 .001)) $ scam -r task6.scm task6.args (0.000000e+00,1.0000000000,4.0000000000,9.0000000000,16.000000000,...) (0.000000e+00,0.5000000000,3.0000000000,9.5000000000,22.000000000,...) (0.000000e+00,1.0000000000,4.0000000000,9.0000000000,16.000000000,...) (same-stream? qs ds 10 0.0010000000) is #t $
(mystery x)
. Define a function named
acc-mystery that accelerates
(ps-mystery x)
using the Euler transform.
Define a function named super-mystery that produces a super accelerated
stream using a tableau of ever-accelerated partial sum streams. All of these
function takes x as their sole arguments.
Define a function named symbolic-mystery that
prints the symbolic result (as a LaTeX math expression) of the series sum, when taken out to infinity.
For example, if the answer is $\pi $,
then
(mystery x) is $\pi$
would be printed.
If the answer is $\mathrm{log}\pi $,
then
(mystery x) is $\log\pi$
would be printed.
In this last example, note the lack of parentheses.
If there is more than one reasonable way to represent the answer,
prefer the one with the fewer number of characters in the LaTeX expression.
Prefer symbolic renderings over numeric ones and
integers over integers rendered as real numbers.
Do not use parentheses except for grouping.
If you are unsure which rendering is best, ask me privately.
Note that the dollar signs in the output
are mandatory. Do not share this answer in any way.
$ cat task7.args (define x 0) (sdisplay 5 (mystery x)) (println) (sdisplay 5 (ps-mystery x)) (println) (sdisplay 5 (acc-mystery x)) (println) (sdisplay 5 (super-mystery x)) (println) (symbolic-mystery) $ scam -r task7.scm task7.args (1.0000000000,-0.000000e+00,0.000000e+00,-0.000000e+00,0.000000e+00,...) (1.0000000000,1.0000000000,1.0000000000,1.0000000000,1.0000000000,...) (1.0000000000,1.0000000000,1.0000000000,1.0000000000,1.0000000000,...) (1.0000000000,1.0000000000,1.0000000000,1.0000000000,1.0000000000,...) (mystery x) is $\log\pi$ $Of course, $\mathrm{log}\pi $ is not the answer. Or is it?
$ cat task8.args (sdisplay 1 (ramanujan)) (println) $ scam -r task8.scm task8.args (1729,...) $
submit proglan lusth test3For your final submission, use the command:
submit proglan lusth assign3