rotate on list

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

rotate on list

Post by newdep »

Hello Lutz,

(Linux 7.5.4)

Im currious what im doing wrong in the following example, perhpas you can
point out the mistake. I could emagin that (net-sessions) is static in itself still the first rotate Is accepted.

>(net-sessions)
(4 3)
>(rotate (net-sessions))
(3 4)
>(rotate (net-sessions))
(3 4)

As you can see the 'rotate only worked once, still rotate is destructive to the
'net-sessions list, its not updated a second time. If you would say that i should isolate the list from 'net-sessions befor doing a rotate (because of the dynamic/static behaviour of the 'net-sessions list) i'll work with that ;-)

Ofcourse a normal list works...

> (set 'x (list 1 2 3 4))
(1 2 3 4)
> (rotate x)
(4 1 2 3)
> (rotate x)
(3 4 1 2)
> (rotate x)
(2 3 4 1)
> (rotate x)
(1 2 3 4)


Regards,
Norman.

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

net-sessions is always creating the new list: (4 3)

No matter how many times you call net-sessions, it will create a new list: (4 3)

If you save the list in a variable say

(setq sessions (net-sessions))

and rotate on the variable sessions your ok.

Eddie

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Hello Eddie, Mmmm your right... i think i mixed up the console output and the
variable i was playing with ;-) lets close this chapter quicky ;-)
Norman.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

correct, 'net-sessions' is not static but reports the currently open listening or connection sockets. Each time 'net-sessions' is called it constructs the new list of currently active sockets.

Lutz

Locked