Notifications
Clear all

[Closed] force interpretation to identifier

I’ve found that c# allows the “@” symbol to be placed in front of a reserved word, so that the compiler is forced to recognize the reserved word as an identifier.

I’m looking for the equivalent in maxscript. How would I go about writing a function that is named “this”? I’m well aware that this is a reserved word.


(
	fn @this =
	(
		print "foo"
	)
	@this()
)

Is there a way to force the maxscript interpreter to recognize reserved words as identifiers?
Why would I want to do this, you ask? Mapping a language to it’s maxscript equivalents sometimes results in reserved word collisions, and this would be an easy way of handling such collisions. An example would be from visual basic .net, where a programmer could declare a class with the name of “this”. Translating that code to maxscript results in a reserved word collision from the token “this”.

2 Replies

I don’t know if this is just too simple, but what about adding something like a normal string prefix to everything? Why does it have to be an official symbol? You could add any valid character/s you want to the start to do this.

Cg.

Yep, adding a prefix is a good solution. Got my eyes stuck in the trees – missed the forest!
I was just hoping that I could bypass the need to add a prefix, because then I’m altering the original author’s code.
However, just adding an underscore “_” to the name should force max to interpret it as an identifier.
I could then strip out underscores if they are the first character, leaving me with the author’s original identifiers.
So, that’s probably how I’ll do it. Thanks Chris!