Reputation: 13
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)
Upvotes: 1
Views: 508
Reputation: 12023
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.
Upvotes: 1