教授が英語で宿題出しやがったんだけど。。。 これ、解ける人いたらどういう問題か教えてくれんか? you must write to primary functions:
(defun evaluate (expression a b) (....)) This function takes any lisp expression and evaluates it with the stipulation that the values passed in through a and b are mapped to x and y, so that if the expression uses the values x and y, the values passed in through a and b will be used in their place.
(defun mutate (expression) (....)) This function will take a mathematical expression, change it according to random rules, and return the resulting new "mutant" expression. Valid input for the function is the list (+ x y) or any expression output by a properly implemented mutate function.
Modifying Mathematical Expressions in Lisp tips:
(random 1.0) ;; generates a random float between 0 and 1 (random 3) ;; generates a random int less than 3 (0, 1, or 2)
915 名前:914(続き) mailto:sage [04/11/02 07:27:48]
rules:
operand rule (rule 1): 20% the operand will become x 20% the operand will become y 60% the operand will be a random float in [0,1]
operator rule (rule 2): 30% of the time the operator will be: + 30% of the time the operator will be: - 30% of the time the operator will be: * 10% of the time the operator will be: expt
mutation: an expression will mutate exactly in one place 20% the operator 40% the first operand 40% the second operand
if an operand is itself an expression, then the mutation will recurse down that branch to select the location of mutation
if an operand is selected it will mutate according to the following rules 60% the operand will mutate according to rule 1 40% the operand will expand the new operator will be selected according to rule 2 the first operand will be identical to the original operand the second operand will be selected according to rule 1
916 名前:914(続き) mailto:sage [04/11/02 07:28:16]
if an operator is selected the possibilities are: 80% the operator will mutate according to rule 2 20% the operator will colapse into an operand according to rule 1
> 20% the operator will colapse into an operand according to rule 1 これの意味がわからん。 20% the expression will colapse into an operand according to rule 1 ということか?
(define evaluate-1 (lambda (op opr1 opr2 a b) (apply (cdr (assoc op *operator*)) (list (cond ((eq? opr1 'x) a) ((eq? opr1 'y) b) (else opr1)) (cond ((eq? opr2 'x) a) ((eq? opr2 'y) b) (else opr2))))))
(define evaluate (lambda (expression a b) (let ((op (car expression)) (opr1 (cadr expression)) (opr2 (caddr expression))) (evaluate-1 op (if (pair? opr1) (evaluate opr1 a b) opr1) (if (pair? opr2) (evaluate opr2 a b) opr2) a b))))
; (evaluate '(+ 4.1 (- y (* x 2.1))) 2.3 3.3) -> 2.5699999999999994
1) Gauche: unarguably best Unicode support, including native read/write syntax for strings, chars, regexps & char-sets; support for SRFI-13 & SRFI-14; charconv libraries and extensions to I/O procedures to specify encoding for ports, including auto-detection of Japanese encodings.
2) PLT >= v299: native Unicode support; regexps and SRFI-13 are Unicode-aware, SRFI-14 is not; port encodings assumed UTF-8.
3) Gambit: native Unicode support, no regexp or SRFI support, encoding for files and terminal is fixed at startup time and limited to Latin-1 or common Unicode encodings (UCS-2, UCS-4 or UTF-8).
4) SISC/Kawa/Jscheme: leverages Java Unicode support; SISC has Unicode aware SRFI-13, Unicode unaware SRFI-14, the others have neither; encoding is determined by default by locale, but SISC and Kawa provide port encoding procedures; Java uses UTF-16 internally which may cause complications with surrogate pairs.
7) Chicken: characters are allowed within the full 21-bit Unicode range, however by default the non-ASCII characters have no read/write syntax. I have a unit almost ready for release that leverages this and assumes UTF-8 encoded strings/ports to provide full Unicode support, including regexps, SRFI-13 and SRFI-14. Chicken has an iconv interface, and I also have a unit with a more friendly interface such as (with-input-from-encoded-file enc file thunk).
8) MIT-Scheme: Unicode chars strings are disjoint types; 'alphabet' type as Unicode-char alternative to char-sets; Unicode string ports; no port encoding utilities.
9) Bigloo: Unicode strings and characters are disjoint types; no port encoding utilities.