presidentbeef / brat

Brat is a little language for people who don't like to be told what to do.
https://www.brat-lang.info/
93 stars 6 forks source link

Function "find" doesn't work #37

Open OdoctorG opened 3 years ago

OdoctorG commented 3 years ago

The builtin function "find" doesnt seem to work, atleast not in the try brat online editor.

Code: "amogus".find "gus"

Ouput:

/home/brat/brat/core/core.lua:2184: attempt to call upvalue 'block' (a table value) stack traceback: /home/brat/brat/core/core.lua: in function 'block' /home/brat/brat/core/core.lua:4440: in function 'each' /home/brat/brat/core/core.lua:2189: in function '_mtemp1_find' [string "string"]:41: in function '_mtemp3_run_underparsed'

stack traceback: [string "string"]:336: in main chunk [C]: in function 'xpcall' /home/brat/brat/core/core.lua:1304: in function 'protect' /home/brat/brat/bin/brat:137: in function 'run_string' /home/brat/brat/bin/brat:162: in main chunk [C]: at 0x5650922ed5b0

Interestingly .include? works but not find

presidentbeef commented 3 years ago

So... string.find has apparently never matched the documentation (the code is 8-9 years old). It's actually called find_first. You can see the mismatch here: https://github.com/presidentbeef/brat/blob/main/core/core.lua#L4910-L4924

string.find is from enumerable.find which takes a function as an argument: https://github.com/presidentbeef/brat/blob/main/core/core.lua#L2176-L2196

And apparently that isn't documented, either! :laughing: