[Newbies] Can a block be a string?

Matthias Berth matthias.berth at googlemail.com
Fri Feb 19 06:42:39 UTC 2010


Andy,

a string and a block are two distinct things in Smalltalk. Seaside
just lets you provide one or the other as an argument for messages
like paragraph: because that's convenient when you write a web
application. Sometimes you want to have plain text in that paragraph,
then you use

  html paragraph: 'some text'.

Other times you want to nest more html structures inside the
paragraph, then you do something like

  html paragraph: [
    html span
      class: 'highlight';
      with: 'more text'
  ]

or, maybe more illustrative of the idea:

  html table: [
    html tableRow: [
      html tableData: 'cell 1'.
      html tableData: 'cell 2'
    ].
    html tableRow: [
      html tableData: 'cell 3'.
      html tableData: 'cell 4'
    ].
  ]


Somewhere in the Seaside code there is a dispatch that processes
strings and blocks differently.


HTH

Matthias

On Thu, Feb 18, 2010 at 11:33 PM, Andy Burnett
<andy.burnett at knowinnovation.com> wrote:
> I am playing around with Seaside 3 and noticed that, for example:
>
> html paragraph: 'text', and
> html paragraph: [html text: 'hello'].
>
> Are both valid.
>
> When I looked at the definition for paragraph:  it says that takes a aBlock,
> but then doesn't seem to do a value: aBlock.  So, what I am wondering is
> whether it is valid to give a string as a block, or whether this is just a
> slightly loose definition of block?
>
> Cheers
> Andy
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>


More information about the Beginners mailing list