A paragraph (A.K.A. function or paragraph) is FiM++'s way of encapsulating code that runs. Very little code (Such as global variable declaration) runs outside paragraphs.
Related Phrases[]
Here are the reserved phrases used in paragraphs:
- Paragraph Declaration
I learned
Today I learned
using
as
with
- Paragraph Returning
Then you get
- Paragraph Ending
That's all about
- Paragraph Calling
I remembered
I would
Name[]
Restrictions[]
Each paragraph name has the following restrictions:
- Must not contain any keywords (However, operators and literals are okay)
- Must not contain any punctuation
- Must begin with one non-whitespace, non-literal character
- Must end with one non-whitespace character character
Freedoms[]
Each paragraph name also has the following freedoms:
- There is no hard limit on the length
- May have any whitespace character in them
- May contain operators that do not share a name with keywords
- May contain literals, as long as they are not at the beginning of the name
- May contain apostrophes, as they are not punctuation
- Encoded in UTF-8
Examples[]
Here are some examples of good paragraph names:
how to fly
- Paragraph names can have spaces in them.
something simple
- Paragraph names don't have to start with "how to".
how to sing Applejack's Drinking Song
- Even though
'
is used to declare character literals, it is used in the middle of a name, so it is okay.
- Even though
when to tell True Facts
- Even though
true
is a literal, FiM++ is case-sensitive, soTrue
is valid for paragraph naming.
- Even though
why Cloud 9 is the best hotel in Cloudsdale
- Even though
9
is a number literal, it is not at the beginning of the paragraph name
- Even though
Here are some examples of bad paragraph names:
why I learned
I learned
is a keyword, so this will not compile.
how to multiply
- "
multiply
" is an operator, so this will not compile.
- "
about Applejack
,
,
and
- compiler thinks "
,
" is the end of the paragraph name "about Applejack
", and doesn't know what to do with the rest
- compiler thinks "
about Friendship
- "
and
" 'is an operator and keyword.
- "
's
arcasm'
uses quotes'
is used to start a character literal (such as'a'
, so the compiler sees this as an unclosed character literal.
99
99
is always a literal, so it cannot be the beginning of a paragraph name. Additionally, the compiler doesn't know how to handle the rest of the line.
Declaration[]
- Main article: Paragraph Declaration
Paragraphs are declared with the text "I learned
", followed by the name of the paragraph and a punctuation. Mane paragraphs start with "Today I learned
". Return types can be left blank for a void return type, or will follow the paragraph name and the word "with
" or "as
. Parameters (values that are sent to the paragraph) follow the return type and the word "using
" and are separated from each other with "and
".
Returning[]
In order to return a value from a paragraph, the the phrase "Then you get
" is used, followed by the returned value, followed by punctuation. Returned values can be paragraphs, variables, or literals. Returned values must be the same type as is specified in the paragraph declaration.
Example[]
Then you get
the result
.
Closing[]
Paragraphs are closed with the phrase "That's all about
", followed by the paragraph's name, followed by a punctuation.
Example[]
That's all about
how to multiply
!
Calling[]
When used to read, store, or return a value, paragraphs are called in the same context as a variable; simply use the name of a paragraph instead of the name of a variable. Parameters can be specified just like they are declared (using "using
"). To call a paragraph and ignore its returned value, start a line with "I remembered
" or "I would
, followed by the paragraph name and any parameters, then the punctuation.
Examples[]
Calling a paragraph and ignoring its return value:
I remembered
how to count
.
Storing the return value of a paragraph into a variable after passing the paragraph two parameters:
The number of pies
is now
how to multiply
using
cakes
and
cookies
.
Mane Paragraphs[]
Mane paragraphs are paragraphs that run without being explicitly called by code. They can also be run by being called in the code. When the program is run, each mane paragraph is run once, in order of declaration.
Phrases (list) | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|