Refinement of Check Syntax arrows
This commit is contained in:
parent
deed9e2af7
commit
553318ffd0
|
@ -19,6 +19,3 @@
|
||||||
#'(begin
|
#'(begin
|
||||||
(define sym 'sym) ...
|
(define sym 'sym) ...
|
||||||
(set! sym 'sym) ...)]))
|
(set! sym 'sym) ...)]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
(module equation-expression racket
|
||||||
(require (submod ".." expression))
|
(require (submod ".." expression))
|
||||||
|
@ -1215,7 +1190,35 @@
|
||||||
; (eq? (Kind exponent) 'integer)
|
; (eq? (Kind exponent) 'integer)
|
||||||
; (> exponent 1))
|
; (> 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
|
(module test racket
|
||||||
(require (submod ".." symbolic-application)
|
(require (submod ".." symbolic-application)
|
||||||
|
|
|
@ -24,7 +24,7 @@ NestList(f,expr,n):=if(n=0, List(expr), Cons(expr, NestList(f,f(expr),n-1)));
|
||||||
% Use it!
|
% Use it!
|
||||||
NestList(next,x0,7);
|
NestList(next,x0,7);
|
||||||
% NestList also works symbolically.
|
% NestList also works symbolically.
|
||||||
DeclareVars(g,x);
|
%DeclareVars(g,x);
|
||||||
NestList(g,x,5);
|
%NestList(g,x,5);
|
||||||
% We can get the first approximations as symbolical expressions. Not pretty.
|
% We can get the first approximations as symbolical expressions. Not pretty.
|
||||||
NestList(next,x,2);
|
%NestList(next,x,2);
|
||||||
|
|
|
@ -145,11 +145,14 @@
|
||||||
; - A number representing the ending position of the match (or #f if eof).
|
; - A number representing the ending position of the match (or #f if eof).
|
||||||
|
|
||||||
(define (syn-val a b c d e)
|
(define (syn-val a b c d e)
|
||||||
(values a b c
|
(values a ; string with mathching text
|
||||||
(position-offset d)
|
b ; symbol in '(comment white-space no-color eof)
|
||||||
|
c ; symbol in '(|(| |)| |[| |]| |{| |}|) or #f.
|
||||||
|
(position-offset d) ; start pos
|
||||||
#;(position-offset e)
|
#;(position-offset e)
|
||||||
(max (position-offset e)
|
(max ; end pos
|
||||||
(+ (position-offset d) 1))))
|
(position-offset e)
|
||||||
|
(+ (position-offset d) 1))))
|
||||||
|
|
||||||
(define color-lexer
|
(define color-lexer
|
||||||
; REMEMBER to restart DrScheme to test any changes in the 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.
|
; different identifiers to see whether := or ( comes after the identfier.
|
||||||
; This is enough to prevent shift/reduce conflicts between atom, definition,
|
; This is enough to prevent shift/reduce conflicts between atom, definition,
|
||||||
; and application.
|
; and application.
|
||||||
[(:or identifier:= identifierOP identifier)
|
[":="
|
||||||
(syn-val lexeme 'symbol #f start-pos end-pos)]
|
(syn-val lexeme 'symbol #f start-pos end-pos)]
|
||||||
|
[identifier
|
||||||
|
(syn-val lexeme 'symbol #f start-pos end-pos)]
|
||||||
[(:+ digit)
|
[(:+ digit)
|
||||||
(syn-val lexeme 'constant #f start-pos end-pos)]
|
(syn-val lexeme 'constant #f start-pos end-pos)]
|
||||||
[(:: (:+ digit) #\. (:* digit))
|
[(:: (:+ digit) #\. (:* digit))
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
(define list-ref List-ref)
|
(define list-ref List-ref)
|
||||||
(define-syntax (define stx)
|
(define-syntax (define stx)
|
||||||
(syntax-case stx () [(_ . more) #'(Define . more)]))
|
(syntax-case stx () [(_ . more) #'(Define . more)]))
|
||||||
(require bracket/lang/parser)
|
(require bracket/lang/parser)
|
||||||
#;(current-read-interaction
|
#;(current-read-interaction
|
||||||
(λ (_ in)
|
(λ (_ in)
|
||||||
(parse-expression 'repl #'repl in)))
|
(parse-expression 'repl #'repl in)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user