Skip to content

Feature request: compile time values to string #1874

@BWindey

Description

As seen in #1873, the compiler gives us compile-time constants, but not an easy way to chain those together when types mismatch.
A compile-time string function like $to_string(num) or more broadly $format_string(format, ...) like what io::printfn() does, would be very nice.

Currently I got a to_string like this:

macro to_string($num) {
	char[] $res;
	$for (;$num != 0; $num = $num / 10)
		$res = { (char) ('0' + $num % 10) } +++ $res;
	$endfor
	return (String) $res;
}

A usecase is to chain together $echo with various compile-time constants like $$FILE (string) and $$LINE (int).

Metadata

Assignees

Labels

AcceptedAccepted Request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions