I wrote some code in Haskell that I'd like to translate in Racket. It's about Parsec and Parsack.
#lang racket
(require parsack)
(define quote-marks "'\"`")
(define quoted-name
(between (oneOf quote-marks)
(oneOf quote-marks)
(many1 (noneOf quote-marks))))
(define not-found
(>>= quoted-name
(λ (name)
(>> (>> $spaces
(string "not found"))
(return (list->string name))))))
(define not-founds
(choice
(list
(>> $eof
(return '()))
(try (>>= not-found
(λ (name)
(>>= not-founds
(λ (others) (return (cons name others)))))))
(>> $anyChar
not-founds))))
The error is:
not-founds: undefined;
cannot reference an identifier before its definition
At first, I thought it was some typo within my code, but it isn't.
It seems that using >>=
instead of >>
makes the code work. I mean:
#lang racket
(require parsack)
(define quote-marks "'\"`")
(define quoted-name
(between (oneOf quote-marks)
(oneOf quote-marks)
(many1 (noneOf quote-marks))))
(define not-found
(>>= quoted-name
(λ (name)
(>> (>> $spaces
(string "not found"))
(return (list->string name))))))
(define not-founds
(choice
(list
(>> $eof
(return '()))
(try (>>= not-found
(λ (name)
(>>= not-founds
(λ (others) (return (cons name others)))))))
;; !!! here !!!
(>>= $anyChar
(λ (_) not-founds)))))
What am I missing here?