Is there a way to have read_term_from_atom/2 work with an upper case functor, e.g. with the following string “Property(x)”.
Or, do i have to first ensure that the functor is lower case — i am trying to avoid manipulating the string received, but it seems i have to lower case the functor first – which will likely require an internal copying of the whole string – something i want to avoid.
Alternatively, for my purpose i could just truncate the functor – such as a right operation with the length of the string minus one … i guess i would need to stitch this together with string_length and substring … which probably also implies processing overhead.
There are several options to, I guess, using the Prolog parser to parse expressions that are pretty close to Prolog but with some more conventional rules. One is the Prolog flag allow_variable_name_as_functor and the other is the Prolog flag var_prefix, which is probably more useful. var_prefix is module local, so you can create a module, set this flag and (probably) define additional operators. Next you can use the module(M) argument of read_term/3 or term_string/3 to use the syntax of the specified module.
The allow_variable_name_as_functor flag is global, but doesn’t conflict with normal Prolog syntax and thus you can probably just set it.
sub_string(S, 1, _, 0, R2) is a lot quicker if the string gets long, especially if the next step is to open it as a stream. A Prolog list of characters requires quite a bit more resources for storing and processing than a simple array as used for SWI-Prolog strings. One of the few reasons to turn an atom or string into a list of characters is to use a DCG on it.
See the var_prefix flag. That might get you close. An alternative can be to use the variable_names(Names) option and call maplist(call, Names) to bind all the variables to their names.