From a2c312741b47c1bf5e98a12545e9ba5671120191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Wed, 5 Jul 2023 22:09:07 +0200 Subject: [PATCH] Duck util-proc. --- doc/d-utils.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++ doc/utils.md | 46 --------------------------------- src/Makefile | 7 ++--- src/gendoc.scm | 3 ++- src/util-proc.scm | 51 ++++++++++++++++++++++++++---------- 5 files changed, 109 insertions(+), 64 deletions(-) diff --git a/doc/d-utils.md b/doc/d-utils.md index 3ae3cd9..f58000d 100644 --- a/doc/d-utils.md +++ b/doc/d-utils.md @@ -274,3 +274,69 @@ most scheme implementations. Returns a list containing only elements matching given ```pred?``` predicate. + +## util-proc [module] + + (import util-proc) + +This module provides a few simple procedures for querying properties +of other procedures. + +### improper-list-info [procedure] + + (improper-list-info lst) + +Returns two values: the proper part of the list length and #t if +there is an improper list end + +### (procedure-arity=? n) [procedure] + + ((procedure-arity=? proc) + n) + +* ```n``` - integer representing the number of arguments +* ```proc``` - procedure to query + +Returns true if the procedure ```proc``` accepts exactly ```n``` +arguments. + +### (procedure-arity>=? n) [procedure] + + ((procedure-arity>=? proc) + n) + +* ```n``` - integer representing the number of arguments +* ```proc``` - procedure to query + +Returns true if the procedure ```proc``` accepts at least ```n``` +arguments. + +### (procedure-arity>? n) [procedure] + + ((procedure-arity>? proc) + n) + +* ```n``` - integer representing the number of arguments +* ```proc``` - procedure to query + +Returns true if the procedure ```proc``` accepts more than ```n``` +arguments. + +### procedure-num-args [procedure] + + (procedure-num-args proc) + +* ```proc``` - procedure to check + +Returns the number of mandatory arguments. + +### procedure-arg-names [procedure] + + (procedure-arg-names proc) + +* ```proc``` - procedure to check + +Returns the (possibly improper) list of arguments the procedure +```proc``` accepts. If it accepts arbitrary number of arguments, it is +signalled by simple symbol instead of pair at the last position. If it +accepts an exact number of arguments, it returns a proper list. diff --git a/doc/utils.md b/doc/utils.md index 7218edc..70b1abc 100644 --- a/doc/utils.md +++ b/doc/utils.md @@ -162,52 +162,6 @@ sent to the address stored within. Sends email using mail(1) command. The arguments ```#:to``` and ```#:subject``` are mandatory. Argument ```#:from``` is optional. -### Proc - - (import util-proc) - -This module provides a few simple procedures for querying properties -of other procedures. - - ((procedure-arity=? n) proc) - -* ```n``` - integer representing the number of arguments -* ```proc``` - procedure to query - -Returns true if the procedure ```proc``` accepts exactly ```n``` -arguments. - - ((procedure-arity>=? n) proc) - -* ```n``` - integer representing the number of arguments -* ```proc``` - procedure to query - -Returns true if the procedure ```proc``` accepts at least ```n``` -arguments. - - ((procedure-arity>? n) proc) - -* ```n``` - integer representing the number of arguments -* ```proc``` - procedure to query - -Returns true if the procedure ```proc``` accepts more than ```n``` -arguments. - - (procedure-num-args proc) - -* ```proc``` - procedure to check - -Returns the number of mandatory arguments. - - (procedure-arg-names proc) - -* ```proc``` - procedure to check - -Returns the (possibly improper) list of arguments the procedure -```proc``` accepts. If it accepts arbitrary number of arguments, it is -signalled by simple symbol instead of pair at the last position. If it -accepts an exact number of arguments, it returns a proper list. - ### Set (List) (import util-set-list) diff --git a/src/Makefile b/src/Makefile index abcf197..9635aed 100644 --- a/src/Makefile +++ b/src/Makefile @@ -60,11 +60,12 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \ util-time.import.scm util-csv.import.scm util-git.import.scm \ util-io.import.scm util-stdout.import.scm \ - util-parser.import.scm util-list.import.scm + util-parser.import.scm util-list.import.scm \ + util-proc.import.scm GENDOC-OBJS=gendoc.o duck-extract.o util-time.o util-csv.o util-io.o \ progress.o testing.o util-proc.o util-git.o util-io.o \ - util-stdout.o util-parser.o util-list.o + util-stdout.o util-parser.o util-list.o util-proc.o .PHONY: imports imports: $(HACKERBASE-DEPS) @@ -130,7 +131,7 @@ listing.import.scm: $(LISTING-SOURCES) UTIL-DICT-LIST-SOURCES=util-dict-list.scm testing.import.scm \ util-tag.import.scm util-proc.import.scm \ - util-set-list.import.scm + util-set-list.import.scm duck.import.scm util-dict-list.o: util-dict-list.import.scm util-dict-list.import.scm: $(UTIL-DICT-LIST-SOURCES) diff --git a/src/gendoc.scm b/src/gendoc.scm index ec1e79a..d18512f 100644 --- a/src/gendoc.scm +++ b/src/gendoc.scm @@ -26,4 +26,5 @@ util-io util-stdout util-parser - util-list) + util-list + util-proc) diff --git a/src/util-proc.scm b/src/util-proc.scm index 2129515..1e9d85c 100644 --- a/src/util-proc.scm +++ b/src/util-proc.scm @@ -25,8 +25,12 @@ (declare (unit util-proc)) -(module +(import duck) + +(module* util-proc + #:doc ("This module provides a few simple procedures for querying properties +of other procedures.") ( improper-list-info @@ -41,9 +45,9 @@ (import scheme (chicken base)) - ;; Returns two values: the proper part of the list length and #t if - ;; there is an improper list end - (define (improper-list-info lst) + (define/doc (improper-list-info lst) + ("Returns two values: the proper part of the list length and #t if +there is an improper list end") (let loop ((lst lst) (len 0)) (if (symbol? lst) @@ -59,31 +63,50 @@ (let-values (((len rest?) (improper-list-info (procedure-information proc)))) (values (sub1 len) rest?))) - ;; Returns true if given procedure arity is exactly n - (define ((procedure-arity=? n) proc) + (define/doc ((procedure-arity=? n) proc) + ("* ```n``` - integer representing the number of arguments +* ```proc``` - procedure to query + +Returns true if the procedure ```proc``` accepts exactly ```n``` +arguments.") (let-values (((args rest?) (procedure-arity-info proc))) (and (not rest?) (= args n)))) - ;; Returns true if given procedure arity is greater than or equal to n - (define ((procedure-arity>=? n) proc) + (define/doc ((procedure-arity>=? n) proc) + ("* ```n``` - integer representing the number of arguments +* ```proc``` - procedure to query + +Returns true if the procedure ```proc``` accepts at least ```n``` +arguments.") (let-values (((args rest?) (procedure-arity-info proc))) (or rest? (>= args n)))) - ;; Returns true if given procedure arity is greater than n - (define ((procedure-arity>? n) proc) + (define/doc ((procedure-arity>? n) proc) + ("* ```n``` - integer representing the number of arguments +* ```proc``` - procedure to query + +Returns true if the procedure ```proc``` accepts more than ```n``` +arguments.") (let-values (((args rest?) (procedure-arity-info proc))) (or rest? (> args n)))) - ;; Returns the number of mandatory arguments - (define (procedure-num-args proc) + (define/doc (procedure-num-args proc) + ("* ```proc``` - procedure to check + +Returns the number of mandatory arguments.") (let-values (((args rest?) (procedure-arity-info proc))) args)) - ;; Returns the formal argument names for given procedure - (define (procedure-arg-names proc) + (define/doc (procedure-arg-names proc) + ("* ```proc``` - procedure to check + +Returns the (possibly improper) list of arguments the procedure +```proc``` accepts. If it accepts arbitrary number of arguments, it is +signalled by simple symbol instead of pair at the last position. If it +accepts an exact number of arguments, it returns a proper list.") (cdr (procedure-information proc))) )