2010년 9월 29일 수요일
[sicp] 1.11
- recursive process
#lang scheme
(define (f n)
(cond ((= n 0) 0)
((= n 1) 1)
((= n 2) 2)
(else (+ (f (- n 1))
(* 2 (f (- n 2)))
(* 3 (f (- n 3)))) ) ) )
- iterative process
#lang scheme
(define (f-iter a b c count)
(if (= count 0)
c
(f-iter (+ a (* 2 b) (* 3 c) )
a b (- count 1) ) ) )
(define (f n )
(f-iter 2 1 0 n) )
2010년 9월 26일 일요일
1.10
Exercise 1.10. The following procedure computes a mathematical function called Ackermann's function.
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
What are the values of the following expressions?
(A 1 10)
(A 2 4)
(A 3 3)
Consider the following procedures, where A is the procedure defined above:
(define (f n) (A 0 n))
(define (g n) (A 1 n))
(define (h n) (A 2 n))
(define (k n) (* 5 n n))
Give concise mathematical definitions for the functions computed by the procedures f, g, and h for positive integer values of n. For example, (k n) computes 5n2.
(A 1 10 ) 풀이
( A 1 10 ) = > 1024
( A 1 ( A 1 9) ) = 512
( A 1 ( A 1 (A 1 8 ) ) = 256
( A 1 ( A 1 ( A 1 (A 1 7 ) ) ) = 128
( A 1 ( A 1 ( A 1 ( A 1 (A 1 6 ) ) ) ) )
....
( A 1 .... ( * 2 1 ) )
(A 2 4 ) 풀이
( A 2 1 ) = > 1
( A 2 2 ) = > 4 -> 2^2
( A 2 3 ) = > 16 -> 2^(2^2)
( A 2 4 ) = > 65536 -> (2^(2^(2^2)))
1. f => 2n
(define (f n) (A 0 n)) 일때 A 함수를 따르면
x = 0 이므로 ( * 2 y ) 이다.
답은 f(n) = 2n
2. g => 2^n
3. h => if n = 0 : f(x) = 0
if n = 1 : f(x) = 2^1
if n >= 2 : f(x) = 2^f(x-1)
나오는 순서도는 생략 ㅡㅡ 너무 쓰기 힘듬 ...
2010년 9월 14일 화요일
eclispse monkey
원본 저자: Yi Tan (yi2004@gmail.com)
eclipse monkey
몇가지 불편한거 추가..
setter/getter 이상한거 수정
property:Type= n -> 실행시
property:Type= new Type(); 으로 변환 되는 기능 추가
2010년 9월 10일 금요일
[flex] ContextMenu 기능 정리
1. ContextMenuItem 추가시에 사용하는 이름이 동일하면 한개만 출력된다.
2. ContextMenuItem 추가시에 사용하는 이름이 "삭제","Del" 이런거 전부 안된다.
위의 내용들은 디버거 써도 에러도 잡히지도 않는다. ㅡㅡ
이걸로 며칠을 고생했는지 ㅠㅠ
슬프다.
2010년 8월 12일 목요일
[struts2] struts2 poi excel result
struts2에서 excel를 출력할 경우가 있는데
인터넷 검색결과 내가 하고 싶은 방식으로 되어 있는 소스가 없었다.
그래서 spring mvc abstractExcelView를 참고해서 struts2용 AbstractView를 만들었다.
[code java]package pmis.common.excel; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.util.ValueStack; public abstract class AbstractExcelResult implements Result { /** The content type for an Excel response */ private static final String CONTENT_TYPE = "application/vnd.ms-excel"; /** The extension to look for existing templates */ private static final String EXTENSION = ".xls"; private String url; public void setUrl(String url) { this.url = url; } @Override public void execute(ActionInvocation invocation) throws Exception { try { HSSFWorkbook workbook; HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); String requestURI = request.getRequestURI(); workbook = new HSSFWorkbook(); buildExcelDocument(invocation.getStack(), workbook, ServletActionContext.getRequest(), ServletActionContext.getResponse()); // Set the content type. response.setContentType(CONTENT_TYPE); response.setHeader("Content-disposition", "attachment;filename="+StringUtils.defaultIfEmpty(url, StringUtils.substring(requestURI,StringUtils.lastIndexOf(requestURI, "/"), StringUtils.indexOf(requestURI, ".")))+EXTENSION); ServletOutputStream out = response.getOutputStream(); workbook.write(out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } } protected abstract void buildExcelDocument( ValueStack valueStack, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception; protected HSSFCell getCell(HSSFSheet sheet, int row, int col) { HSSFRow sheetRow = sheet.getRow(row); if (sheetRow == null) { sheetRow = sheet.createRow(row); } HSSFCell cell = sheetRow.getCell(col); if (cell == null) { cell = sheetRow.createCell(col); } return cell; } } [/code]
위의 소스를 확장해서 각각의 페이지별로 Excel를 만들때는
[code java]package pmis.system.loginstat; import java.math.BigDecimal; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import pmis.common.excel.AbstractExcelResult; import com.opensymphony.xwork2.util.ValueStack; public class LoginStatExcelResult extends AbstractExcelResult { @Override protected void buildExcelDocument(ValueStack valueStack, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { //여기에 구현 } } [/code]
그리고
xml 페이지에선
result type 선언
[code xml]
action 선언에선
[code xml]2010년 8월 9일 월요일
[sicp] 1.9
1.9
첫번째 : iterative
a : counter
b : product
a가 1 감소할때마다 b는 1씩 증가해서 a가 0이 되면 b는 결과 출력
erlang 버젼
[code] -module(iterative). -export([inc/1,dec/1,plus/2]). inc(A)->A+1. dec(A)->A-1. plus(0,B) -> B; plus(A,B)-> plus(dec(A),inc(B)). [/code]
두번째 : recursive
전형적인 재귀
a가 1씩 감소할떄마다 재귀호출를 1번씩 해서 총 a가 감소만 만큼 재귀호출한 후에
a만큼 다시 더하는 방식
[code] #lang scheme (define ( inc a ) (- a -1)) (define (dec a) (- a 1)) (define (+ a b) (if (= a 0) b (inc (+ (dec a) b)))) (+ 4 5) [/code]
2010년 8월 3일 화요일
[scala] Scala에서 사용하는 Actor가 ...
항상 thread safe 하지 않다는 내용이다.
Erlang부분까지는 기억이 안 나는데 연결된 링크까지 가서 보게 되면
scala에서 사용하는 Actor 모델은 결코 deadlock에 안전하지 않다는 내용이다.
정확하게 읽으신 분들이 태클 부탁드립니다.