Literal Identifier when Scheme Language Custom Structure

xiaoxiao2021-03-06  65

The Scheme language allows users to customize special syntax structures such as Let-Syntax. There is a less conspirable LITERAL IDENTIFIER in Pattern Language when defining this grammatical structure, which is the in the following syntax:

(Syntax-Rules ...)

The Interpretation of Literal Identifier is more embarrassing in the Scheme Standard R5RS. I wrote a small example according to my understanding, probably played the role of supplementation:

;; Do not use Literal Identifier to define syntax z (Syntax-Rules ((z ( xy)) (( XY))))) ;;; The result of the following line is 7 (z ( ) 3 4)) ;; The result of the following line is -1, and the plus number after local change (( -)) (z ( 3 4))))

;;; Define syntax Z (Define-Syntax Z ((z ( xy)))))))) ;;;; The result of the following line is still 7 (z (z (z (z (z (z) 3 4)) ;;; below this line error: z: BAD SYNTAX IN: (z ( 3 4)) ;;; Different when defined syntax (actually binding different) plus, unable to apply Syntax (LET (( -)) (z ( 3 4))))))

With this example, the more complicated example mentioned in R5RS is better understood:

(Define-Syntax Cond (Syntax-Rules ((Else Result1 Result2 ...) ((Test => Result) (LET) ((TEMP) Test))))))))))))))))) ((TEST => Result) CLAUSE1 CLAUSE2 ... ((TEMP TEST) (COND CLAUSE 1 CLAUSE2) )))) ((TEST)) TEST) ((TEST) CLAUSE1 CLAUSE2 ...) (IF TEMP TEMP (COND CLAUSE1 CLAUSE2 ...))))))))) Cond (Test Result1 Result2 ...))) ((Test Result1 Result2 ...) CLAUSE1 CLAUSE2 ...) (IF Test (Begin Result1 Result2 ... (COND CLAUSE1 CLAUSE2 ...)))))))

Based on the COND definition of the above, the following code

(Let ((=> #f)) (COND (#t => 'OK))); =) OK

Will be interpreted as (here => is considered variable instead of gramming elements)

(Let ((=> #f)) (if #t (begin => 'ok))) instead of

(Let ((=> #f)) (Let ((Temp #)) (IF TEMP ('OK Temp))))))))

Because local => has been changed, it cannot be matched to the syntax rules containing =>.

转载请注明原文地址:https://www.9cbs.com/read-112127.html

New Post(0)