-
Notifications
You must be signed in to change notification settings - Fork 81
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
Rewrite: extern(Device, function) ==> function(Device) #517
Comments
Hi @ejgroene , I am happy about your interest in ASP and our systems! |
I don't understand the question/problem. From the snippets above, I do not see why you cannot use |
Thank you for bringing these under my attention. I subscribed to both. |
Thank you for your response. Yes, there is a reason, but I left it out to make the question simpler. In fact, I am creating a tool to be used by others and they can define how in- and outputs map to I/O ports, like:
If they have to make these mappings themselves every time, the tool would be very clumsy to use. Inside the tool, I translate it to (keeping the port-mapping elsewhere):
That works, but I'd rather write the rules using (without having to write translation rules by hand):
And if that works, if would be very nice for the users to be able to also write the
This would hopefully to cleaner, more readable code with less mistakes. Can the Python API do this? |
You can rewrite a program using clingo's ast. But you could also come up with any other way to specify the input, yaml for example, and translate it into the format you require. |
After a lot of thinking and experimenting, I came up with a relatively simple solution, with one ingredient that might be interesting for enhancement to Clingo. I created a simple
(substitutions are recursive replacements, aliases are simple replacements) The alias and the substitution allow me to automate 80% of the machinery. Most importantly, the rules for alias and substitution can be generic, defined in my One thing though still must be written each and every time the API is used. Since the newly created literals (by
These are just to introduce the functions As I was doing this, I discovered that Clingo works with arbitrary function names:
just gives a new function As a functional programmer, this makes me think: wouldn't it be nice if ASP would allow functions to be first class citizens and have them assigned to variables right in the code? One could then write:
Given Wouldn't that be a nice enhancement to metaprogramming, next to |
You are entering dangerous territory here. Function names should follow identifier syntax. This is currently not enforced and there are already some features that would break if you do this. For example, reading aspif format. I might add checks in the future to catch this.
Such kind of statements would not increase the expressiveness of the system. You could simply replace all occurrences of If you know the possible values of |
I will not enter that territory, I understand that things could break; it is only what triggered me thinking about first class functions.
Exactly! For me, being able to offer a library that allows user to write cleaner and better readable code using
I don't really understand what you are saying here. Is grounding not about knowing all possible values for a variable? That means that possible 'dynamic' functions are known as well, isn't it? Anyway, thanks for your remarks; they made me think and come up with a new solution. |
A short update. I have implemented a First a program defines
These
This allows me to create an ASP library that supports its users to write cleaner code. Of course it only makes sense for externals. |
Question.
I have a logic program for PLCs in which a predicate like:
means there is an external literal:
With these I create rules like:
This rule is then tested with additional logic, which is the whole point of having this ASP program. If all tests succeed, this rule, exactly as it is, then is translated to code for the PLC. I use grounding and reification for that.
However, I would like to write this rule and all its tests in a more direct way, like:
This would make my test code more readable and independent of the way it is derived from the definitions.
I know I can project things using
#show
, but beside for the tests, there is no solving and hence no model.Is there a way to rewrite the following?
The text was updated successfully, but these errors were encountered: