How are you counting the groups?
Well, just in case: if rx
is the string form of a regexp, then (format "(?:~a)?" rx)
produces a regexp that accepts the empty string and produces the same number of sub-matches as rx
.
I’ll try that. Thanks!
I haven’t thought it through much at all really. I just know that there’s a fixed number of identifiers so that limits the regexp complexity, and I’d like to catch regexp mistakes at compile time as much as possible.
@lupino8211 has joined the channel
@jhemann has joined the channel
How stable/reliable are the <https://docs.racket-lang.org/syntax/Experimental.html?q=syntax%2Dparse|experimental libraries of syntax/parse?>
That’s a question for @ryanc I think.
They’re stable. I don’t plan to remove or make breaking changes to any of them.
Are there any caveats regarding the libraries?
None come to mind right now.
What happens if the regexp fails to match?
I see, thanks. I’ll try that.
Hi all! I started to learn racket a while ago, for language creating purposes. I wanted to create small language that will utilize racket’s ffi abilities, but now i’m desperate and don’t know how to make language work… https://github.com/readysloth/REPLify
Main idea was to separate loading library and defining foreign functions in two macroses: + use — creates dynamic library binding + header — creates function binding for library
Currently launching racket example.ffi
spits out ffiREPL.rkt:73:9: define-lib-func: unbound identifier
in: define-lib-func
location...:
ffiREPL.rkt:73:9
context...:
Which is in header
macro. As I understand it is because two identifiers bound separately. Where am I wrong? Thank you.
Does it help to move (define-syntax-rule (use lib) (define-ffi-definer define-lib-func (ffi-lib lib)))
into the expansion?
Can you elaborate, please?
Well, if define-lib-func
can’t be seen where it is, then you need to move, so it becomes bound where you reference it.
I skimmed the code and I can’t point to anything specific, but I am concerned about the use of plain lists such as (define (define-func str)
(match (parse-proto str)
([list name sign]
`(define-lib-func ,name ,(_fun (map make-ffi-type (rest sign)) ->
(make-ffi-type (first sign)))))))
to construct your expansion.
It might work, but I expect you to have better results if you work with syntax objects instead.
currently, a very useless error message
So i need to merge use
and header
macros together?
Also i tried, but did not understand: should i return syntax object from these macros? Because then it just prints it out…
In Scala-world (and I suppose Haskell), you’d get a Some(result) or a None, then you could pattern-match on that.
It’s too complicated for me to figure out what’s going on. Experience tells me, that constructing pieces of code as plain lists often leads to binding problems. The solution is often to use syntax objects. This is a vague answer, but I can’t be more precise.
Thank you! I forgot to change function in mapping… I also changed list to syntax, but now map
prints many ffi-defines because it executes in runtime (not in compile time), i guess Can i somehow shift it? '(#<syntax:ffiREPL.rkt:87:11 (define-lib-func memmove (_fun _pointer _pointer _size -> _pointer))>
#<syntax:ffiREPL.rkt:87:11 (define-lib-func memset (_fun _pointer _int _size -> _pointer))>
#<syntax:ffiREPL.rkt:87:11 (define-lib-func memcmp (_fun _pointer _pointer _size -> _int))>
...
I think I’d like it to work just like (match-define (list a b c) #f)
does except with an error message saying why the regexp didn’t match
Ok. Is it normal that a non-match is an error? Or, “it didn’t work out so let’s see if something else works?” I’m thinking someone could supply input that would inadvertently cause a program to give up. Unless you catch the error and recover that way.
It seems roughly the same as any other kind of unexpected input: either raise a contract error or wrap everything to handle it some other way
and in this case I’m mostly interested in streamlining the happy path
I’m persnickety because I parse NWS weather bulletins, which follow a pretty regular pattern, regular enough that we have regular expressions (going back to 2006) that handle most of the bulletin types. Except once in a while a human does something human (at NWS) and we get a bulletin that is missing something (usually lat/lon polygons) or something is malformed. Downstream we get all kinds of alarms from the database checks, the global this doesn’t match country that, a county supervisor calls HQ “How could we didn’t get an alert for that flood?” or “How come you alerted us for a tornado that wasn’t near us?” etc. We go digging, find the original alert text, and somewhere in there it was a regexp that didn’t match, so a piece of a bulletin was effectively missing.
The best error ever of this type (which was no fault of a regexp) was a call from someone in St. Louis, upset that there was an alert for a flood when there was no flood in St. Louis. But there was a flood 50 miles west, and the multipolygon for St. Louis included a little square 50 miles west of the city that was city property that was nowhere near the city, and that little square did have a flood.
Oh yeah, that kind of use case definitely requires planning for failure isolation
hmm, maybe I could build something on top of the guarded-block
macro: (guarded-block
(define string "aabbbbc")
(regexp-guard (as bs cs) #rx"(a*)(b*)(c*)" string else
"regexp didn't match!")
(+ (string-length as) (string-length bs) (string-length cs)))
(context for guarded-block
macro: https://groups.google.com/g/racket-users/c/H-EppBmQ7oU)
Two problems/questions about the Makefile.
Are
JOB_OPTIONS
andPLT_SETUP_OPTIONS
supposed to function in the same way? I tried:PLT_SETUP_OPTIONS="-D" make both
make both JOB_OPTIONS="-D"
.
The latter succeeds. The first does not (meaning it still builds the documentation).
- For the latter, it issues
-D -D
toraco setup
, so it errors with the “can’t have more than one-D
” error. Is there a way to make it work?
Hello, I am writing a web application. I created a hash table (make-hash) in the application. When the web application is running, i can’t use hash-remove!
to remove a data. But hash-remove!
can work in interactive window.
@jsx610278856 when you say you “can’t use” it, do you mean that there’s an error message? or that it just doesn’t remove it and it looks like nothing happened?
it just doesn’t remove it and it looks like nothing happened, thank you
I use Racket 7.9.
Did you mean to use make both PLT_SETUP_OPTIONS=-D
? If you put PLT_SETUP_OPTIONS=-D
at the front, that means something different (in a shell like bash).
I’m not sure JOB_OPTIONS
wouldn’t work, although it’s intended for -j <N>
.
Oh, I read
> JOB_OPTIONS as a makefile variable and PLT_SETUP_OPTIONS as an environment variable and thought that PLT_SETUP_OPTIONS
is a real environment variable, so PLT_SETUP_OPTIONS="-D" make both
ought to work. Isn’t that the case?
Ah, I see. That description as an environment variable is a holdover from an old strategy that didn’t work out.
So, I’ll fix the build docs.
looks like there is a missing symbolify
call to get the key in delete!
Thank you