racket: fix apply/vector
authorJoel Martin <github@martintribe.org>
Sun, 22 Mar 2015 19:43:26 +0000 (14:43 -0500)
committerJoel Martin <github@martintribe.org>
Sun, 22 Mar 2015 19:43:26 +0000 (14:43 -0500)
- re-order apply/vector tests into optional section.

docs/TODO
racket/core.rkt
tests/step9_try.mal

index 86c3465..95f39bd 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -3,7 +3,6 @@ All:
 
     - test that *ARGV* gets set properly
     - test to make sure slurp captures final newline
-    - fix long line splitting in runtest
     - Give runtest knowledge of optional tests and report as non-fatal
     - regular expression matching in runtest
     - add re (use in rep) everywhere and use that (to avoid printing)
index 1cb41bf..8db1647 100644 (file)
                        exc)))
 
 ;; Sequence functions
+(define do_apply
+  (lambda a
+    (let* ([f (first a)]
+           [lst (_to_list (last a))]
+           [args (append (take (drop a 1) (- (length a) 2)) lst)])
+      (apply f args))))
+
 (define conj
   (lambda a
     (if (vector? (first a))
@@ -88,7 +95,7 @@
     'rest     _rest
     'empty?   _empty?
     'count    _count
-    'apply    apply
+    'apply    do_apply
     'map      (lambda (f s) (_to_list (_map f s)))
     'conj     conj
 
index 18930fe..b432040 100644 (file)
 ;=>5
 (apply + 4 (list 5))
 ;=>9
-(apply + 4 [5])
-;=>9
 (apply prn (list 1 2 "3" (list)))
 ; 1 2 "3" ()
 (apply prn 1 2 (list "3" (list)))
 ; 1 2 "3" ()
-(apply prn 1 2 ["3" 4])
-; 1 2 "3" 4
-;=>nil
 
 ;; Testing apply function with user functions
 (apply (fn* (a b) (+ a b)) (list 2 3))
 ;=>5
 (apply (fn* (a b) (+ a b)) 4 (list 5))
 ;=>9
-(apply (fn* (a b) (+ a b)) [2 3])
-;=>5
-(apply (fn* (a b) (+ a b)) 4 [5])
-;=>9
 
 ;; Testing map function
 (def! nums (list 1 2 3))
 (sequential? "abc")
 ;=>false
 
+;; Testing apply function with core functions and arguments in vector
+(apply + 4 [5])
+;=>9
+(apply prn 1 2 ["3" 4])
+; 1 2 "3" 4
+;=>nil
+;; Testing apply function with user functions and arguments in vector
+(apply (fn* (a b) (+ a b)) [2 3])
+;=>5
+(apply (fn* (a b) (+ a b)) 4 [5])
+;=>9
+
 
 ;; Testing map function with vectors
 (map (fn* (a) (* 2 a)) [1 2 3])