I have a protocol students:
:- protocol(student).
:- public([
name/1,
surname/1,
studies/1,
marks/1
]).
:- end_protocol.
Now I want to make an object which name is an ID (Integer), but when I'm trying to do this with create_object(18342, [implements(student)], [], [name(john), surname(smith), studies(it), marks(ok)]).
swilgt gives mi the error:
ERROR: Type error: 'object_identifier' expected, found '18342' (an integer)
Ofc I could use quotation marks, but I don't want to. Is there an option to use integer as a name, or have I use string and add id/1 into the protocol?
Indeed is (currently) not possible to use an integer as an object identifier. One alternative is indeed to use an atom, e.g.
'133'instead of123. Don't use a string, e.g."123"as the actual meaning of double quoted text depends on thedouble_quotesstandard Prolog flag, whose only portable value iscodes(i.e."123"is parsed as[49,50,51].A portable way to convert between an integer and an atom is to use the standard predicates
number_codes/2andatom_codes/2(ornumber_chars/2andatom_chars/2). Some supported backend Prolog systems also provide proprietary built-in predicates to directly convert between numbers and atoms.