1

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)
2
  • nevermind, I figured out I don't need this.
    – jesse
    Apr 17, 2014 at 6:47
  • you should probably delete the question, then… Apr 17, 2014 at 16:15

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.