Hi Sven,

Why not simply:

        (ZnServer startOn: 1337)
           onRequestRespond: [:request |: ZnResponse ok: 'Hello world']


This is the closest form to that node.js example and really show the
power of Smalltalk and its closures. Also understandable to everyone
including the (IMHO) majority, who don't understand design patterns like
Delegate well.

Best regards
Janko


S, Sven Van Caekenberghe piše:
> 
> On 01 Jul 2011, at 12:31, Nick Ager wrote:
> 
>> or even:
>>
>> hello world:
>> ((ZnServer defaultOn: 1337)
>>      delegate: (ZnDispatcherDelegate new 
>>              map: '/' to: [ :request :response | response entity: (ZnEntity 
>> text:  'Hello World!') ])) start 
>>
>> echo:
>> ((ZnServer defaultOn: 1337)
>>       delegate: (ZnDispatcherDelegate new 
>>              map: '/' to: [ :request :response | response entity: (ZnEntity 
>> with: request contents) ])) start
>>
>>
> 
> Yes, of course Nick, but then you better use the prefixes:
> 
> ((ZnServer defaultOn: 1337)
>       delegate: (ZnDispatcherDelegate new 
>               map: '/hello' to: [ :request :response | response entity: 
> (ZnEntity text:  'Hello World!') ])) start    
> 
> ((ZnServer defaultOn: 1337)
>       delegate: (ZnDispatcherDelegate new 
>               map: '/echo' to: [ :request :response | response entity: 
> (ZnEntity with: request contents) ])) start
> 
> Writing the shortest possible server code is a dubioius challenge. Although 
> few Smalltalker would be happy to use verbose and heavy Java and XML. It is 
> important that simple things be easy, short and elegant and complex things be 
> possible.
> 
> Sven
> 
> 
> 

-- 
Janko Mivšek
Svetovalec za informatiko
Eranova d.o.o.
Ljubljana, Slovenija
www.eranova.si
tel:  01 514 22 55
faks: 01 514 22 56
gsm: 031 674 565

Reply via email to