Re: Making json.l parse floating point

2019-03-30 Thread C K Kashyap
Looks like this PR  was
closed. Shouldn't we iterate and get this fixed. I am happy to update the
PR.

Regards,
Kashyap

On Sat, Mar 30, 2019 at 4:32 AM Alexander Burger 
wrote:

> On Sat, Mar 30, 2019 at 10:51:44AM +, Alexander Williams wrote:
> > The use of (++ Value) instead of (pop 'Value) may be an improvement, but
> it
> > breaks backward compatibility with older clients since the time you
> > implemented (++ Value), so I can't accept that in my libraries just
> yet.. at
> > least not until I'm certain I don't have any applications with older
> > PicoLisp clients deployed in the wild.
>
> Oops, right.
>
> But as the namespace system (04mar17) is newer than '++' (24nov16), it will
> also break on such old systems.
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: Making json.l parse floating point

2019-03-30 Thread Alexander Burger
On Sat, Mar 30, 2019 at 10:51:44AM +, Alexander Williams wrote:
> The use of (++ Value) instead of (pop 'Value) may be an improvement, but it
> breaks backward compatibility with older clients since the time you
> implemented (++ Value), so I can't accept that in my libraries just yet.. at
> least not until I'm certain I don't have any applications with older
> PicoLisp clients deployed in the wild.

Oops, right.

But as the namespace system (04mar17) is newer than '++' (24nov16), it will
also break on such old systems.

☺/ A!ex

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


Re: Making json.l parse floating point

2019-03-30 Thread Alexander Williams
The use of (++ Value) instead of (pop 'Value) may be an improvement, but 
it breaks backward compatibility with older clients since the time you 
implemented (++ Value), so I can't accept that in my libraries just yet.. 
at least not until I'm certain I don't have any applications with older 
PicoLisp clients deployed in the wild.


Thanks.


AW

On Thu, 28 Mar 2019, Alexander Burger wrote:


Hi Kashyap,


I made a tiny change to support floating point (to be used with scaling
that is). I wanted to get it reviewed to confirm if I am not missing
something.

I added a condition to  json-parse-unicode in json.l



If you mean this line


[*(and (= "." (car Value))) (pop 'Value)  (link R '. (pop
'Value)) ]*


I think it is fine, though I have not studied the whole JSon library.

A minor improvement could be to replace all calls like (pop 'Value) with
(++ Value) which is a tiny little bit smaller and faster, but that's only
cosmetics.


But what REALLY nags me is that this code is still around:

 (local MODULE_INFO *Msg err-throw)
 (local json-parse-file json-parse-string json-parse-unicode 
json-count-brackets)
 ...

This is WRONG!! It is a pity that this is still public and being propagated as
an example! Please don't use it!

The correct syntax is:

 (local) (MODULE_INFO *Msg err-throw)
 (local) (json-parse-file json-parse-string json-parse-unicode 
json-count-brackets)
 ...

'local' takes NO arguments. It must read the symbols from the input stream.
Otherwise the symbols ARE already read when 'local' runs and will possibly
be found in the wrong namespace.

☺/ A!ex

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


Re: Making json.l parse floating point

2019-03-30 Thread Alexander Williams

Hi,

I appreciate the desire to improve my code, but please open issues or make 
pull requests to me on GitHub, because I don't follow the PicoLisp mailing 
list closely: https://github.com/aw/picolisp-json


Thanks,


AW

On Wed, 27 Mar 2019, C K Kashyap wrote:


Hi,
I am trying to write a script to parse data from IEX (
https://iextrading.com/developer/docs/) - naturally, the stock quotes are
in floating point numbers.

I made a tiny change to support floating point (to be used with scaling
that is). I wanted to get it reviewed to confirm if I am not missing
something.

I added a condition to  json-parse-unicode in json.l


[de json-parse-unicode (Value)

 (pack

   (make

 (while Value

   (let R (pop 'Value)

 (cond

   [(= "\^" R) (link "\\\^") ] # ^ becomes \^

   [(and (= "\\" R) (= "u" (car Value))) (let U (cut 5 'Value)
(link (json-parse-unicode-special (pack (tail 4 U) ] # \u hex

   [(and (= "\\" R) (= "b" (car Value))) (pop 'Value) (link (char
(hex "08") ] # \b backspace

   [(and (= "\\" R) (= "f" (car Value))) (pop 'Value) (link (char
(hex "0C") ] # \f formfeed

   [*(and (= "." (car Value))) (pop 'Value)  (link R '. (pop
'Value)) ]*

   (T (link R)) ]



Regards,

Kashyap



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


Re: Making json.l parse floating point

2019-03-28 Thread C K Kashyap
Super  that works like a charm ... I'll create a PR :)

On Thu, Mar 28, 2019 at 7:56 AM Alexander Burger 
wrote:

> Hi Kashyap,
>
> > Regarding the (local) - I'll take a look if I can produce a Pull Request
> > with the fix. I wonder though if it has anything to do with the "problem
> > with namespace" mentioned under the "Usage" section of
> > https://github.com/aw/picolisp-json
>
> Yes, indeed. This must be one reason. With PicoLisp version 17.3.4 (the
> corresponding entry in doc/ChangeLog is "04mar17, Namespace chaining
> instead of
> merging") the namespace system was completely rewritten. The former
> experimental
> way of using namespaces turned out impractical, but the current one,
> chaining
> namespaces into a search order (analog to Forth "vocabularies"), is very
> useful.
> I use it a lot in my projects.
>
>
> Concerning json.l, one critical point may be that this lib seems to be
> intended
> also for pil32 and thus should load also without namespace support.
>
> For that I would recommend the following solution:
>
>(unless (== 64 64) (from ""))
>
>(symbols 'json 'pico)
>
>(local) (MODULE_INFO *Msg err-throw json-parse-file json-parse-string
>json-parse-unicode json-count-brackets json-array-check
> json-object-check
>json-object-check-separator link-generic link-array link-object
>link-object-value iterate-object iterate-list make-null make-boolean
>make-json-number make-json-string make-json-array make-generic
> make-object
>make-array)
>
>
>
> This skips (i.e. does not read) the whole symbols stuff. The list following
> (local) should contain all symbols private in this lib.
>
> Let me know if you need further input.
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: Making json.l parse floating point

2019-03-28 Thread Alexander Burger
Hi Kashyap,

> Regarding the (local) - I'll take a look if I can produce a Pull Request
> with the fix. I wonder though if it has anything to do with the "problem
> with namespace" mentioned under the "Usage" section of
> https://github.com/aw/picolisp-json

Yes, indeed. This must be one reason. With PicoLisp version 17.3.4 (the
corresponding entry in doc/ChangeLog is "04mar17, Namespace chaining instead of
merging") the namespace system was completely rewritten. The former experimental
way of using namespaces turned out impractical, but the current one, chaining
namespaces into a search order (analog to Forth "vocabularies"), is very useful.
I use it a lot in my projects.


Concerning json.l, one critical point may be that this lib seems to be intended
also for pil32 and thus should load also without namespace support.

For that I would recommend the following solution:

   (unless (== 64 64) (from ""))

   (symbols 'json 'pico)

   (local) (MODULE_INFO *Msg err-throw json-parse-file json-parse-string
   json-parse-unicode json-count-brackets json-array-check json-object-check
   json-object-check-separator link-generic link-array link-object
   link-object-value iterate-object iterate-list make-null make-boolean
   make-json-number make-json-string make-json-array make-generic make-object
   make-array)

   

This skips (i.e. does not read) the whole symbols stuff. The list following
(local) should contain all symbols private in this lib.

Let me know if you need further input.

☺/ A!ex

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


Re: Making json.l parse floating point

2019-03-28 Thread C K Kashyap
Thans Alex,
Regarding the (local) - I'll take a look if I can produce a Pull Request
with the fix. I wonder though if it has anything to do with the "problem
with namespace" mentioned under the "Usage" section of
https://github.com/aw/picolisp-json
Regards,
Kashyap



On Wed, Mar 27, 2019 at 11:51 PM Alexander Burger 
wrote:

> Hi Kashyap,
>
> > I made a tiny change to support floating point (to be used with scaling
> > that is). I wanted to get it reviewed to confirm if I am not missing
> > something.
> >
> > I added a condition to  json-parse-unicode in json.l
> > 
>
> If you mean this line
>
> > [*(and (= "." (car Value))) (pop 'Value)  (link R '. (pop
> > 'Value)) ]*
>
> I think it is fine, though I have not studied the whole JSon library.
>
> A minor improvement could be to replace all calls like (pop 'Value) with
> (++ Value) which is a tiny little bit smaller and faster, but that's only
> cosmetics.
>
>
> But what REALLY nags me is that this code is still around:
>
>   (local MODULE_INFO *Msg err-throw)
>   (local json-parse-file json-parse-string json-parse-unicode
> json-count-brackets)
>   ...
>
> This is WRONG!! It is a pity that this is still public and being
> propagated as
> an example! Please don't use it!
>
> The correct syntax is:
>
>   (local) (MODULE_INFO *Msg err-throw)
>   (local) (json-parse-file json-parse-string json-parse-unicode
> json-count-brackets)
>   ...
>
> 'local' takes NO arguments. It must read the symbols from the input stream.
> Otherwise the symbols ARE already read when 'local' runs and will possibly
> be found in the wrong namespace.
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Making json.l parse floating point

2019-03-27 Thread C K Kashyap
Hi,
I am trying to write a script to parse data from IEX (
https://iextrading.com/developer/docs/) - naturally, the stock quotes are
in floating point numbers.

I made a tiny change to support floating point (to be used with scaling
that is). I wanted to get it reviewed to confirm if I am not missing
something.

I added a condition to  json-parse-unicode in json.l


[de json-parse-unicode (Value)

  (pack

(make

  (while Value

(let R (pop 'Value)

  (cond

[(= "\^" R) (link "\\\^") ] # ^ becomes \^

[(and (= "\\" R) (= "u" (car Value))) (let U (cut 5 'Value)
(link (json-parse-unicode-special (pack (tail 4 U) ] # \u hex

[(and (= "\\" R) (= "b" (car Value))) (pop 'Value) (link (char
(hex "08") ] # \b backspace

[(and (= "\\" R) (= "f" (car Value))) (pop 'Value) (link (char
(hex "0C") ] # \f formfeed

[*(and (= "." (car Value))) (pop 'Value)  (link R '. (pop
'Value)) ]*

(T (link R)) ]



Regards,

Kashyap