# PyFlies: A Domain-Specific Language for Designing Experiments in Psychology
## 4 Language Abstract and Concrete Syntaxes
### Test Definition  
In this part of the study, one should go to the _EriksenFlanker_ folder on the left side, click the _New File_ button and type in the name _eriksen.pf_. It is important to provide the _pf_ file extension as it is used by the editor to recognize files as PyFlies specifications.  
In the editor, one should provide the code from Listing 15. Instead of just copy/pasting, one should try to type the code to become comfortable the editor. You will notice that PyFlies provides code snippets. For example, when you start typing word test, you will be provided with the possibility to expand the test snippet. Press the TAB key to expand the snippet. Type the name of the test EriksenFlanker and press TAB again to go to the next field. Each code snippet can provide multiple fields/locations.  
```
1 directions=[left,right]
2 congruencies=[incongruent,congruent]
3 repeats=1
4
5 testEriksenFlanker{
6
7|repeat|direction|category|
8|-----------|-----------|
9|1..repeatsloop|directionsloop|congruenciesloop|
10

Figure 4: Visual stimuli for the Eriksen flanker task: (**a–b**) congruent; (**c–d**) incongruent

fix -> cross() for 1000..3000 choose exec -> image(file \"images/{(direction)}-{(category)}.png\", size 100) keyboard(validdirections,correctdirection) error -> sound(freq800) for 300 correct -> sound(freq400) for 300

In lines 7-9 is a condition table with three variables: repeat, direction, and category. The repeat variable loops over a range 1..repeats where repeats is a parameter specified during the flow of the experiment (line 8 in Listing 17). It controls the total number of test trials. Our expanded table contains all possible triplets of repeat, direction, and category with a total of repeats x 2 x 2 number of rows.

In line 11, we specify the fix phase as a cross shape displayed with a random duration chosen from the range of [1000, 3000] ms.

In the exec phase (lines 12-13), an image is displayed with a size set to 100% and unspecified duration. Since the duration is not specified, the stimulus runs until the end of the phase. In this case, the keyboard component that follows controls when the phase is going to finish. The filename of the image given in line 12 has interpolated values direction and category. These values are provided for each trial by the condition table. For example, a valid file name can be images/left-incongruent.png.

The keyboard component given in line 13 specifies valid responses as a list of directions. We shall later provide mappings from directions to keyboard keys in the target configuration section (Section 6.5). This task has only one correct response, and it is given by the direction variable of the current trial.

The last thing to do is to define optional correct and error phases. Here, we want to give audible feedback to the subject with different frequencies for correct and error responses. For that, we use the sound component with given frequencies and the duration set to 300 ms.

### Screens Definition

To prepare the subject for each batch of trials, we define two screens given in Listing 16. We have an intro screen that introduces the test to the subject. Our experiment will show this screen at the beginning before the practice trials run. The real screen will be shown after the practice run finish but before real trials start. These screens are plain text without any dynamically rendered parts.
``` screenintro| Welcome ------- In the following test you will be presented with a line of 5 arrows pointing left or right. You should respond by the direction of the *middle arrow* as fast as possible by pressing left or right arrow on the keyboard or touching/clicking the appropriate button on the screen. You will first do a practice run with 4 trials. A real run with 20 trial will be performed afterwards. Press SPACE or touch/click the screen to continue screen real block ================================Now a real block of trials will be performed.  
Press SPACE or touch/click the screen to continue }