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.
(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.
(define (main) (setPort (open (getElement ScamArgs 1) 'read)) (println (apply zeno (readExpr))) )Example:
$ echo "(1 1 1)" > task1.args $ scam -r task1.scm task1.args 0.0833333333 $Constraints: division should always be real number division.
$ echo "(1 2 3)" > task2.args $ scam -r task2.scm task2.args 4 $Constraints: Your implementation should use the minimum number of comparisons, semantically speaking. You are only allowed to call the
<
function to do your comparisons
and you must only pass two arguments.
You may not use local defines.
(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-1}{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-1}{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 0, 0 when i is t-1,
and 255 when i is $\genfrac{}{}{0.1ex}{}{t-1}{2}$.
The three color functions should return zero when
i is equal to t.
In calculating color values,
convert to an integer at the last moment
by rounding.
$ echo "(0.0 0.0 100)" > task3.args $ scam -r task3.scm task3.args 100 0 0 0 $Constraints: You are only allowed the following top-level functions: main, resistance, mred, mgreen, and mblue. They must be defined in the order given. The only local definitions allowed are functions definitions. You are only allowed to call each of these functions once. Use a value of 3.14159265358979323846 for $\pi $.
$ echo "(1)" > task4.args $ scam -r task4.scm task4.args 1.0000000000 $Constraints: Input is a positive number, either a real number or an integer. Test for convergence by comparing consecutive guesses to see if they are close enough; do not compare with strict equality. Your function root12 should return a real number. Your main function should not do any special formatting when printing the result. You may only have two top level functions, main and root12.
(pt 1)
should print out:
1while
(pt 3)
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 "(1)" > task4.args $ scam -r task4.scm task4.args 1 $Constraints: You are only allowed the following top-level functions: main and pt. The bottom row in your triangle should have no preceding spaces. Higher rows should be indented, as shown, with spaces. Your method for computing a single element in the triangle should implement a recursive process using the traditional recursive method. The pt function should return
nil
after printing the rows of
the triangle.
(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.args $ echo "(2)" >> task6.args $ echo "(1 2)" >> task6.args $ echo "(3)" >> task6.args $ scam -r task6.scm task6.args (length (get (quote parameters) f1)) is 2 (length (get (quote parameters) f2)) is 1 7 $Constraints: You are only allowed the following top-level functions: main and pfa.
$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.args $ scam -r task7.scm task7.args 0 $Constraints: You are only allowed the following top-level functions: main and zarp. Your zarp 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 |
(define (main) (setPort (open (getElement ScamArgs 1) 'read)) (define args (readExpr)) (println "half of " (car args) " is " (halve (car args))) (println "half of " (cadr args) " is " (halve (cadr args))) (println (car args) " squared is " (square (car args))) (println (cadr args) " squared is " (square (cadr args))) (println (apply babyl args)) )Example:
$ echo "(21 42)" > task8.args $ scam -r task8.scm task8.args half of 21 is 10 half of 42 is 21 21 squared is 441 42 squared is 1764 882Constraints: You are only allowed the following top-level functions: main, babyl, square, and halve. The only built-in mathematical operations allowed are addition and subtraction. The functions babyl, square and halve should implement iterative processes. 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 returns 1 imystery returns 1 ? $The question mark in the last line of output, of course, should be 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.
Do not share this answer in any way.
$ echo "(0)" > task10.text $ scam -r task10.scm task10.text ramanujan ramanujan returns 0.000000e+00 iramanujan returns 0.000000e+00 ? $The question mark in the last line of output, of course, should be 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.
Do not share this answer in any way.
submit proglan lusth test1For your final submission, use the command:
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.