Changeset 39586 in project


Ignore:
Timestamp:
02/08/21 17:26:57 (3 weeks ago)
Author:
juergen
Message:

dotted-lambdas 1.2 with new test version

Location:
release/5/dotted-lambdas
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • release/5/dotted-lambdas/tags/1.2/dotted-lambdas.egg

    r39485 r39586  
    33((synopsis "lambda equivalents with dots as trailing symbols")
    44 (category lang-exts)
    5  (version "1.1")
     5 (version "1.2")
    66 (license "BSD")
    77 (test-dependencies simple-tests)
  • release/5/dotted-lambdas/tags/1.2/dotted-lambdas.scm

    r39485 r39586  
    7979With no argument it returns the encapsulated list and with one argument,
    8080an index, returns the list's value at that index.
     81Returns the list's length with negative index.
    8182]|#
    8283(define (callable lst)
     
    8586      (() lst)
    8687      ((k)
    87        (list-ref lst k)))))
     88       (cond
     89         ((negative? k) len)
     90         ((>= k len)
     91          (error 'callable "out of range" k))
     92         (else
     93          (list-ref lst k)))))))
    8894
    8995#|[
    90 (lambda* (x ... xs ..) xpr . xprs)
    91 (lambda* (x ... xs ...) xpr . xprs)
    92 (lambda* (x ... xs ....) xpr . xprs)
    93 (lambda* (x ...) xpr . xprs)
     96(lambda* (x !!! xs ..) xpr . xprs)
     97(lambda* (x !!! xs ...) xpr . xprs)
     98(lambda* (x !!! xs ....) xpr . xprs)
    9499--- macro ---
    95 the first three evaluate to (lambda (x ... . xs) xpr . xprs)
    96 making xs callable and checking if xs is of length at most 1,
     100An alternative to (lambda (x ... . xs) xpr . xprs).
     101Makes xs callable and checks if xs is of length at most 1,
    97102arbitrary or at least1, respectively.
    98 The last one evaluates to ordinary (lambda (x ...) xpr . xprs)
    99103]|#
    100104(define-syntax lambda*
     
    114118         (error 'lambda* "not enough arguments for ...." xs)
    115119         (let ((xs (callable xs))) xpr . xprs))))
    116     ((_ (x !!!) xpr . xprs) ; without dots: normal lambda
    117      (lambda (x !!!) xpr . xprs))
    118120    ))
    119121
     
    121123
    122124#|[
    123 (define* (name x ... xs ..) xpr . xprs)
    124 (define* (name x ... xs ...) xpr . xprs)
    125 (define* (name x ... xs ....) xpr . xprs)
    126 (define* (name x ...) xpr . xprs)
     125(define* (name x !!! xs ..) xpr . xprs)
     126(define* (name x !!! xs ...) xpr . xprs)
     127(define* (name x !!! xs ....) xpr . xprs)
    127128--- macro ---
    128129syntactic sugar for, e.g.
    129 (define name (lambda* (x ... xs ..) xpr . xprs))
     130(define name (lambda* (x !!! xs ..) xpr . xprs))
    130131]|#
    131132(define-syntax define*
     
    137138    ((_ (name x !!! xs ....) xpr . xprs)
    138139     (define name (lambda* (x !!! xs ....) xpr . xprs)))
    139     ((_ (name x !!!) xpr . xprs)
    140      (define name (lambda* (x !!!) xpr . xprs)))
    141140    ))
    142141
     
    157156        "With no argument it returns the encapsulated list and with one argument,"
    158157        "an index, returns the list's value at that index."
     158        "Returns the list's length with negative index."
    159159        )
    160160      (lambda*
    161161        macro:
    162         (lambda* (x ... xs ..) xpr . xprs)
    163         (lambda* (x ... xs ...) xpr . xprs)
    164         (lambda* (x ... xs ....) xpr . xprs)
    165         (lambda* (x ...) xpr . xprs)
    166         "the first three evaluate to (lambda (x ... . xs) xpr . xprs)"
    167         "making xs callable and checking if xs is of length at most 1,"
     162        (lambda* (x !!! xs ..) xpr . xprs)
     163        (lambda* (x !!! xs ...) xpr . xprs)
     164        (lambda* (x !!! xs ....) xpr . xprs)
     165        "An alternative to (lambda (x ... . xs) xpr . xprs)."
     166        "Makes xs callable and checks if xs is of length at most 1,"
    168167        "arbitrary or at least1, respectively."
    169         "The last one evaluates to ordinary (lambda (x ...) xpr . xprs)"
    170168        )
    171169      (define
    172170        macro:
    173         (define* (name x ... xs ..) xpr . xprs)
    174         (define* (name x ... xs ...) xpr . xprs)
    175         (define* (name x ... xs ....) xpr . xprs)
    176         (define* (name x ...) xpr . xprs)
    177         (define name (lambda* (x ... xs ..) xpr . xprs))
     171        (define* (name x !!! xs ..) xpr . xprs)
     172        (define* (name x !!! xs ...) xpr . xprs)
     173        (define* (name x !!! xs ....) xpr . xprs)
     174        (define name (lambda* (x !!! xs ..) xpr . xprs))
    178175        "syntactic sugar for, e.g."
    179176        )
  • release/5/dotted-lambdas/tags/1.2/tests/run.scm

    r39485 r39586  
    33(import simple-tests (chicken base) (chicken condition))
    44
    5 (define-checks
    6   (calls verbose? lst (callable '(0 1 2 3)) lst0 (callable '()))
     5(define-tester
     6  (calls? lst (callable '(0 1 2 3)) lst0 (callable '()))
    77  (condition-case (lst0 0) ((exn) #f))
    88  #f
     
    1111  (lst 3)
    1212  3
     13  (lst -1)
     14  4
    1315  (condition-case (lst 5) ((exn) #f))
    14   #f
    15   (condition-case (lst -1) ((exn) #f))
    1616  #f)
    1717
    18 (define-checks
    19   (lambdas verbose?)
     18(define-tester
     19  (lambdas?)
    2020  ((lambda* (xs ...) (list (xs 0) (xs 1) (xs 2))) 1 2 3)
    2121  '(1 2 3)
     
    3434  (condition-case ((lambda* (x y zs ....) (list x y zs)) 1 2) ((exn) #f))
    3535  #f
    36   ((lambda* (a b) (list a b)) 1 2)
    37   '(1 2)
    3836  ((lambda* (as ...) (as)) 1 2 3)
    3937  '(1 2 3)
     
    4947(define* (baz xs ..) (list (xs)))
    5048
    51 (define-checks
    52   (defines verbose?)
     49(define-tester
     50  (defines?)
    5351  (inc 5)
    5452  6
     
    6866  #f)
    6967
    70 (check-all DOTTED-LAMBDAS
    71   (calls)
    72   (lambdas)
    73   (defines)
     68(test-all DOTTED-LAMBDAS
     69  calls?
     70  lambdas?
     71  defines?
    7472  )
  • release/5/dotted-lambdas/trunk/dotted-lambdas.egg

    r39485 r39586  
    33((synopsis "lambda equivalents with dots as trailing symbols")
    44 (category lang-exts)
    5  (version "1.1")
     5 (version "1.2")
    66 (license "BSD")
    77 (test-dependencies simple-tests)
  • release/5/dotted-lambdas/trunk/dotted-lambdas.scm

    r39485 r39586  
    7979With no argument it returns the encapsulated list and with one argument,
    8080an index, returns the list's value at that index.
     81Returns the list's length with negative index.
    8182]|#
    8283(define (callable lst)
     
    8586      (() lst)
    8687      ((k)
    87        (list-ref lst k)))))
     88       (cond
     89         ((negative? k) len)
     90         ((>= k len)
     91          (error 'callable "out of range" k))
     92         (else
     93          (list-ref lst k)))))))
    8894
    8995#|[
    90 (lambda* (x ... xs ..) xpr . xprs)
    91 (lambda* (x ... xs ...) xpr . xprs)
    92 (lambda* (x ... xs ....) xpr . xprs)
    93 (lambda* (x ...) xpr . xprs)
     96(lambda* (x !!! xs ..) xpr . xprs)
     97(lambda* (x !!! xs ...) xpr . xprs)
     98(lambda* (x !!! xs ....) xpr . xprs)
    9499--- macro ---
    95 the first three evaluate to (lambda (x ... . xs) xpr . xprs)
    96 making xs callable and checking if xs is of length at most 1,
     100An alternative to (lambda (x ... . xs) xpr . xprs).
     101Makes xs callable and checks if xs is of length at most 1,
    97102arbitrary or at least1, respectively.
    98 The last one evaluates to ordinary (lambda (x ...) xpr . xprs)
    99103]|#
    100104(define-syntax lambda*
     
    114118         (error 'lambda* "not enough arguments for ...." xs)
    115119         (let ((xs (callable xs))) xpr . xprs))))
    116     ((_ (x !!!) xpr . xprs) ; without dots: normal lambda
    117      (lambda (x !!!) xpr . xprs))
    118120    ))
    119121
     
    121123
    122124#|[
    123 (define* (name x ... xs ..) xpr . xprs)
    124 (define* (name x ... xs ...) xpr . xprs)
    125 (define* (name x ... xs ....) xpr . xprs)
    126 (define* (name x ...) xpr . xprs)
     125(define* (name x !!! xs ..) xpr . xprs)
     126(define* (name x !!! xs ...) xpr . xprs)
     127(define* (name x !!! xs ....) xpr . xprs)
    127128--- macro ---
    128129syntactic sugar for, e.g.
    129 (define name (lambda* (x ... xs ..) xpr . xprs))
     130(define name (lambda* (x !!! xs ..) xpr . xprs))
    130131]|#
    131132(define-syntax define*
     
    137138    ((_ (name x !!! xs ....) xpr . xprs)
    138139     (define name (lambda* (x !!! xs ....) xpr . xprs)))
    139     ((_ (name x !!!) xpr . xprs)
    140      (define name (lambda* (x !!!) xpr . xprs)))
    141140    ))
    142141
     
    157156        "With no argument it returns the encapsulated list and with one argument,"
    158157        "an index, returns the list's value at that index."
     158        "Returns the list's length with negative index."
    159159        )
    160160      (lambda*
    161161        macro:
    162         (lambda* (x ... xs ..) xpr . xprs)
    163         (lambda* (x ... xs ...) xpr . xprs)
    164         (lambda* (x ... xs ....) xpr . xprs)
    165         (lambda* (x ...) xpr . xprs)
    166         "the first three evaluate to (lambda (x ... . xs) xpr . xprs)"
    167         "making xs callable and checking if xs is of length at most 1,"
     162        (lambda* (x !!! xs ..) xpr . xprs)
     163        (lambda* (x !!! xs ...) xpr . xprs)
     164        (lambda* (x !!! xs ....) xpr . xprs)
     165        "An alternative to (lambda (x ... . xs) xpr . xprs)."
     166        "Makes xs callable and checks if xs is of length at most 1,"
    168167        "arbitrary or at least1, respectively."
    169         "The last one evaluates to ordinary (lambda (x ...) xpr . xprs)"
    170168        )
    171169      (define
    172170        macro:
    173         (define* (name x ... xs ..) xpr . xprs)
    174         (define* (name x ... xs ...) xpr . xprs)
    175         (define* (name x ... xs ....) xpr . xprs)
    176         (define* (name x ...) xpr . xprs)
    177         (define name (lambda* (x ... xs ..) xpr . xprs))
     171        (define* (name x !!! xs ..) xpr . xprs)
     172        (define* (name x !!! xs ...) xpr . xprs)
     173        (define* (name x !!! xs ....) xpr . xprs)
     174        (define name (lambda* (x !!! xs ..) xpr . xprs))
    178175        "syntactic sugar for, e.g."
    179176        )
  • release/5/dotted-lambdas/trunk/tests/run.scm

    r39485 r39586  
    33(import simple-tests (chicken base) (chicken condition))
    44
    5 (define-checks
    6   (calls verbose? lst (callable '(0 1 2 3)) lst0 (callable '()))
     5(define-tester
     6  (calls? lst (callable '(0 1 2 3)) lst0 (callable '()))
    77  (condition-case (lst0 0) ((exn) #f))
    88  #f
     
    1111  (lst 3)
    1212  3
     13  (lst -1)
     14  4
    1315  (condition-case (lst 5) ((exn) #f))
    14   #f
    15   (condition-case (lst -1) ((exn) #f))
    1616  #f)
    1717
    18 (define-checks
    19   (lambdas verbose?)
     18(define-tester
     19  (lambdas?)
    2020  ((lambda* (xs ...) (list (xs 0) (xs 1) (xs 2))) 1 2 3)
    2121  '(1 2 3)
     
    3434  (condition-case ((lambda* (x y zs ....) (list x y zs)) 1 2) ((exn) #f))
    3535  #f
    36   ((lambda* (a b) (list a b)) 1 2)
    37   '(1 2)
    3836  ((lambda* (as ...) (as)) 1 2 3)
    3937  '(1 2 3)
     
    4947(define* (baz xs ..) (list (xs)))
    5048
    51 (define-checks
    52   (defines verbose?)
     49(define-tester
     50  (defines?)
    5351  (inc 5)
    5452  6
     
    6866  #f)
    6967
    70 (check-all DOTTED-LAMBDAS
    71   (calls)
    72   (lambdas)
    73   (defines)
     68(test-all DOTTED-LAMBDAS
     69  calls?
     70  lambdas?
     71  defines?
    7472  )
Note: See TracChangeset for help on using the changeset viewer.