Built-in Functions
Here is a list of Hop's built-in functions. Because Hop functions can be overloaded, some of them have multiple signatures. Functions with brackets after their names are generic. Generic functions are described in the generics chapter.
-
.- duplicate a value on the stackfn .[T] T -> T T
-
~- pop a value from the stackfn ~[T] T
-
@- get a pointer to stack's top valuefn @[T] T -> T *T
-
put- print a primitive valuefn put intfn put floatfn put bytefn put bool
-
putln- print a primitive value with a newlinefn putln intfn putln floatfn putln bytefn putln bool
-
puts- print a stringfn puts *byte
-
putlns- print a string with a newlinefn putlns *byte
-
putc- print a characterfn putc int
-
putlnc- print a character with a newlinefn putlnc int
-
putp- print a pointerfn putp[T] *T
-
putlnp- print a pointer with a newlinefn putlnp[T] *T
-
ln- print a newlinefn ln
-
read- read a pointerfn read[T] *T -> T
-
write- write to a pointerfn write[T] *T T
-
exit- exit the program with the given exit codefn exit int
-
realloc- reallocate an allocated pointerfn realloc[T] *T int -> *T
-
free- free an allocated pointerfn free[T] *T
-
copy- copy values from one pointer to anotherfn copy[T] let dst: *T src: *T n: int
-
pow- raise onefloatto the power of anotherfn pow float float -> float
-
random- generate a randomfloatin [0, 1)fn random -> float
-
time- get the current time in secondsfn time -> float
-
stdin- read a line from stdin into a heap-allocated string (or return null on failure)fn -> *byte
-
to_byte- convert a number to abytefn to_byte int -> bytefn to_byte float -> byte
-
to_int- convert a number to anintfn to_int byte -> intfn to_int float -> intfn to_int[T] *T -> int
-
to_float- convert a number to afloatfn to_float byte -> floatfn to_float int -> float
-
+- add two numbersfn + byte byte -> bytefn + byte int -> intfn + byte float -> floatfn + int byte -> intfn + int int -> intfn + int float -> floatfn + float byte -> floatfn + float int -> floatfn + float float -> floatfn +[T] *T int -> *Tfn +[T] int *T -> *T
-
-- subtract two numbersfn - byte byte -> bytefn - byte int -> intfn - byte float -> floatfn - int byte -> intfn - int int -> intfn - int float -> floatfn - float byte -> floatfn - float int -> floatfn - float float -> floatfn -[T] *T int -> *Tfn -[T] *T *T -> int
-
*- multiply two numbersfn * byte byte -> bytefn * byte int -> intfn * byte float -> floatfn * int byte -> intfn * int int -> intfn * int float -> floatfn * float byte -> floatfn * float int -> floatfn * float float -> float
-
/- divide two numbersfn / byte byte -> bytefn / byte int -> intfn / byte float -> floatfn / int byte -> intfn / int int -> intfn / int float -> floatfn / float byte -> floatfn / float int -> floatfn / float float -> float
-
%- calculate the modulus of two numbersfn % byte byte -> bytefn % byte int -> intfn % byte float -> floatfn % int byte -> intfn % int int -> intfn % int float -> floatfn % float byte -> floatfn % float int -> floatfn % float float -> float
-
&- logical andfn & byte byte -> bytefn & int int -> intfn & bool bool -> bool
-
^- logical xorfn ^ byte byte -> bytefn ^ int int -> intfn ^ bool bool -> bool
-
|- logical orfn | byte byte -> bytefn | int int -> intfn | bool bool -> bool
-
<<- bit shift leftfn << byte byte -> bytefn << byte int -> bytefn << int byte -> intfn << int int -> int
-
>>- bit shift rightfn >> byte byte -> bytefn >> byte int -> bytefn >> int byte -> intfn >> int int -> int
-
==- check if two numbers are equalfn == byte byte -> boolfn == byte int -> boolfn == byte float -> boolfn == int byte -> boolfn == int int -> boolfn == int float -> boolfn == float byte -> boolfn == float int -> boolfn == float float -> boolfn ==[T] *T *T -> bool
-
!=- check if two numbers are not equalfn != byte byte -> boolfn != byte int -> boolfn != byte float -> boolfn != int byte -> boolfn != int int -> boolfn != int float -> boolfn != float byte -> boolfn != float int -> boolfn != float float -> boolfn !=[T] *T *T -> bool
-
<- compare two numbersfn < byte byte -> boolfn < byte int -> boolfn < byte float -> boolfn < int byte -> boolfn < int int -> boolfn < int float -> boolfn < float byte -> boolfn < float int -> boolfn < float float -> boolfn <[T] *T *T -> bool
-
<=- compare two numbersfn <= byte byte -> boolfn <= byte int -> boolfn <= byte float -> boolfn <= int byte -> boolfn <= int int -> boolfn <= int float -> boolfn <= float byte -> boolfn <= float int -> boolfn <= float float -> boolfn <=[T] *T *T -> bool
-
>- compare two numbersfn > byte byte -> boolfn > byte int -> boolfn > byte float -> boolfn > int byte -> boolfn > int int -> boolfn > int float -> boolfn > float byte -> boolfn > float int -> boolfn > float float -> boolfn >[T] *T *T -> bool
-
>=- compare two numbersfn >= byte byte -> boolfn >= byte int -> boolfn >= byte float -> boolfn >= int byte -> boolfn >= int int -> boolfn >= int float -> boolfn >= float byte -> boolfn >= float int -> boolfn >= float float -> boolfn >=[T] *T *T -> bool
-
!- logical notfn ! bool -> boolfn ! byte -> bytefn ! int -> int
-
neg- negate a numberfn neg int -> intfn neg float -> float
-
strcmp- compare 2 stringsfn strcmp *byte *byte -> int
-
streq- check if 2 strings are equalfn streq *byte *byte -> bool
-
strcpy- copy a string from one allocation to anotherfn strcpy let dst: *byte src: *byte
-
strlen- find a string's lengthfn strlen *byte -> int
-
read_file- read a file into a heap-allocated string (or return null on failure)fn read_file *byte -> *byte
-
write_to_file- write a string to a file (and return true on success)fn write_to_file let text: *byte file_path: *byte -> bool
-
append_to_file- append a string to a file (and return true on success)fn append_to_file let text: *byte file_path: *byte -> bool