Re: [Readable-discuss] noop patch - add type information
Am 17.11.2013 23:38, schrieb David A. Wheeler: On Sun, 17 Nov 2013 21:31:34 +0100, Jörg F. Wittenberger: In an attempt to better understand and document the source code I added type annotations (using the chicken's syntax and using chicken to verify it). I like this idea. In a few places this patch changes return values to intentionally return (values)... which is also okay by me. Unless anyone complains soon (Alan?), I plan to add it. It might be a bad idea to return no values instead of some undefined. Not sure, but I'd believe that notably chicken would do worse on returning no values instead of the fake value it returns for undefined returns. Also the patch introduces warnings that way. But nevertheless, I think the documentation it serves makes it worth. -- DreamFactory - Open Source REST JSON Services for HTML5 Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471iu=/4140/ostg.clktrk ___ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss
Re: [Readable-discuss] noop patch - add type information
Am 18.11.2013 10:38, schrieb Jörg F. Wittenberger: Am 17.11.2013 23:38, schrieb David A. Wheeler: On Sun, 17 Nov 2013 21:31:34 +0100, Jörg F. Wittenberger: In an attempt to better understand and document the source code I added type annotations (using the chicken's syntax and using chicken to verify it). I like this idea. In a few places this patch changes return values to intentionally return (values)... which is also okay by me. Unless anyone complains soon (Alan?), I plan to add it. It might be a bad idea to return no values instead of some undefined. Not sure, but I'd believe that notably chicken would do worse on returning no values instead of the fake value it returns for undefined returns. Also the patch introduces warnings that way. Attached a slightly better version of the add types patch. This one replaces (values) with a (no-values) syntax from the compatibility layer and has those procedures, which used to return no values or undefined values type-annotated as returning undefined. --- kernel.scm.orig 2013-11-17 21:23:38.0 +0100 +++ kernel.scm 2013-11-18 12:04:32.0 +0100 @@ -176,6 +176,19 @@ (define-module (readable kernel))) (else )) +; Chicken compatible type annotations. Ignored on other platforms. +(cond-expand + (chicken + (define-type :reader-proc: (input-port - *)) + (define-type :reader-token: (pair symbol *)) + (define-type :reader-indent-token: (list string *)) + (define-syntax no-values (syntax-rules () ((_) (void + ) + (else + (define-syntax : (syntax-rules () ((_ . rest) #f))) + (define-syntax no-values (syntax-rules () ((_) (if #f #t + )) + ; Implementation specific extension to flush output on ports. (cond-expand (guile ; Don't use define-syntax, that doesn't work on all guiles @@ -237,7 +250,7 @@ (define (init-sweet) ; Default guile stack size is FAR too small (debug-set! stack 50) - (values)) + (no-values)) ; Guile was the original development environment, so the algorithm ; practically acts as if it is in Guile. @@ -310,7 +323,7 @@ (define (setup-primitive-load) (cond (primitive-load-replaced - (values)) + (no-values)) (else (module-set! (resolve-module '(guile)) 'primitive-load (lambda (filename) @@ -463,7 +476,7 @@ (begin body ... ; A do-nothing. -(define (init-sweet) (values)) +(define (init-sweet) (no-values)) ; We use my-* procedures so that the ; port automatically keeps track of source position. @@ -594,9 +607,11 @@ (define keyword-syntax (make-parameter #f)) ; Returns a true value (not necessarily #t) + (: char-line-ending? (* -- boolean)) (define (char-line-ending? char) (memv char line-ending-chars)) ; Create own version, in case underlying implementation omits some. + (: my-char-whitespace? (char -- boolean)) (define (my-char-whitespace? c) (or (char-whitespace? c) (memv c whitespace-chars))) @@ -605,16 +620,18 @@ ; guile use annoying (EOF won't be correctly detected) due to a guile bug ; (in guile before version 2.0.8, peek-char incorrectly ; *consumes* EOF instead of just peeking). + (: consume-end-of-line (input-port - *)) (define (consume-end-of-line port) (let ((c (my-peek-char port))) (cond ((eqv? c carriage-return) - (my-read-char port) + (my-read-char port) (if (eqv? (my-peek-char port) linefeed) (my-read-char port))) ((eqv? c linefeed) (my-read-char port) + (: consume-to-eol (input-port - *)) ; FIXME (define (consume-to-eol port) ; Consume every non-eol character in the current line. ; End on EOF or end-of-line char. @@ -625,6 +642,7 @@ (my-read-char port) (consume-to-eol port) + (: consume-to-whitespace (input-port - (or eof null))) (define (consume-to-whitespace port) ; Consume to whitespace (let ((c (my-peek-char port))) @@ -648,6 +666,7 @@ (display \n))) data) + (: my-read-delimited-list (:reader-proc: char input-port - *)) (define (my-read-delimited-list my-read stop-char port) ; Read the inside of a list until its matching stop-char, returning list. ; stop-char needs to be closing paren, closing bracket, or closing brace. @@ -690,7 +709,9 @@ ; Read preservation, replacement, and mode setting ; - + (: default-scheme-read :reader-proc:) (define default-scheme-read read) + (: replace-read :reader-proc:) (define replace-read replace-read-with) (define (restore-traditional-read) (replace-read-with default-scheme-read)) @@ -708,8 +729,9 @@ (define (enable-sweet) (replace-read sweet-read)) - (define current-read-mode #f) + (define current-read-mode #f) ;; OBSOLETE? + (: set-read-mode deprecated) ; not yet, just as a
Re: [Readable-discuss] noop patch - add type information
On Mon, 18 Nov 2013 12:09:43 +0100, Jörg F. Wittenberger joerg.wittenber...@softeyes.net wrote: Attached a slightly better version of the add types patch. This one replaces (values) with a (no-values) syntax from the compatibility layer and has those procedures, which used to return no values or undefined values type-annotated as returning undefined. Thanks! I had to tweak them, but we now use (no-values). Note: Yesterday I added annotations for some of the procedures you didn't annotate. --- David A. Wheeler -- Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311iu=/4140/ostg.clktrk ___ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss
Re: [Readable-discuss] noop patch - add type information
Jörg F. Wittenberger scripsit: IMHO there should be no undefined *value* as such. It should be just undefined what's being returned. If - for some reason - some fake value need to be there to satisfy some other condition, so be it. But Scheme would IMHO be better off along the default Racket way. See http://trac.sacrideo.us/wg/wiki/OneArmedIf for details on how different Schemes do it. There is a fairly strong consensus to return an undefined-value value, but no Scheme standard prescribes such an object. -- Evolutionary psychology is the theory John Cowan that men are nothing but horn-dogs, http://www.ccil.org/~cowan and that women only want them for their money. co...@ccil.org --Susan McCarthy (adapted) -- Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311iu=/4140/ostg.clktrk ___ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss
[Readable-discuss] noop patch - add type information
In an attempt to better understand and document the source code I added type annotations (using the chicken's syntax and using chicken to verify it). So far I'm only through to the read-related procedures. But it's so much, I solicit comments from those who know the code. At least it still compiles and works, even using chickens -strict-types mode (which, in between when there was one badly broken type declaration, did already result in non-working code --- supporting my understanding that chicken's -strict-types mode is not a noop.). --- kernel.scm.orig 2013-11-17 21:23:38.0 +0100 +++ kernel.scm 2013-11-17 21:23:52.0 +0100 @@ -176,6 +176,17 @@ (define-module (readable kernel))) (else )) +; Chicken compatible type annotations. Ignored on other platforms. +(cond-expand + (chicken + (define-type :reader-proc: (input-port - *)) + (define-type :reader-token: (pair symbol *)) + (define-type :reader-indent-token: (list string *)) + ) + (else + (define-syntax : (syntax-rules ((_ . rest) #f))) + )) + ; Implementation specific extension to flush output on ports. (cond-expand (guile ; Don't use define-syntax, that doesn't work on all guiles @@ -594,9 +605,11 @@ (define keyword-syntax (make-parameter #f)) ; Returns a true value (not necessarily #t) + (: char-line-ending? (* -- boolean)) (define (char-line-ending? char) (memv char line-ending-chars)) ; Create own version, in case underlying implementation omits some. + (: my-char-whitespace? (char -- boolean)) (define (my-char-whitespace? c) (or (char-whitespace? c) (memv c whitespace-chars))) @@ -605,16 +618,18 @@ ; guile use annoying (EOF won't be correctly detected) due to a guile bug ; (in guile before version 2.0.8, peek-char incorrectly ; *consumes* EOF instead of just peeking). + (: consume-end-of-line (input-port - *)) (define (consume-end-of-line port) (let ((c (my-peek-char port))) (cond ((eqv? c carriage-return) - (my-read-char port) + (my-read-char port) (if (eqv? (my-peek-char port) linefeed) (my-read-char port))) ((eqv? c linefeed) (my-read-char port) + (: consume-to-eol (input-port - *)) ; FIXME (define (consume-to-eol port) ; Consume every non-eol character in the current line. ; End on EOF or end-of-line char. @@ -625,6 +640,7 @@ (my-read-char port) (consume-to-eol port) + (: consume-to-whitespace (input-port - (or eof null))) (define (consume-to-whitespace port) ; Consume to whitespace (let ((c (my-peek-char port))) @@ -648,6 +664,7 @@ (display \n))) data) + (: my-read-delimited-list (:reader-proc: char input-port - *)) (define (my-read-delimited-list my-read stop-char port) ; Read the inside of a list until its matching stop-char, returning list. ; stop-char needs to be closing paren, closing bracket, or closing brace. @@ -690,7 +707,9 @@ ; Read preservation, replacement, and mode setting ; - + (: default-scheme-read :reader-proc:) (define default-scheme-read read) + (: replace-read :reader-proc:) (define replace-read replace-read-with) (define (restore-traditional-read) (replace-read-with default-scheme-read)) @@ -708,8 +727,9 @@ (define (enable-sweet) (replace-read sweet-read)) - (define current-read-mode #f) + (define current-read-mode #f) ;; OBSOLETE? + (: set-read-mode deprecated) ; not yet, just as a marker for the open questions (define (set-read-mode mode port) ; TODO: Should be per-port (cond @@ -764,17 +784,20 @@ #\ #\;) ; Could add #\# or #\| whitespace-chars)) + (: consume-whitespace (input-port -)) (define (consume-whitespace port) (let ((char (my-peek-char port))) (cond -((eof-object? char)) +((eof-object? char) (values)) ((eqv? char #\;) (consume-to-eol port) (consume-whitespace port)) ((my-char-whitespace? char) (my-read-char port) - (consume-whitespace port) + (consume-whitespace port)) + (else (values) + (: read-until-delim (input-port (list-of char) - (list-of char))) (define (read-until-delim port delims) ; Read characters until eof or a character in delims is seen. ; Do not consume the eof or delimiter. @@ -785,6 +808,7 @@ ((memv c delims) '()) (else (my-read-char port) (cons c (read-until-delim port delims)) + (: read-error (* - . *)) (define (read-error message) (display Error: (current-error-port)) (display message (current-error-port)) @@ -795,20 +819,30 @@ ; Return the number by reading from port, and prepending starting-lyst. ; Returns #f if it's not a number. + (: read-number (input-port (list-of char) - (or number
Re: [Readable-discuss] noop patch - add type information
David A. Wheeler scripsit: I like this idea. In a few places this patch changes return values to intentionally return (values)... which is also okay by me. For the record, I've never been a fan of returning zero values when you have nothing in particular to return. R6RS and R7RS authorize returning multiple values where the continuation ignores the values, but R5RS does not, and indeed SCM, SigScheme, Shoe, and Owl Lisp do not permit it: they throw errors to `(begin (values) 3)` and `(begin (values 1 2) 3)`, rather than returning 3 as other R5RS systems do. In my own code, I always return the value of `(if #f #f)`, which is typically a Scheme's undefined-value value. But I can live with it. -- Her he asked if O'Hare Doctor tidings sent from far John Cowan coast and she with grameful sigh him answered that http://ccil.org/~cowan O'Hare Doctor in heaven was. Sad was the man that word co...@ccil.org to hear that him so heavied in bowels ruthful. All she there told him, ruing death for friend so young,James Joyce, Ulysses algate sore unwilling God's rightwiseness to withsay. Oxen of the Sun -- DreamFactory - Open Source REST JSON Services for HTML5 Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471iu=/4140/ostg.clktrk ___ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss
Re: [Readable-discuss] noop patch - add type information
David A. Wheeler scripsit: I like this idea. In a few places this patch changes return values to intentionally return (values)... which is also okay by me. On Sun, 17 Nov 2013 20:33:16 -0500, John Cowan co...@mercury.ccil.org wrote: For the record, I've never been a fan of returning zero values when you have nothing in particular to return. R6RS and R7RS authorize returning multiple values where the continuation ignores the values, but R5RS does not, and indeed SCM, SigScheme, Shoe, and Owl Lisp do not permit it: they throw errors to `(begin (values) 3)` and `(begin (values 1 2) 3)`, rather than returning 3 as other R5RS systems do. Yec. That is just mistaken, erroneous, fallacious, ill-judged, and in a thousand other ways wrong. It may be standards-compliant, but still wrong. That is really awful, I would never have guessed that. Since the return value CAN'T matter, it SHOULD NOT matter!!! Thanks for letting us know - that would clearly impact portability. In my own code, I always return the value of `(if #f #f)`, which is typically a Scheme's undefined-value value. Yes, but if that gets back to the REPL it may do something funny. By definition that is undefined. But I can live with it. Yes, but I want to make this *more* portable not *less*. Maybe we should define our own no-value value, and use a macro to define it. Then it can be defined as (values) or (if #f #f) or whatever for the various Schemes. I prefer (values) since that cannot harm a REPL, but only when the Scheme won't blow up while using it. I wonder what a good name would be for no useful value. (void)? --- David A. Wheeler -- DreamFactory - Open Source REST JSON Services for HTML5 Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471iu=/4140/ostg.clktrk ___ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss
Re: [Readable-discuss] noop patch - add type information
David A. Wheeler scripsit: That is just mistaken, erroneous, fallacious, ill-judged, and in a thousand other ways wrong. It may be standards-compliant, but still wrong. That is really awful, I would never have guessed that. Since the return value CAN'T matter, it SHOULD NOT matter!!! Thanks for letting us know - that would clearly impact portability. I wouldn't worry too much about portability to SigScheme, Shoe, or Owl Lisp, frankly. SCM may be another matter; I'm not sure how widely used it is any more. Yes, but if that gets back to the REPL it may do something funny. By definition that is undefined. By definition it's an undefined *value*. In all the Schemes I have, it returns either an undefined-value object (which the REPL suppresses the printing of) or some random object such as #t or #f. The exception is Racket, in which it is a syntax error: there is no guarantee that the default Racket language is Scheme conformant, though. But I can live with it. Yes, but I want to make this *more* portable not *less*. Maybe we should define our own no-value value, and use a macro to define it. Why a macro? It can be just a function (as it is in Chicken, named `void`) or even just a global variable. -- Business before pleasure, if not too bloomering long before. --Nicholas van Rijn John Cowan co...@ccil.org http://www.ccil.org/~cowan -- DreamFactory - Open Source REST JSON Services for HTML5 Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471iu=/4140/ostg.clktrk ___ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss