Programming/lisp2012. 12. 31. 21:35
c의 for나 while과 비슷한 반복문 키워드로
loop, dotimes, dolist 등이 있다.

(let ((<var1> <init1>) (<var2> <init2>) …)
<body> )

– Declares local variables.  It is best to declare variables before using them.

(dotimes (<counter> <limit> <result>)
<body>)
(let ((sum 0))
    (dotimes (i 10 sum) (setq sum (+ sum i))) ) => 45
 
[링크 : http://logic.stanford.edu/classes/cs157/2004/programming/lisp.pdf

xlisp 설명서 발췌
Looping Constructs

basic looping form
(loop <expr>...)

fsubr

<expr> the body of the loop
returns never returns (must use non-local exit, such as return)



general looping form
(do (<binding>...) (<texpr> <rexpr>...) <expr>...)
(do* (<binding>...) (<texpr> <rexpr>...) <expr>...)

fsubr. do binds simultaneously, do* binds sequentially

<binding> the variable bindings each of which is either:

1) a symbol (which is initialized to NIL)
2) a list of the form: (<sym> <init> [<step>])

where:
<sym> is the symbol to bind
<init> the initial value of the symbol
<step> a step expression

<texpr> the termination test expression
<rexpr> result expressions (the default is NIL)
<expr> the body of the loop (treated like an implicit prog)
returns the value of the last result expression



loop through a list
(dolist (<sym> <expr> [<rexpr>]) <expr>...)

fsubr

<sym> the symbol to bind to each list element
<expr> the list expression
<rexpr> the result expression (the default is NIL)
<expr> the body of the loop (treated like an implicit prog)
returns the result expression



loop from zero to n-1
(dotimes (<sym> <expr> [<rexpr>]) <expr>...)

fsubr

<sym> the symbol to bind to each value from 0 to n-1
<expr> the number of times to loop (a fixnum)
<rexpr> the result expression (the default is NIL)
<expr> the body of the loop (treated like an implicit prog)
returns the result expression 

'Programming > lisp' 카테고리의 다른 글

lisp 전역변수 / 지역변수  (0) 2013.01.09
lisp car / cdr  (0) 2013.01.03
clisp  (0) 2012.12.29
lisp 기본함수  (0) 2012.12.29
xlisp-plus 3.05  (0) 2012.12.29
Posted by 구차니