diff --git a/bracket/bracket-lang.rkt b/bracket/bracket-lang.rkt index 8efdda327..23afebc5d 100644 --- a/bracket/bracket-lang.rkt +++ b/bracket/bracket-lang.rkt @@ -19,6 +19,3 @@ #'(begin (define sym 'sym) ... (set! sym 'sym) ...)])) - - - diff --git a/bracket/bracket.rkt b/bracket/bracket.rkt index 007b0f851..7d0f0dcbf 100644 --- a/bracket/bracket.rkt +++ b/bracket/bracket.rkt @@ -728,32 +728,7 @@ -#;(module pattern-matching racket - (require (submod ".." expression)) - (define (linear-form u x) - ; u expression, x a symbol - (if (eq? u x) - (list 1 0) - (case (kind u) - [(symbol-id integer fraction real complex) - (list 0 u)] - [(Times) - (if (free-of u x) - (list 0 u) - (let ([u/x (Quotient u x)]) - (if (Free-of u/x x) - (list u/x 0) - #f)))] - [(Plus) - (let ([f (linear-form (operand u 1) x)]) - (and f - (let ([r (linear-form (Minus u (operand u 1)))]) - (and r - (list (+ (operand f 0) (operand r 0)) - (+ (operand f 1) (operand r 1)))))))] - [else - (and (free-of u x) - (list 0 u))])))) + (module equation-expression racket (require (submod ".." expression)) @@ -1215,7 +1190,35 @@ ; (eq? (Kind exponent) 'integer) ; (> exponent 1)) ) - + + +#;(module pattern-matching racket + (require (submod ".." expression) + (submod ".." bracket)) + (define (linear-form u x) + ; u expression, x a symbol + (if (eq? u x) + (list 1 0) + (case (kind u) + [(symbol-id integer fraction real complex) + (list 0 u)] + [(Times) + (if (free-of u x) + (list 0 u) + (let ([u/x (Quotient u x)]) + (if (Free-of u/x x) + (list u/x 0) + #f)))] + [(Plus) + (let ([f (linear-form (operand u 1) x)]) + (and f + (let ([r (linear-form (Minus u (operand u 1)))]) + (and r + (list (+ (operand f 0) (operand r 0)) + (+ (operand f 1) (operand r 1)))))))] + [else + (and (free-of u x) + (list 0 u))])))) (module test racket (require (submod ".." symbolic-application) diff --git a/bracket/examples/newton-iteration.rkt b/bracket/examples/newton-iteration.rkt index 1ff59e976..945375a5d 100644 --- a/bracket/examples/newton-iteration.rkt +++ b/bracket/examples/newton-iteration.rkt @@ -24,7 +24,7 @@ NestList(f,expr,n):=if(n=0, List(expr), Cons(expr, NestList(f,f(expr),n-1))); % Use it! NestList(next,x0,7); % NestList also works symbolically. -DeclareVars(g,x); -NestList(g,x,5); +%DeclareVars(g,x); +%NestList(g,x,5); % We can get the first approximations as symbolical expressions. Not pretty. -NestList(next,x,2); +%NestList(next,x,2); diff --git a/bracket/lang/parser.rkt b/bracket/lang/parser.rkt index 4457cd8f8..9f938f865 100644 --- a/bracket/lang/parser.rkt +++ b/bracket/lang/parser.rkt @@ -145,11 +145,14 @@ ; - A number representing the ending position of the match (or #f if eof). (define (syn-val a b c d e) - (values a b c - (position-offset d) + (values a ; string with mathching text + b ; symbol in '(comment white-space no-color eof) + c ; symbol in '(|(| |)| |[| |]| |{| |}|) or #f. + (position-offset d) ; start pos #;(position-offset e) - (max (position-offset e) - (+ (position-offset d) 1)))) + (max ; end pos + (position-offset e) + (+ (position-offset d) 1)))) (define color-lexer ; REMEMBER to restart DrScheme to test any changes in the color-lexer. @@ -175,8 +178,10 @@ ; different identifiers to see whether := or ( comes after the identfier. ; This is enough to prevent shift/reduce conflicts between atom, definition, ; and application. - [(:or identifier:= identifierOP identifier) + [":=" (syn-val lexeme 'symbol #f start-pos end-pos)] + [identifier + (syn-val lexeme 'symbol #f start-pos end-pos)] [(:+ digit) (syn-val lexeme 'constant #f start-pos end-pos)] [(:: (:+ digit) #\. (:* digit)) diff --git a/bracket/lang/reader.rkt b/bracket/lang/reader.rkt index 07ddcc511..8f8bb284f 100644 --- a/bracket/lang/reader.rkt +++ b/bracket/lang/reader.rkt @@ -69,7 +69,7 @@ (define list-ref List-ref) (define-syntax (define stx) (syntax-case stx () [(_ . more) #'(Define . more)])) - (require bracket/lang/parser) + (require bracket/lang/parser) #;(current-read-interaction (λ (_ in) (parse-expression 'repl #'repl in)))