Skip to content

Commit 1a51363

Browse files
committedMar 29, 2016
doc/tutorial: add missing type annotation in LED example. Closes #356
1 parent 3c09577 commit 1a51363

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

Diff for: ‎doc/manual/getting_started_core.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ A method or function running on the core device (which we call a "kernel") may c
4343

4444
Modify the code as follows: ::
4545

46-
def input_led_state():
47-
return int(input("Enter desired LED state: "))
46+
def input_led_state() -> TBool:
47+
return bool(input("Enter desired LED state: "))
4848

4949
class LED(EnvExperiment):
5050
def build(self):
@@ -70,6 +70,8 @@ You can then turn the LED off and on by entering 0 or 1 at the prompt that appea
7070

7171
What happens is the ARTIQ compiler notices that the ``input_led_state`` function does not have a ``@kernel`` decorator and thus must be executed on the host. When the core device calls it, it sends a request to the host to execute it. The host displays the prompt, collects user input, and sends the result back to the core device, which sets the LED state accordingly.
7272

73+
RPC functions must always return a value of the same type. When they return a non-``None`` value, the compiler should be informed in advance of the type of the value, which is what the ``-> TBool`` annotation is for.
74+
7375
The ``break_realtime`` call is necessary to waive the real-time requirements of the LED state change (as the ``input_led_state`` function can take an arbitrarily long time). This will become clearer later as we explain timing control.
7476

7577
Algorithmic features

0 commit comments

Comments
 (0)
Please sign in to comment.