Re: Bug in the JSON example in rosetta

2012-01-27 Thread José Romero
On Fri, 27 Jan 2012 13:58:50 +0100
Alexander Burger  wrote:

> On Fri, Jan 27, 2012 at 01:48:41PM +0100, Alexander Burger wrote:
> > Let me check more thoroughly.
> 
> How about that?
> 
>(de readJson ()
>   (case (read "_")
>  ...
>  (T
> (let X @
>(if (and (= "-" X) (format (peek)))
>   (- (read))
>   X ) ) ) ) )

That seems to work for all my test cases, thanks! Changed it in the
Rosetta page too.

-José
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Bug in the JSON example in rosetta

2012-01-27 Thread Alexander Burger
On Fri, Jan 27, 2012 at 01:48:41PM +0100, Alexander Burger wrote:
> Let me check more thoroughly.

How about that?

   (de readJson ()
  (case (read "_")
 ...
 (T
(let X @
   (if (and (= "-" X) (format (peek)))
  (- (read))
  X ) ) ) ) )
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Bug in the JSON example in rosetta

2012-01-27 Thread Alexander Burger
On Fri, Jan 27, 2012 at 01:45:12PM +0100, Alexander Burger wrote:
> We can simply add the "-" character to the atom-specifiers:

Sorry, forget that. These are only for symbols :(

Let me check more thoroughly.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Bug in the JSON example in rosetta

2012-01-27 Thread Alexander Burger
Hi José,

> Hmmm, it still doesn't work quite well, it chokes on negative

Oops again ;-)

> numbers, no idea how to fix that. :(

We can simply add the "-" character to the atom-specifiers:

   (de readJson ()
  (case (read "-_")
 ("{"
...

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Bug in the JSON example in rosetta

2012-01-27 Thread José Romero
Hmmm, it still doesn't work quite well, it chokes on negative
numbers, no idea how to fix that. :(

-José
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Bug in the JSON example in rosetta

2012-01-27 Thread José Romero
On Fri, 27 Jan 2012 12:55:29 +0100
Alexander Burger  wrote:

> Hi José,
> 
> > Looks like the example JSON functions choke on empty objects. I
> > made a
> 
> Oops. Right.
> 
> 
> > If it's OK I'll edit the task page, buggy code is ugly code!
> 
> Indeed. Please do so. Many thanks!

Done!

> 
> Cheers,
> - Alex

-José
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Bug in the JSON example in rosetta

2012-01-27 Thread Alexander Burger
Hi José,

> Looks like the example JSON functions choke on empty objects. I made a

Oops. Right.


> If it's OK I'll edit the task page, buggy code is ugly code!

Indeed. Please do so. Many thanks!

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Bug in the JSON example in rosetta

2012-01-27 Thread José Romero
Looks like the example JSON functions choke on empty objects. I made a
quick and dirty fix, but I'm not sure if I introduced extra bugs.

Diff follows:
##
--- json.orig.l 2012-01-27 07:34:25.0 -0300
+++ json.l  2012-01-27 07:46:32.0 -0300
@@ -6,7 +6,7 @@
(case (read "_")
   ("{"
  (make
-(for (X (readJson)  T  (readJson))
+(for (X (readJson) (not (= "}" X)) (readJson))
(checkJson ":" (readJson))
(link (cons X (readJson)))
(T (= "}" (setq X (readJson
@@ -14,7 +14,7 @@
   ("["
  (make
 (link T)  # Array marker
-(for (X (readJson)  T  (readJson))
+(for (X (readJson) (not (= "]" X)) (readJson))
(link X)
(T (= "]" (setq X (readJson
(checkJson "," X) ) ) )
@@ -22,7 +22,7 @@
  
 (de printJson (Item)  # For simplicity, without indentation
(cond
-  ((atom Item) (print Item))
+  ((atom Item) (if Item (print @) (prin "{}")))
   ((=T (car Item))
  (prin "[")
  (map
##

Tested with this:
: (pipe (prinl "{\"one\":[[],[1,2,3],[],[]],\"two\":{}}") (readJson)) 
-> (("one" T (T) (T 1 2 3) (T) (T)) ("two"))
: (printJson @)  
{"one": [[], [1, 2, 3], [], []], "two": {}}-> "}"

If it's OK I'll edit the task page, buggy code is ugly code!

Cheers,
-José
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe