DynamicPL
-
Context managerDynamicPL/Python 2019. 11. 9. 23:32
1. Overview Context managers allow you to allocate and release resources precisely when you want to. The most widely used example of context managers is the with a statement. Suppose you have two related operations which you’d like to execute as a pair, with a block of code in between. Context managers allow you to do specifically that. For example: 2. Description 2.1 Context In python, context ..
-
DecoratorsDynamicPL/Python 2019. 11. 7. 18:36
1. Overview In general a decorator function: Takes a function as an argument Returns a closure The closure usually accepts any combination of parameters Runs some code in the inner function (closure) The closure function calls the original function using the arguments passed to the closure Returns whatever is returned by that function call 2. Description 2.1 Decorator function def counter(fn): c..
-
ClosureDynamicPL/Python 2019. 11. 7. 17:09
1. Overview Closure can be consist of a function plus an extended scope that contains the free variables. 2. Description 2.1 Free Variable and Inner Function Functions defined inside another function can access the outer (nonlocal) variables def outer(): x = [1, 2, 3] print('outer:', hex(id(x))) def inner(): print('inner:', hex(id(x))) print(x) return inner fn = outer() fn() x is a free variable..
-
First-Class Object and High-Order functionDynamicPL/Python 2019. 11. 2. 14:02
1. Overview In programming language design, a first-class citizen (also type, object, entity, or value) in a given programming language is an entity that supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, modified, and assigned to a variable. In mathematics and computer science, a higher-ord..
-
SliceDynamicPL/Python 2019. 10. 28. 15:54
1. Overview Slicing relies on indexing. It only works with sequence types. 2. Description 2.1 Capability on sequence types 2.2 Sequence type 2.3 Slice start and stop bounds 2.4 Step value 2.5 Range equivalence 2.6 Transformation [i:j] 2.7 Transformations [i:j:k], k > 0 2.8 Transformations [i:j:k], k < 0 2.9 indices method 2.10 Summary 3. Example 3.1 Example 1 3.2 Example 2 4. References https://..
-
SequenceDynamicPL/Python 2019. 10. 26. 16:26
1. Definition In Math: $S=x_{1},x_{2},x_{3},\cdots $ Note The sequence of indices: 1, 2, 3, ... We can refer to any item in the sequence by using its index number S[2] So we have a concept of the first element, the second element, and so on Python lists have a concept of positional order, but set do not A list is a sequence type A set is not a sequence type 2. Built-In Sequence Types 2.1 Mutable..
-
Destructuring, Spread, Rest parameters, Default parameters, Maps and ArraysDynamicPL/Javascript 2019. 10. 24. 19:28
1. Overview There are several new features added in ES6 which are Destructing, Spread, Rest, Default parameter, and so on. 2. Description 2.1 Destructing // ES5 var john = ['John', 26]; //var name = john[0]; //var age = john[1]; // ES6 // assign each element to variable const [name, age] = ['John', 26]; console.log(name); console.log(age); const obj = { firstName: 'John', lastName: 'Smith' }; co..
-
Arrow functionDynamicPL/Javascript 2019. 10. 24. 17:43
1. Overview Arrow functions which are added in ES6 are so simple and share the surrounding this keyword. Unlike normal function, arrow functions don't get their own "this" keyword. 2. Description 2.1 Expression const years = [1990, 1965, 1982, 1937]; // ES5 var ages5 = years.map(function(el) { return 2016 - el; }); console.log(ages5); // ES6 // a lots less code let ages6 = years.map(el => 2016 -..