Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] add lists as part of a belief by constructing a literal with a tuple representing the list #11

Open
ccarstens opened this issue Sep 19, 2019 · 4 comments

Comments

@ccarstens
Copy link

A belief containing a list as an argument can be constructed by passing tuples representing the list to the Literal constructor. e.g

my_literal = Literal("my_functor", ((12, 45), ))

is equivalent to the literal within ASL

my_functor([12, 45])
@niklasf
Copy link
Owner

niklasf commented Sep 19, 2019

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.

@ccarstens
Copy link
Author

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! :)

@niklasf
Copy link
Owner

niklasf commented Sep 19, 2019

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, ))))

@ccarstens
Copy link
Author

Oh okay, I see.
I guess using tuples and knowing that they'll be cast to agent speak lists does the job! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants