Wow! Thanks so much. I'm enjoying PicoLisp a lot, by the way.

On Mon, Jul 23, 2018 at 3:56 PM, Alexander Burger <[email protected]> wrote:
> He Curtis,
>
>> The third tutorial, "Working with tables in PicoLisp", has the following
>> code to sort a table:
>>  ...
>> Still, it seems so complicated. Is there a simpler way of doing this?
>
> Indeed! I wonder why there is so much and complicated code. You can do it all
> out of the box.
>
> : (setq *People
>    (quote
>       (name John phone 123456 age 56)
>       (name Fred phone 654321 age 35)
>       (name Fred phone 236597 age 38)
>       (name Hank phone 078965 age 23) ) )
> -> ((name ...
>
> # Sort by the second element (the name)
> : (by cadr sort *People)
> -> ((name Fred phone 236597 age 38) (name Fred phone 654321 age 35)
>    (name Hank phone 78965 age 23) (name John phone 123456 age 56))
>
> # Sort by the 4th element (the phone nomber)
> : (by cadddr sort *People)
> -> ((name Hank phone 78965 age 23) (name John phone 123456 age 56)
>    (name Fred phone 236597 age 38) (name Fred phone 654321 age 35))
>
> : (by '((L) (get L 4)) sort *People)
> ->  ... # same
>
> # Sort by finding the element after 'name'
> : (by '((L) (cadr (memq 'name L))) sort *People)
> -> ((name Fred phone 236597 age 38) (name Fred phone 654321 age 35)
>    (name Hank phone 78965 age 23) (name John phone 123456 age 56))
>
> # Sort by finding the element after 'age'
> : (by '((L) (cadr (memq 'age L))) sort *People)
> -> ((name Hank phone 78965 age 23) (name Fred phone 654321 age 35)
>    (name Fred phone 236597 age 38) (name John phone 123456 age 56))
>
> —Alex
>
> --
> UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe

--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe

Reply via email to