Skip to content

docs-cs: routine! #106

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

Merged
merged 2 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cs/SUMMARY.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
.. link:datatypes/handle.adoc[Datový typ handle!]
.. link:datatypes/char.adoc[Datový typ char!]
.. link:datatypes/integer.adoc[Datový typ integer!]
.. link:datatypes/handle.adoc[Datový typ handle!]
.. link:datatypes/image.adoc[Datový typ image!]
.. link:datatypes/issue.adoc[Datový typ issue!]
.. link:datatypes/lit-path.adoc[Datový typ lit-path!]
Expand All @@ -24,10 +23,10 @@
.. link:datatypes/none.adoc[Datový typ none!]
.. link:datatypes/object.adoc[Datový typ object!]
.. link:datatypes/pair.adoc[Datový typ pair!]
.. link:datatypes/paren.adoc[Datový typ paren!]
.. link:datatypes/path.adoc[Datový typ path!]
.. link:datatypes/percent.adoc[Datový typ percent!]
.. link:datatypes/refinement.adoc[Datový typ refinement!]
.. link:datatypes/routine.adoc[Datový typ routine!]
.. link:datatypes/set-path.adoc[Datový typ set-path!]
.. link:datatypes/set-word.adoc[Datový typ set-word!]
.. link:datatypes/string.adoc[Datový typ string!]
Expand Down
80 changes: 80 additions & 0 deletions cs/datatypes/routine.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
= Routine! datatype
:toc:
:numbered:

== Úvodem

Hodnota `routine!` představuje funkci pro danou specifikaci a tělo Red/System.

Specifikace přijímá jako argument datový typ Redu a vrací hodnotu, jež automaticky konvertuje při volání na příslušné typy soustavy Red/System.

Dokumentaci pro Red/System lze nalézti zde: https://static.red-lang.org/red-system-specs.html

Typ `routine!` je člen typesetů `default!` a `any-function!`

== Vytvoření

Hodnoty routine! lze vytvořit s použitím funkce `routine`.

== Literálová skladba

```
<routine> ::= routine <routine-spec> <routine-body>
<routine-spec> ::= [<docstring>° <routine-argument>* <locals>° <routine-return>°]
<routine-argument> ::= <word> <argument doc>° | <word> [<type-literal>] <argument-doc>°
<locals> ::= /local <routine-argument>*
<routine-return> ::= return: [<type-literal>]
<type-literal> ::= any-type! | <type-name>
<routine-body> ::= <block>
```

=== Vytvoření při runtime

Hodnoty routine! nejsou pro interpreter povoleny. Musejí být uvedeny typem `set-word` a následně kompilovány.

```red
Red []

increment: routine [
n [integer!]
return: [integer!]
][
n + 1
]
```

Argumenty rutin tvoří jedno slovo typu `any-type!` nebo aliasem struct! ze soustavy Red/System, definovaným zde: https://github.com/red/red/blob/master/runtime/datatypes/structures.reds.

*Příklad*

`integer!` je přeložan na ekvivalent soustavy Red/System:

```red
red-integer!: alias struct! [
header [integer!] ;-- cell header
padding [integer!] ;-- align value on 64-bit boundary
value [integer!] ;-- 32-bit signed integer value
_pad [integer!]
]
```

== Testování hodnot

K ověření, zda hodnota je typu `routine`, použijeme funkce `routine?`.

```red
routine? :increment
```

Datový typ zadané hodnoty získáme dotazem `type?`.

```red
type? :increment
```


== Předdefinovaná slova

=== Funkce

`routine`, `routine?`