zxul767 / lox

An interpreter for the Lox language
1 stars 0 forks source link

Add `str` native class in `jlox` #24

Closed zxul767 closed 1 year ago

zxul767 commented 1 year ago

All string literals (which we already had) are now automatically promoted to str, which allows us to write things like: "hello world".starts_with("hello")

Opportunistically, we add the help function to the standard library which allows us to look up basic information about variables in Lox:

>>> help(sin)
{ sin(n:number) -> number } : <built-in function>

>>> help(str)
{ str(value:any) -> str } : <built-in class>

>>> help("".starts_with)
{ starts_with(prefix:str) -> bool } : <built-in method>

>>> help(10)
10.0 : number

>>> help(true)
true : boolean

>>> help(false)
false : boolean

>>> var r = (1 == 2)
>>> help(r)
false : boolean