Re: What is the structure of a namespace

2021-04-17 Thread polifemo
ok, I see how your understanding of the underlying machine informs your
description of the tree structure. Being aware of lists as chains of cons
cells is still not intuitive for me. But I'll practice this view, since I
agree that your explanation is simpler and more deeply true.

Thanks for answering my questions! Having such clear an practically
immediate feedback makes it a joy to learn. I really am grateful.

On Sat, Apr 17, 2021 at 1:00 AM Alexander Burger 
wrote:

> On Fri, Apr 16, 2021 at 03:13:10PM -0500, polifemo wrote:
> > OH! I think I'm getting it!
> > for example, 'simul is '(\~ ("permute" ("shuffle" ("flood" ("G" NIL "gen"
> > ...
>
> > Something that confused me was that first symbol, '\~. It is not a valid
> > picolisp symbol!
>
> Correct. The special symbol \~ is new in pil21 and is only used as a marker
> (e.g. for error checks). It is not absolutely necessary, and did not exist
> in
> pil64.
>
>
> > But now that I see that a namespace is a cons of a "short
> > name namespace" and a "long name namespace", no symbol from either
> > namespace would be a reasonable root for the tree. So that arbitrary
> symbol
> > (\~) was chosen as the root. The cadr of 'simul are the short names, and
> > there is no caddr because there are no long names!
>
> Yes, though not the caddr but the cddr.
>
> In summary, a namespace consists of 2 cells:
>
>+--+-+ +---+---+
>|  \~  |  ---+>| short | long  |
>+--+-+ +---+---+
>
>
># Create empty namespace
>: (symbols 'ap 'pico)
>-> (pico)
>
>ap: ap
>-> (\~ NIL)
>
># Two cells
>
>+--+-+ +-+-+
>|  \~  |  ---+>|  /  |  /  |
>+--+-+ +-+-+
>
>
>ap: (local) (abc def ghijklmo pqrstuvw)
>
>ap: ap
>-> (\~ (abc NIL def) ghijklmo NIL pqrstuvw)
>
>ap: (car ap)
>-> \~
>
>ap: (cadr ap)
>-> (abc NIL def)
>
>$ap: (cddr ap)
>-> (ghijklmo NIL pqrstuvw)
>
>ap: (all 'ap)
>-> (abc def ghijklmo pqrstuvw)
>
>
> > One of the things that confused me was the way trees are represented. For
> > example, given this tree:
> >
> >  9
> >   8
> >7
> >   6
> > 5
> >  4
> >   3
> >2
> >   1
> >
> > I would have represented it as a nested list in this way:
> > (5 (2 (1 NIL NIL) (3 NIL (4 NIL NIL))) (7 (6 NIL NIL) (8 NIL (9 NIL
> NIL
> > That is, each new branch is inside its own list. Intuitive, but quite
> > wasteful, given that conses are memory in picolisp.
> >
> > But the picolisp way is:
> > (5 (2 (1) 3 NIL 4) 7 (6) 8 NIL 9)
> > this is hard for me to describe, but something like...
> > Every second element is the left branch of the element before it, and
> every
> > third element is the right branch of the element two places back.
>
> If we look at it this way, it is very simple:
>
>1. A tree node consists of either one or two cells. Leaf nodes need
> only one
>   cell.
>2. The first cell of a node has the payload (value) in its CAR, and the
>   subtrees (or NIL for leaf nodes) in its CDR.
>3. The second cell of a node holds the subtrees. The left one in the
> CAR and
>   the right one in the CDR.
>
> As leaf nodes need only one cell, and half of the nodes in a (balanced)
> tree are
> leaf nodes, such a tree occupies one and a half cells per node on the
> average.
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Unsubscribe

2021-04-17 Thread picolisp
Good bye picol...@dnmx.org :-(
You are now unsubscribed





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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
Hi Andras,

> Perfect, it works as expected on macOS.

Great! :)


> Finally I’ve got demoApp working: the culprit was the Safari browser.
> With Firefox it works!

I see. But then the Pil GUI must somehow be faulty too.

☺/ A!ex

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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Andras Pahi
Hi Alex,

Perfect, it works as expected on macOS.

Finally I’ve got demoApp working: the culprit was the Safari browser.
With Firefox it works!

Regards,
Andras Pahi

> On 2021. Apr 17., at 16:54, Alexander Burger  wrote:
> 
> On Sat, Apr 17, 2021 at 04:35:09PM +0200, Alexander Burger wrote:
>> OK, as ppoll() works fine on Linux (tests passed), I will keep it. This 
>> covers
>> most use cases, including Servers (Debian), PilBox (Android) and smaller 
>> stuff
>> (Raspi).
>> 
>> I put an #ifdef for other systems, using poll() and setting infinite timeout
>> above 24 days.
> 
> Done!! Released a new pil21.tgz :)
> 
> @Andras: Can you test on Mac again?
> 
> ☺/ A!ex
> 
> -- 
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
On Sat, Apr 17, 2021 at 04:35:09PM +0200, Alexander Burger wrote:
> OK, as ppoll() works fine on Linux (tests passed), I will keep it. This covers
> most use cases, including Servers (Debian), PilBox (Android) and smaller stuff
> (Raspi).
> 
> I put an #ifdef for other systems, using poll() and setting infinite timeout
> above 24 days.

Done!! Released a new pil21.tgz :)

@Andras: Can you test on Mac again?

☺/ A!ex

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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
On Sat, Apr 17, 2021 at 04:21:53PM +0200, Alexander Burger wrote:
> Hmm, I'm just testing the ppoll() version ... What to do?

OK, as ppoll() works fine on Linux (tests passed), I will keep it. This covers
most use cases, including Servers (Debian), PilBox (Android) and smaller stuff
(Raspi).

I put an #ifdef for other systems, using poll() and setting infinite timeout
above 24 days.


BTW, the problems on MacOS are not explained with this. Even more as we now know
that on Linux too the 64 bit timeout was truncated to 32 bits. And I think
nowhere (e.g. demo app) such a big timeout was passed so that the value wrapped
to negative. Something else must be seriously wrong.

☺/ A!ex

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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
Hi Andras,

> Just one remark, ppoll(2) is Linux-specific.

Oh, you are right! Too bad, it would have been a perfect replacement!

Good that you mention this, I did not pay attention.


> I know there is a perfectly portable API - Linux.

Yes :)

Hmm, I'm just testing the ppoll() version ... What to do?

☺/ A!ex

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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Andras Pahi
Hi Alex,

Just one remark, ppoll(2) is Linux-specific.
I know there is a perfectly portable API - Linux.

Regards,
Andras Pahi

> On 2021. Apr 17., at 15:53, Alexander Burger  wrote:
> 
> On Sat, Apr 17, 2021 at 02:15:42PM +0200, Alexander Burger wrote:
>> But as you saw in my last mail, the whole question is obsolete. I have to 
>> adjust
>> pil21 anyway.
> 
> I will use ppoll(2).
> 
> ☺/ A!ex
> 
> -- 
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
On Sat, Apr 17, 2021 at 02:15:42PM +0200, Alexander Burger wrote:
> But as you saw in my last mail, the whole question is obsolete. I have to 
> adjust
> pil21 anyway.

I will use ppoll(2).

☺/ A!ex

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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
Hi Andras,

> Maybe the definition of
> 
> #define __INT_MAX__ 2147483647
> 
> could be used ? It is predefined by the clang/gcc preprocessor.

Yeah, should be portable enough.

But as you saw in my last mail, the whole question is obsolete. I have to adjust
pil21 anyway.

☺/ A!ex

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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
Hi all,

On Sat, Apr 17, 2021 at 01:02:20PM +0200, Alexander Burger wrote:
> Hmm, too bad! I tested here with 64-bit integers with
> 
>#if (int)-1 == 0x
> 
> and it worked.

Uuhh! Sorry! I was completely off the track!

'int' is *always* 32 bit in size, on every system I've seen so far!
How could I forget and confuse this?

So the whole concept of 292MY in pil21 is nonsense. It never worked, because
poll() would never wake up for timeouts greater than 24.86 days.

It seems I never ran a test with such a timeout ;)


Anyway, I will fix pil21.

.. but this does not explain the MacOS problems ...

☺/ A!ex

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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Andras Pahi
Hi Alex,

Maybe the definition of

#define __INT_MAX__ 2147483647

could be used ? It is predefined by the clang/gcc preprocessor.

Regards,
Andras Pahi


> On 2021. Apr 17., at 13:02, Alexander Burger  wrote:
> Unfortunately, "#if sizeof(int) == 4" is not allowed in C, that's why I used 
> the
> above construct.
> 
> Does anybody have a better idea?
> 
> ☺/ A!ex
> 
> -- 
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
Hi Andras,

> According to the man page on macOS, poll returns:
> 
>  [EINVAL]   The nfds argument is greater than OPEN_MAX or the
> timeout argument is less than -1.

That explains it! So the specification of poll() is indeed different from the
Linux one.


> The check at compile time is not triggered on macOS, the following program
> prints “false”:
> 
> #include 
> #include 
> 
> int main(int argc, char*argv[])
> {
> #if (int)-1 == 0x
> printf("true");
> #else
> printf("false");
> #endif
>   return 0;

Hmm, too bad! I tested here with 64-bit integers with

   #if (int)-1 == 0x

and it worked.


Unfortunately, "#if sizeof(int) == 4" is not allowed in C, that's why I used the
above construct.

Does anybody have a better idea?

☺/ A!ex

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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Andras Pahi
Hi Alex,

Thank you for looking after this.

According to the man page on macOS, poll returns:

 [EINVAL]   The nfds argument is greater than OPEN_MAX or the
timeout argument is less than -1.

The check at compile time is not triggered on macOS, the following program
prints “false”:

#include 
#include 

int main(int argc, char*argv[])
{
#if (int)-1 == 0x
printf("true");
#else
printf("false");
#endif
  return 0;
}

Regards,
Andras Pahi

> On 2021. Apr 17., at 11:42, Alexander Burger  wrote:
> 
> Hi Andras,
> 
>> It is very strange indeed, on macOS Mojave gPoll() receives sometimes timeout
>> values which when casted to (int) results in values less than -1 (eg. -3).
>> This results in EINVAL errors in poll().
> 
> The EINVAL is indeed strange. According to the man page any negative timout
> should result in an infinite wait.
> 
> 
>> I have inserted a code snippet which truncates the timeout to -1 then I can 
>> get
>> to the login page in the demo app.
> 
> This should not be necessary since PicoLip 21.4.15. It checks at compile time
> whether it is a system with 32-bit int's, and then passes -1 for larger 
> numbers:
> 
>   #if (int)-1 == 0x
>  else if (timeout > 2147483647)  // Fit into 32 bits (max 24 days)
> timeout = -1;
>   #endif
> 
> I cannot test it here. Can you verify that it works?
> 
> 
>> Entering eg. “ben”, “ben” results in dropping the connection. The task 
>> handling the connection
>> is forked, as I see in the process list.
> 
> Hmm, so the above is not enough. There must be some other problem, perhaps 
> also
> related to 32-bit integers.
> 
> ☺/ A!ex
> 
> 
> -- 
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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



Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Alexander Burger
Hi Andras,

> It is very strange indeed, on macOS Mojave gPoll() receives sometimes timeout
> values which when casted to (int) results in values less than -1 (eg. -3).
> This results in EINVAL errors in poll().

The EINVAL is indeed strange. According to the man page any negative timout
should result in an infinite wait.


> I have inserted a code snippet which truncates the timeout to -1 then I can 
> get
> to the login page in the demo app.

This should not be necessary since PicoLip 21.4.15. It checks at compile time
whether it is a system with 32-bit int's, and then passes -1 for larger numbers:

   #if (int)-1 == 0x
  else if (timeout > 2147483647)  // Fit into 32 bits (max 24 days)
 timeout = -1;
   #endif

I cannot test it here. Can you verify that it works?


> Entering eg. “ben”, “ben” results in dropping the connection. The task 
> handling the connection
> is forked, as I see in the process list.

Hmm, so the above is not enough. There must be some other problem, perhaps also
related to 32-bit integers.

☺/ A!ex


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


Re: Why do waitFd and gPoll use 292MY for timeout?

2021-04-17 Thread Andras Pahi
Hi,

It is very strange indeed, on macOS Mojave gPoll() receives sometimes timeout
values which when casted to (int) results in values less than -1 (eg. -3).
This results in EINVAL errors in poll().

I have inserted a code snippet which truncates the timeout to -1 then I can get
to the login page in the demo app.

Entering eg. “ben”, “ben” results in dropping the connection. The task handling 
the connection
is forked, as I see in the process list.

Any ideas how to get further ?

Thanks,
Andras Pahi

> On 2021. Apr 16., at 7:43, Andras Pahi  wrote:
> 
> Hi Alex,
> 
> Thank you for your suggestions, I have traced listen and wait and both have
> The parameters are as expected (Ms is NIL, Sd is 17).
> 
> As Mike tested on macOS Big Sur and it worked, the problem is in my setup.
> 
> Regards,
> Andras
> 
>> On 2021. Apr 15., at 19:11, Alexander Burger  wrote:
>> 
>> Hi Andras,
>> 
>>> 
>>> /pil app/main.l -ap~main -'go 4040' +
>>> 6538 = 58885 48782252818959702~
>>> ap: !? (wait Ms T "Sd")
>>> Select error: Invalid argument
>>> ...
>>> It has the same behavior as the previous version of pil21.
>> 
>> Yeah, I thought about it, and came to the conclusion that today's change in
>> gPoll() is only relevant for very large (> 24 days) timeouts. Such a timeout 
>> is
>> seldom used, I think.
>> 
>> So what causes the above error?
>> 
>> It happens in 'listen' (line 94 in @lib/net.l):
>> 
>>  (de listen (Sd Ms)
>> (loop
>>(NIL (wait Ms T Sd))
>>(T (accept Sd) @) ) )
>> 
>> "Select error" is issued by poll(). But which argument is ivalid?
>> 
>> Can you try to trace or debug?
>> 
>> Is the socket descriptor invalid? The 'Ms' argument must be NIL cause listen 
>> is
>> called by 'server' as (listen P). Thus 'wait' passes 292MY to waitFd().
>> 
>> Any idea?
>> 
>> ☺/ A!ex
>> 
>> -- 
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
> 


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


Re: What is the structure of a namespace

2021-04-17 Thread Alexander Burger
On Fri, Apr 16, 2021 at 03:13:10PM -0500, polifemo wrote:
> OH! I think I'm getting it!
> for example, 'simul is '(\~ ("permute" ("shuffle" ("flood" ("G" NIL "gen"
> ...

> Something that confused me was that first symbol, '\~. It is not a valid
> picolisp symbol!

Correct. The special symbol \~ is new in pil21 and is only used as a marker
(e.g. for error checks). It is not absolutely necessary, and did not exist in
pil64.


> But now that I see that a namespace is a cons of a "short
> name namespace" and a "long name namespace", no symbol from either
> namespace would be a reasonable root for the tree. So that arbitrary symbol
> (\~) was chosen as the root. The cadr of 'simul are the short names, and
> there is no caddr because there are no long names!

Yes, though not the caddr but the cddr.

In summary, a namespace consists of 2 cells:

   +--+-+ +---+---+
   |  \~  |  ---+>| short | long  |
   +--+-+ +---+---+


   # Create empty namespace
   : (symbols 'ap 'pico)
   -> (pico)

   ap: ap
   -> (\~ NIL)

   # Two cells

   +--+-+ +-+-+
   |  \~  |  ---+>|  /  |  /  |
   +--+-+ +-+-+


   ap: (local) (abc def ghijklmo pqrstuvw)

   ap: ap
   -> (\~ (abc NIL def) ghijklmo NIL pqrstuvw)

   ap: (car ap)
   -> \~

   ap: (cadr ap)
   -> (abc NIL def)

   $ap: (cddr ap)
   -> (ghijklmo NIL pqrstuvw)

   ap: (all 'ap)
   -> (abc def ghijklmo pqrstuvw)


> One of the things that confused me was the way trees are represented. For
> example, given this tree:
> 
>  9
>   8
>7
>   6
> 5
>  4
>   3
>2
>   1
> 
> I would have represented it as a nested list in this way:
> (5 (2 (1 NIL NIL) (3 NIL (4 NIL NIL))) (7 (6 NIL NIL) (8 NIL (9 NIL NIL
> That is, each new branch is inside its own list. Intuitive, but quite
> wasteful, given that conses are memory in picolisp.
> 
> But the picolisp way is:
> (5 (2 (1) 3 NIL 4) 7 (6) 8 NIL 9)
> this is hard for me to describe, but something like...
> Every second element is the left branch of the element before it, and every
> third element is the right branch of the element two places back.

If we look at it this way, it is very simple:

   1. A tree node consists of either one or two cells. Leaf nodes need only one
  cell.
   2. The first cell of a node has the payload (value) in its CAR, and the
  subtrees (or NIL for leaf nodes) in its CDR.
   3. The second cell of a node holds the subtrees. The left one in the CAR and
  the right one in the CDR.

As leaf nodes need only one cell, and half of the nodes in a (balanced) tree are
leaf nodes, such a tree occupies one and a half cells per node on the average.

☺/ A!ex

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