scam FILENAMEwhere
FILENAME
is replaced by the name of the program you wish to run.
All assignment submissions should supply a program named author.scm.
This program should look like:
(define (main) (println "AUTHOR: Rita Recursion rrita@crimson.ua.edu") ) (main)with the name and email replaced by your own name and email.
(define (main) (setPort (open (getElement ScamArgs 1) 'read)) (println (apply fact (readExpr))) ) (define (fact n) (if (< n 2) 1 (* n (fact (- n 1)))) )The expression beginning with setPort sets the input file pointer to the file named by the first command line argument. The file should contain a parenthesized list of the arguments to be passed to the fact function. The readExpr call in the second expression reads this list of arguments and returns them to the apply function, which passes these arguments to the fact function. Here is one way to run the task5 program.
$ echo "(5)" > task5.text $ scam -r task5.scm task5.text 120 $The filename task5.text is the first command-line argument. The
-r
option informs Scam to run the main function after the program
has been loaded.
(println " The quick brown fox m u p j e d over the lazy dog ")which will print out as:
The quick brown fox m u p j e d over the lazy dogA useful debugging function inspect. Here is an example usage:
(inspect (+ 2 3))which produces the output:
(+ 2 3) is 5Another useful debugging function is pause. It takes no arguments, stopping execution until a newline is entered from the keyboard.
(inspect (cond ((= x y) 0) ((> x y) 1) ((< x y) -1) ) )and
(inspect (my-cond (= x y) 0 (> x y) 1 (< x y) -1 ) )where my-cond is defined as
(define (my-cond @) (define (iter items) (if (null? items) nil (if (car items) (cadr items) (iter (cddr items)) ) ) ) (iter @) )In particular, give a concrete example in which the behavior is different. You will need to come up with specific cases that show this difference.
$ scam -r task1.scm When the fribberjab of the blorsch is in gurble, then cond will wassulate while my-cond will quaterroff. $
$ echo "(1 2 3)" > task2.text $ scam -r task2.scm task2.text sum 4 $ scam -r task2.scm task2.text comparisons 6 $Note: the number of comparisons shown may or may not be minimal. You can test the second command-line argument with the equal? predicate:
(if (equal? (getElement 2 ScamArgs) "sum") ...)Constraints: Your implementation should use the minimum number of comparisons, both logically and syntactically. Your implementation should also use a minimum of darkspace. You are only allowed to call the
<
function to do your comparisons.
Do not use lists to solve this problem.
(x,y)
being in the set if the
following iteration never diverges to infinity:
mred(i,t)
should return 255
when i is 0,
0 when i is t-1,
and 180 when i is $\genfrac{}{}{0.1ex}{}{t}{2}$.
The mblue function should
model a sine wave that spans a quarter cycle, as well.
The call
mblue(i,t)
should return 0
when i is 0, 255 when i is t-1,
and 180 when i is $\genfrac{}{}{0.1ex}{}{t}{2}$.
The mgreen function should model a sine wave that
spans a half cycle.
The call
mgreen(i,t)
should
return 0 when i is 1, 0 when i is t-1,
and 255 when i is $\genfrac{}{}{0.1ex}{}{t}{2}$.
The three color functions should return zero when
i is equal to t.
$ echo "(0.0 0.0 100)" > task3.text $ scam -r task3.scm task3.text 100 0 0 0 $Constraints: You are not allowed to use any local definitions or lets. You are only allowed to call resistance once. Use a value of 3.14159265358979323846 for $\pi $.
$ echo "(1)" > task4.text $ scam -r task4.scm task4.text 1.000000 $
(pt 0)
should print out:
1while
(pt 2)
should print out:
1 1 1 1 2 1Don't worry if the triangle gets skewed to the right when entries become greater than 9.
$ echo "(0)" > task4.text $ scam -r task4.scm task4.text 1 $Constraints: the bottom row should have no preceding spaces. Higher rows should be indented, as shown, with spaces.
(define (f x y z) (+ x (* y z))) (f a b c) (((pfa f 2) a b) c)The function that takes the remaining arguments will need to be variadic. You will also need to use the cons function and the apply function (the same function as found in your main function). Here are some examples of a variadic function using cons and apply:
(define (plus0 @) (apply + @)) (define (plus1 a @) (apply + (cons a @))) (define (plus2 a b @) (apply + (cons a (cons b @)))) (plus0 1 2 3 4 5) (plus1 1 2 3 4 5) (plus2 1 2 3 4 5) (+ 1 2 3 4 5)The last four expressions should evaluate to the same result.
(define (main) (setPort (open (getElement ScamArgs 1) 'read)) (define f (readExpr)) (define first (readExpr)) (define second (readExpr)) (define third (readExpr)) (define f1 (apply pfa (cons (eval f this) first))) (define f2 (apply f1 second)) (define f3 (apply f2 third)) (inspect (length (get 'parameters f1))) (inspect (length (get 'parameters f2))) (println f3) )Example:
$ echo "(define (f x y z) (+ x (* y z)))" > task6.text $ echo "(2)" >> task6.text $ echo "(1 2)" >> task6.text $ echo "(3)" >> task6.text $ scam -r task5.scm task5.text (length (get (quote parameters) f1)) is 2 (length (get (quote parameters) f2)) is 1 7 $
$zarp\left(i\right)=i$ | if $i<3$ |
$zarp\left(i\right)=zarp(i-1)+2\times zarp(i-2)-zarp(i-3)$ | otherwise |
$ echo "(0)" > task7.text $ scam -r task7.scm task7.text 0 $Constraints: Your function must implement an iterative process.
$square\left(i\right)=1$ | if $i=1$ |
$square\left(i\right)=square(i-1)+i+i-1$ | otherwise |
$ echo "(21 42)" > task8.text $ scam -r task8.scm task8.text babyl 882 $ echo "(42)" > task8.text $ scam -r task8.scm task8.text square 1764 $ echo "(21)" > task8.text $ scam -r task8.scm task8.text halve 10Constraints: The only built-in mathematical operations allowed are addition and subtraction. The functions square and halve should implement an iterative process. The halve function must run in sub-linear time.
e = [2; 1,2,1, 1,4,1, 1,6,1, 1,8,1, 1,10,1, ...]In this notation, 2 is the augend and the remaining numbers represent the continued fraction addend. The numbers specify the denominators in the continued fraction (the numerators are all assumed to be one). For example, the list
[2; 1,2,3]is represented in fraction form as:
[1; 1,1,1, 5,1,1, 9,1,1, 13,1,1, ...]Define a function called mystery that when given an integer argument n, computes the value of this equation to n terms (where each term is a group of three digits in the series above).
$ echo "(0)" > task9.text $ scam -r task9.scm task9.text mystery 1 $ scam -r task9.scm task9.text imystery 1 $ scam -r task9.scm task9.text infinite ? $The question mark in the last interaction are, of course, replaced with the LaTeX math equation that represents the answer. For example, if the answer was $\pi $, then the question mark would be replaced by
$\pi$
. If the answer is
$\mathrm{log}\pi $, then the question mark would be replaced by
$\log\pi$
.
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.
$ echo "(0)" > task10.text $ scam -r task10.scm task10.text ramanujan 0 $ scam -r task10.scm task10.text iramanujan 0 $ scam -r task10.scm task10.text answer ? $The question mark in the last interaction are, of course, replaced with the LaTeX math equation that represents the answer. For example, if the answer was $\pi $, then the question mark would be replaced by
$\pi$
. If the answer is
$\mathrm{log}\pi $, then the question mark would be replaced by
$\log\pi$
.
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.
make clean
and then
send me all the files in your directory by running the command:
submit proglan lusth test1For your final submission, run a
make clean
and use the command:
submit proglan lusth assign1Again, your implementation may be developed on other hardware and operating systems, but it must also compile and run cleanly and correctly on a Linux system.
submit proglan lusth assign1The submit program will bundle up all the files in your current directory and ship them to me. Thus it is very important that only the files related to the assignment are in your directory (you may submit test cases and test scripts). This includes subdirectories as well since all the files in any subdirectories will also be shipped to me, so be careful. You may submit as many times as you want before the deadline; new submissions replace old submissions.