Re: Review request for my JSON parsing implementation

2019-05-04 Thread C K Kashyap
Gentle reminder :)

On Fri, May 3, 2019 at 6:24 PM C K Kashyap  wrote:

> Hi all,
> I've made an attempt at JSON parsing. I did this since json.l at
> https://github.com/aw/picolisp-json does not handle floating numbers and
> that is something I need. I also took it as an opportunity to implement
> something bigger than a function and get some feedback about it - I used
> xml.l from picolisp source as a reference. What would be a good way to use
> this implementation to parse an json string - as opposed to input from a
> file.
> The code is located here -
> https://gist.github.com/ckkashyap/90602086fd4edafa75897a131f8cb88a - I
> also have it inline for the folks reluctant to click on the link :)
>
> (de parse-json ()
>  (skip)
>  (case (peek)
>   ("\"" (read-string))
>   ("{" (read-object))
>   ("[" (read-array))
>   ("t" (read-bare-word "true"))
>   ("f" (read-bare-word "false"))
>   ("n" (read-bare-word "null"))
>   (T (read-number
>
> (de expect (C)
>  (skip)
>  (let P (peek)
>(unless (= P C) (quit (pack "Expected <" C "> Got <" P ">")
>
> (de read-string ()
>  (expect "\"")
>  (char)
>  (let R
>   (make
> (while (not (= (peek) "\""))
>   (case (peek)
>("\\" (char) (link (char)))
>(T (link (char))
>   (char)
>   (pack R)))
>
> (de read-object () (read-collection read-key-value "{" "}"))
>
> (de read-array () (read-collection parse-json "[" "]"))
>
> (de read-bare-word (W)
>   (skip)
>   (let R
> (pack
>  (make (do (length W) (link (char)
>(prog (unless (= W R) (quit (pack "Expected " W ", got " R))) R)))
>
> (de read-number ()
>  (skip)
>  (let (
>Neg (if (= "-" (peek)) (char))
>_ (unless (isNum (peek)) (quit (pack "Not an number " (peek
>Flt NIL
>R (make (while (isNum (peek)) (if (= "." (peek)) (setq Flt T)) (link 
> (char)
>(round (pack (if Neg "-") R (unless Flt ".0")
>
> (de read-key-value ()
>  (let (
>k (read-string)
>_ (skip)
>_ (unless (= (char) ":") (exit ":" (peek)))
>v (parse-json))
>(list k v)))
>
> (de read-collection (F S E)
>  (expect S)
>  (char)
>  (let R
>(make
>  (while (not (= (peek) E))
>(link (F))
>(skip)
>(if (= (peek) ",") (prog (char) (skip) (if (= E (peek)) (quit 
> "Incorrect collection termination"))
>(char)
>R))
>
> (de isNum (n) (or (= "." n) (num? (format n
>
>
> Regards,
> Kashyap
>


Re: Behavior of sort

2019-05-04 Thread Lindsay Lawrence
Hi,

The sort is destructive of the input.
https://software-lab.de/doc/refS.html#sort
There are other functions that behave like this that you need to be aware
of when writing code.
You have to assign the result of the sort to another variable. Back to
itself is fine.

: (setq L '((3) (2) (1)))
-> ((3) (2) (1))
: (show L)
-> ((3) (2) (1))
: (setq L (sort L))
-> ((1) (2) (3))
: (show L)
-> ((1) (2) (3))
: (length L)
-> 3

Regards,
/Lindsay


On Sat, May 4, 2019 at 7:32 AM C K Kashyap  wrote:

> Hi all,
>
> I noticed an odd behavior of sort -
>
> (setq L '((2) (1) ))
>
>
> (println (length L)) # 2 as expected
>
> (sort L)
>
> (println (length L)) # why 1?
>
> (println L) # ((2))
>
> (bye)
>
> I would expect sort not to change the length. Am I missing something here
> or is sort broken?
> Regards,
> Kashyap
>


Re: Behavior of sort

2019-05-04 Thread Alexander Burger
Hi  Kashyap,

> I noticed an odd behavior of sort -
> (setq L '((2) (1) ))
> (sort L)

Note that 'sort' is a destructive function, it modifies the order of cells
in-place. Thus you must use the return value of 'sort', it may return another
cell than was passed to it.

In the above, the return value of 'sort' is ignored and thus lost.

Try either

: (length (sory L))

or

: (setq L (sort L))

☺/ A!ex

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


Behavior of sort

2019-05-04 Thread C K Kashyap
Hi all,

I noticed an odd behavior of sort -

(setq L '((2) (1) ))


(println (length L)) # 2 as expected

(sort L)

(println (length L)) # why 1?

(println L) # ((2))

(bye)

I would expect sort not to change the length. Am I missing something here
or is sort broken?
Regards,
Kashyap


Re: PicoLisp for 9-11 years' kids

2019-05-04 Thread Nehal
On Sun, Apr 28, 2019, 22:02 Joh-Tob Schäg  Hello Nehal,
> I've been doing some catching up on these videos.
> Mr. Alabhya Singh took quiet some time to explain this mathematical problem
> with the different approaches. I recall that in Germany when i was
> confronted with the same problem (apply + (range 1 N)), i was taught the
> Gauss approach
> (/ (* N (- N 1)) 2) directly.
> I was not consciously aware that
> (= (apply + (range 11 20)) (+ (apply + (range 1 10)) (* 10 10)))
> Nice trick.
>

Wonderful! Sessions shared here are first introduction to children of Lisp.
Currently these aren't the tricks they're doing. They're toying with Emacs
Scratch Buffer and simple symbolic expressions, trying to solve basic math
problems they see in day to day life.


That makes me recall an childhood incident where i came distressed from
> Kindergarden (I would have been between 5 and 7) when i realized i ran out
> of numbers to count.
>
> > My goal was to find the highest number i can count (looking back it's
> that
> > i run out of ways to say a number when i try to find the highest number i
> > can say):
> >
> > "one,two,tree,(annoyed pause) this goes till ten like that"
> > "eleven,twelve,(let's skip the small steps) next is twenty, then
> > thirty,forty,fifty, this goes to slow as well, i never finish that way,
> so
> > next is one hundred, so next is one thousand, ten thousand, one hundred
> > thousand, thousand thousand, (??) that sounds funny, so it must go on
> like
> > "thousand-thousand-thousand-..." and i now can say all the numbers"
> > It turned out it did not.
> > I found the next care taker and said "When i grow up i want make
> > thousand-thousand €"
> > He answered: "You mean like 2000€?"
> > I was shocked, 2000 was way smaller than i had in mind. "No like
> thousand,
> > ten-thousand, hundred thousand, thousand-thousand, ten-thousand-thousand"
> > He answered: "It is not thousand-thousand it is called a million"
> > It dawned on me that for some stupid reason people decided to call
> > thousand-thousand a million. Why would they want to do that it is way
> more
> > fun to say thousand-thousand-thousand than thousand-million?
> > By the time i was ready to ask the question the staff had left in a hurry





Re: Philosophical implications of teaching PicoLisp

2019-05-04 Thread Nehal
Thanks! I absolutely agree with you. What a depiction!

For us, Lisp is just a way of dealing data in a different way (syntax)
(with kids).

We'll also be holding lectures in tribal schools, it's going to a fun
activity for sure.

Also the kids are experiencing a different life, things in an integrated
way, math in art, art in Yoga asanas and Yoga in health/food.

What matters most, is happiness in learning and smiles on their faces.

Philosophy is living it in practicality.

Best,

-
NEHAL SINGHAL


On Sun, Apr 28, 2019, 19:14 Guido Stepken  Lisp is IMHO the only programming language (i speak 23) that puts
> "transformation" into foreground. Like - with us humans - it's unimportant
> who you "are" (in contrary to Object Oriented Languages), but only how we
> can transform each other, we do interfere with each other. The "inbetween"
> here plays a much more important role.
>
> "Learning" here means to change the way, neurons are connected. But it's
> still the same neuron, that enables us to solve new problems.
>
> Lisp is a good model to train that kind of thinking. Especially because in
> Lisp all "data is code code is data", which makes it extreamly easy not
> only to transform streams of data, but also transform steams of PicoLisp
> code as well.
>
> Have fun!
>
>
> Nehal  schrieb am So., 28. Apr. 2019, 15:20:
>
>> Dear Mr Alexander,
>>
>> Thanks for appreciating our efforts. This was all unplanned and
>> spontaneous. Infact we started to approach Lisp syntax with addition of
>> numbers from 1 to 100. So all kids were focused on numbers. Syntax was just
>> natural. The best thing was they enjoyed. And there was no fear of
>> programming. At the end of the session they were told that it was Lisp and
>> they can use Emacs Scratch Buffer for complex problems (they're already
>> using Org mode for drafting journals to send us mails).
>>
>> Your response was forwarded to parents of these children. It was highly
>> encouraging for them, seeing it coming from the creator of PicoLisp
>> himself.
>>
>> We'll keep the PicoLisp mailing list updated about further activities.
>>
>> Thanks
>> Nehal
>>
>> -
>>
>>
>> On Sat, Apr 27, 2019, 13:19 Alexander Burger >  wrote:
>>
>>> Dear Nehal,
>>>
>>> wow, thats impressing!
>>>
>>> > We have begun Lisp sessions here with kids. Many other kids joined.
>>> Without
>>> > explicitly telling about symbolic expressions they learned to traverse,
>>> > understand, solve lisp as mathematical puzzles.
>>> >
>>> > The session was taken by my mentor and co-worker, Alabhya Singh,
>>> Alumnus
>>> > IIT Kharagpur. Session is in Hindi but explanation on board can be
>>> easily
>>> > understood.
>>>
>>> These kids are amazing. I don't understand the words, but at one point I
>>> believe
>>> I even heard one kid speculating about infinity (well, not completely
>>> correct as
>>> (/ 10 10) would rather be 1 ;) ... at that age!
>>>
>>> Thanks for sharing this!!
>>> ☺/ A!ex
>>>
>>> --
>>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>>
>>