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 noargument 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.
(nloop (lambda (x y) (inspect (list x y))) '(0 2) '(0 3))should produce the following output:
(list x y) is (0 0) (list x y) is (0 1) (list x y) is (0 2) (list x y) is (1 0) (list x y) is (1 1) (list x y) is (1 2)Example:
$ # (nloop (lambda (x) (inspect x)) (0 1)) $ echo "(lambda (x) (inspect x))" > task1.args $ echo "((0 1))" >> task1.args $ scam r task1.scm task1.args x is 0 $Define your main such that it evaluates the first expression read, as in pfa task in the previous assignment.
(define (f x y z) (+ x y z)) (f a b c) ((pfa f) a b c) ((pfa f a) b c) ((pfa f a b) c) ((pfa f a b c))If the wrong number of arguments are supplied, you should throw one of the following exceptions:
(throw 'MALFORMED_FUNCTION_CALL "too many arguments") (throw 'MALFORMED_FUNCTION_CALL "too few arguments")Example:
$ # ((pfa f 1) 1) $ echo "(define (f a b) (+ a b))" > task2.args $ echo "(1)" >> task2.args $ echo "(1)" >> task2.args $ scam r task2.scm task2.args 2 $Your main will need to evaluate the first expression.
+
,

,
*
,
/
, and
^
where
^
represents the exponentiation
operator.
The precedence of the operators increases in the order given.
Thus
+
has
the lowest precedence while
^
has the
highest precedence.
As an example,
(infix>postfix '(2 + 3 * x ^ 5 + a))would return the list:
(2 3 x 5 ^ * + a +)Note that all operators are left associative.
$ # (infix>postfix '(2 + 3)) $ echo "(2 + 3)" > task3.args $ scam r task3.scm task3.args (2 3 +) $
(if2cond `(if (< a b) a b))should return the list:
(cond ((< a b) a) (else b))Both functions should work recursively. That is, both should handle nested ifs and nested conds, respectively You may assume that all ifs have both a true expression and a false expression and that all conds have an else. You may also assume that each action of a cond clause and both clauses of an if are single expressions and are neither begin blocks and nor lambda expressions.
# (if2cond '(if #t 0 1)) # (cond2if '(cond (#t 0) (else 1))) $ echo "(if #t 0 1)" > task4.args $ echo "(cond (#t 0) (else 1))" >> task4.args $ scam r task4.scm task4.args (cond (#t 0) (else 1)) (if #t 0 1) $
(define (identity x) x)Understand that we are not defining zero as the identity function but as a function that returns the identity function.
(define (increment number) (lambda (incrementer) (define (resolver base) (incrementer ((number incrementer) base)) ) resolver ) )We can see that incrementing zero is equivalent to defining one as:
(lambda (incrementer) (define (resolver base) (incrementer base) ) resolver )Next, define two functions named add and multiply that add and multiply two of these functional numbers, respectively. Your add routine should add numbers directly (i.e. without using increment and the like).
$ echo "(define num1 (lambda (f) (lambda (x) x)))" > task5.args $ echo "(define num2 (lambda (f) (lambda (x) (f x))))" >> task5.args $ echo "(define (inc x) (+ x 1))" >> task5.args $ echo "(define base 0)" >> task5.args $ scam r task5.scm task5.args 1 0 $Your main function should evaluate all four expressions and the print the following expressions;
(((add num1 num2) inc) base) (((multiply num1 num2) inc) base)Constraints: You are only allowed the following toplevel functions: main, increment, add, and multiply. Your add function should not use the increment function. Your multiply function should not use the add function. You will likely need to do some research on Church numerals.
$ # (map+ + (1 2 3) (4 5 6) (7 8 9)) $ echo "+" > task6.args $ echo "((1 2 3) (4 5 6) (7 8 9))" >> task6.args (12 15 18) $Your main function should evaluate the first expression and should apply map+ to the cons of the evaluated first expression and the second expression.
((7 6) (6 7) (5 5) (4 3) (3 1) (2 4) (1 2) (0 0))Note that the row numbers and column numbers start with 0 (unlike the textbook version). Note also that the above solution is incorrect.
#t
) or high to low (if the flag is
#f
).
If there is no solution, queens should return the empty list.
'h
s and
't
s, generates a list function that
extracts the appropriate element(s). An
'h
implies taking
the car while a
't
implies taking the cdr. Actions should
be performed from left to right. For example:
(extract 't '(1 2 3 4))should return
(2 3 4)
. Also,
(extract 'th '(1 2 3 4))should return 2.
(extract 'ht '((1) 2 3 4))should return
nil
.
(car (string 'htt)) (cdr (string 'htt))The two expressions above evaluate to
"h"
and
"tt"
.
""
is equivalent to nil.
$ echo hht > task8.args $ echo (((1 2)) 3) >> task8.args $ scam r task8.scm task8.args (2) $
(4 9 1 8 0 3 9)
.
$ echo (1 2) > task9.args $ echo (3 4) >> task9.args $ scam r task9.scm task9.args (1 2) plus (3 4) is (4 6) (1 2) minus (3 4) is ( 2 2) (1 2) times (3 4) is (4 0 8) (1 2) divided by (3 4) is (0) $Negative numbers should be represented by a leading minus sign. For example, the number 4918039 would be represented by the list
( 4 9 1 8 0 3 9)
.
Note: the minus sign is the symbol generated by
(quote )
,
not the builtin subtraction
function.
(define old+ +)and then redefining new ones, as in:
(define (+ a b) ... )The new functions should call the old functions, if appropriate. Furthermore, if the operation processing two regular integers will cause an overflow or underflow, the regular integers should be first converted to big integers. Conversely, if a big integer result fits into a regular integer, the big integer should be converted to a regular integer. For easy of testing, assume an regular integer ranges from ${2}^{15}$ to ${2}^{15}1$. Examples:
(+ 234 5) ;yields a regular int (+ '(2 3 4) 5) ;yields a regular int (+ 234 '(5)) ;yields a regular int (+ 32767 32767) ;yields a big int (* 10000 4) ;yields a big int ( '(4 0 0 0 0) '(1 0 0 0 0)) ;yields a regular intYour functions cannot refer to any regular integers outside the assumed range.
submit proglan lusth test2For your final submission, use the command:
submit proglan lusth assign2