diff options
| -rw-r--r-- | brainfuck.html.markdown | 32 | ||||
| -rw-r--r-- | es-es/csharp-es.html.markdown | 631 | ||||
| -rw-r--r-- | go.html.markdown | 10 | ||||
| -rw-r--r-- | ko-kr/clojure-kr.html.markdown | 383 | ||||
| -rw-r--r-- | lua.html.markdown | 15 | ||||
| -rw-r--r-- | objective-c.html.markdown | 10 | ||||
| -rw-r--r-- | ro-ro/python-ro.html.markdown | 489 | ||||
| -rw-r--r-- | tr-tr/c-tr.html.markdown | 4 | ||||
| -rw-r--r-- | tr-tr/php-tr.html.markdown | 18 | 
9 files changed, 1561 insertions, 31 deletions
| diff --git a/brainfuck.html.markdown b/brainfuck.html.markdown index 2b7ce4db..9282381f 100644 --- a/brainfuck.html.markdown +++ b/brainfuck.html.markdown @@ -1,11 +1,12 @@  ---  language: brainfuck  contributors: -    - ["Prajit Ramachandran", "http://prajitr.github.io"] +    - ["Prajit Ramachandran", "http://prajitr.github.io/"] +    - ["Mathias Bynens", "http://mathiasbynens.be/"]  --- -Brainfuck is an extremely minimal programming language (just 8 commands) and  -is Turing complete. +Brainfuck (not capitalized except at the start of a sentence) is an extremely +minimal Turing-complete programming language with just 8 commands.  ```  Any character not "><+-.,[]" (excluding quotation marks) is ignored. @@ -27,7 +28,7 @@ There are eight commands:  [ and ] form a while loop. Obviously, they must be balanced. -Let's look at some basic Brainfuck programs. +Let's look at some basic brainfuck programs.  ++++++ [ > ++++++++++ < - ] > +++++ . @@ -45,21 +46,18 @@ print cell #2's value. 65 is 'A' in ASCII, so 'A' is printed to the terminal.  , [ > + < - ] > . -This program reads a character from the user input, copies the character into -another cell, and prints out the same character. - -, reads in a character from the user into cell #1. Then we start a loop. Move -to cell #2, increment the value at cell #2, move back to cell #1, and decrement -the value at cell #1. This continues on until cell #1 is 0, and cell #2 holds -cell #1's old value. Because we're on cell #1 at the end of the loop, move to -cell #2, and then print out the value in ASCII. +This program reads a character from the user input and copies the character into +cell #1. Then we start a loop. Move to cell #2, increment the value at cell #2, +move back to cell #1, and decrement the value at cell #1. This continues on +until cell #1 is 0, and cell #2 holds cell #1's old value. Because we're on +cell #1 at the end of the loop, move to cell #2, and then print out the value +in ASCII.  Also keep in mind that the spaces are purely for readibility purposes. You  -could just as easily write it as +could just as easily write it as:  ,[>+<-]>. -  Try and figure out what this program does:  ,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>   @@ -73,7 +71,7 @@ problem: at the end of the inner loop, cell #2 is zero. To solve this problem,  we also increment cell #4, and then recopy cell #4 into cell #2.  ``` -And that's Brainfuck. Not that hard, eh? For fun, you can write your own  -Brainfuck programs, or you can write a Brainfuck interpreter in another  +And that's brainfuck. Not that hard, eh? For fun, you can write your own  +brainfuck programs, or you can write a brainfuck interpreter in another   language. The interpreter is fairly simple to implement, but if you're a -masochist, trying writing a Brainfuck interpreter... in Brainfuck. +masochist, try writing a brainfuck interpreter… in brainfuck. diff --git a/es-es/csharp-es.html.markdown b/es-es/csharp-es.html.markdown new file mode 100644 index 00000000..7d1a1201 --- /dev/null +++ b/es-es/csharp-es.html.markdown @@ -0,0 +1,631 @@ +--- +language: c# +contributors: +    - ["Irfan Charania", "https://github.com/irfancharania"] +    - ["Max Yankov", "https://github.com/golergka"] +translators: +    - ["Olfran Jiménez", "https://twitter.com/neslux"]	 +filename: LearnCSharp-es.cs +--- + +C# es un lenguaje orientado a objetos elegante y de tipado seguro que +permite a los desarrolladores construir una variedad de aplicaciones +seguras y robustas que se ejecutan en el Framework .NET. + +[Lee más aquí.](http://msdn.microsoft.com/es-es/library/vstudio/z1zx9t92.aspx) + +```c# +// Los comentarios de una sola línea comienzan con // +/* +Los comentarios de múltiples líneas son de esta manera +*/ +/// <summary> +/// Este es un comentario de documentación XML +/// </summary> + +// Especifica el espacio de nombres que estará usando la aplicación +using System; +using System.Collections.Generic; + + +// Define un ambito para organizar el código en "paquetes" +namespace Learning +{ +	// Cada archivo .cs debe contener al menos una clase con el mismo nombre que el archivo +    // Se permite colocar cualquier nombre, pero no deberías por cuestiones de consistencia. +    public class LearnCSharp +    { +		// Una aplicación de consola debe tener un método main como punto de entrada +        public static void Main(string[] args) +        { +			// Usa Console.WriteLine para imprimir líneas +            Console.WriteLine("Hello World"); +            Console.WriteLine( +                "Integer: " + 10 + +                " Double: " + 3.14 + +                " Boolean: " + true); + +			// Para imprimir sin una nueva línea, usa Console.Write +            Console.Write("Hello "); +            Console.Write("World"); + + +            /////////////////////////////////////////////////// +            // Variables y Tipos +            // +            // Declara una variable usando <tipo> <nombre> +            /////////////////////////////////////////////////// + +            // Sbyte - Entero de 8 bits con signo +            // (-128 <= sbyte <= 127) +            sbyte fooSbyte = 100; + +            // Byte - Entero de 8 bits sin signo +            // (0 <= byte <= 255) +            byte fooByte = 100; + +            // Short - Entero de 16 bits con signo +            // (-32,768 <= short <= 32,767) +            short fooShort = 10000; + +            // Ushort - Entero de 16 bits sin signo +            // (0 <= ushort <= 65,535) +            ushort fooUshort = 10000; + +            // Integer - Entero de 32 bits con signo +            // (-2,147,483,648 <= int <= 2,147,483,647) +            int fooInt = 1; + +            // Uinteger - Entero de 32 bits sin signo +            // (0 <= uint <= 4,294,967,295) +            uint fooUint = 1; + +            // Long - Entero de 64 bits con signo +            // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) +            long fooLong = 100000L; +            // L es usado para indicar que esta variable es de tipo long o ulong +            // un valor sin este sufijo es tratado como int o uint dependiendo del tamaño. + +            // Ulong - Entero de 64 bits sin signo +            // (0 <= ulong <= 18,446,744,073,709,551,615) +            ulong fooUlong = 100000L; + +            // Float - Precisión simple de 32 bits. IEEE 754 Coma flotante +            // Precisión: 7 dígitos +            float fooFloat = 234.5f; +			// f es usado para indicar que el valor de esta variable es de tipo float +            // de otra manera sería tratado como si fuera de tipo double. + +            // Double - Doble precisión de 32 bits. IEEE 754 Coma flotante +            // Precisión: 15-16 dígitos +            double fooDouble = 123.4; + +            // Bool - true & false (verdadero y falso) +            bool fooBoolean = true; +            bool barBoolean = false; + +			// Char - Un solo caracter Unicode de 16 bits +            char fooChar = 'A'; + +            // Strings +            string fooString = "My string is here!"; +            Console.WriteLine(fooString); + +            // Formato de cadenas +            string fooFs = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2); +            Console.WriteLine(fooFormattedString); + +            // Formato de fechas +            DateTime fooDate = DateTime.Now; +            Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy")); + +			// \n es un caracter de escape que comienza una nueva línea +            string barString = "Printing on a new line?\nNo Problem!"; +            Console.WriteLine(barString); + +            // Puede ser escrito mejor usando el símbolo @ +            string bazString = @"Here's some stuff +    on a new line!"; +            Console.WriteLine(bazString); + +            // Las comillas deben ser escapadas +            // usa \" para escaparlas +            string quotedString = "some \"quoted\" stuff"; +            Console.WriteLine(quotedString); + +			// usa "" cuando las cadenas comiencen con @ +            string quotedString2 = @"some MORE ""quoted"" stuff"; +            Console.WriteLine(quotedString2); + +			// Usa const o readonly para hacer las variables inmutables +			// los valores const son calculados en tiempo de compilación +            const int HOURS_I_WORK_PER_WEEK = 9001; + +            // Tipos que aceptan valores NULL (Nullable) +			// cualquier tipo de dato puede ser un tipo nulo añadiendole el sufijo ? +            // <tipo>? <variable> = <valor> +            int? nullable = null; +            Console.WriteLine("Nullable variable: " + nullable); + +			// Para usar valores nulos, tienes que usar la propiedad Value +			// o usar conversión explícita +            string? nullableString = "not null"; +            Console.WriteLine("Nullable value is: " + nullableString.Value + " or: " + (string) nullableString ); + +			// ?? is una manera corta de especificar valores por defecto +            // en caso de que la variable sea null +            int notNullable = nullable ?? 0; +            Console.WriteLine("Not nullable variable: " + notNullable); + +			// var - el compilador escogerá el tipo de dato más apropiado basado en el valor +            var fooImplicit = true; + +            /////////////////////////////////////////////////// +            // Estructura de datos +            /////////////////////////////////////////////////// +            Console.WriteLine("\n->Data Structures"); + +            // Arreglos +			// El tamaño del arreglo debe decidirse al momento de la declaración +            // El formato para declarar un arreglo es el siguiente: +            // <tipo_de_dato>[] <nombre_variable> = new <tipo_de_dato>[<tamaño>]; +            int[] intArray = new int[10]; +            string[] stringArray = new string[1]; +            bool[] boolArray = new bool[100]; + +			// Otra forma de declarar e inicializar un arreglo +            int[] y = { 9000, 1000, 1337 }; + +			// Indexar arreglos - Acceder a un elemento +            Console.WriteLine("intArray @ 0: " + intArray[0]); + +			// Los arreglos son de índice cero y son mutables. +            intArray[1] = 1; +            Console.WriteLine("intArray @ 1: " + intArray[1]); // => 1 + +            // Listas +			// Las listas son usadas más frecuentemente que los arreglos ya que son más flexibles +			// El formato para declarar una lista es el siguiente: +            // List<tipo_de_dato> <nombre_variable> = new List<tipo_de_dato>(); +            List<int> intList = new List<int>(); +            List<string> stringList = new List<string>(); + +            // Otra forma de declarar e inicializar una lista +            List<int> z = new List<int> { 9000, 1000, 1337 }; + +            // Indexar una lista - Acceder a un elemento +            // Las listas son de índice cero y son mutables. +            Console.WriteLine("z @ 0: " + z[2]); + +            // Las listas no tienen valores por defecto; +            // Un valor debe ser añadido antes de acceder al índice +            intList.Add(1); +            Console.WriteLine("intList @ 0: " + intList[0]); + + +            // Otras estructuras de datos a chequear: +            // +            // Pilas/Colas +            // Diccionarios +            // Colecciones de sólo lectura +            // Tuplas (.Net 4+) + + +            /////////////////////////////////////// +            // Operadores +            /////////////////////////////////////// +            Console.WriteLine("\n->Operators"); + +            int i1 = 1, i2 = 2; // Modo corto para múltiples declaraciones + +            // La aritmética es sencilla +            Console.WriteLine("1+2 = " + (i1 + i2)); // => 3 +            Console.WriteLine("2-1 = " + (i2 - i1)); // => 1 +            Console.WriteLine("2*1 = " + (i2 * i1)); // => 2 +            Console.WriteLine("1/2 = " + (i1 / i2)); // => 0 (0.5 truncated down) + +            // Módulo +            Console.WriteLine("11%3 = " + (11 % 3)); // => 2 + +            // Operadores de comparación +            Console.WriteLine("3 == 2? " + (3 == 2)); // => false +            Console.WriteLine("3 != 2? " + (3 != 2)); // => true +            Console.WriteLine("3 > 2? " + (3 > 2)); // => true +            Console.WriteLine("3 < 2? " + (3 < 2)); // => false +            Console.WriteLine("2 <= 2? " + (2 <= 2)); // => true +            Console.WriteLine("2 >= 2? " + (2 >= 2)); // => true + +            // Operadores a nivel de bits +            /* +            ~       Complemento a nivel de bits +            <<      Desplazamiento a la izquierda con signo +            >>      Desplazamiento a la derecha con signo +            >>>     Desplazamiento a la derecha sin signo +            &       AND a nivel de bits +            ^       XOR a nivel de bits +            |       OR a nivel de bits +            */ + +            // Incremento +            int i = 0; +            Console.WriteLine("\n->Inc/Dec-remento"); +            Console.WriteLine(i++); //i = 1. Posincrementación +            Console.WriteLine(++i); //i = 2. Preincremento +            Console.WriteLine(i--); //i = 1. Posdecremento +            Console.WriteLine(--i); //i = 0. Predecremento + + +            /////////////////////////////////////// +            // Estructuras de control +            /////////////////////////////////////// +            Console.WriteLine("\n->Control Structures"); + +            // Las condiciones if son como en lenguaje c +            int j = 10; +            if (j == 10) +            { +                Console.WriteLine("I get printed"); +            } +            else if (j > 10) +            { +                Console.WriteLine("I don't"); +            } +            else +            { +                Console.WriteLine("I also don't"); +            } + +            // Operador ternario +			// Un simple if/else puede ser escrito de la siguiente manera; +            // <condición> ? <true> : <false> +            string isTrue = (true) ? "True" : "False"; +            Console.WriteLine("Ternary demo: " + isTrue); + + +            // Bucle while +            int fooWhile = 0; +            while (fooWhile < 100) +            { +                //Console.WriteLine(fooWhile); +                //Incrementar el contador +                //Iterar 99 veces, fooWhile 0->99 +                fooWhile++; +            } +            Console.WriteLine("fooWhile Value: " + fooWhile); + +            // Bucle Do While +            int fooDoWhile = 0; +            do +            { +                //Console.WriteLine(fooDoWhile); +                //Incrementar el contador +                //Iterar 99 veces, fooDoWhile 0->99 +                fooDoWhile++; +            } while (fooDoWhile < 100); +            Console.WriteLine("fooDoWhile Value: " + fooDoWhile); + +            // Bucle For +            int fooFor; +            //Estructura del bucle for => for(<declaración_inicial>; <condición>; <incremento>) +            for (fooFor = 0; fooFor < 10; fooFor++) +            { +                //Console.WriteLine(fooFor); +                //Iterated 10 times, fooFor 0->9 +            } +            Console.WriteLine("fooFor Value: " + fooFor); + +            // Switch Case +			// El switch funciona con los tipos de datos byte, short, char e int +            // También funciona con las enumeraciones (discutidos en in Tipos Enum), +            // la clase string y algunas clases especiales que encapsulan +            // tipos primitivos: Character, Byte, Short, Integer. +            int month = 3; +            string monthString; +            switch (month) +            { +                case 1: +                    monthString = "January"; +                    break; +                case 2: +                    monthString = "February"; +                    break; +                case 3: +                    monthString = "March"; +                    break; +                default: +                    monthString = "Some other month"; +                    break; +            } +            Console.WriteLine("Switch Case Result: " + monthString); + + +            //////////////////////////////// +            // Conversión de tipos de datos +            //////////////////////////////// + +            // Convertir datos + +            // Convertir String a Integer +            // esto generará una excepción al fallar la conversión +            int.Parse("123");//retorna una versión entera de "123" + +            // TryParse establece la variable a un tipo por defecto +            // en este caso: 0 +            int tryInt; +            int.TryParse("123", out tryInt); + +            // Convertir Integer a String +            // La clase Convert tiene algunos métodos para facilitar las conversiones +            Convert.ToString(123); + +            /////////////////////////////////////// +            // Clases y Funciones +            /////////////////////////////////////// + +            Console.WriteLine("\n->Classes & Functions"); + +            // (Definición de la clase Bicycle (Bicicleta)) + +            // Usar new para instanciar una clase +            Bicycle trek = new Bicycle(); + +            // Llamar a los métodos del objeto +            trek.speedUp(3); // Siempre deberías usar métodos setter y métodos getter +            trek.setCadence(100); + +            // ToString es una convención para mostrar el valor del objeto. +            Console.WriteLine("trek info: " + trek.ToString()); + +            // Instanciar otra nueva bicicleta +            Bicycle octo = new Bicycle(5, 10); +            Console.WriteLine("octo info: " + octo.ToString()); + +            // Instanciar un Penny Farthing (Biciclo) +            PennyFarthing funbike = new PennyFarthing(1, 10); +            Console.WriteLine("funbike info: " + funbike.ToString()); + +            Console.Read(); +        } // Fin del método main + + +    } // Fin de la clase LearnCSharp + +    // Puedes incluir otras clases en un archivo .cs + + +    // Sintaxis para la declaración de clases: +    // <public/private/protected> class <nombre_de_clase>{ +    //    //campos, constructores, funciones todo adentro de la clase. +    //    //las funciones son llamadas métodos como en java. +    // } + +    public class Bicycle +    { +        // Campos/Variables de la clase Bicycle +        public int cadence; // Public: Accesible desde cualquier lado +        private int _speed;  // Private: Sólo es accesible desde dentro de la clase +        protected int gear; // Protected: Accesible desde clases y subclases +        internal int wheels; // Internal: Accesible en el ensamblado +        string name; // Todo es privado por defecto: Sólo es accesible desde dentro de esta clase + +        // Enum es un tipo valor que consiste un una serie de constantes con nombres +        public enum Brand +        { +            AIST, +            BMC, +            Electra, +            Gitane +        } +        // Definimos este tipo dentro de la clase Bicycle, por lo tanto es un tipo anidado +        // El código afuera de esta clase debería referenciar este tipo como Bicycle.Brand + +        public Brand brand; // Declaramos un tipo enum, podemos declarar un campo de este tipo + +        // Los miembros estáticos pertenecen al tipo mismo, no a un objeto en específico. +        static public int bicyclesCreated = 0; +        // Puedes acceder a ellos sin referenciar ningún objeto: +        // Console.WriteLine("Bicycles created: " + Bicycle.bicyclesCreated); + +        // Los valores readonly (Sólo lectura) son establecidos en tiempo de ejecución +        // sólo pueden ser asignados al momento de la declaración o dentro de un constructor +        readonly bool hasCardsInSpokes = false; // privado de sólo lectura + +        // Los constructores son una forma de crear clases +        // Este es un constructor por defecto +        private Bicycle() +        { +            gear = 1; +            cadence = 50; +            _speed = 5; +            name = "Bontrager"; +            brand = Brand.AIST; +            bicyclesCreated++; +        } + +        // Este es un constructor específico (contiene argumentos) +        public Bicycle(int startCadence, int startSpeed, int startGear, +                       string name, bool hasCardsInSpokes, Brand brand) +        { +            this.gear = startGear; // La palabra reservada "this" señala el objeto actual +            this.cadence = startCadence; +            this._speed = startSpeed; +            this.name = name; // Puede ser útil cuando hay un conflicto de nombres +            this.hasCardsInSpokes = hasCardsInSpokes; +            this.brand = brand; +        } + +        // Los constructores pueden ser encadenados +        public Bicycle(int startCadence, int startSpeed, Brand brand) : +            this(startCadence, startSpeed, 0, "big wheels", true) +        { +        } + +        // Sintaxis para Funciones: +        // <public/private/protected> <tipo_retorno> <nombre_funcion>(<args>) + +        // Las clases pueden implementar getters y setters para sus campos +        // o pueden implementar propiedades + +        // Sintaxis para la declaración de métodos: +        // <ámbito> <tipo_retorno> <nombre_método>(<argumentos>) +        public int GetCadence() +        { +            return cadence; +        } + +        // Los métodos void no requieren usar return +        public void SetCadence(int newValue) +        { +            cadence = newValue; +        } + +        // La palabra reservada virtual indica que este método puede ser sobrescrito +        public virtual void SetGear(int newValue) +        { +            gear = newValue; +        } + +        // Los parámetros de un método pueden tener valores por defecto. +		// En este caso, los métodos pueden ser llamados omitiendo esos parámetros +        public void SpeedUp(int increment = 1) +        { +            _speed += increment; +        } + +        public void SlowDown(int decrement = 1) +        { +            _speed -= decrement; +        } + +        // Propiedades y valores get/set +        // Cuando los datos sólo necesitan ser accedidos, considera usar propiedades. +        // Las propiedades pueden tener get, set o ambos +        private bool _hasTassles; // variable privada +        public bool HasTassles // acceso público +        { +            get { return _hasTassles; } +            set { _hasTassles = value; } +        } + +        // Las propiedades pueden ser auto implementadas +        public int FrameSize +        { +            get; +            // Puedes especificar modificadores de acceso tanto para get como para set +            // esto significa que sólo dentro de la clase Bicycle se puede modificar Framesize +            private set; +        } + +        //Método para mostrar los valores de atributos de este objeto. +        public override string ToString() +        { +            return "gear: " + gear + +                    " cadence: " + cadence + +                    " speed: " + _speed + +                    " name: " + name + +                    " cards in spokes: " + (hasCardsInSpokes ? "yes" : "no") + +                    "\n------------------------------\n" +                    ; +        } + +        // Los métodos también pueden ser estáticos. Puede ser útil para métodos de ayuda +        public static bool DidWeCreateEnoughBycles() +        { +            // Dentro de un método esático, +			// Sólo podemos hacer referencia a miembros estáticos de clases +            return bicyclesCreated > 9000; +        }   // Si tu clase sólo necesita miembros estáticos, +		    // considera establecer la clase como static. + +    } // fin de la clase Bicycle + +    // PennyFarthing es una subclase de Bicycle +    class PennyFarthing : Bicycle +    { +        // (Penny Farthings son las bicicletas con una rueda delantera enorme. +        // No tienen engranajes.) + +        // llamar al constructor de la clase padre +        public PennyFarthing(int startCadence, int startSpeed) : +            base(startCadence, startSpeed, 0, "PennyFarthing", true) +        { +        } + +        public override void SetGear(int gear) +        { +            gear = 0; +        } + +        public override string ToString() +        { +            string result = "PennyFarthing bicycle "; +            result += base.ToString(); // Llamar a la versión base del método +            return reuslt; +        } +    } + +    // Las interfaces sólo contienen las declaraciones +	// de los miembros, sin la implementación. +    interface IJumpable +    { +        void Jump(int meters); // todos los miembros de interfaces son implícitamente públicos +    } + +    interface IBreakable +    { +		// Las interfaces pueden contener tanto propiedades como métodos, campos y eventos +        bool Broken { get; } +    } + +	// Las clases sólo heredan de alguna otra clase, pero pueden implementar +	// cualquier cantidad de interfaces +    class MountainBike : Bicycle, IJumpable, IBreakable +    { +        int damage = 0; + +        public void Jump(int meters) +        { +            damage += meters; +        } + +        public void Broken +        { +            get +            { +                return damage > 100; +            } +        } +    } +} // Fin del espacio de nombres + +``` + +## Temas no cubiertos + + * Flags + * Attributes + * Generics (T), Delegates, Func, Actions, lambda expressions + * Static properties + * Exceptions, Abstraction + * LINQ + * ASP.NET (Web Forms/MVC/WebMatrix) + * Winforms + * Windows Presentation Foundation (WPF) + + + +## Lecturas recomendadas + + * [DotNetPerls](http://www.dotnetperls.com) + * [C# in Depth](http://manning.com/skeet2) + * [Programming C#](http://shop.oreilly.com/product/0636920024064.do) + * [LINQ](http://shop.oreilly.com/product/9780596519254.do) + * [MSDN Library](http://msdn.microsoft.com/es-es/library/618ayhy6.aspx) + * [ASP.NET MVC Tutorials](http://www.asp.net/mvc/tutorials) + * [ASP.NET Web Matrix Tutorials](http://www.asp.net/web-pages/tutorials) + * [ASP.NET Web Forms Tutorials](http://www.asp.net/web-forms/tutorials) + * [Windows Forms Programming in C#](http://www.amazon.com/Windows-Forms-Programming-Chris-Sells/dp/0321116208) + + + +[Convenciones de código de C#](http://msdn.microsoft.com/es-es/library/vstudio/ff926074.aspx) diff --git a/go.html.markdown b/go.html.markdown index 4db76a49..3a3800dd 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -1,4 +1,4 @@ ---- +---  name: Go  category: language  language: Go @@ -46,7 +46,7 @@ func main() {  }  // Functions have parameters in parentheses. -// If there are no parameters, empty parens are still required. +// If there are no parameters, empty parentheses are still required.  func beyondHello() {      var x int // Variable declaration.  Variables must be declared before use.      x = 3     // Variable assignment. @@ -71,7 +71,7 @@ func learnTypes() {  can include line breaks.` // same string type      // non-ASCII literal.  Go source is UTF-8. -    g := 'Σ' // rune type, an alias for uint32, holds a UTF-8 code point +    g := 'Σ' // rune type, an alias for uint32, holds a unicode code point      f := 3.14195 // float64, an IEEE-754 64-bit floating point number      c := 3 + 4i  // complex128, represented internally with two float64s @@ -251,7 +251,7 @@ func learnConcurrency() {      fmt.Println(<-c, <-c, <-c) // channel on right, <- is "receive" operator.      cs := make(chan string)       // another channel, this one handles strings. -    cc := make(chan chan string)  // a channel of channels. +    cc := make(chan chan string)  // a channel of string channels.      go func() { c <- 84 }()       // start a new goroutine just to send a value      go func() { cs <- "wordy" }() // again, for cs this time      // Select has syntax like a switch statement but each case involves @@ -259,7 +259,7 @@ func learnConcurrency() {      // that are ready to communicate.      select {      case i := <-c: // the value received can be assigned to a variable -        fmt.Println("it's a", i) +        fmt.Printf("it's a %T", i)      case <-cs: // or the value received can be discarded          fmt.Println("it's a string")      case <-cc: // empty channel, not ready for communication. diff --git a/ko-kr/clojure-kr.html.markdown b/ko-kr/clojure-kr.html.markdown new file mode 100644 index 00000000..0b9d13b2 --- /dev/null +++ b/ko-kr/clojure-kr.html.markdown @@ -0,0 +1,383 @@ +--- +language: clojure +filename: learnclojure.clj +contributors: +    - ["Adam Bard", "http://adambard.com/"] +translators: +    - ["netpyoung", "http://netpyoung.github.io/"] +lang: ko-kr +--- + +Clojure는 Java 가상머신을 위해 개발된 Lisp 계통의 언어입니다 +이는 Common Lisp보다 순수 [함수형 프로그래밍](https://en.wikipedia.org/wiki/Functional_programming)을 더욱 강조했으며,  +상태를 있는 그대로 다루기 위해 다양한 [STM](https://en.wikipedia.org/wiki/Software_transactional_memory) 을 지원하는 프로그램들을 갖췄습니다. + +이를 조합하여, 병행처리(concurrent processing)를 매우 단순하게 처리할 수 있으며, +대게 자동으로 처리될 수 있도록 만들 수 있습니다. + +(Clojure 1.2 이상의 버전이 필요로 합니다.) + + +```clojure +; 주석은 세미콜론(;)으로 시작합니다. + +; Clojure는 "폼(forms)"으로 구성되었으며, +; 폼은 괄호로 감싸져있으며, 공백으로 구분된 것들이 나열된 것입니다. +; +; clojure의 reader는 첫번째로 오는 것을 +; 함수 혹은 매크로를 호출하는 것, 그리고 나머지를 인자라고 가정합니다. + +; namespace를 지정하기 위해, 파일에서 우선적으로 호출해야될 것은 ns입니다. +(ns learnclojure) + +; 간단한 예제들: + +; str 은 인자로 받은 것들을 하나의 문자열로 만들어줍니다. +(str "Hello" " " "World") ; => "Hello World" + +; 직관적인 수학 함수들을 갖고 있습니다. +(+ 1 1) ; => 2 +(- 2 1) ; => 1 +(* 1 2) ; => 2 +(/ 2 1) ; => 2 + +; = 로 동일성을 판별할 수 있습니다. +(= 1 1) ; => true +(= 2 1) ; => false + +; 논리연산을 위한 not 역시 필요합니다. +(not true) ; => false + +; 중첩된 폼(forms)은 기대한대로 동작합니다. +(+ 1 (- 3 2)) ; = 1 + (3 - 2) => 2 + +; 타입 +;;;;;;;;;;;;; + +; Clojure는 부울(boolean), 문자열, 숫자를 위해 Java의 object 타입을 이용합니다. +; `class` 를 이용하여 이를 확인할 수 있습니다. +(class 1) ; 정수는 기본적으로 java.lang.Long입니다. +(class 1.); 소수는 java.lang.Double입니다. +(class ""); 문자열은 쌍따옴표로 감싸져 있으며, java.lang.String입니다. +(class false) ; 부울값은 java.lang.Boolean입니다. +(class nil); nil은 "null"값입니다. + +; 데이터 리스트 자체를 만들고자 한다면, +; '를 이용하여 평가(evaluate)되지 않도록 막아야 합니다. +'(+ 1 2) ; => (+ 1 2) +; (quote (+ 1 2)) 를 줄여서 쓴것 + +; quote 가 된 리스트를 평가할 수 도 있습니다. +(eval '(+ 1 2)) ; => 3 + +; 컬렉션(Collections) & 시퀀스(Sequences) +;;;;;;;;;;;;;;;;;;; + +; 리스트(List)는 연결된(linked-list) 자료구조이며, 벡터(Vector)는 배열이 뒤로붙는(array-backed) 자료구조입니다. +; 리스트와 벡터 모두 java 클래스입니다! +(class [1 2 3]); => clojure.lang.PersistentVector +(class '(1 2 3)); => clojure.lang.PersistentList + +; 간단하게 (1 2 3)로 리스트를 나타낼 수 있지만, +; reader가 함수라고 여기지 못하게 quote(')를 해줘야 합니다. +; 따라서, (list 1 2 3)는 '(1 2 3)와 같습니다. + +; "컬렉션"은 단순하게 데이터의 그룹입니다. +; 리스트와 벡터 모두 컬렉션입니다: +(coll? '(1 2 3)) ; => true +(coll? [1 2 3]) ; => true + +; "시퀀스" (seq) 는 데이터 리스트를 추상적으로 기술한 것입니다. +; 리스트는 시퀀스입니다. +(seq? '(1 2 3)) ; => true +(seq? [1 2 3]) ; => false + +; 시퀀스는 접근하고자 하는 항목만 제공해주면 됩니다. +; 따라서, 시퀀스는 lazy 할 수 있습니다 -- 무한하게 늘어나는 것을 정의할 수 있습니다: +(range 4) ; => (0 1 2 3) +(range) ; => (0 1 2 3 4 ...) (an infinite series) +(take 4 (range)) ;  (0 1 2 3) + +; cons 를 이용하여 리스트나 벡터의 시작부에 항목을 추가할 수 있습니다. +(cons 4 [1 2 3]) ; => (4 1 2 3) +(cons 4 '(1 2 3)) ; => (4 1 2 3) + +; conj 는 컬렉션에 가장 효율적인 방식으로 항목을 추가합니다. +; 리스트는 시작부분에 삽입하고, 벡터는 끝부분에 삽입합니다. +(conj [1 2 3] 4) ; => [1 2 3 4] +(conj '(1 2 3) 4) ; => (4 1 2 3) + +; concat 을 이용하여 리스트와 벡터를 서로 합칠 수 있습니다. +(concat [1 2] '(3 4)) ; => (1 2 3 4) + +; filter, map 을 이용하여 컬렉션을 다룰 수 있습니다. +(map inc [1 2 3]) ; => (2 3 4) +(filter even? [1 2 3]) ; => (2) + +; reduce 를 이용하여 줄여나갈 수 있습니다. +(reduce + [1 2 3 4]) +; = (+ (+ (+ 1 2) 3) 4) +; => 10 + +; reduce 는 초기 값을 인자로 취할 수 도 있습니다. +(reduce conj [] '(3 2 1)) +; = (conj (conj (conj [] 3) 2) 1) +; => [3 2 1] + +; 함수 +;;;;;;;;;;;;;;;;;;;;; + +; fn 을 이용하여 함수를 만들 수 있습니다 . +; 함수는 항상 마지막 문장을 반환합니다. +(fn [] "Hello World") ; => fn + +; (정의한 것을 호출하기 위해선, 괄호가 더 필요합니다.) +((fn [] "Hello World")) ; => "Hello World" + +; def 를 이용하여 var 를 만들 수 있습니다. +(def x 1) +x ; => 1 + +; var 에 함수를 할당시켜보겠습니다. +(def hello-world (fn [] "Hello World")) +(hello-world) ; => "Hello World" + +; defn 을 이용하여 짧게 쓸 수 도 있습니다. +(defn hello-world [] "Hello World") + +; [] 는 함수의 인자 목록을 나타냅니다. +(defn hello [name] +  (str "Hello " name)) +(hello "Steve") ; => "Hello Steve" + +; 약자(shorthand)를 써서 함수를 만들 수 도 있습니다: +(def hello2 #(str "Hello " %1)) +(hello2 "Fanny") ; => "Hello Fanny" + +; 함수가 다양한 인자를 받도록 정의할 수 도 있습니다. +(defn hello3 +  ([] "Hello World") +  ([name] (str "Hello " name))) +(hello3 "Jake") ; => "Hello Jake" +(hello3) ; => "Hello World" + +; 함수는 여러 인자를 시퀀스로 취할 수 있습니다. +(defn count-args [& args] +  (str "You passed " (count args) " args: " args)) +(count-args 1 2 3) ; => "You passed 3 args: (1 2 3)" + +; 개별적으로 받는 것과, 시퀀스로 취하는 것을 같이 쓸 수 도 있습니다. +(defn hello-count [name & args] +  (str "Hello " name ", you passed " (count args) " extra args")) +(hello-count "Finn" 1 2 3) +; => "Hello Finn, you passed 3 extra args" + + +; 맵(Maps) +;;;;;;;;;; + +; 해쉬맵(hash map)과 배열맵(array map)은 공통된 인터페이스를 공유합니다. +; 해쉬맵은 찾기가 빠르지만, 키의 순서가 유지되지 않습니다. +(class {:a 1 :b 2 :c 3}) ; => clojure.lang.PersistentArrayMap +(class (hash-map :a 1 :b 2 :c 3)) ; => clojure.lang.PersistentHashMap + +; 배열맵은 여러 연산을 거쳐 자연스레 해쉬맵이 됩니다. +; 만일 이게 커진다 하더라도, 걱정할 필요가 없습니다. + +; 맵은 해쉬가 가능한 타입이라면 어떠한 것이든 키로써 활용이 가능하지만, 보통 키워드를 이용하는 것이 가장 좋습니다. +; 키워드(Keyword)는 문자열과 비슷하지만, 보다 효율적인 면이 있습니다. +(class :a) ; => clojure.lang.Keyword + +(def stringmap {"a" 1, "b" 2, "c" 3}) +stringmap  ; => {"a" 1, "b" 2, "c" 3} + +(def keymap {:a 1, :b 2, :c 3}) +keymap ; => {:a 1, :c 3, :b 2} + +; 여기서, 쉽표가 공백으로 취급되며, 아무 일도 하지 않는다는 것을 주목하시기 바랍니다. + +; 맵에서 값을 얻어오기 위해선, 함수로써 맵을 호출해야 합니다. +(stringmap "a") ; => 1 +(keymap :a) ; => 1 + +; 키워드 역시 맵에서 함수를 얻어올 때 사용할 수 있습니다! +(:b keymap) ; => 2 + +; 하지만, 문자열로는 하면 안됩니다. +;("a" stringmap) +; => Exception: java.lang.String cannot be cast to clojure.lang.IFn + +; 없는 값을 얻어오고자 하면, nil이 반환됩니다. +(stringmap "d") ; => nil + +; assoc 를 이용하여 해쉬맵에 새로운 키를 추가할 수 있습니다. +(def newkeymap (assoc keymap :d 4)) +newkeymap ; => {:a 1, :b 2, :c 3, :d 4} + +; 하지만, 변경할 수 없는(immutable) clojure 타입이라는 것을 기억해야 합니다! +keymap ; => {:a 1, :b 2, :c 3} + +; dissoc 를 이용하여 키를 제거할 수 있습니다. +(dissoc keymap :a :b) ; => {:c 3} + +; 쎗(Set:집합) +;;;;;; + +(class #{1 2 3}) ; => clojure.lang.PersistentHashSet +(set [1 2 3 1 2 3 3 2 1 3 2 1]) ; => #{1 2 3} + +; conj 로 항목을 추가할 수 있습니다. +(conj #{1 2 3} 4) ; => #{1 2 3 4} + +; disj 로 제거할 수 도 있습니다. +(disj #{1 2 3} 1) ; => #{2 3} + +; 존재하는지 확인할 목적으로, 쎗을 함수로 사용할 수 도 있습니다. +(#{1 2 3} 1) ; => 1 +(#{1 2 3} 4) ; => nil + +; clojure.sets 네임스페이스(namespace)에는 더 많은 함수들이 있습니다. + +; 유용한 폼(forms) +;;;;;;;;;;;;;;;;; + +; clojure에선, if 와 매크로(macro)를 가지고, +; 다른 여러 논리 연산들을 만들 수 있습니다. +(if false "a" "b") ; => "b" +(if false "a") ; => nil + +; let 을 이용하여 임시적으로 바인딩(binding)을 구축할 수 있습니다. +(let [a 1 b 2] +  (> a b)) ; => false + +; do 로 문단을 묶을 수 도 있습니다. +(do +  (print "Hello") +  "World") ; => "World" (prints "Hello") + +; 함수는 암시적으로 do 를 가지고 있습니다. +(defn print-and-say-hello [name] +  (print "Saying hello to " name) +  (str "Hello " name)) +(print-and-say-hello "Jeff") ;=> "Hello Jeff" (prints "Saying hello to Jeff") + +; let 역시 그러합니다. +(let [name "Urkel"] +  (print "Saying hello to " name) +  (str "Hello " name)) ; => "Hello Urkel" (prints "Saying hello to Urkel") + +; 모듈(Modules) +;;;;;;;;;;;;;;; + +; "use" 를 이용하여 module에 있는 모든 함수들을 얻어올 수 있습니다. +(use 'clojure.set) + +; 이제 쎗(set:집합)연산을 사용 할 수 있습니다. +(intersection #{1 2 3} #{2 3 4}) ; => #{2 3} +(difference #{1 2 3} #{2 3 4}) ; => #{1} + +; 함수들 중에 일 부분만을 가져올 수 도 있습니다. +(use '[clojure.set :only [intersection]]) + +; require 를 이용하여 모듈을 import할 수 있습니다. +(require 'clojure.string) + +; / 를 이용하여 모듈에 있는 함수를 호출 할 수 있습니다. +; 여기, clojure.string 라는 모듈에, blank? 라는 함수가 있습니다. +(clojure.string/blank? "") ; => true + +; import시, 모듈에 짧은 이름을 붙여줄 수 있습니다. +(require '[clojure.string :as str]) +(str/replace "This is a test." #"[a-o]" str/upper-case) ; => "THIs Is A tEst." +; (#"" denotes a regular expression literal) + +; :require 를 이용하여, 네임스페이스에서 require 를 사용할 수 있습니다. +; 아레와 같은 방법을 이용하면, 모듈을 quote하지 않아도 됩니다. +(ns test +  (:require +    [clojure.string :as str] +    [clojure.set :as set])) + +; Java +;;;;;;;;;;;;;;;;; + +; Java는 유용한 많은 표준 라이브러리를 가지고 있으며, +; 이를 어떻게 활용할 수 있는지 알아보도록 하겠습니다. + +; import 로 java 모듈을 불러올 수 있습니다. +(import java.util.Date) + +; ns 와 함께 import 를 할 수 도 있습니다. +(ns test +  (:import java.util.Date +           java.util.Calendar)) + +; 새로운 인스턴스를 만들기 위해선, 클래스 이름 끝에 "."을 찍습니다. +(Date.) ; <a date object> + +; . 을 이용하여 메소드를 호출할 수 있습니다. +; 아니면, 줄여서 ".메소드"로도 호출 할 수 있습니다. +(. (Date.) getTime) ; <a timestamp> +(.getTime (Date.)) ; exactly the same thing. + +; / 를 이용하여 정적메소드를 호출 할 수 있습니다. +(System/currentTimeMillis) ; <a timestamp> (system is always present) + +; doto 를 이용하여 상태가 변하는(mutable) 클래스들을 좀 더 편하게(tolerable) 다룰 수 있습니다. +(import java.util.Calendar) +(doto (Calendar/getInstance) +  (.set 2000 1 1 0 0 0) +  .getTime) ; => A Date. set to 2000-01-01 00:00:00 + +; STM +;;;;;;;;;;;;;;;;; + +; Software Transactional Memory 는 clojure가 영구적인(persistent) 상태를 다루는 방식입니다. +; clojure가 이용하는 몇몇 자료형(construct)이 있습니다. + +; 가장 단순한 것은 atom 입니다. 초기 값을 넣어보도록 하겠습니다. +(def my-atom (atom {})) + +; swap! 으로 atom을 갱신(update)할 수 있습니다! +; swap! 은 함수를 인자로 받아, 그 함수에 대해 현재 atom에 들어있는 값을 첫번째 인자로, +; 나머지를 두번째 인자로 하여 호출합니다. +(swap! my-atom assoc :a 1) ; Sets my-atom to the result of (assoc {} :a 1) +(swap! my-atom assoc :b 2) ; Sets my-atom to the result of (assoc {:a 1} :b 2) + +; '@' 를 이용하여 atom을 역참조(dereference)하여 값을 얻을 수 있습니다. +my-atom  ;=> Atom<#...> (atom 객체가 반환됩니다.) +@my-atom ; => {:a 1 :b 2} + +; 여기 atom을 이용한 단순한 카운터가 있습니다. +(def counter (atom 0)) +(defn inc-counter [] +  (swap! counter inc)) + +(inc-counter) +(inc-counter) +(inc-counter) +(inc-counter) +(inc-counter) + +@counter ; => 5 + +; STM을 구성하는 다른 것들에는 ref 와 agent 가 있습니다. +; Refs: http://clojure.org/refs +; Agents: http://clojure.org/agents +``` + +### 읽어볼거리 + +부족한 것이 많았지만, 다행히도 채울 수 있는 것들이 많이 있습니다. + +Clojure.org에 많은 문서들이 보관되어 있습니다: +[http://clojure.org/](http://clojure.org/) + +Clojuredocs.org는 core 함수들에 대해 다양한 예제와 문서를 보유하고 있습니다: +[http://clojuredocs.org/quickref/Clojure%20Core](http://clojuredocs.org/quickref/Clojure%20Core) + +4Clojure는 clojure/FP 스킬을 올릴 수 있는 좋은 길입니다: +[http://www.4clojure.com/](http://www.4clojure.com/) + +Clojure-doc.org는 많고 많은 문서들을 보유하고 있습니다: +[http://clojure-doc.org/](http://clojure-doc.org/) diff --git a/lua.html.markdown b/lua.html.markdown index 7325a1cf..369de908 100644 --- a/lua.html.markdown +++ b/lua.html.markdown @@ -125,6 +125,9 @@ f = function (x) return x * x end  -- And so are these:  local function g(x) return math.sin(x) end +local g = function(x) return math.xin(x) end +-- Equivalent to local function g(x)..., except referring +-- to g in the function body won't work as expected.  local g; g  = function (x) return math.sin(x) end  -- the 'local g' decl makes g-self-references ok. @@ -133,6 +136,10 @@ local g; g  = function (x) return math.sin(x) end  -- Calls with one string param don't need parens:  print 'hello'  -- Works fine. +-- Calls with one table param don't need parens +-- either (more on tables below): +print {} -- Works fine too. +  ----------------------------------------------------  -- 3. Tables. @@ -203,7 +210,7 @@ f2 = {a = 2, b = 3}  metafraction = {}  function metafraction.__add(f1, f2) -  sum = {} +  local sum = {}    sum.b = f1.b * f2.b    sum.a = f1.a * f2.b + f2.a * f1.b    return sum @@ -266,7 +273,7 @@ eatenBy = myFavs.animal  -- works! thanks, metatable  Dog = {}                                   -- 1.  function Dog:new()                         -- 2. -  newObj = {sound = 'woof'}                -- 3. +  local newObj = {sound = 'woof'}          -- 3.    self.__index = self                      -- 4.    return setmetatable(newObj, self)        -- 5.  end @@ -301,7 +308,7 @@ mrDog:makeSound()  -- 'I say woof'         -- 8.  LoudDog = Dog:new()                           -- 1.  function LoudDog:makeSound() -  s = self.sound .. ' '                       -- 2. +  local s = self.sound .. ' '                 -- 2.    print(s .. s .. s)  end @@ -322,7 +329,7 @@ seymour:makeSound()  -- 'woof woof woof'      -- 4.  -- If needed, a subclass's new() is like the base's:  function LoudDog:new() -  newObj = {} +  local newObj = {}    -- set up newObj    self.__index = self    return setmetatable(newObj, self) diff --git a/objective-c.html.markdown b/objective-c.html.markdown index 9e9f43e7..926a4a0d 100644 --- a/objective-c.html.markdown +++ b/objective-c.html.markdown @@ -160,7 +160,7 @@ int main (int argc, const char * argv[])      int jj;      for (jj=0; jj < 4; jj++)      { -        NSLog(@"%d,", jj++); +        NSLog(@"%d,", jj);      } // => prints "0,"         //           "1,"        //           "2," @@ -223,7 +223,7 @@ int main (int argc, const char * argv[])  // }  // -/+ (type) Method declarations;  // @end -@interface MyClass : NSObject <MyCustomProtocol> +@interface MyClass : NSObject <MyProtocol>  {      int count;      id data; @@ -241,14 +241,14 @@ int main (int argc, const char * argv[])  + (NSString *)classMethod;  // - for instance method -- (NSString *)instanceMethodWithParmeter:(NSString *)string; +- (NSString *)instanceMethodWithParameter:(NSString *)string;  - (NSNumber *)methodAParameterAsString:(NSString*)string andAParameterAsNumber:(NSNumber *)number;  @end  // Implement the methods in an implementation (MyClass.m) file: -@implementation UserObject +@implementation MyClass  // Call when the object is releasing  - (void)dealloc @@ -271,7 +271,7 @@ int main (int argc, const char * argv[])      return [[self alloc] init];  } -- (NSString *)instanceMethodWithParmeter:(NSString *)string +- (NSString *)instanceMethodWithParameter:(NSString *)string  {      return @"New string";  } diff --git a/ro-ro/python-ro.html.markdown b/ro-ro/python-ro.html.markdown new file mode 100644 index 00000000..0654fc8f --- /dev/null +++ b/ro-ro/python-ro.html.markdown @@ -0,0 +1,489 @@ +--- +language: python +contributors: +    - ["Louie Dinh", "http://ldinh.ca"] +translators: +    - ["Ovidiu Ciule", "https://github.com/ociule"] lang: ro-ro filename: python-ro.html.markdown +filename: learnpython.py +--- + +Python a fost creat de Guido Van Rossum la începutul anilor '90. Python a devenit astăzi unul din +cele mai populare limbaje de programare. M-am indrăgostit de Python pentru claritatea sa sintactică. +Python este aproape pseudocod executabil. + +Opinia dumneavoastră este binevenită! Puteţi sa imi scrieţi la [@ociule](http://twitter.com/ociule) sau ociule [at] [google's email service] + +Notă: Acest articol descrie Python 2.7, dar este util şi pentru Python 2.x. O versiune Python 3 va apărea +în curând, în limba engleză mai întâi. + +```python +# Comentariile pe o singură linie încep cu un caracter diez. +""" Şirurile de caractere pe mai multe linii pot fi încadrate folosind trei caractere ", şi sunt des +    folosite ca şi comentarii pe mai multe linii. +""" + +#################################################### +## 1. Operatori şi tipuri de date primare  +#################################################### + +# Avem numere +3 #=> 3 + +# Matematica se comportă cum ne-am aştepta +1 + 1 #=> 2 +8 - 1 #=> 7 +10 * 2 #=> 20 +35 / 5 #=> 7 + +# Împărţirea este un pic surprinzătoare. Este de fapt împărţire pe numere întregi şi rotunjeşte +# automat spre valoarea mai mică +5 / 2 #=> 2 + +# Pentru a folosi împărţirea fără rest avem nevoie de numere reale  +2.0     # Acesta e un număr real +11.0 / 4.0 #=> 2.75 ahhh ... cum ne aşteptam  + +# Ordinea operaţiilor se poate forţa cu paranteze +(1 + 3) * 2 #=> 8 + +# Valoriile boolene sunt şi ele valori primare +True +False + +# Pot fi negate cu operatorul not +not True #=> False +not False #=> True + +# Egalitatea este == +1 == 1 #=> True +2 == 1 #=> False + +# Inegalitate este != +1 != 1 #=> False +2 != 1 #=> True + +# Comparaţii +1 < 10 #=> True +1 > 10 #=> False +2 <= 2 #=> True +2 >= 2 #=> True + +# Comparaţiile pot fi inlănţuite!  +1 < 2 < 3 #=> True +2 < 3 < 2 #=> False + +# Şirurile de caractere pot fi încadrate cu " sau ' +"Acesta e un şir de caractere." +'Şi acesta este un şir de caractere.' + +# Şirurile de caractere pot fi adăugate! +"Hello " + "world!" #=> "Hello world!" + +# Un şir de caractere poate fi folosit ca o listă  +"Acesta e un şir de caractere"[0] #=> 'A' + +# Caracterul % (procent) poate fi folosit pentru a formata şiruri de caractere : +"%s pot fi %s" % ("şirurile", "interpolate") + +# O metodă mai nouă de a formata şiruri este metoda "format" +# Este metoda recomandată +"{0} pot fi {1}".format("şirurile", "formatate") +# Puteţi folosi cuvinte cheie dacă nu doriţi sa număraţi  +"{nume} vrea să mănânce {fel}".format(nume="Bob", fel="lasagna") + +# "None", care reprezintă valoarea nedefinită, e un obiect +None #=> None + +# Nu folosiţi operatorul == pentru a compara un obiect cu None +# Folosiţi operatorul "is" +"etc" is None #=> False +None is None  #=> True + +# Operatorul "is" testeaza dacă obiectele sunt identice. +# Acastă operaţie nu e foarte folositoare cu tipuri primare, +# dar e foarte folositoare cu obiecte. + +# None, 0, şi şiruri de caractere goale sunt evaluate ca si fals, False.  +# Toate celelalte valori sunt adevărate, True. +0 == False  #=> True +"" == False #=> True + + +#################################################### +## 2. Variabile şi colecţii +#################################################### + +# Printarea este uşoară  +print "Eu sunt Python. Încântat de cunoştinţă!"  + + +# Nu este nevoie sa declari variabilele înainte de a le folosi  +o_variabila = 5    # Convenţia este de a folosi caractere_minuscule_cu_underscore  +o_variabila #=> 5 + +# Dacă accesăm o variabilă nefolosită declanşăm o excepţie. +# Vezi secţiunea Control de Execuţie pentru mai multe detalii despre excepţii. +alta_variabila # Declanşează o eroare de nume  + +# "If" poate fi folosit într-o expresie. +"yahoo!" if 3 > 2 else 2 #=> "yahoo!" + +# Listele sunt folosite pentru colecţii +li = [] +# O listă poate avea valori de la început  +alta_li = [4, 5, 6] + +# Se adaugă valori la sfârşitul lister cu append  +li.append(1)    #li e acum [1] +li.append(2)    #li e acum [1, 2] +li.append(4)    #li e acum [1, 2, 4] +li.append(3)    #li este acum [1, 2, 4, 3] +# Se şterg de la sfarşit cu pop  +li.pop()        #=> 3 şi li e acum [1, 2, 4] +# Să o adaugăm înapoi valoarea +li.append(3)    # li e din nou [1, 2, 4, 3] + +# Putem accesa valorile individuale dintr-o listă cu operatorul index  +li[0] #=> 1 +# Valoarea speciala -1 pentru index accesează ultima valoare +li[-1] #=> 3 + +# Dacă depaşim limitele listei declanşăm o eroare IndexError +li[4] # Declanşează IndexError + +# Putem să ne uităm la intervale folosind sintaxa de "felii"  +# În Python, intervalele sunt închise la început si deschise la sfârşit.  +li[1:3] #=> [2, 4] +# Fără început +li[2:] #=> [4, 3] +# Fără sfarşit +li[:3] #=> [1, 2, 4] + +# Putem şterge elemente arbitrare din lista cu operatorul "del" care primeşte indexul lor +del li[2] # li e acum [1, 2, 3] + +# Listele pot fi adăugate +li + alta_li #=> [1, 2, 3, 4, 5, 6] - Notă: li si alta_li nu sunt modificate!  + +# Concatenăm liste cu "extend()" +li.extend(alta_li) # Acum li este [1, 2, 3, 4, 5, 6] + +# Se verifică existenţa valorilor in lista cu "in"  +1 in li #=> True + +# Şi lungimea cu "len()" +len(li) #=> 6 + + +# Tuplele sunt ca şi listele dar imutabile  +tup = (1, 2, 3) +tup[0] #=> 1 +tup[0] = 3  # Declanşează TypeError + +# Pot fi folosite ca şi liste  +len(tup) #=> 3 +tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6) +tup[:2] #=> (1, 2) +2 in tup #=> True + +# Tuplele pot fi despachetate  +a, b, c = (1, 2, 3)     # a este acum 1, b este acum 2 şi c este acum 3 +# Tuplele pot fi folosite şi fără paranteze  +d, e, f = 4, 5, 6 +# Putem inversa valori foarte uşor!  +e, d = d, e     # d este acum 5 şi e este acum 4 + + +# Dicţionarele stochează chei şi o valoare pentru fiecare cheie +dict_gol = {} +# Şi un dicţionar cu valori  +dict_cu_valori = {"unu": 1, "doi": 2, "trei": 3} + +# Căutaţi valori cu [] +dict_cu_valori["unu"] #=> 1 + +# Obţinem lista cheilor cu "keys()" +dict_cu_valori.keys() #=> ["trei", "doi", "unu"] +# Notă - ordinea cheilor obţinute cu keys() nu este garantată.  +# Puteţi obţine rezultate diferite de exemplul de aici.  + +# Obţinem valorile cu values()  +dict_cu_valori.values() #=> [3, 2, 1] +# Notă - aceeaşi ca mai sus, aplicată asupra valorilor. + +# Verificăm existenţa unei valori cu "in"  +"unu" in dict_cu_valori #=> True +1 in dict_cu_valori #=> False + +# Accesarea unei chei care nu exista declanşează o KeyError +dict_cu_valori["four"] # KeyError + +# Putem folosi metoda "get()" pentru a evita KeyError +dict_cu_valori.get("one") #=> 1 +dict_cu_valori.get("four") #=> None +# Metoda get poate primi ca al doilea argument o valoare care va fi returnată +# când cheia nu este prezentă.  +dict_cu_valori.get("one", 4) #=> 1 +dict_cu_valori.get("four", 4) #=> 4 + +# "setdefault()" este o metodă pentru a adăuga chei-valori fără a le modifica, dacă cheia există deja +dict_cu_valori.setdefault("five", 5) #dict_cu_valori["five"] este acum 5 +dict_cu_valori.setdefault("five", 6) #dict_cu_valori["five"] exista deja, nu este modificată, tot 5 + + +# Set este colecţia mulţime +set_gol = set() +# Putem crea un set cu valori +un_set = set([1,2,2,3,4]) # un_set este acum set([1, 2, 3, 4]), amintiţi-vă ca mulţimile garantează unicatul! + +# În Python 2.7, {} poate fi folosit pentru un set  +set_cu_valori = {1, 2, 2, 3, 4} # => {1 2 3 4} + +# Putem adăuga valori cu add  +set_cu_valori.add(5) # set_cu_valori este acum {1, 2, 3, 4, 5} + +# Putem intersecta seturi  +alt_set = {3, 4, 5, 6} +set_cu_valori & alt_set #=> {3, 4, 5} + +# Putem calcula uniunea cu | +set_cu_valori | alt_set #=> {1, 2, 3, 4, 5, 6} + +# Diferenţa între seturi se face cu - +{1,2,3,4} - {2,3,5} #=> {1, 4} + +# Verificăm existenţa cu "in"  +2 in set_cu_valori #=> True +10 in set_cu_valori #=> False + + +#################################################### +## 3. Controlul Execuţiei +#################################################### + +# O variabilă  +o_variabila = 5 + +# Acesta este un "if". Indentarea este importanta în python! +# Printează "o_variabila este mai mică ca 10" +if o_variabila > 10: +    print "o_variabila e mai mare ca 10." +elif o_variabila < 10:    # Clauza elif e opţională.  +    print "o_variabila este mai mică ca 10." +else:           # Şi else e opţional. +    print "o_variabila este exact 10." + + +""" +Buclele "for" pot fi folosite pentru a parcurge liste +Vom afişa: +    câinele este un mamifer  +    pisica este un mamifer +    şoarecele este un mamifer +""" +for animal in ["câinele", "pisica", "şoarecele"]: +    # Folosim % pentru a compune mesajul  +    print "%s este un mamifer" % animal +     +""" +"range(număr)" crează o lista de numere  +de la zero la numărul dat +afişează: +    0 +    1 +    2 +    3 +""" +for i in range(4): +    print i + +""" +While repetă pana când condiţia dată nu mai este adevărată.  +afişează: +    0 +    1 +    2 +    3 +""" +x = 0 +while x < 4: +    print x +    x += 1  # Prescurtare pentru x = x + 1 + +# Recepţionăm excepţii cu blocuri try/except  + +# Acest cod e valid in Python > 2.6: +try: +    # Folosim "raise" pentru a declanşa o eroare  +    raise IndexError("Asta este o IndexError") +except IndexError as e: +    pass    # Pass nu face nimic. În mod normal aici ne-am ocupa de eroare.  + + +#################################################### +## 4. Funcţii +#################################################### + +# Folosim "def" pentru a defini funcţii  +def add(x, y): +    print "x este %s şi y este %s" % (x, y) +    return x + y    # Funcţia poate returna valori cu "return"  + +# Apelăm funcţia "add" cu parametrii  +add(5, 6) #=> Va afişa "x este 5 şi y este 6" şi va returna 11  + +# Altă cale de a apela funcţii: cu parametrii numiţi  +add(y=6, x=5)   # Ordinea parametrilor numiţi nu contează  + +# Putem defini funcţii care primesc un număr variabil de parametrii nenumiţi +# Aceşti parametrii nenumiţi se cheamă si poziţinali +def varargs(*args): +    return args + +varargs(1, 2, 3) #=> (1,2,3) + + +# Şi putem defini funcţii care primesc un număr variabil de parametrii numiţi +def keyword_args(**kwargs): +    return kwargs + +# Hai să vedem cum merge  +keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"} + +# Se pot combina  +def all_the_args(*args, **kwargs): +    print args +    print kwargs +""" +all_the_args(1, 2, a=3, b=4) va afişa: +    (1, 2) +    {"a": 3, "b": 4} +""" + +# Când apelăm funcţii, putem face inversul args/kwargs! +# Folosim * pentru a expanda tuple şi ** pentru a expanda kwargs. +args = (1, 2, 3, 4) +kwargs = {"a": 3, "b": 4} +all_the_args(*args) # echivalent cu foo(1, 2, 3, 4) +all_the_args(**kwargs) # echivalent cu foo(a=3, b=4) +all_the_args(*args, **kwargs) # echivalent cu foo(1, 2, 3, 4, a=3, b=4) + +# În Python, funcţiile sunt obiecte primare +def create_adder(x): +    def adder(y): +        return x + y +    return adder + +add_10 = create_adder(10) +add_10(3) #=> 13 + +# Funcţiile pot fi anonime  +(lambda x: x > 2)(3) #=> True + +# Există funcţii de ordin superior (care operează pe alte funcţii) predefinite  +map(add_10, [1,2,3]) #=> [11, 12, 13] +filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7] + +# Putem folosi scurtături de liste pentru a simplifica munca cu map si filter  +[add_10(i) for i in [1, 2, 3]]  #=> [11, 12, 13] +[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7] + +#################################################### +## 5. Clase +#################################################### + +# Moştenim object pentru a crea o nouă clasă  +class Om(object): + +    # Acesta este un atribut al clasei. Va fi moştenit de toate instanţele.  +    species = "H. sapiens" + +    # Constructor (mai degrabă, configurator de bază)  +    def __init__(self, nume): +        # Valoarea parametrului este stocată in atributul instanţei  +        self.nume = nume + +    # Aceasta este o metoda a instanţei. +    # Toate metodele primesc "self" ca si primul argument. +    def spune(self, mesaj): +       return "%s: %s" % (self.nume, mesaj) + +    # O metodă a clasei. Este partajată de toate instanţele. +    # Va primi ca si primul argument clasa căreia îi aparţine.  +    @classmethod +    def get_species(cls): +        return cls.species + +    # O metoda statica nu primeste un argument automat.  +    @staticmethod +    def exclama(): +        return "*Aaaaaah*" + + +# Instanţiem o clasă  +i = Om(nume="Ion") +print i.spune("salut")  # afişează: "Ion: salut" + +j = Om("George") +print j.spune("ciau")   # afişează George: ciau" + +# Apelăm metoda clasei  +i.get_species() #=> "H. sapiens" + +# Modificăm atributul partajat  +Om.species = "H. neanderthalensis" +i.get_species() #=> "H. neanderthalensis" +j.get_species() #=> "H. neanderthalensis" + +# Apelăm metoda statică  +Om.exclama() #=> "*Aaaaaah*" + + +#################################################### +## 6. Module +#################################################### + +# Pentru a folosi un modul, trebuie importat  +import math +print math.sqrt(16) #=> 4 + +# Putem importa doar anumite funcţii dintr-un modul  +from math import ceil, floor +print ceil(3.7)  #=> 4.0 +print floor(3.7) #=> 3.0 + +# Putem importa toate funcţiile dintr-un modul, dar nu este o idee bună +# Nu faceţi asta! +from math import * + +# Numele modulelor pot fi modificate la import, de exemplu pentru a le scurta  +import math as m +math.sqrt(16) == m.sqrt(16) #=> True + +# Modulele python sunt pur şi simplu fişiere cu cod python.  +# Puteţi sa creaţi modulele voastre, şi sa le importaţi. +# Numele modulului este acelasi cu numele fişierului. + +# Cu "dir" inspectăm ce funcţii conţine un modul +import math +dir(math) + + +``` + +## Doriţi mai mult? + +### Gratis online, în limba engleză + +* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/) +* [Dive Into Python](http://www.diveintopython.net/) +* [The Official Docs](http://docs.python.org/2.6/) +* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/) +* [Python Module of the Week](http://pymotw.com/2/) + +### Cărţi, în limba engleză + +* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20) +* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20) +* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20) + diff --git a/tr-tr/c-tr.html.markdown b/tr-tr/c-tr.html.markdown index 50bca246..128901de 100644 --- a/tr-tr/c-tr.html.markdown +++ b/tr-tr/c-tr.html.markdown @@ -95,6 +95,10 @@ int main() {      // is not evaluated (except VLAs (see below)).      // The value it yields in this case is a compile-time constant.      int a = 1; + +    // size_t bir objeyi temsil etmek için kullanılan 2 byte uzunluğundaki bir  +    // işaretsiz tam sayı tipidir +      size_t size = sizeof(a++); // a++ is not evaluated      printf("sizeof(a++) = %zu where a = %d\n", size, a);      // prints "sizeof(a++) = 4 where a = 1" (on a 32-bit architecture) diff --git a/tr-tr/php-tr.html.markdown b/tr-tr/php-tr.html.markdown index 94bc31ff..c5576fd7 100644 --- a/tr-tr/php-tr.html.markdown +++ b/tr-tr/php-tr.html.markdown @@ -67,6 +67,9 @@ $float = 1.234;  $float = 1.2e3;  $float = 7E-10; +// Değişken Silmek +unset($int1) +  // Aritmetik  $sum        = 1 + 1; // 2  $difference = 2 - 1; // 1 @@ -183,6 +186,13 @@ $y = 0;  echo $x; // => 2  echo $z; // => 0 +// Dump'lar değişkenin tipi ve değerini yazdırır +var_dump($z); // int(0) yazdırılacaktır + +// Print'ler ise değişkeni okunabilir bir formatta yazdıracaktır.  +print_r($array); // Çıktı: Array ( [0] => One [1] => Two [2] => Three ) + +  /********************************   * Mantık   */ @@ -478,10 +488,18 @@ class MyClass          print 'MyClass';      } +    //final anahtar kelimesi bu metodu override edilemez yapacaktır.      final function youCannotOverrideMe()      {      } +/* +Bir sınıfın özelliğini ya da metodunu statik yaptığınız takdirde sınıfın bir  +objesini oluşturmadan bu elemana erişebilirsiniz. Bir özellik statik tanımlanmış  +ise obje üzerinden bu elemana erişilemez. (Statik metodlar öyle değildir.) +*/ + +      public static function myStaticMethod()      {          print 'I am static'; | 
