diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c5f30b10..3cdec7cbf 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * replace `undefined` with `#void`, and `null` with `#null` * characters are again unboxed into strings by JavaScript code [#329](https://github.com/jcubic/lips/issues/329) * code that throw exception now return exit code 1 +* change order of arguments in `take` ### Features * add `vector-for-each` and `vector-copy!` function from R7RS * add `string-for-each`, `string-downcase`, and `string-upcase` from R7RS diff --git a/dist/std.min.scm b/dist/std.min.scm index c96dc0074..5463eecef 100644 --- a/dist/std.min.scm +++ b/dist/std.min.scm @@ -61,8 +61,8 @@ (define (await value) "(await value)\u000A\u000AUnquotes a quoted promise so it can be automagically evaluated (resolved\u000Ato its value)." (if (instanceof lips.QuotedPromise value) (value.valueOf) value)) (define-macro (quote-promise expr) "(quote-promise expr) or '>expr\u000A\u000AMacro used to escape automati awaiting of the expression. It will be wrapped\u000Awith a JavaScript class that behaves like Promise but will not be automatically\u000Aresolved by LIPS like normal promises are." (quasiquote (let ((env)) (set! env (current-environment)) (env.set (Symbol.for "__promise__") true) (let ((env)) (set! env (current-environment)) (env.set (Symbol.for "__promise__") false) (unquote expr))))) (define (defmacro? obj) "(defmacro? expression)\u000A\u000AChecks if object is a macro and it's expandable." (and (macro? obj) (. obj (quote defmacro)))) -(define (n-ary n fn) "(n-ary n fn)\u000A\u000AReturns a new function that limits the number of arguments to n." (lambda args (apply fn (take n args)))) -(define (take n lst) "(take n list)\u000A\u000AReturns n first values of the list." (let iter ((result (quote ())) (i n) (lst lst)) (if (or (null? lst) (<= i 0)) (reverse result) (iter (cons (car lst) result) (- i 1) (cdr lst))))) +(define (n-ary n fn) "(n-ary n fn)\u000A\u000AReturns a new function that limits the number of arguments to n." (lambda args (apply fn (take args n)))) +(define (take lst n) "(take list n)\u000A\u000AReturns n first values of the list." (let loop ((result (quote ())) (i n) (lst lst)) (if (or (null? lst) (<= i 0)) (reverse result) (loop (cons (car lst) result) (- i 1) (cdr lst))))) (define (zip . lists) "(zip list1 list2 ...)\u000A\u000AReturn list where elements are taken from each list.\u000Ae.g.:\u000A(zip '(1 2 3) '(2 3 4))\u000A;; ==> '((1 2) (2 3) (3 4))" (if (or (null? lists) (some null? lists)) (quote ()) (cons (map car lists) (apply zip (map cdr lists))))) (define unary (%doc "(unary fn)\u000A\u000AReturns a new function with arguments limited to one." (curry n-ary 1))) (define binary (%doc "(binary fn)\u000A\u000AReturns a new function with arguments limited to two." (curry n-ary 2))) diff --git a/dist/std.scm b/dist/std.scm index 07d444c83..f9c479400 100644 --- a/dist/std.scm +++ b/dist/std.scm @@ -849,17 +849,17 @@ Returns a new function that limits the number of arguments to n." (lambda args - (apply fn (take n args)))) + (apply fn (take args n)))) ;; ----------------------------------------------------------------------------- -(define (take n lst) - "(take n list) +(define (take lst n) + "(take list n) Returns n first values of the list." - (let iter ((result '()) (i n) (lst lst)) + (let loop ((result '()) (i n) (lst lst)) (if (or (null? lst) (<= i 0)) (reverse result) - (iter (cons (car lst) result) (- i 1) (cdr lst))))) + (loop (cons (car lst) result) (- i 1) (cdr lst))))) ;; ----------------------------------------------------------------------------- (define (zip . lists) diff --git a/dist/std.xcb b/dist/std.xcb index df1a2a055..8ab74d93f 100644 Binary files a/dist/std.xcb and b/dist/std.xcb differ diff --git a/lib/bootstrap.scm b/lib/bootstrap.scm index fb4c288f2..0a1a1ff51 100755 --- a/lib/bootstrap.scm +++ b/lib/bootstrap.scm @@ -849,17 +849,17 @@ Returns a new function that limits the number of arguments to n." (lambda args - (apply fn (take n args)))) + (apply fn (take args n)))) ;; ----------------------------------------------------------------------------- -(define (take n lst) - "(take n list) +(define (take lst n) + "(take list n) Returns n first values of the list." - (let iter ((result '()) (i n) (lst lst)) + (let loop ((result '()) (i n) (lst lst)) (if (or (null? lst) (<= i 0)) (reverse result) - (iter (cons (car lst) result) (- i 1) (cdr lst))))) + (loop (cons (car lst) result) (- i 1) (cdr lst))))) ;; ----------------------------------------------------------------------------- (define (zip . lists)