rotate on list

Started by newdep, February 27, 2004, 11:58:02 AM

Previous topic - Next topic

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.
-- (define? (Cornflakes))

eddier

#1
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

#2
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.
-- (define? (Cornflakes))

Lutz

#3
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