about summary refs log blame commit diff stats
path: root/arc/mu
blob: 858438b8c04030990929ff16650d0d40f548760f (plain) (tree)
1
2
3
4
5
6
7
8
9
           
 





                                  
 

                                                                          




                                                                                           







                                    


                                                            
#!/bin/bash
#
# To run a program:
#   $ mu [mu files]
# To run a file of tests (in arc):
#   $ mu test [arc files]
# To start an interactive session:
#   $ mu repl
#
# To mess with load levels and selectively run parts of the codebase, skip
# this script and call load.arc directly.

if [[ $1 == "test" ]]
then
  shift
  ./anarki/arc load.arc "$@"  # test currently assumed to be arc files rather than mu files
elif [[ $1 == "repl" ]]
then
  if [ "$(type rlwrap)" ]
  then
    rlwrap -C mu ./anarki/arc mu.arc
  else
    ./anarki/arc mu.arc
  fi
else
  ./anarki/arc load.arc mu.arc -- "$@"  # mu files from args
fi
ll your evaluator always look up FOO before looking up A? Explain why or why not. (c) Show an example interaction with Scheme in which the result of the interaction depends on whether or not the procedure expression is evaluated before the argument expressions. 3. Modify the metacircular evaluator to allow type-checking of arguments to procedures. Here is how the feature should work. When a new procedure is defined, a formal parameter can be either a symbol as usual or else a list of two elements. In this case, the second element is a symbol, the name of the formal parameter. The first element is an expression whose value is a predicate function. That function should return #t if the argument is valid. For example, here is a procedure foo that has type-checked parameters num and list: > (define (foo (integer? num) ((lambda (x) (not (null? x))) list)) (nth num list)) FOO > (foo 3 '(a b c d e)) C > (foo 3.5 '(a b c d e)) Error: wrong argument type -- 3.5 > (foo 2 '()) Error: wrong argument type -- () In this example we define a procedure foo with two formal parameters, named num and list. When foo is invoked, the evaluator will check to see that the first actual argument is an integer and that the second actual argument is not empty. The expression whose value is the desired predicate function should be evaluated with respect to foo's defining environment. 4. Suppose you have a procedure that takes several arguments, e.g., (define (foo a b c d e f) ...) Now you want to invoke this procedure. You are providing values explicitly for the parameters a and b, but you have the remaining arguments in a list. If you had all the arguments in a list, you could say (apply foo arglist) but instead you have to say something awkward like (apply foo (cons a-value (cons b-value arglist))) We'd like to invent a new notation, allowing you to invoke the procedure by saying (foo a-value b-value . arglist) In this notation, arglist must be a symbol whose value is a list. Your job is to modify the metacircular evaluator to accept this notation. NOTE 1: Although this looks similar to the notation (define (foo a b . args) ...) used to create a procedure that accepts variable numbers of arguments, it's not the same feature. This time we're talking about the invocation of the procedure, not the definition of the procedure. NOTE 2: You should assume that the (read) procedure has already taken care of translating the dot notation into an improper list, which is what you'll see as the expression to be evaluated.