Open ccarstens opened 5 years ago
That's correct. The embedding is as follows:
Python | Agentspeak |
---|---|
int, float | number |
string | string |
tuple, agentspeak.LinkedList | list |
agentspeak.Literal | literal |
agentspeak.Var, agentspeak.Wildcard | variable |
*any other object** | opaque |
*) That means it's valid to create a Literal("foo", (MyObject(), ))
. On the AgentSpeak side MyObject is completely opaque, but it can be used in unification and passed to Python actions that might be able to do something with it.
About agentspeak.LinkedList, I saw that the constructor takes head
and tail
as arguments.
LinkedList([1, 2, 3], [4, 5, 6])
results in
[
[1, 2, 3],
[4, 5, 6]
]
and not in
[1, 2, 3, 4, 5, 6]
*) That means it's valid to create a Literal("foo", (MyObject(), )). On the AgentSpeak side MyObject is completely opaque, but it can be used in unification and passed to Python actions that might be able to do something with it.
That is incredibly good to know! Thank you! :)
Avoid LinkedList, if you can.
It is only required to represent the [Head|Tail]
syntax from AgentSpeak. We cannot use tuples for that, because Tail matches a list of unknown length.
For example:
>>> [Head|Tail] = [1,2,3,4].
Head = 1
Tail = [2, 3, 4]
The proper way to construct a LinkedList would be:
LinkedList(1, (2, 3, 4))
LinkedList(1, LinkedList(2, (3, 4)))
LinkedList(1, LinkedList(2, LinkedList(3, (4, ))))
Oh okay, I see. I guess using tuples and knowing that they'll be cast to agent speak lists does the job! :)
A belief containing a list as an argument can be constructed by passing tuples representing the list to the Literal constructor. e.g
is equivalent to the literal within ASL