Re: [Chicken-users] json-abnf fails to parse booleans
Hello, Thank you for your bug report, and for your efforts to harmonize the different JSON implementations. I have made the changes you suggest, except for the following: - due to a limitation in abnf/lexgen-derived parsers, #f cannot be a value returned by a parser. So the JSON true and false values are represented by '(#t) and '(#f). - I prefer to use the Chicken module system to handle namespace issues, so that instead of renaming the parser procedure, I would import it as (import (prefix json-abnf: json-abnf)). So I have not changed the name of the procedure exported by json-abnf. I have implemented the rest of your suggestions, added or modified the corresponding unit tests, and made a new release of json-abnf. Thanks again for your efforts. -Ivan ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] json-abnf fails to parse booleans
2011/11/28 Ivan Raikov ivan.g.rai...@gmail.com: - due to a limitation in abnf/lexgen-derived parsers, #f cannot be a value returned by a parser. So the JSON true and false values are represented by '(#t) and '(#f). Can you explain this? I tried my patch with some booleans and it seems to work: (pp (parse-json {\pi\:3.14,\f\:false,\t\:true,\n\:null,\l\:[1,2],\s\:\\})) ;; = ((pi . 3.14) (f . #f) (t . #t) (n . null) (l . #(1 2)) (s . )) (pp (parse-json [true])) ;; = #(#t) ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Why does the JSON egg map JSON structs to Scheme vectors instead of alists?
On Sun, Nov 27, 2011 at 06:39:52PM +0100, Moritz Heidkamp wrote: Vok Vojwo cev...@gmail.com writes: I think the Medea egg intends to do it the right way. But it seems to be buggy. And it has a voracious appetite It does indeed :-) Medea fails to parse the data: (use medea) (read-json json) ;; = #f Thanks for the hint. I managed to bisect it down to a Unicode character in one of the strings (’). Looking at medea's test suite I found this: ;; (test-read '#(Дҫ) [\Дҫ\]) ; FIXME genturfahi needs utf8 support for that to work So thanks for the reminder, I should mention this limitation in medea's documentation. Alan, would it be possible to make genturfahi UTF-8 aware? Yes. I will accomplish it over the hackathon weekend. My first attempt didn't go well, though it was because I was having trouble getting basic UTF-like things working in Chicken at all. I actually have some of the required support ready to be checked in here in my local repository. -Alan -- .i ma'a lo bradi cu penmi gi'e du ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Correct behavior of SRFI-1 any
I'm writing an implementation of SRFI-1 in Javascript (just for fun) and I have a question about SRFI-1's any procedure. In the docs it says that (any) does not return a simple boolean (#t or #f), but a general value, however it also says that any must be called with a procedure taking n arguments and returning a boolean result. I've been testing my implementation against Chicken for correctness and here's what I get on Chicken: #;2 (any (lambda (x) (if (even? x) x)) '(1 2 3)) #;3 (any (lambda (x) (even? x)) '(1 2 3)) #t #;4 (any even? '(1 3 5)) #f For #3 and #4 any correctly returns #t and #f respectively. However for #2 shouldn't any return 2 instead of, what I'm assuming is, (void)? What is the correct behavior here? From SRFI-1: any pred clist1 clist2 ... - value Applies the predicate across the lists, returning true if the predicate returns true on any application. If there are n list arguments clist1 ... clistn, then *pred must be a procedure taking n arguments and returning a boolean result*. any applies pred to the first elements of the clisti parameters. If this application returns a true value, any immediately returns that value. Otherwise, it iterates, applying pred to the second elements of the clisti parameters, then the third, and so forth. The iteration stops when a true value is produced or one of the lists runs out of values; in the latter case, any returns #f. The application of pred to the last element of the lists is a tail call. Note the difference between find and any -- find returns the element that satisfied the predicate; *any returns the true value that the predicate produced*. *Like every, any's name does not end with a question mark -- this is to indicate that it does not return a simple boolean (#t or #f), but a general value.* (any integer? '(a 3 b 2.7)) = #t (any integer? '(a 3.1 b 2.7)) = #f (any '(3 1 4 1 5) '(2 7 1 8 2)) = #t -- Nick Zarczynski Rent a Geek IT Services http://rentageekit.com Blog 4 http://nickzarr.com ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Correct behavior of SRFI-1 any
On Nov 28, 2011, at 9:01 PM, Nick Zarr wrote: I've been testing my implementation against Chicken for correctness and here's what I get on Chicken: #;2 (any (lambda (x) (if (even? x) x)) '(1 2 3)) #;3 (any (lambda (x) (even? x)) '(1 2 3)) #t #;4 (any even? '(1 3 5)) #f For #3 and #4 any correctly returns #t and #f respectively. However for #2 shouldn't any return 2 instead of, what I'm assuming is, (void)? What is the correct behavior here? Nick, #;2 (any (lambda (x) (if (even? x) x)) '(1 2 3)) Change that to (any (lambda (x) (if (even? x) x #f)) '(1 2 3)) or more idiomatically (any (lambda (x) (and (even? x) x)) '(1 2 3)) Your if statement returns void in the false case (technically, an unspecified value; in Chicken, it's void). But the only false value in Scheme is #f. Therefore your predicate always returns a true value for the first value it hits, so it will return void for 1. It would have returned 2 if the first value were 2: #;7 (any (lambda (x) (if (even? x) x)) '(2 3)) 2 Replacing if with and is the way we usually handle that. Jim___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Correct behavior of SRFI-1 any
Nick Zarr scripsit: I'm writing an implementation of SRFI-1 in Javascript (just for fun) and I have a question about SRFI-1's any procedure. In the docs it says that (any) does not return a simple boolean (#t or #f), but a general value, however it also says that any must be called with a procedure taking n arguments and returning a boolean result. The latter is clearly in error: the predicate argument to ANY, EVERY, and LIST-INDEX can return any value. The words and returning a boolean result should be removed from the specification. I've been testing my implementation against Chicken for correctness and here's what I get on Chicken: #;2 (any (lambda (x) (if (even? x) x)) '(1 2 3)) #;3 (any (lambda (x) (even? x)) '(1 2 3)) #t #;4 (any even? '(1 3 5)) #f For #3 and #4 any correctly returns #t and #f respectively. However for #2 shouldn't any return 2 instead of, what I'm assuming is, (void)? What is the correct behavior here? No, that's the difference between ANY and FIND. FIND returns the element which satisfies the predicate, whereas ANY returns what the predicate returns, in this case (void), because that is a true value. Chicken is doing the Right Thing. -- La mayyitan ma qadirun yatabaqqa sarmadiJohn Cowan Fa idha yaji' al-shudhdhadh fa-l-maut qad yantahi. co...@ccil.org --Abdullah al-Hazred, Al-`Azif http://www.ccil.org/~cowan ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users