문제

I am trying to parse some function to (let([x 1]) x) but racket read [ as (. Is there any simple way that I can keep it []?

this is what returns when I try to escape with backslash[ backslash]:

    (let (|[| fact #f |]| |[| fact2 #f |]| |[| fact3 #f |]|) fact3)

what I want is:

,   (let ([fact #f][fact2 #f][fact3 #f]) fact3)
도움이 되었습니까?

해결책

If you are using the read-syntax primitive, then the parentheses within the parsed data structure have a paren-shape property that will tell you if they were square or not.

For example:

> (define stx-1 (read-syntax #f (open-input-string "(hello)")))
> (define stx-2 (read-syntax #f (open-input-string "[hello]")))
> stx-1
#<syntax::1 (hello)>
> stx-2
#<syntax::1 (hello)>
> (syntax-property stx-1 'paren-shape)
#f
> (syntax-property stx-2 'paren-shape)
#\[

So the syntax data structure can remember that the square brackets are there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top