[Chicken-hackers] [PATCH] deprecate constant declaration, document pure
Attached is a patch that adds documentation for the pure declaration, which declares a toplevel identifier to name a procedure that is free of side effects (and thus calls to it may be eliminated). This declaration was previously named constant, which is now deprecated. cheers, felix commit 397219495718e3e0723e36ae86810d4601223c3a Author: felix fe...@call-with-current-continuation.org Date: Tue Sep 13 10:11:28 2011 +0200 - marked constant declaration as deprecated - documented pure declaration, which is a synonym for the deprecated constant declaration diff --git a/compiler.scm b/compiler.scm index 92529ce..fef3bb7 100644 --- a/compiler.scm +++ b/compiler.scm @@ -1467,7 +1467,8 @@ (warning invalid argument to `inline-limit' declaration spec) ) ) ) - ((constant pure) ;XXX pure is undocumented + ((constant ; DEPRECATED + pure) (let ((syms (cdr spec))) (if (every symbol? syms) (for-each diff --git a/manual/Declarations b/manual/Declarations index 74d4d5d..de40a09 100644 --- a/manual/Declarations +++ b/manual/Declarations @@ -61,14 +61,6 @@ Declares that the given identifiers are always bound to procedure values. Enables or disables syntax-checking of embedded C/C++ code fragments. Checking C syntax is the default. -=== constant - - [declaration specifier] (constant IDENTIFIER ...) - -Declares the procedures with the names {{IDENTIFIER ...}} as constant, that is, as not having any -side effects. This can help the compiler to remove non-side-effecting expressions. - - === enforce-argument-types [declaration-specifier] (enforce-argument-types IDENTIFIER ...) @@ -233,6 +225,16 @@ enables profiling decorations for all globally defined procedures. With this declaration, profiling can be enabled for selected procedures. +=== pure + + [declaration specifier] (pure IDENTIFIER ...) + +Declares the procedures with the names {{IDENTIFIER ...}} as +referentially transparent, that is, as not having any side +effects. This can help the compiler to remove non-side-effecting +expressions. + + === number-type === fixnum-arithmetic ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers
Re: [Chicken-hackers] [PATCH] deprecate constant declaration, document pure
On Tue, Sep 13, 2011 at 10:21:58AM +0200, Felix wrote: Attached is a patch that adds documentation for the pure declaration, which declares a toplevel identifier to name a procedure that is free of side effects (and thus calls to it may be eliminated). This declaration was previously named constant, which is now deprecated. Looks fine to me. Cheers, Peter -- http://sjamaan.ath.cx -- The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music. -- Donald Knuth ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers
Re: [Chicken-hackers] [PATCH] deprecate constant declaration, document pure
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 09/13/2011 09:34 AM, Peter Bex wrote: On Tue, Sep 13, 2011 at 10:21:58AM +0200, Felix wrote: Attached is a patch that adds documentation for the pure declaration, which declares a toplevel identifier to name a procedure that is free of side effects (and thus calls to it may be eliminated). This declaration was previously named constant, which is now deprecated. Looks fine to me. I concur! I now feel compelled to bother to declare this kind of thing in my own code... Cheers, Peter ABS - -- Alaric Snell-Pym http://www.snell-pym.org.uk/alaric/ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk5vFq4ACgkQRgz/WHNxCGp8qgCfeW9eWzism7KLEXFXE6qdQFPN r8EAn06y1+2oYTpynA/E/8S62/FrsFAy =buOd -END PGP SIGNATURE- ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers
Re: [Chicken-hackers] [PATCH] Add non-destructive version of alist-update!
Hi Felix, Felix fe...@call-with-current-continuation.org writes: Thanks, Moritz. Here a few suggestions: - alist-update copies more of the argument list than necessary, it only has to copy up to the first matching entry - an entry for types.db is missing thanks for the feedback, attached is an updated version of the patch. I hope I got the types.db entry right! By the way: I noticed that when an unknown comparison procedure is passed alist-update! it will also accept non-alists, e.g.: #;1 (alist-update! 123 123 '(x y z) =) ((123 . 123) x y z) Whereas for example the default (eqv?) gives: #;2 (alist-update! 123 123 '(x y z)) Error: (assv) bad argument type: x Not sure if this is really a problem. Moritz From fa0a758cf2bac89a5507c6aaf548527974e2ef1d Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp mor...@twoticketsplease.de Date: Tue, 13 Sep 2011 15:17:10 +0200 Subject: [PATCH] add alist-update, a non-destructive version of alist-update! alist-update only copies as much of the alist as needed (i.e. up until the matching pair) add documentation and a types.db entry for alist-update add tests for both alist-update and alist-update! --- data-structures.import.scm |1 + data-structures.scm | 13 + manual/Unit data-structures |7 --- tests/data-structures-tests.scm | 18 ++ tests/runtests.sh |3 +++ types.db|1 + 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/data-structures-tests.scm diff --git a/data-structures.import.scm b/data-structures.import.scm index 245c7c4..2fd71bf 100644 --- a/data-structures.import.scm +++ b/data-structures.import.scm @@ -29,6 +29,7 @@ '(-string alist-ref alist-update! + alist-update always?; DEPRECATED any? atom? diff --git a/data-structures.scm b/data-structures.scm index 7da3698..8d47f7f 100644 --- a/data-structures.scm +++ b/data-structures.scm @@ -231,6 +231,19 @@ EOF lst) (cons (cons x y) lst) ) ) ) +(define (alist-update k v lst #!optional (cmp eqv?)) + (let loop ((lst lst)) +(if (null? lst) +(list (cons k v)) +(let ((a (##sys#slot lst 0))) + (cond ((not (pair? a)) + (error 'alist-update bad argument type a)) +((cmp (##sys#slot a 0) k) + (cons (cons k v) (##sys#slot lst 1))) +(else + (cons (cons (##sys#slot a 0) (##sys#slot a 1)) + (loop (##sys#slot lst 1) + (define (alist-ref x lst #!optional (cmp eqv?) (default #f)) (let* ([aq (cond [(eq? eq? cmp) assq] [(eq? eqv? cmp) assv] diff --git a/manual/Unit data-structures b/manual/Unit data-structures index 6f3e8c1..5412ea4 100644 --- a/manual/Unit data-structures +++ b/manual/Unit data-structures @@ -19,15 +19,16 @@ Looks up {{KEY}} in {{ALIST}} using {{TEST}} as the comparison function (or {{eq no test was given) and returns the cdr of the found pair, or {{DEFAULT}} (which defaults to {{#f}}). - alist-update! + alist-update +procedure(alist-update KEY VALUE ALIST [TEST])/procedure procedure(alist-update! KEY VALUE ALIST [TEST])/procedure If the list {{ALIST}} contains a pair of the form {{(KEY . X)}}, then this procedure replaces {{X}} with {{VALUE}} and returns {{ALIST}}. If {{ALIST}} contains no such item, then -{{alist-update!}} returns {{((KEY . VALUE) . ALIST)}}. The optional argument +{{alist-update}} returns {{((KEY . VALUE) . ALIST)}}. The optional argument {{TEST}} specifies the comparison procedure to search a matching pair in {{ALIST}} -and defaults to {{eqv?}}. +and defaults to {{eqv?}}. {{alist-update!}} is the destructive version of {{alist-update}}. atom? diff --git a/tests/data-structures-tests.scm b/tests/data-structures-tests.scm new file mode 100644 index 000..df4b559 --- /dev/null +++ b/tests/data-structures-tests.scm @@ -0,0 +1,18 @@ + data-structures-tests.scm + + +(use data-structures) + +(let ((alist '((foo . 123) (bar . baz + (alist-update! 'foo 999 alist) + (assert (= (alist-ref 'foo alist) 999)) + (alist-update! 'qux 'nope alist) + (assert (not (alist-ref 'qux alist))) + (assert (eq? 'yep (alist-ref 'qux (alist-update! 'qux 'yep alist + (assert (eq? 'ok (alist-ref bar (alist-update! bar 'ok alist equal?) equal? + +(let ((alist '((foo . 123) (bar . baz + (alist-update 'foo 999 alist) + (assert (= (alist-ref 'foo alist) 123)) + (assert (eq? 'yep (alist-ref 'qux (alist-update 'qux 'yep alist + (assert (eq? 'ok (alist-ref bar (alist-update bar 'ok alist equal?) equal? \ No newline at end of file diff --git a/tests/runtests.sh b/tests/runtests.sh index 4a24457..f0c19ce 100644 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -294,6 +294,9 @@ echo srfi-18 tests ... $interpret -s simple-thread-test.scm $interpret -s mutex-test.scm +echo
Re: [Chicken-hackers] [PATCH] sequence type corrections and enhancements
On Sun, Sep 11, 2011 at 12:26:45AM +0200, Felix wrote: Hello! The attached patch implements a correction of the available sequence type specifiers. Currently (list T) and (vector T) designate lists or vectors with an unknown number of elements of the given type. This is suboptimal, because fixed-length lists/vectors (with possibly different element types) can not be handled by the flow analysis. I'm trying to get some basic understanding of how the scrutinizer works, but I can't get it to output the debugging info. I run csc on a test program with -:D but that doesn't seem to trigger the output (though AFAIK that should set fudge factor 13), and I also used DEBUGBUILD=1 while building Chicken. So (list T) and (vector T) have been renamed to (list-of T) and (vector-of T) (which is compatible to the type-syntax of some other obscure Scheme implementation). (list T ...)/(vector T ...) now specify lists/vectors of fixed length with elements of the given types. Here's an idea: Wouldn't it be useful to also have a way to encode the length of the list, when it is known? For example, when using MAP, if you know the length of the input list you also know the length of the output list. Then later, when LENGTH is called, you can just return the known length of that list instead of walking it. The scrutinizer can also give a warning for other procedures that require a list of at least n items when passed a list of a different length. I don't know if there are enough other such procedures to make this really a big performance boost, though. Cheers, Peter -- http://sjamaan.ath.cx -- The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music. -- Donald Knuth ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers
Re: [Chicken-hackers] [PATCH] sequence type corrections and enhancements
On Sun, Sep 11, 2011 at 12:26:45AM +0200, Felix wrote: The attached patch implements a correction of the available sequence type specifiers. This is quite a big patch, but I can see that the changes to types.db and the tests are mostly about mechanical changes. I don't quite grok the scrutinizer code yet, but from what I understand the patch is good. Currently (list T) and (vector T) designate lists or vectors with an unknown number of elements of the given type. This is suboptimal, because fixed-length lists/vectors (with possibly different element types) can not be handled by the flow analysis. So (list T) and (vector T) have been renamed to (list-of T) and (vector-of T) (which is compatible to the type-syntax of some other obscure Scheme implementation). (list T ...)/(vector T ...) now specify lists/vectors of fixed length with elements of the given types. I think you overlooked these entries: - reverse: argument and result - member, assv, assoc: specialization types Also, member has a (forall a) in its declaration but doesn't use it, which looks wrong to me. Further, set-groups! from POSIX is declared to accept a generic list. This could probably be improved to (list-of (or fixnum number)), I think. Cheers, Peter -- http://sjamaan.ath.cx -- The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music. -- Donald Knuth ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers
Re: [Chicken-hackers] [PATCH] sequence type corrections and enhancements
I'm trying to get some basic understanding of how the scrutinizer works, but I can't get it to output the debugging info. I run csc on a test program with -:D but that doesn't seem to trigger the output (though AFAIK that should set fudge factor 13), and I also used DEBUGBUILD=1 while building Chicken. If you pass -:d directly to the chicken program, does that produce output? So (list T) and (vector T) have been renamed to (list-of T) and (vector-of T) (which is compatible to the type-syntax of some other obscure Scheme implementation). (list T ...)/(vector T ...) now specify lists/vectors of fixed length with elements of the given types. Here's an idea: Wouldn't it be useful to also have a way to encode the length of the list, when it is known? For example, when using MAP, if you know the length of the input list you also know the length of the output list. Then later, when LENGTH is called, you can just return the known length of that list instead of walking it. The scrutinizer can also give a warning for other procedures that require a list of at least n items when passed a list of a different length. I don't know if there are enough other such procedures to make this really a big performance boost, though. I'm afraid the complexity this requires exceeds the gain. Compile-time range checking is nice, but would only catch the trivial cases. cheers, felix ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers
[Chicken-hackers] [PATCH] C_TARGET_INCLUDE_HOME fix for cygwin
Hi, Attached is a patch to fix C_TARGET_INCLUDE_HOME for cygwin. Best wishes. Mario -- http://parenteses.org/mario From e6211ff140bfd8d3bebc25458d94b9e51e9e7424 Mon Sep 17 00:00:00 2001 From: Mario Domenech Goulart mario.goul...@gmail.com Date: Tue, 13 Sep 2011 20:27:52 -0300 Subject: [PATCH] C_TARGET_INCLUDE_HOME fix for cygwin --- Makefile.cygwin |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Makefile.cygwin b/Makefile.cygwin index 6f8d09f..f56bc29 100644 --- a/Makefile.cygwin +++ b/Makefile.cygwin @@ -226,7 +226,7 @@ chicken-defaults.h: echo # define C_TARGET_SHARE_HOME \$(TARGET_PREFIX)/share\ $@ echo #endif $@ echo #ifndef C_TARGET_INCLUDE_HOME $@ - echo # define C_TARGET_INCLUDE_HOME \$(TARGET_PREFIX)/include\ $@ + echo # define C_TARGET_INCLUDE_HOME \$(TARGET_PREFIX)/include/chicken\ $@ echo #endif $@ echo #ifndef C_TARGET_STATIC_LIB_HOME $@ echo # define C_TARGET_STATIC_LIB_HOME \$(TARGET_PREFIX)/lib\ $@ -- 1.6.6.1 ___ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers