mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 10:14:58 +02:00
Merge remote-tracking branch 'upstream/master'
* upstream/master: Add section on eunit in erlang doc Add clarification on bind / match with = op in erlang. Fixes #1139 Removed random "r" Add to contributors Misc. typos and formatting More explanation on virtual destructors Clarify character literals Fixing typo in julia-es.html.markdown [xml/id] Translated JSON to Indonesian (json-id) [xml/id] Translated XML to Indonesian (xml-id) Aligned the comment block [javascript] Fix for issue 1248 Fixed some grammatical issues/typos Typos fixed in julia-es.html.markdown [c++/pt-br] Fix translate on editing object as parameters Update c++.html.markdown Add lang: to header of Python3 cs-cz file. All class constants can be accessed statically Add `kbd` tag Fixed the description of attributes and elements.
This commit is contained in:
@@ -5,6 +5,7 @@ contributors:
|
|||||||
- ["Steven Basart", "http://github.com/xksteven"]
|
- ["Steven Basart", "http://github.com/xksteven"]
|
||||||
- ["Matt Kline", "https://github.com/mrkline"]
|
- ["Matt Kline", "https://github.com/mrkline"]
|
||||||
- ["Geoff Liu", "http://geoffliu.me"]
|
- ["Geoff Liu", "http://geoffliu.me"]
|
||||||
|
- ["Connor Waters", "http://github.com/connorwaters"]
|
||||||
lang: en
|
lang: en
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -53,11 +54,11 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
// However, C++ varies in some of the following ways:
|
// However, C++ varies in some of the following ways:
|
||||||
|
|
||||||
// In C++, character literals are one byte.
|
// In C++, character literals are chars
|
||||||
sizeof('c') == 1
|
sizeof('c') == sizeof(char) == 1
|
||||||
|
|
||||||
// In C, character literals are the same size as ints.
|
// In C, character literals are ints
|
||||||
sizeof('c') == sizeof(10)
|
sizeof('c') == sizeof(int)
|
||||||
|
|
||||||
|
|
||||||
// C++ has strict prototyping
|
// C++ has strict prototyping
|
||||||
@@ -159,9 +160,9 @@ void foo()
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Includes all symbols from `namesapce Second` into the current scope. Note
|
// Includes all symbols from namespace Second into the current scope. Note
|
||||||
// that simply `foo()` no longer works, since it is now ambiguous whether
|
// that simply foo() no longer works, since it is now ambiguous whether
|
||||||
// we're calling the `foo` in `namespace Second` or the top level.
|
// we're calling the foo in namespace Second or the top level.
|
||||||
using namespace Second;
|
using namespace Second;
|
||||||
|
|
||||||
Second::foo(); // prints "This is Second::foo"
|
Second::foo(); // prints "This is Second::foo"
|
||||||
@@ -256,7 +257,7 @@ string tempObjectFun() { ... }
|
|||||||
string retVal = tempObjectFun();
|
string retVal = tempObjectFun();
|
||||||
|
|
||||||
// What happens in the second line is actually:
|
// What happens in the second line is actually:
|
||||||
// - a string object is returned from `tempObjectFun`
|
// - a string object is returned from tempObjectFun
|
||||||
// - a new string is constructed with the returned object as arugment to the
|
// - a new string is constructed with the returned object as arugment to the
|
||||||
// constructor
|
// constructor
|
||||||
// - the returned object is destroyed
|
// - the returned object is destroyed
|
||||||
@@ -268,15 +269,15 @@ string retVal = tempObjectFun();
|
|||||||
// code:
|
// code:
|
||||||
foo(bar(tempObjectFun()))
|
foo(bar(tempObjectFun()))
|
||||||
|
|
||||||
// assuming `foo` and `bar` exist, the object returned from `tempObjectFun` is
|
// assuming foo and bar exist, the object returned from tempObjectFun is
|
||||||
// passed to `bar`, and it is destroyed before `foo` is called.
|
// passed to bar, and it is destroyed before foo is called.
|
||||||
|
|
||||||
// Now back to references. The exception to the "at the end of the enclosing
|
// Now back to references. The exception to the "at the end of the enclosing
|
||||||
// expression" rule is if a temporary object is bound to a const reference, in
|
// expression" rule is if a temporary object is bound to a const reference, in
|
||||||
// which case its life gets extended to the current scope:
|
// which case its life gets extended to the current scope:
|
||||||
|
|
||||||
void constReferenceTempObjectFun() {
|
void constReferenceTempObjectFun() {
|
||||||
// `constRef` gets the temporary object, and it is valid until the end of this
|
// constRef gets the temporary object, and it is valid until the end of this
|
||||||
// function.
|
// function.
|
||||||
const string& constRef = tempObjectFun();
|
const string& constRef = tempObjectFun();
|
||||||
...
|
...
|
||||||
@@ -301,7 +302,7 @@ basic_string(basic_string&& other);
|
|||||||
// Idea being if we are constructing a new string from a temporary object (which
|
// Idea being if we are constructing a new string from a temporary object (which
|
||||||
// is going to be destroyed soon anyway), we can have a more efficient
|
// is going to be destroyed soon anyway), we can have a more efficient
|
||||||
// constructor that "salvages" parts of that temporary string. You will see this
|
// constructor that "salvages" parts of that temporary string. You will see this
|
||||||
// concept referred to as the move semantic.
|
// concept referred to as "move semantics".
|
||||||
|
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
// Classes and object-oriented programming
|
// Classes and object-oriented programming
|
||||||
@@ -349,7 +350,10 @@ public:
|
|||||||
// These are called when an object is deleted or falls out of scope.
|
// These are called when an object is deleted or falls out of scope.
|
||||||
// This enables powerful paradigms such as RAII
|
// This enables powerful paradigms such as RAII
|
||||||
// (see below)
|
// (see below)
|
||||||
// Destructors must be virtual to allow classes to be derived from this one.
|
// The destructor should be virtual if a class is to be derived from;
|
||||||
|
// if it is not virtual, then the derived class' destructor will
|
||||||
|
// not be called if the object is destroyed through a base-class reference
|
||||||
|
// or pointer.
|
||||||
virtual ~Dog();
|
virtual ~Dog();
|
||||||
|
|
||||||
}; // A semicolon must follow the class definition.
|
}; // A semicolon must follow the class definition.
|
||||||
@@ -492,9 +496,10 @@ int main () {
|
|||||||
/////////////////////
|
/////////////////////
|
||||||
|
|
||||||
// Templates in C++ are mostly used for generic programming, though they are
|
// Templates in C++ are mostly used for generic programming, though they are
|
||||||
// much more powerful than generics constructs in other languages. It also
|
// much more powerful than generic constructs in other languages. They also
|
||||||
// supports explicit and partial specialization, functional-style type classes,
|
// support explicit and partial specialization and functional-style type
|
||||||
// and also it's Turing-complete.
|
// classes; in fact, they are a Turing-complete functional language embedded
|
||||||
|
// in C++!
|
||||||
|
|
||||||
// We start with the kind of generic programming you might be familiar with. To
|
// We start with the kind of generic programming you might be familiar with. To
|
||||||
// define a class or function that takes a type parameter:
|
// define a class or function that takes a type parameter:
|
||||||
@@ -506,7 +511,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// During compilation, the compiler actually generates copies of each template
|
// During compilation, the compiler actually generates copies of each template
|
||||||
// with parameters substituted, and so the full definition of the class must be
|
// with parameters substituted, so the full definition of the class must be
|
||||||
// present at each invocation. This is why you will see template classes defined
|
// present at each invocation. This is why you will see template classes defined
|
||||||
// entirely in header files.
|
// entirely in header files.
|
||||||
|
|
||||||
@@ -520,13 +525,13 @@ intBox.insert(123);
|
|||||||
Box<Box<int> > boxOfBox;
|
Box<Box<int> > boxOfBox;
|
||||||
boxOfBox.insert(intBox);
|
boxOfBox.insert(intBox);
|
||||||
|
|
||||||
// Up until C++11, you must place a space between the two '>'s, otherwise '>>'
|
// Until C++11, you had to place a space between the two '>'s, otherwise '>>'
|
||||||
// will be parsed as the right shift operator.
|
// would be parsed as the right shift operator.
|
||||||
|
|
||||||
// You will sometimes see
|
// You will sometimes see
|
||||||
// template<typename T>
|
// template<typename T>
|
||||||
// instead. The 'class' keyword and 'typename' keyword are _mostly_
|
// instead. The 'class' keyword and 'typename' keywords are _mostly_
|
||||||
// interchangeable in this case. For full explanation, see
|
// interchangeable in this case. For the full explanation, see
|
||||||
// http://en.wikipedia.org/wiki/Typename
|
// http://en.wikipedia.org/wiki/Typename
|
||||||
// (yes, that keyword has its own Wikipedia page).
|
// (yes, that keyword has its own Wikipedia page).
|
||||||
|
|
||||||
@@ -582,12 +587,15 @@ try {
|
|||||||
// Do not allocate exceptions on the heap using _new_.
|
// Do not allocate exceptions on the heap using _new_.
|
||||||
throw std::runtime_error("A problem occurred");
|
throw std::runtime_error("A problem occurred");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch exceptions by const reference if they are objects
|
// Catch exceptions by const reference if they are objects
|
||||||
catch (const std::exception& ex)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
std::cout << ex.what();
|
std::cout << ex.what();
|
||||||
|
}
|
||||||
|
|
||||||
// Catches any exception not caught by previous _catch_ blocks
|
// Catches any exception not caught by previous _catch_ blocks
|
||||||
} catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
std::cout << "Unknown exception caught";
|
std::cout << "Unknown exception caught";
|
||||||
throw; // Re-throws the exception
|
throw; // Re-throws the exception
|
||||||
@@ -597,8 +605,8 @@ catch (const std::exception& ex)
|
|||||||
// RAII
|
// RAII
|
||||||
///////
|
///////
|
||||||
|
|
||||||
// RAII stands for Resource Allocation Is Initialization.
|
// RAII stands for "Resource Acquisition Is Initialization".
|
||||||
// It is often considered the most powerful paradigm in C++,
|
// It is often considered the most powerful paradigm in C++
|
||||||
// and is the simple concept that a constructor for an object
|
// and is the simple concept that a constructor for an object
|
||||||
// acquires that object's resources and the destructor releases them.
|
// acquires that object's resources and the destructor releases them.
|
||||||
|
|
||||||
@@ -619,9 +627,9 @@ void doSomethingWithAFile(const char* filename)
|
|||||||
// Unfortunately, things are quickly complicated by error handling.
|
// Unfortunately, things are quickly complicated by error handling.
|
||||||
// Suppose fopen can fail, and that doSomethingWithTheFile and
|
// Suppose fopen can fail, and that doSomethingWithTheFile and
|
||||||
// doSomethingElseWithIt return error codes if they fail.
|
// doSomethingElseWithIt return error codes if they fail.
|
||||||
// (Exceptions are the preferred way of handling failure,
|
// (Exceptions are the preferred way of handling failure,
|
||||||
// but some programmers, especially those with a C background,
|
// but some programmers, especially those with a C background,
|
||||||
// disagree on the utility of exceptions).
|
// disagree on the utility of exceptions).
|
||||||
// We now have to check each call for failure and close the file handle
|
// We now have to check each call for failure and close the file handle
|
||||||
// if a problem occurred.
|
// if a problem occurred.
|
||||||
bool doSomethingWithAFile(const char* filename)
|
bool doSomethingWithAFile(const char* filename)
|
||||||
@@ -735,21 +743,23 @@ class Foo {
|
|||||||
virtual void bar();
|
virtual void bar();
|
||||||
};
|
};
|
||||||
class FooSub : public Foo {
|
class FooSub : public Foo {
|
||||||
virtual void bar(); // overrides Foo::bar!
|
virtual void bar(); // Overrides Foo::bar!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 0 == false == NULL (most of the time)!
|
// 0 == false == NULL (most of the time)!
|
||||||
bool* pt = new bool;
|
bool* pt = new bool;
|
||||||
*pt = 0; // Sets the value points by 'pt' to false.
|
*pt = 0; // Sets the value points by 'pt' to false.
|
||||||
pt = 0; // Sets 'pt' to the null pointer. Both lines compile without warnings.
|
pt = 0; // Sets 'pt' to the null pointer. Both lines compile without warnings.
|
||||||
|
|
||||||
// nullptr is supposed to fix some of that issue:
|
// nullptr is supposed to fix some of that issue:
|
||||||
int* pt2 = new int;
|
int* pt2 = new int;
|
||||||
*pt2 = nullptr; // Doesn't compile
|
*pt2 = nullptr; // Doesn't compile
|
||||||
pt2 = nullptr; // Sets pt2 to null.
|
pt2 = nullptr; // Sets pt2 to null.
|
||||||
|
|
||||||
// But somehow 'bool' type is an exception (this is to make `if (ptr)` compile).
|
// There is an exception made for bools.
|
||||||
|
// This is to allow you to test for null pointers with if(!ptr),
|
||||||
|
// but as a consequence you can assign nullptr to a bool directly!
|
||||||
*pt = nullptr; // This still compiles, even though '*pt' is a bool!
|
*pt = nullptr; // This still compiles, even though '*pt' is a bool!
|
||||||
|
|
||||||
|
|
||||||
@@ -776,12 +786,12 @@ vector<Foo> v;
|
|||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
v.push_back(Foo());
|
v.push_back(Foo());
|
||||||
|
|
||||||
// Following line sets size of v to 0, but destructors don't get called,
|
// Following line sets size of v to 0, but destructors don't get called
|
||||||
// and resources aren't released!
|
// and resources aren't released!
|
||||||
v.empty();
|
v.empty();
|
||||||
v.push_back(Foo()); // New value is copied into the first Foo we inserted in the loop.
|
v.push_back(Foo()); // New value is copied into the first Foo we inserted
|
||||||
|
|
||||||
// Truly destroys all values in v. See section about temporary object for
|
// Truly destroys all values in v. See section about temporary objects for
|
||||||
// explanation of why this works.
|
// explanation of why this works.
|
||||||
v.swap(vector<Foo>());
|
v.swap(vector<Foo>());
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ contributors:
|
|||||||
translators:
|
translators:
|
||||||
- ["Tomáš Bedřich", "http://tbedrich.cz"]
|
- ["Tomáš Bedřich", "http://tbedrich.cz"]
|
||||||
filename: learnpython3.py
|
filename: learnpython3.py
|
||||||
|
lang: cs-cz
|
||||||
---
|
---
|
||||||
|
|
||||||
Python byl vytvořen Guidem Van Rossum v raných 90. letech. Nyní je jedním z nejpopulárnějších jazyků.
|
Python byl vytvořen Guidem Van Rossum v raných 90. letech. Nyní je jedním z nejpopulárnějších jazyků.
|
||||||
|
@@ -7,19 +7,19 @@ contributors:
|
|||||||
filename: learncss.css
|
filename: learncss.css
|
||||||
---
|
---
|
||||||
|
|
||||||
In early days of web there was no visual elements, just pure text. But with the
|
In the early days of the web there were no visual elements, just pure text. But with the
|
||||||
further development of browser fully visual web pages also became common.
|
further development of browsers, fully visual web pages also became common.
|
||||||
CSS is the standard language that exists to keep the separation between
|
CSS is the standard language that exists to keep the separation between
|
||||||
the content (HTML) and the look-and-feel of web pages.
|
the content (HTML) and the look-and-feel of web pages.
|
||||||
|
|
||||||
In short, what CSS does is to provide a syntax that enables you to target
|
In short, what CSS does is to provide a syntax that enables you to target
|
||||||
different elements on an HTML page and assign different visual properties to them.
|
different elements on an HTML page and assign different visual properties to them.
|
||||||
|
|
||||||
Like any other language, CSS has many versions. Here we focus on CSS2.0
|
Like any other languages, CSS has many versions. Here we focus on CSS2.0,
|
||||||
which is not the most recent but the most widely supported and compatible version.
|
which is not the most recent version, but is the most widely supported and compatible version.
|
||||||
|
|
||||||
**NOTE:** Because the outcome of CSS is some visual effects, in order to
|
**NOTE:** Because the outcome of CSS consists of visual effects, in order to
|
||||||
learn it, you need try all different things in a
|
learn it, you need try everything in a
|
||||||
CSS playground like [dabblet](http://dabblet.com/).
|
CSS playground like [dabblet](http://dabblet.com/).
|
||||||
The main focus of this article is on the syntax and some general tips.
|
The main focus of this article is on the syntax and some general tips.
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ filename: learnerlang.erl
|
|||||||
%% 1. Variables and pattern matching.
|
%% 1. Variables and pattern matching.
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
% In Erlang new variables are bound with an `=` statement.
|
||||||
Num = 42. % All variable names must start with an uppercase letter.
|
Num = 42. % All variable names must start with an uppercase letter.
|
||||||
|
|
||||||
% Erlang has single-assignment variables; if you try to assign a different
|
% Erlang has single-assignment variables; if you try to assign a different
|
||||||
@@ -32,9 +33,11 @@ Num = 42. % All variable names must start with an uppercase letter.
|
|||||||
Num = 43. % ** exception error: no match of right hand side value 43
|
Num = 43. % ** exception error: no match of right hand side value 43
|
||||||
|
|
||||||
% In most languages, `=` denotes an assignment statement. In Erlang, however,
|
% In most languages, `=` denotes an assignment statement. In Erlang, however,
|
||||||
% `=` denotes a pattern-matching operation. `Lhs = Rhs` really means this:
|
% `=` denotes a pattern-matching operation. When an empty variable is used on the
|
||||||
% evaluate the right side (`Rhs`), and then match the result against the
|
% left hand side of the `=` operator to is bound (assigned), but when a bound
|
||||||
% pattern on the left side (`Lhs`).
|
% varaible is used on the left hand side the following behaviour is observed.
|
||||||
|
% `Lhs = Rhs` really means this: evaluate the right side (`Rhs`), and then
|
||||||
|
% match the result against the pattern on the left side (`Lhs`).
|
||||||
Num = 7 * 6.
|
Num = 7 * 6.
|
||||||
|
|
||||||
% Floating-point number.
|
% Floating-point number.
|
||||||
@@ -299,6 +302,39 @@ CalculateArea ! {circle, 2}. % 12.56000000000000049738
|
|||||||
% The shell is also a process; you can use `self` to get the current pid.
|
% The shell is also a process; you can use `self` to get the current pid.
|
||||||
self(). % <0.41.0>
|
self(). % <0.41.0>
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
%% 5. Testing with EUnit
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
% Unit tests can be written using EUnits's test generators and assert macros
|
||||||
|
-module(fib).
|
||||||
|
-export([fib/1]).
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
fib(0) -> 1;
|
||||||
|
fib(1) -> 1;
|
||||||
|
fib(N) when N > 1 -> fib(N-1) + fib(N-2).
|
||||||
|
|
||||||
|
fib_test_() ->
|
||||||
|
[?_assert(fib(0) =:= 1),
|
||||||
|
?_assert(fib(1) =:= 1),
|
||||||
|
?_assert(fib(2) =:= 2),
|
||||||
|
?_assert(fib(3) =:= 3),
|
||||||
|
?_assert(fib(4) =:= 5),
|
||||||
|
?_assert(fib(5) =:= 8),
|
||||||
|
?_assertException(error, function_clause, fib(-1)),
|
||||||
|
?_assert(fib(31) =:= 2178309)
|
||||||
|
].
|
||||||
|
|
||||||
|
% EUnit will automatically export to a test() fucntion to allo running the tests
|
||||||
|
% in the erlang shell
|
||||||
|
fib:test()
|
||||||
|
|
||||||
|
% The popular erlang build tool Rebar is also compatible with EUnit
|
||||||
|
% ```
|
||||||
|
% rebar eunit
|
||||||
|
% ```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
@@ -45,7 +45,7 @@ Esto se basa en la versión `0.3.11`.
|
|||||||
# Los comentarios de una línea comienzan con una almohadilla (o signo de gato).
|
# Los comentarios de una línea comienzan con una almohadilla (o signo de gato).
|
||||||
|
|
||||||
#=
|
#=
|
||||||
Los commentarios multilínea pueden escribirse
|
Los comentarios multilínea pueden escribirse
|
||||||
usando '#=' antes de el texto y '=#'
|
usando '#=' antes de el texto y '=#'
|
||||||
después del texto. También se pueden anidar.
|
después del texto. También se pueden anidar.
|
||||||
=#
|
=#
|
||||||
@@ -174,7 +174,7 @@ otraVariable_123! = 6 # => 6
|
|||||||
otra_variable
|
otra_variable
|
||||||
|
|
||||||
* Los nombres de los tipos comienzan con una letra mayúscula y separación de
|
* Los nombres de los tipos comienzan con una letra mayúscula y separación de
|
||||||
palabras se muestra con CamelCase en vez de guion bajo:
|
palabras se muestra con CamelCase en vez de guión bajo:
|
||||||
|
|
||||||
OtroTipo
|
OtroTipo
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ matrix = [1 2; 3 4]
|
|||||||
3 4
|
3 4
|
||||||
=#
|
=#
|
||||||
|
|
||||||
# Añadir cosas a la final de un arreglo con push! y append!.
|
# Añadir cosas al final de un arreglo con push! y append!.
|
||||||
push!(a, 1) # => [1]
|
push!(a, 1) # => [1]
|
||||||
push!(a, 2) # => [1,2]
|
push!(a, 2) # => [1,2]
|
||||||
push!(a, 4) # => [1,2,4]
|
push!(a, 4) # => [1,2,4]
|
||||||
@@ -237,7 +237,7 @@ a[end] # => 6
|
|||||||
shift!(a) # => 1 y a es ahora: [2,4,3,4,5,6]
|
shift!(a) # => 1 y a es ahora: [2,4,3,4,5,6]
|
||||||
unshift!(a, 7) # => [7,2,4,3,4,5,6]
|
unshift!(a, 7) # => [7,2,4,3,4,5,6]
|
||||||
|
|
||||||
# Los nombres de funciónes que terminan en exclamaciones indican que modifican
|
# Los nombres de funciones que terminan en exclamaciones indican que modifican
|
||||||
# su o sus argumentos de entrada.
|
# su o sus argumentos de entrada.
|
||||||
arr = [5, 4, 6] # => 3-element Array{Int64,1}: [5,4,6]
|
arr = [5, 4, 6] # => 3-element Array{Int64,1}: [5,4,6]
|
||||||
sort(arr) # => [4,5,6] y arr es todavía: [5,4,6]
|
sort(arr) # => [4,5,6] y arr es todavía: [5,4,6]
|
||||||
@@ -710,7 +710,7 @@ end
|
|||||||
# Sólo define una función del mismo nombre que el tipo y llama al constructor
|
# Sólo define una función del mismo nombre que el tipo y llama al constructor
|
||||||
# existente para obtener un valor del tipo correcto.
|
# existente para obtener un valor del tipo correcto.
|
||||||
|
|
||||||
# Este es un constructor externo porque es fuera de la definición del tipo.
|
# Este es un constructor externo porque está fuera de la definición del tipo.
|
||||||
Leon(rugido::String) = Leon("verde", rugido)
|
Leon(rugido::String) = Leon("verde", rugido)
|
||||||
|
|
||||||
type Pantera <: Gato # Pantera también es un a subtipo de Gato
|
type Pantera <: Gato # Pantera también es un a subtipo de Gato
|
||||||
@@ -730,10 +730,10 @@ end
|
|||||||
########################
|
########################
|
||||||
|
|
||||||
# En Julia, todas las funciones nombradas son funciones genéricas.
|
# En Julia, todas las funciones nombradas son funciones genéricas.
|
||||||
# Esto significa que se construyen a partir de muchos métodosmás pequeños.
|
# Esto significa que se construyen a partir de muchos métodos más pequeños.
|
||||||
# Cada constructor de Leon es un método de la función genérica Leon.
|
# Cada constructor de Leon es un método de la función genérica Leon.
|
||||||
|
|
||||||
# Por ejemplo, vamos a hacer métodos para para Leon, Pantera, y Tigre de una
|
# Por ejemplo, vamos a hacer métodos para Leon, Pantera, y Tigre de una
|
||||||
# función genérica maullar:
|
# función genérica maullar:
|
||||||
|
|
||||||
# acceso utilizando notación de puntos
|
# acceso utilizando notación de puntos
|
||||||
|
60
id-id/json-id.html.markdown
Normal file
60
id-id/json-id.html.markdown
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
language: json
|
||||||
|
filename: learnjson.json
|
||||||
|
contributors:
|
||||||
|
- ["Anna Harren", "https://github.com/iirelu"]
|
||||||
|
- ["Marco Scannadinari", "https://github.com/marcoms"]
|
||||||
|
translators
|
||||||
|
- ["Rizky Luthfianto", "https://github.com/rilut"]
|
||||||
|
---
|
||||||
|
|
||||||
|
JSON adalah format pertukaran data yang sangat simpel, kemungkinan besar,
|
||||||
|
ini adalah "Learn X in Y Minutes" yang paling singkat.
|
||||||
|
|
||||||
|
Murninya, JSON tidak mempunyai fitur komentar, tapi kebanyakan parser akan
|
||||||
|
menerima komentar bergaya bahasa C (`//`, `/* */`). Namun, pada halaman ini,
|
||||||
|
hanya dicontohkan JSON yang 100% valid.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"kunci": "nilai",
|
||||||
|
|
||||||
|
"kunci": "harus selalu diapit tanda kutip",
|
||||||
|
"angka": 0,
|
||||||
|
"strings": "Halø, dunia. Semua karaktor unicode diperbolehkan, terumasuk \"escaping\".",
|
||||||
|
"punya tipe data boolean?": true,
|
||||||
|
"nilai kosong": null,
|
||||||
|
|
||||||
|
"angka besar": 1.2e+100,
|
||||||
|
|
||||||
|
"obyek": {
|
||||||
|
"komentar": "Most of your structure will come from objects.",
|
||||||
|
|
||||||
|
"array": [0, 1, 2, 3, "Array bisa berisi apapun.", 5],
|
||||||
|
|
||||||
|
"obyek lainnya": {
|
||||||
|
"komentar": "Obyek-obyek JSON dapat dibuat bersarang, sangat berguna."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"iseng-iseng": [
|
||||||
|
{
|
||||||
|
"sumber potassium": ["pisang"]
|
||||||
|
},
|
||||||
|
[
|
||||||
|
[1, 0, 0, 0],
|
||||||
|
[0, 1, 0, 0],
|
||||||
|
[0, 0, 1, "neo"],
|
||||||
|
[0, 0, 0, 1]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
"gaya alternatif": {
|
||||||
|
"komentar": "lihat ini!"
|
||||||
|
, "posisi tanda koma": "tak masalah. selama sebelum nilai berikutnya, valid-valid saja"
|
||||||
|
, "komentar lainnya": "betapa asyiknya"
|
||||||
|
},
|
||||||
|
|
||||||
|
"singkat": "Dan Anda selesai! Sekarang Anda tahu apa saja yang disediakan oleh JSON."
|
||||||
|
}
|
||||||
|
```
|
129
id-id/xml-id.html.markdown
Normal file
129
id-id/xml-id.html.markdown
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
---
|
||||||
|
language: xml
|
||||||
|
filename: learnxml.xml
|
||||||
|
contributors:
|
||||||
|
- ["João Farias", "https://github.com/JoaoGFarias"]
|
||||||
|
translators:
|
||||||
|
- ["Rizky Luthfianto", "https://github.com/rilut"]
|
||||||
|
---
|
||||||
|
|
||||||
|
XML adalah bahasa markup yang dirancang untuk menyimpan dan mengirim data.
|
||||||
|
|
||||||
|
Tidak seperti HTML, XML tidak menentukan bagaimana menampilkan atau format data, hanya membawanya.
|
||||||
|
|
||||||
|
* Sintaks XML
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<!-- Komentar di XML seperti ini -->
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<tokobuku>
|
||||||
|
<buku category="MEMASAK">
|
||||||
|
<judul lang="en">Everyday Italian</judul>
|
||||||
|
<pengarang>Giada De Laurentiis</pengarang>
|
||||||
|
<tahun>2005</tahun>
|
||||||
|
<harga>30.00</harga>
|
||||||
|
</buku>
|
||||||
|
<buku category="ANAK">
|
||||||
|
<judul lang="en">Harry Potter</judul>
|
||||||
|
<pengarang>J K. Rowling</pengarang>
|
||||||
|
<tahun>2005</tahun>
|
||||||
|
<harga>29.99</harga>
|
||||||
|
</buku>
|
||||||
|
<buku category="WEB">
|
||||||
|
<judul lang="en">Learning XML</judul>
|
||||||
|
<pengarang>Erik T. Ray</pengarang>
|
||||||
|
<tahun>2003</tahun>
|
||||||
|
<harga>39.95</harga>
|
||||||
|
</buku>
|
||||||
|
</tokobuku>
|
||||||
|
|
||||||
|
<!-- Di atas adalah contoh file XML biasa.
|
||||||
|
Dimulai dengan deklarasi, menginformasikan beberapa metadata (opsional).
|
||||||
|
|
||||||
|
XML menggunakan struktur pohon. Di atas, simpul akar adalah 'tokobuku',
|
||||||
|
yang memiliki tiga node anak, para 'buku'. Node-node tersebut dapat memiliki
|
||||||
|
node-node anak, dan seterusnya ...
|
||||||
|
|
||||||
|
Node dibuat menggunakan tag buka/tutup, dan node-node anak hanya
|
||||||
|
berada di antara tag buka dan tutup .-->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- XML membawa dua jenis data:
|
||||||
|
1 - Atribut -> Itu metadata tentang sebuah node.
|
||||||
|
Biasanya, parser XML menggunakan informasi ini untuk menyimpan data dengan
|
||||||
|
benar. Hal ini ditandai dengan muncul dengan format nama = "nilai" dalam pembukaan tag.
|
||||||
|
2 - Elemen -> Itu data yang murni.
|
||||||
|
Itulah yang parser akan mengambil dari file XML.
|
||||||
|
Elemen muncul antara tag membuka dan menutup.-->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Di bawah ini, unsur dengan dua atribut-->
|
||||||
|
<file type="gif" id="4293">komputer.gif</file>
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* Dokumen yang well-formated & Validasi
|
||||||
|
|
||||||
|
Sebuah dokumen XML disebut well-formated jika sintaksisnya benar.
|
||||||
|
Namun, juga mungkin untuk mendefinisikan lebih banyak batasan dalam dokumen,
|
||||||
|
menggunakan definisi dokumen, seperti DTD dan XML Schema.
|
||||||
|
|
||||||
|
Sebuah dokumen XML yang mengikuti definisi dokumen disebut valid,
|
||||||
|
jika sesuai dokumen itu.
|
||||||
|
|
||||||
|
Dengan alat ini, Anda dapat memeriksa data XML di luar logika aplikasi.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
|
||||||
|
<!-- Di bawah, Anda dapat melihat versi sederhana dari dokumen tokobuku,
|
||||||
|
dengan penambahan definisi DTD .-->
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE catatan SYSTEM "tokobuku.dtd">
|
||||||
|
<tokobuku>
|
||||||
|
<buku category="MEMASAK">
|
||||||
|
<judul >Everyday Italian</judul>
|
||||||
|
<harga>30.00</harga>
|
||||||
|
</buku>
|
||||||
|
</tokobuku>
|
||||||
|
|
||||||
|
<!-- This DTD could be something like:-->
|
||||||
|
|
||||||
|
<!DOCTYPE catatan
|
||||||
|
[
|
||||||
|
<!ELEMENT tokobuku (buku+)>
|
||||||
|
<!ELEMENT buku (judul,harga)>
|
||||||
|
<!ATTLIST buku category CDATA "Sastra">
|
||||||
|
<!ELEMENT judul (#PCDATA)>
|
||||||
|
<!ELEMENT harga (#PCDATA)>
|
||||||
|
]>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- DTD dimulai dengan deklarasi.
|
||||||
|
Berikut, node akar dinyatakan, membutuhkan 1 atau lebih anak node 'buku'.
|
||||||
|
Setiap 'buku' harus berisi tepat satu 'judul' dan 'harga' dan atribut
|
||||||
|
disebut 'kategori', dengan "Sastra" sebagai nilai default.
|
||||||
|
Node yang 'judul' dan 'harga' mengandung karakter data diurai .-->
|
||||||
|
|
||||||
|
<!-- DTD dapat dideklarasikan di dalam file XML itu sendiri .-->
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!DOCTYPE catatan
|
||||||
|
[
|
||||||
|
<!ELEMENT tokobuku (buku+)>
|
||||||
|
<!ELEMENT buku (judul,harga)>
|
||||||
|
<!ATTLIST buku category CDATA "Sastra">
|
||||||
|
<!ELEMENT judul (#PCDATA)>
|
||||||
|
<!ELEMENT harga (#PCDATA)>
|
||||||
|
]>
|
||||||
|
|
||||||
|
<tokobuku>
|
||||||
|
<buku category="MEMASAK">
|
||||||
|
<judul >Everyday Italian</judul>
|
||||||
|
<harga>30.00</harga>
|
||||||
|
</buku>
|
||||||
|
</tokobuku>
|
||||||
|
```
|
@@ -475,9 +475,6 @@ myNumber === myNumberObj; // = false
|
|||||||
if (0){
|
if (0){
|
||||||
// This code won't execute, because 0 is falsy.
|
// This code won't execute, because 0 is falsy.
|
||||||
}
|
}
|
||||||
if (Number(0)){
|
|
||||||
// This code *will* execute, because Number(0) is truthy.
|
|
||||||
}
|
|
||||||
|
|
||||||
// However, the wrapper objects and the regular builtins share a prototype, so
|
// However, the wrapper objects and the regular builtins share a prototype, so
|
||||||
// you can actually add functionality to a string, for instance.
|
// you can actually add functionality to a string, for instance.
|
||||||
|
@@ -232,6 +232,12 @@ can be anything so long as they are unique. -->
|
|||||||
I want to type *this text surrounded by asterisks* but I don't want it to be
|
I want to type *this text surrounded by asterisks* but I don't want it to be
|
||||||
in italics, so I do this: \*this text surrounded by asterisks\*.
|
in italics, so I do this: \*this text surrounded by asterisks\*.
|
||||||
|
|
||||||
|
<!-- Keyboard keys -->
|
||||||
|
<!-- In Github Flavored Markdown, you can use a <kbd> tag to represent keyboard keys -->
|
||||||
|
|
||||||
|
Your computer crashed? Try sending a
|
||||||
|
<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Del</kbd>
|
||||||
|
|
||||||
<!-- Tables -->
|
<!-- Tables -->
|
||||||
<!-- Tables are only available in Github Flavored Markdown and are slightly
|
<!-- Tables are only available in Github Flavored Markdown and are slightly
|
||||||
cumbersome, but if you really want it: -->
|
cumbersome, but if you really want it: -->
|
||||||
|
@@ -487,7 +487,7 @@ class MyClass
|
|||||||
* Declaring class properties or methods as static makes them accessible without
|
* Declaring class properties or methods as static makes them accessible without
|
||||||
* needing an instantiation of the class. A property declared as static can not
|
* needing an instantiation of the class. A property declared as static can not
|
||||||
* be accessed with an instantiated class object (though a static method can).
|
* be accessed with an instantiated class object (though a static method can).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function myStaticMethod()
|
public static function myStaticMethod()
|
||||||
{
|
{
|
||||||
@@ -495,7 +495,9 @@ class MyClass
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Class constants can always be accessed statically
|
||||||
echo MyClass::MY_CONST; // Outputs 'value';
|
echo MyClass::MY_CONST; // Outputs 'value';
|
||||||
|
|
||||||
echo MyClass::$staticVar; // Outputs 'static';
|
echo MyClass::$staticVar; // Outputs 'static';
|
||||||
MyClass::myStaticMethod(); // Outputs 'I am static';
|
MyClass::myStaticMethod(); // Outputs 'I am static';
|
||||||
|
|
||||||
|
@@ -304,7 +304,7 @@ void Dog::Dog()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Objetos (como strings) devem ser passados por referência
|
// Objetos (como strings) devem ser passados por referência
|
||||||
// se você está modificando-os ou referência const se você não é.
|
// se você pretende modificá-los, ou com const caso contrário.
|
||||||
void Dog::setName(const std::string& dogsName)
|
void Dog::setName(const std::string& dogsName)
|
||||||
{
|
{
|
||||||
name = dogsName;
|
name = dogsName;
|
||||||
|
@@ -198,7 +198,7 @@ li[::-1] # => [3, 4, 2, 1]
|
|||||||
|
|
||||||
# Remove arbitrary elements from a list with "del"
|
# Remove arbitrary elements from a list with "del"
|
||||||
del li[2] # li is now [1, 2, 3]
|
del li[2] # li is now [1, 2, 3]
|
||||||
r
|
|
||||||
# You can add lists
|
# You can add lists
|
||||||
li + other_li # => [1, 2, 3, 4, 5, 6]
|
li + other_li # => [1, 2, 3, 4, 5, 6]
|
||||||
# Note: values for li and for other_li are not modified.
|
# Note: values for li and for other_li are not modified.
|
||||||
|
@@ -49,10 +49,11 @@ Unlike HTML, XML does not specify how to display or to format data, just carry i
|
|||||||
<!-- XML carries two kind of data:
|
<!-- XML carries two kind of data:
|
||||||
1 - Attributes -> That's metadata about a node.
|
1 - Attributes -> That's metadata about a node.
|
||||||
Usually, the XML parser uses this information to store the data properly.
|
Usually, the XML parser uses this information to store the data properly.
|
||||||
It is characterized by appearing in parenthesis within the opening tag
|
It is characterized by appearing with the format name="value" within the opening
|
||||||
|
tag.
|
||||||
2 - Elements -> That's pure data.
|
2 - Elements -> That's pure data.
|
||||||
That's what the parser will retrieve from the XML file.
|
That's what the parser will retrieve from the XML file.
|
||||||
Elements appear between the open and close tags, without parenthesis. -->
|
Elements appear between the open and close tags. -->
|
||||||
|
|
||||||
|
|
||||||
<!-- Below, an element with two attributes -->
|
<!-- Below, an element with two attributes -->
|
||||||
|
Reference in New Issue
Block a user