View CaseClass.scala
// 스칼라의 문법인 케이스 클래스와 패턴 매칭 코드로 살펴보기
// regular, non-encapsulated data structures 가 필요할 때 케이스 클래스 사용
// Programming In Scala 15장 예제 코드로 구성 됨
abstract class Expr
case class Var(name: String) extends Expr
case class Number(num: Double) extends Expr
case class UnOp(operator: String, arg: Expr) extends Expr
case class BinOp(operator: String, left: Expr, right: Expr) extends Expr
View Equaltest.scala
case class Dummy(a: Int, b: Double)
val obj1 = Dummy(1, 10.0)
val obj2 = Dummy(2, 20.0)
val obj3 = Dummy(1, 10.0)
obj1 == obj2
obj1 equals obj2
obj1 == obj3
View EqualTest.java
public class EqualTest{
public static void main(String []args){
new EqualTest().test();
}
private void test() {
Dummy obj1 = new Dummy(1, 10.0);
Dummy obj2 = new Dummy(2, 20.0);
Dummy obj3 = new Dummy(1, 10.0);
System.out.println("obj1 == obj2: " + (obj1 == obj2) + " / obj1.equals(obj2): " + obj1.equals(obj2) );
View tail_rec_exp.c
int _twoExponential(int exponent, int acc) {
if ( exponent == 0 ) {
return acc;
}
acc *= 2;
return _twoExponential(--exponent, acc);
}
int exponential(int num) {
View Rational.scala
package nfm.ex06
/**
* Programming In Scala 2/e List 6.5 코드
* 분수 Class
* @param n 분자
* @param d 분모
*/
/* 스칼라에 있는 문법: Class에서 기본 생성자 선언 가능
View temp.ino
float tempC;
int reading;
int tempPin = 0;
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL);
}
void loop()
{
View temp_humi.ino
//Arduino Sample Code for SHT1x Humidity and Temperature Sensor
//www.DFRobot.com
//Version 1.0
#include <SHT1x.h>
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
View writeXLS.py
# coding: utf-8
from xlwt import Workbook
book = Workbook()
sheet1 = book.add_sheet(u'Ex Sheet1')
sheet2 = book.add_sheet(u'Ex Sheet2')
sheet1.write(0,0, u'Name')
sheet1.write(0,1, u'Sex')
View readXLS.py
# coding: utf-8
from xlrd import open_workbook
wb = open_workbook('simple.xls')
for sheet in wb.sheets():
print(u'Sheet:' + sheet.name)
print("Number of Sheets: " + str(wb.nsheets))
View factorial.scala
def factorial(n: Int): Int = {
def loop(acc: Int, n: Int): Int =
if (n == 0) acc
else loop(acc*n, n-1)
loop(1, n)
}