Changeset 33846 in project


Ignore:
Timestamp:
02/11/17 14:15:54 (3 years ago)
Author:
juergen
Message:

holes 1.4 with curry @> and @< and ->proc renamed @@

Location:
release/4/holes
Files:
3 edited
5 copied

Legend:

Unmodified
Added
Removed
  • release/4/holes/tags/1.4/holes.scm

    r33732 r33846  
    3333
    3434#|[
    35 Besides the documentation procedure, this module exports only one macro,
    36 ->proc, and a sharp-read-macro, ##, which abbreviates the call of
    37 that macro.
     35Besides the documentation procedure, this module exports two curry
     36procedure, @> and @<, one macro, @@ with alias ->proc, and a
     37sharp-read-macro, ##, which abbreviates the call of that latter macro.
    3838
    3939The macro transforms expressions with zero or more holes into a
     
    4848]|#
    4949
    50 (module holes (->proc holes)
     50(module holes (holes @@ @> @< ->proc)
    5151  (import scheme
    52           (only chicken print set-sharp-read-syntax!))
     52          (only chicken error case-lambda print set-sharp-read-syntax!))
    5353  (import-for-syntax (only chicken receive))
    5454
    55 (define-syntax ->proc
     55;;; (@@ code)
     56;;; ---------
     57;;; returns a procedure with arguments the holes in code
     58(define-syntax @@
    5659  (er-macro-transformer
    5760    (lambda (form rename compare?)
     
    155158               ,code)))))))
    156159
     160;;; (->proc code)
     161;;; -------------
     162;;; alias to @@
     163;;; deprecated
     164(define-syntax ->proc
     165  (syntax-rules ()
     166    ((_ code)
     167     (@@ code))))
     168
    157169(set-sharp-read-syntax! #\#
    158   (lambda (port) `(->proc ,(read port))))
    159 
    160 (define (holes)
    161   (for-each print
    162     (list "->proc"
    163           "macro:"
    164           "(->proc code)"
    165           "  either:"
    166           "  extracts holes, i.e. a pair of bangs"
    167           "  possible enclosing a seqence of digits"
    168           "  from code, sorts them numerically while"
    169           "  removing duplicates, and uses"
    170           "  the resulting list as argument list of"
    171           "  a procedure with body code."
    172           "  or:"
    173           "  searches code for a colon and treats the symbols"
    174           "  to the left as argument-list of a procedure with"
    175           "  body the expressions to the right."
    176           "  Can be called with sharp-read-syntax ##"
    177           "  Note, that ##code is always a procedure!")))
     170  (lambda (port) `(@@ ,(read port))))
     171
     172;;; (@> proc . head)
     173;;; ----------------
     174;;; returns a curried procedure with arguments tail, which applies proc to
     175;;; (append head tail)
     176(define (@> proc . head)
     177  (lambda tail
     178    (apply proc (append head tail))))
     179
     180
     181;;; (@< proc . tail)
     182;;; ----------------
     183;;; returns a curried procedure with arguments head, which applies proc to
     184;;; (append head tail)
     185(define (@< proc . tail)
     186  (lambda head
     187    (apply proc (append head tail))))
     188
     189;;; (holes [sym])
     190;;; -------------
     191;;; documentation procderue
     192(define holes
     193  (let ((als '(
     194    (holes
     195      procedure:
     196      (holes sym ..)
     197      "documentation procedure")
     198    (@@
     199      macro:
     200      (@@ code)
     201      "either:"
     202      "extracts holes, i.e. a pair of bangs"
     203      "possible enclosing a seqence of digits"
     204      "from code, sorts them numerically while"
     205      "removing duplicates, and uses"
     206      "the resulting list as argument list of"
     207      "a procedure with body code."
     208      "or:"
     209      "searches code for a colon and treats the symbols"
     210      "to the left as argument-list of a procedure with"
     211      "body the expressions to the right."
     212      ""
     213      "Can be called with sharp-read-syntax ##"
     214      "Note, that (@@ code), and hence ##code,"
     215      "is always a procedure!")
     216    (@>
     217      procedure:
     218      (@> proc . head)
     219      "returns a curried procedure with arguments tail"
     220      "which applies proc to (append head tail)")
     221    (@<
     222      procedure:
     223      (@< proc . tail)
     224      "returns a curried procedure with arguments head"
     225      "which applies proc to (append head tail)")
     226    (->proc
     227      macro:
     228      (->proc code)
     229      "alias to @@"
     230      "deprecated")
     231    )))
     232    (case-lambda
     233      (()
     234       (map car als))
     235      ((sym)
     236       (let ((pair (assq sym als)))
     237         (if pair
     238           (for-each print (cdr pair))
     239           (error "Not in list"
     240                  sym
     241                  (map car als))))))))
    178242
    179243) ; module holes
  • release/4/holes/tags/1.4/holes.setup

    r33732 r33846  
    77 'holes
    88 '("holes.so" "holes.import.so")
    9  '((version "1.3")))
     9 '((version "1.4")))
    1010
  • release/4/holes/tags/1.4/tests/run.scm

    r33732 r33846  
    33
    44
    5 (pe '(->proc (+ !1! 5)))
    6 (pe '(->proc '(1 . 2)))
    7 (pe '(->proc (+ 5 (* !! 2))))
    8 (pe '(->proc (!! 1 2 3)))
    9 (pe '(->proc '(1 2 #(3 4 !! 6))))
     5(pe '(@@ (+ !1! 5)))
     6(pe '(@@ '(1 . 2)))
     7(pe '(@@ (+ 5 (* !! 2))))
     8(pe '(@@ (!! 1 2 3)))
     9(pe '(@@ '(1 2 #(3 4 !! 6))))
    1010
    1111(print "\n\n")
     
    1313(define-test (holes?)
    1414  (check
     15    (equal? ((@> map add1) '(0 1 2)) '(1 2 3))
     16    (= ((@< list-ref 2) '(0 1 2 3)) 2)
     17    (= ((@@ 5)) 5)
     18    (= (##5) 5)
    1519    (procedure? ##(vector 1 !!))
    1620    (procedure? ##(lambda (x) (- x !!)))
    1721    (= ((##(lambda (x) (- x !!)) 2) 3) 1)
    18     (= (##5) 5)
    1922    (equal? (call-with-values
    2023              ##(values 1 2 3)
  • release/4/holes/trunk/holes.scm

    r33732 r33846  
    3333
    3434#|[
    35 Besides the documentation procedure, this module exports only one macro,
    36 ->proc, and a sharp-read-macro, ##, which abbreviates the call of
    37 that macro.
     35Besides the documentation procedure, this module exports two curry
     36procedure, @> and @<, one macro, @@ with alias ->proc, and a
     37sharp-read-macro, ##, which abbreviates the call of that latter macro.
    3838
    3939The macro transforms expressions with zero or more holes into a
     
    4848]|#
    4949
    50 (module holes (->proc holes)
     50(module holes (holes @@ @> @< ->proc)
    5151  (import scheme
    52           (only chicken print set-sharp-read-syntax!))
     52          (only chicken error case-lambda print set-sharp-read-syntax!))
    5353  (import-for-syntax (only chicken receive))
    5454
    55 (define-syntax ->proc
     55;;; (@@ code)
     56;;; ---------
     57;;; returns a procedure with arguments the holes in code
     58(define-syntax @@
    5659  (er-macro-transformer
    5760    (lambda (form rename compare?)
     
    155158               ,code)))))))
    156159
     160;;; (->proc code)
     161;;; -------------
     162;;; alias to @@
     163;;; deprecated
     164(define-syntax ->proc
     165  (syntax-rules ()
     166    ((_ code)
     167     (@@ code))))
     168
    157169(set-sharp-read-syntax! #\#
    158   (lambda (port) `(->proc ,(read port))))
    159 
    160 (define (holes)
    161   (for-each print
    162     (list "->proc"
    163           "macro:"
    164           "(->proc code)"
    165           "  either:"
    166           "  extracts holes, i.e. a pair of bangs"
    167           "  possible enclosing a seqence of digits"
    168           "  from code, sorts them numerically while"
    169           "  removing duplicates, and uses"
    170           "  the resulting list as argument list of"
    171           "  a procedure with body code."
    172           "  or:"
    173           "  searches code for a colon and treats the symbols"
    174           "  to the left as argument-list of a procedure with"
    175           "  body the expressions to the right."
    176           "  Can be called with sharp-read-syntax ##"
    177           "  Note, that ##code is always a procedure!")))
     170  (lambda (port) `(@@ ,(read port))))
     171
     172;;; (@> proc . head)
     173;;; ----------------
     174;;; returns a curried procedure with arguments tail, which applies proc to
     175;;; (append head tail)
     176(define (@> proc . head)
     177  (lambda tail
     178    (apply proc (append head tail))))
     179
     180
     181;;; (@< proc . tail)
     182;;; ----------------
     183;;; returns a curried procedure with arguments head, which applies proc to
     184;;; (append head tail)
     185(define (@< proc . tail)
     186  (lambda head
     187    (apply proc (append head tail))))
     188
     189;;; (holes [sym])
     190;;; -------------
     191;;; documentation procderue
     192(define holes
     193  (let ((als '(
     194    (holes
     195      procedure:
     196      (holes sym ..)
     197      "documentation procedure")
     198    (@@
     199      macro:
     200      (@@ code)
     201      "either:"
     202      "extracts holes, i.e. a pair of bangs"
     203      "possible enclosing a seqence of digits"
     204      "from code, sorts them numerically while"
     205      "removing duplicates, and uses"
     206      "the resulting list as argument list of"
     207      "a procedure with body code."
     208      "or:"
     209      "searches code for a colon and treats the symbols"
     210      "to the left as argument-list of a procedure with"
     211      "body the expressions to the right."
     212      ""
     213      "Can be called with sharp-read-syntax ##"
     214      "Note, that (@@ code), and hence ##code,"
     215      "is always a procedure!")
     216    (@>
     217      procedure:
     218      (@> proc . head)
     219      "returns a curried procedure with arguments tail"
     220      "which applies proc to (append head tail)")
     221    (@<
     222      procedure:
     223      (@< proc . tail)
     224      "returns a curried procedure with arguments head"
     225      "which applies proc to (append head tail)")
     226    (->proc
     227      macro:
     228      (->proc code)
     229      "alias to @@"
     230      "deprecated")
     231    )))
     232    (case-lambda
     233      (()
     234       (map car als))
     235      ((sym)
     236       (let ((pair (assq sym als)))
     237         (if pair
     238           (for-each print (cdr pair))
     239           (error "Not in list"
     240                  sym
     241                  (map car als))))))))
    178242
    179243) ; module holes
  • release/4/holes/trunk/holes.setup

    r33732 r33846  
    77 'holes
    88 '("holes.so" "holes.import.so")
    9  '((version "1.3")))
     9 '((version "1.4")))
    1010
  • release/4/holes/trunk/tests/run.scm

    r33732 r33846  
    33
    44
    5 (pe '(->proc (+ !1! 5)))
    6 (pe '(->proc '(1 . 2)))
    7 (pe '(->proc (+ 5 (* !! 2))))
    8 (pe '(->proc (!! 1 2 3)))
    9 (pe '(->proc '(1 2 #(3 4 !! 6))))
     5(pe '(@@ (+ !1! 5)))
     6(pe '(@@ '(1 . 2)))
     7(pe '(@@ (+ 5 (* !! 2))))
     8(pe '(@@ (!! 1 2 3)))
     9(pe '(@@ '(1 2 #(3 4 !! 6))))
    1010
    1111(print "\n\n")
     
    1313(define-test (holes?)
    1414  (check
     15    (equal? ((@> map add1) '(0 1 2)) '(1 2 3))
     16    (= ((@< list-ref 2) '(0 1 2 3)) 2)
     17    (= ((@@ 5)) 5)
     18    (= (##5) 5)
    1519    (procedure? ##(vector 1 !!))
    1620    (procedure? ##(lambda (x) (- x !!)))
    1721    (= ((##(lambda (x) (- x !!)) 2) 3) 1)
    18     (= (##5) 5)
    1922    (equal? (call-with-values
    2023              ##(values 1 2 3)
Note: See TracChangeset for help on using the changeset viewer.