-
Notifications
You must be signed in to change notification settings - Fork 40
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
Output a variable within a production? #8
Comments
Sorry, forgot to respond. Indeed, you cannot print arbitrary texts in productions if you write production rules using productionstring. However, you can do this if you create the rule without productionstring. Basically, all productions are underlyingly generator functions and productionstring converts a string into a generator function. If you write a production directly as a generator function, you can print whatever you like, since you stepped outside of pyactr and work directly with Python. I am putting an example here from the tutorial u1_count.py. Instead of specifying the rule increment using productionstring, you could create a generator function as shown below, and then you can put a Python code inside that generator function and it will be triggered when the rule is selected.
|
Thank you for the response and example! Part of my goal is making things easier for people to read & understand, so this solution is kind of sub-optimal for my purposes. I had some success with straight text by monkey patching def print_text(*args):
text = ''.join(args[1:])
text = text.strip("'")
print(text)
Buffer.print_text = print_text and then using it in the production like this:
But there are a couple of problems with this approach.
Do you think this approach (or something like it) can be made to work? It would be a lot easier to read & understand. (For a larger view of what I'm trying to do - I'm generating code for pyactr, ccm suite (also Python), and ACT-R (Lisp) from a common format. So I'm trying to maintain functional parity as well as making the code readable and easy to compare with the other frameworks.) |
This is an interesting project. It would be very useful to have that. I have a PhD student who was thinking about something similar - he wanted to compare Lisp ACT-R and pyactr. I'll let him know about your work. I am curious to hear how you proceed, please keep me updated, you can find my e-mail on my website. Re printing: if you just need to print some text, you can also do that directly in pyactr. The command
Printing values of ACT-R variables cannot be done directly, unfortunately. However, you could always print the value of the slot to which the variable is bound. So, for example, in the case above if you need to get the value of y, you just specify |
Yes - that's another part of my motivation - comparing the different implementations. (In fact as I was developing gactar I directly compared my generated pyactr code with my generated lisp code to ensure my productions were correct.) I've started by implementing the basics of ACT-R in my language and since it forces the user to use this restricted set of commands, I'm hoping it will raise questions - i.e. I can do this in X, but I can't do it in Y - should I be able to? So it can raise technical questions to a more theoretical level. Obviously what I have is just a starting point, but I wanted to get it out there to see if there's any interest and hopefully foster discussion. I had seen I think mapping vars back to slots could work with some more internal bookkeeping on my side. Printing a string from two different buffers can't be addressed by this. e.g. Thank you for the feedback! |
I figured out a way to do this using some funky monkey patches. If anyone needs to do this in the future, you can see what I did in this PR. The python code in
|
(I arrived back here while looking at something related and thought I would update for anyone who runs across this.) Since I commented here, I've moved that python code out of import pyactr_print and use it in your productions:
@jakdot If you would be interested in including this in pyactr, I would be happy to integrate it and create a pull request. |
How do I output a variable within a production?
In ACT-R, I can do this:
I found
Buffer.show
which lets me output a specific slot, but I can't find anything that does the equivalent of the ACT-R!output!
for variables (and arbitrary text).Thank you!
The text was updated successfully, but these errors were encountered: