picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

apply.l (2373B)


      1 # 21may10abu
      2 # (c) Software Lab. Alexander Burger
      3 
      4 ### apply ###
      5 (test 6 (apply + (1 2 3)))
      6 (test 360 (apply * (5 6) 3 4))
      7 (test 27 (apply '((X Y Z) (* X (+ Y Z))) (3 4 5)))
      8 (test (5 7 9) (apply mapcar '((1 2 3) (4 5 6)) +))
      9 
     10 
     11 ### pass ###
     12 (test 24 ((quote (N . @) (* N (pass + 6))) 2 1 2 3))
     13 
     14 
     15 ### maps ###
     16 (let L '((1 . a) (2 . b) flg)
     17    (test L (let X (box) (putl X (reverse L)) (make (maps link X)))) )
     18 
     19 
     20 ### map ###
     21 (test '((1 2 3) (2 3) (3)) (make (map link (1 2 3))))
     22 
     23 
     24 ### mapc ###
     25 (test (1 2 3) (make (mapc link (1 2 3))))
     26 
     27 
     28 ### maplist ###
     29 (test '(((1 2 3) A B C) ((2 3) B C) ((3) C)) (maplist cons (1 2 3) '(A B C)))
     30 
     31 
     32 ### mapcar ###
     33 (test (5 7 9) (mapcar + (1 2 3) (4 5 6)))
     34 (test (26 38 52 68) (mapcar '((X Y) (+ X (* Y Y))) (1 2 3 4) (5 6 7 8)))
     35 
     36 
     37 ### mapcon ###
     38 (test (1 2 3 4 5 2 3 4 5 3 4 5 4 5 5) (mapcon copy (1 2 3 4 5)))
     39 
     40 
     41 ### mapcan ###
     42 (test '(c b a f e d i h g) (mapcan reverse '((a b c) (d e f) (g h i))))
     43 
     44 
     45 ### filter ###
     46 (test (1 2 3) (filter num? (1 A 2 (B) 3 CDE)))
     47 
     48 
     49 ### extract ###
     50 (let (A NIL  B 1  C NIL  D 2  E NIL  F 3)
     51    (test (1 2 3)
     52       (extract val '(A B C D E F)) )
     53    (test (1 2 3)
     54       (extract val '(B D E F)) ) )
     55 
     56 
     57 ### seek ###
     58 (test (12 19 22) (seek '((X) (> (car X) 9)) (1 5 8 12 19 22)))
     59 
     60 
     61 ### find ###
     62 (test '(B) (find pair (1 A 2 (B) 3 CDE)))
     63 (test 4 (find > (1 2 3 4 5 6) (6 5 4 3 2 1)))
     64 (test 4 (find '((A B) (> A B)) (1 2 3 4 5 6) (6 5 4 3 2 1)))
     65 
     66 
     67 ### pick ###
     68 (test "Hello"
     69    (pick '((X) (get X 'str))
     70       (list (box) (prog1 (box) (put @ 'str "Hello")) (box)) ) )
     71 
     72 
     73 ### cnt ###
     74 (test 2 (cnt cdr '((1 . T) (2) (3 4) (5))))
     75 
     76 
     77 ### sum ###
     78 (test 6 (sum val (list (box 1) (box) (box 2) (box 'a) (box 3))))
     79 
     80 
     81 ### maxi mini ###
     82 (let (A 1 B 2 C 3)
     83    (test 'C (maxi val '(A B C)))
     84    (test 'A (mini val '(A B C)))
     85    (test '(A B C) (by val sort '(C A B))) )
     86 
     87 
     88 ### fish ###
     89 (test (1 2 3)
     90    (fish gt0 '(a -2 (1 b (-3 c 2)) 3 d -1)) )
     91 (test '(a b c d)
     92    (fish sym? '(a -2 (1 b (-3 c 2)) 3 d -1)) )
     93 
     94 
     95 ### by ###
     96 (test '(A B C)
     97    (let (A 1 B 2 C 3)
     98       (by val sort '(C A B)) ) )
     99 (test '((3 11 9 5 7 1) (6 2 4 10 12 8))
    100    (by '((N) (bit? 1 N))
    101       group
    102       (3 11 6 2 9 5 4 10 12 7 8 1) ) )
    103 (test '(("x" "x" "x") ("y") ("z" "z"))
    104    (by name group '("x" "x" "y" "z" "x" "z")) )
    105 (test '((123 "xyz") ((1 2) "XY") ("abcd" (1 2 3 4)))
    106    (by length group '(123 (1 2) "abcd" "xyz" (1 2 3 4) "XY")) )
    107 
    108 # vi:et:ts=3:sw=3