Best way to implement actions

Hello everybody, I have a quick question on how to go about adding some code to my action concept.
So I want to implement something like the above. I already created a action concept which is empty.
I would want to have the ability to add parameters and write some simple code like above. 
How do i go on to do this in the easiest way? How do I add the possibility of adding parameters and what do i have to do to be able to add the code to the body of the actions. Would I need to implement statement concepts for this or are there any predefined concepts for stuff like that? Sorry new to MPS and just trying around. Thanks in advance.

0
21 comments

The ConceptFunction concept is pretty close, I think. Check out the doc at https://www.jetbrains.com/help/mps/2021.3/concept-functions.html

 

1

Thanks for the response. 

0

I tried around with the ConceptFunctions and I want to know if there is a way to get Parameters that are the type of an concept. In the example above it says action deposit(Tokentransaction t), I got a concept for Tokentransaction already and want it to be the type of the parameter for the action conceptfunction. How can I do something like this? I tried using stuff that is in the tutorial that you sent but I can't seem to make it work.

0

You define the type of the concept function's parameter in the getType() method of the corresponding ConceptFunctionParameter. If you want to pass in nodes of the TokenTransaction concept, the getType() method should be returning node<TokenTransaction>.

1


I am at this point and I don't know how to make the getType return a TokenTransaction node from here. In the tutorial it's put as <string>; to return a string but even that does not seem to work for me. How do I change the return type for getType()?

0

 

When I try to enter it like this it gives me this error message.

0

Is there also a way to edit the editor to look something like action(TokenTransaction) without the return type behind? It should give me the Parameters behind the name.


And I want to know how to make it possible to enter more than 1 Parametertype. For example action(Duration). Would i just need to make another ConceptFunctionParameter for that and add it through the behaviour like the TokenTransaction?

0

If your want your own class to be the type of concept function's parameter, you should be using the ClassifierType, perhaps with a quotation or a light-weight quotation.

You are right about adding multiple parameters, just create another concept function parameter concept.

1

If you define an editor for your concept function, it will be used instead of the one provided by the ConceptFunction concept.

1

Hey Vaclav, Thank you for all of your responses.
1. Could you maybe be a bit more specific about the ClassifierType? I searched for some example code but could not find any. What would I need to do to be able to return a node of a concept that I already made in the getType() function of the ConceptFunctionParameter? 
2. I know that if I define an editor for my concept function that this will be used, my question was more like if there is a way to use a custom editor and show the parameter name in my custom editor. I was searching for the right code to make the parameter name be included in my custom editor.

0

ClassifierType is a type that refers a Classifier (a java class). So you should create a quotation, insert ClassifierType and then select the desired Classifier, e.g. TokenTransaction.

The names of the parameters should normally be shown in the function's header, provided the parameter has an alias defined.

1

ClassifierType is a type that refers a Classifier (a java class). So you should create a quotation, insert ClassifierType and then select the desired Classifier, e.g. TokenTransaction.

I can't find anything about how to create a quotation online, is there any info on how to work with quotations online or could you tell me where to start? Also I read about the ClassifierType, would it be needed to create my own ClassifierType concept or could I use the default one if there is such thing? Your advice seems like I would just have to create a quotation and insert a ClassifierType (which is default) and select the Classifier? Or would I need to create a new ClassifierType TokenTransaction for this case?

0

The names of the parameters should normally be shown in the function's header, provided the parameter has an alias defined.

What I want is the "TokenTransaction" which is the ParameterType to be shown in my default editor. I'm missing the statement which let's me get the ParameterType in my custom editor for the action concept.


0

Hi Leon, if you want, come to the MPS Office Hours (https://specificlanguages.com/mps-office-hours/) within the next hour, and I could help you sort this out online much faster than via back-and-forth in the forum.

1

And I think there is some confusion due to unclear nature of TokenTransaction. What is it? A Java class, a concept, something else?

1

Sorry, I should have provided more fundamental information. Quotations are documented at https://www.jetbrains.com/help/mps/quotations.html

Other than that, you are correct about creating a quotation. A ClassifierType is provided by BaseLanguage, you only need to define the class for TokenTransaction.

0

Hi Leon, if you want, come to the MPS Office Hours (https://specificlanguages.com/mps-office-hours/) within the next hour, and I could help you sort this out online much faster than via back-and-forth in the forum.

This sounds super helpful. I signed up for it and will attend next week, couldn't manage to join this past hour. 

"And I think there is some confusion due to unclear nature of TokenTransaction. What is it? A Java class, a concept, something else?"
TokenTransaction_Parameter is a ConceptFunctionParameter and TokenTransaction is a simple concept within my language. 

"Other than that, you are correct about creating a quotation. A ClassifierType is provided by BaseLanguage, you only need to define the class for TokenTransaction."
So I would create a quotation for my concept TokenTransaction and use that quotation within the TokenTransaction_Parameter which extends ConceptFunctionParameter right?


0

ClassifierType refers to a Java class. So you would need to create a Java class for the TokenTransaction concept (you could name the class TokenTransaction as well). Then you could refer to that class in the quotation that would build the ClassifierType.

1

ClassifierType refers to a Java class. So you would need to create a Java class for the TokenTransaction concept (you could name the class TokenTransaction as well). Then you could refer to that class in the quotation that would build the ClassifierType.

Okay, that sounds good. I'll create an empty Java Class for TokenTransaction and will follow up with more questions in the office hours next week. Thanks a lot and see you next week.

 

0

To implement this, you'll need to follow a few steps depending on the environment or framework you're using. Here's a general approach:

  1. Define Parameters:
    • In your action concept, define the parameters you want to pass. This could involve creating input fields, variables, or other mechanisms to capture user inputs or other data.
  2. Write Simple Code:
    • Depending on the platform, you might be able to directly write the code within the action concept. For instance, if you're using a workflow tool, there might be a code block or script action you can use.
    • If you're coding in a language like Python, JavaScript, or another, you can define a function that takes your parameters as inputs and performs the necessary actions.
      Do the same as i mentioned because i fixed it at snapchatplanetsinfo
0

Please sign in to leave a comment.