tags:

views:

52

answers:

1

I asked this question a few weeks ago about port http://stackoverflow.com/questions/1291127/rebol-smallest-http-server-in-the-world-why-first-wait-listen-port

listen-port is an object

first listen-port is self so still don't understand why self doesn't equal listen-port that is why do we need

http-port: first wait listen-port

if wait returns listen-port and first listen port is the same as self or listen-port then the above code is not the same as

http-port: wait listen-port

?

+1  A: 

listen-port is a port! value, not an object! value. A port! can be seen as a derivation from object! datatype and having a specialized purpose. FIRST behaviour (as all other action! values) is polymorphic.

For object! values, it returns the list of words defined in that object context (plus the special self-referencing word 'self) :

foo: make object! [bar: 3]
first foo
== [self bar]

For port! values, FIRST will have two different behaviours depending on the port! type :

  • client port : it sends the PICK action to the port internal handler (first port == pick port 1).

  • server port : it will call the ACCEPT action to the underlying C socket to retrieve a new connection port! value, allowing communication with the client.

So :

wait listen-port

returns the listen-port value when an event happens.

http-port: first wait listen-port

returns a new port! value connected to the client referenced by 'http-port.