๋ชฉ๋ก์ ์ฒด ๊ธ (1103)
KoreanFoodie's Study

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala datatypes part2 Pattern Matching A way to use algebraic datatypes Syntax: e match { case C1(...) => e1 ... case Cn(...) => en } Example : sealed abstract class IList case class INil() extends IList case class ICons(hd: Int, tl: IList) extends IList def x: IList = ICons(2, ICons(1, INil())) def length(xs: IList) : Int = xs match { case INil() => 0 case ICons(x, tl) => 1 + length(t..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ datatypes์ ๋ํด ์์๋ณด์ Types in general Introdection : How to construct elements Elimination : How to use elements of the type Primitive types : Int, Boolean, Double, String... Intro for Int: ...,-2,-1,0,1,2 Elim for Int: +,-,*,/... -Function types : Int => Int, (Int => Int)=>(Int => Int) Intro: (x:T)=>e Elim: f(v) Tuples Intro : (1, 2, 3) : (Int, Int, Int) (1, "a") : (Int, String) ..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์์ currying์ ๋ํด ์์๋ณด์ Currying Why we use currying? Let's look at the code, simplified by currying. def sum(f: Int=>Int, a: Int, b: Int): Int = if (a Int): (Int, Int) => Int = { def sumF(a: Int, b: Int): Int = if (a Int)(a: Int, b: Int): Int = if (a T can be turned into one of type T1 => (T2 => (... Tn =>T) This is called 'currying' named after Haskell Brooks Curry. The opposite di..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ closure์ ๋ํด ์์๋ณด์ Parameterized expression vs. values Functions defined using “def” are not values but parameterized expressions. • Anonymous functions are values. • But, parameterized expressions are implicitly converted to values. • Explicit conversion: f _ • Anonymous functions can be seen as syntactic sugar: (x:T)=>e is equivalent to { def \_\_noname(x:T) = e; \_\_noname \_ }..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ tail recursion์ ์์๋ด ์๋ค Recursion needs care Let's look at typical summation fuction. def sum(n: Int) : Int = if (n x*x*x, n) // or def sumLinear(n: Int) = sum((x)=>x, n) def sumSquare(n: Int) = sum((x)=>x*x, n) def sumCubes(n: Int) = sum((x)=>x*x*x, n) Excercise def sum(f: Int => Int, a: Int, b: Int): Int = if (a Int, a: Int, b: Int): Int = if (a Int, inival: Int, f: Int => Int, ..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์์ lazy val์ ๋ํด ์์๋ณด์ Blocks and Name Scoping Blocks in scala Block is an expression. It also allow nested name binding. Block allows arbitraty order of "def"s, but not "val"s(think about why). Scope of names Block example : val t = 0 def f(x: Int) = t + g(x) def g(x: Int) = x * x val x = f(5) val r = { val t = 10 val s = f(5) t + s } val y = t + r A definition inside a block is on..

์ค์นผ๋ผ์์ call by value์ call by name์ ์ฐจ์ด๋ฅผ ์์๋ณด์ There is two strategy to evaluate values. Call-by-value Evaluate the arguments first, then apply the function to them Call-by-name Just apply the function to its arguments, without evaluating them Let's see the example. def square (x: Int) = x * x [cbv] square(1+1) ~ square(2) ~ 2 * 2 ~ 4 [cbn] square(1+1) ~ (1+1) * (1+1) ~ 2 * (1+1) ~ 2 * 2 ~ 4 So wha..

ํ์ด์ฌ์ผ๋ก ๋ง๋ ๊ฐ๋จํ ํฌ๋กค๋ฌ ์ฐธ๊ณ ์๋ฃ : ์น ํฌ๋กค๋ฌ ๋ง๋ค๊ธฐ, Implicit vs. Explict wait ๋น๊ตํ๊ธฐ ์ ํฌ๋ธ์์ ์์ ๋ค์ด๋ก๋ํ๋ ์์ ์๋ํ ํ๊ธฐ ์น๊ตฌ๊ฐ ์ ํฌ๋ธ๋ฅผ ํตํด ์์ ์ ๋ณํํด์ ๋ค์ด๋ก๋ ๋ฐ๋ ๊ฒ์ ๋ณด๊ณ , ์ด๋ฅผ ๊ฐํธํ๊ฒ ํด์ฃผ๊ณ ์ ํ์ด์ฌ selenium module, chromedriver์ ์ด์ฉํด ์คํํค(Win+R)๋ฅผ ํตํด ์ฝ๊ฒ ์์ ์ ๋ค์ด๋ก๋ํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์์ต๋๋ค. ์, ์ฐธ๊ณ ๋ก mp3juices.cc ๋ผ๋ ์ฌ์ดํธ๋ก๋ถํฐ ์์ ์ ๋ณํํด์ ๋ค์ด์ ํ๋๋ฐ, ์ฌ๊ธฐ๊ฐ ์ ์ผ ๊น๋ํ ๊ฒ ๊ฐ์์(์ ๊ธฐ์ค) Prerequsite : Python3 (Latest version is recommemded) Installing 3rd party modules (pyperclip, seleniu..

ํ์ด์ฌ์์ ๊น๋จน์ ์ ์๋ ์์ํ ์ฌํญ๋ค์ ๋ฆฌ๋ง์ธ๋ํ๋ ํฌ์คํธ์ ๋๋ค. ์ฝ๋๋ค์ automatetheboringstuff.com์์ ์ฐธ์กฐํ์ต๋๋ค. ์ ์์ Backslash on Windows and Forward Slash on OS X and Linux >>> import os >>> os.path.join('usr', 'bin', 'spam') 'usr\\bin\\spam' The os.path.join() function is helpful if you need to create strings for filenames. These strings will be passed to several of the file-related functions introduced in this chapter. For..

ํ์ด์ฌ์์ ๊น๋จน์ ์ ์๋ ์์ํ ์ฌํญ๋ค์ ๋ฆฌ๋ง์ธ๋ํ๋ ํฌ์คํธ์ ๋๋ค. ์ฝ๋๋ค์ automatetheboringstuff.com์์ ์ฐธ์กฐํ์ต๋๋ค. ์ ์์ Raw Strings A raw string completely ignores all escape characters and prints any backslash that appears in the string. >>> print(r'That is Carol\'s cat.') That is Carol\'s cat. Slicing strings >>> spam = 'Hello world!' >>> spam[0] 'H' >>> spam[4] 'o' >>> spam[-1] '!' >>> spam[0:5] 'Hello' >>> spam[:5] 'Hello' >..