array literal - a misunderstanding?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

array literal - a misunderstanding?

Thomas Fischer
Hello list,

I'm starting for a couple of days with smalltalk/squeak - maybe it's not my last post  :)

I like to construct a flat array, but get a nested array:

#(1 2 (1 + 3))      "unexpected result: #(1 2 #(1 #+ 3)) "

Why squeak means, that "(1 + 3)" is an array and not 4?

The syntax for an array literal is defined via"#(" - isn't it?

salute
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: array literal - a misunderstanding?

Mathieu SUEN
Is because the #(..) array is a literal build at compile time.
If you want a flat array use the {} syntax.
But this is specific to Squeak. You will not find it in VW for example.

Rather prefer the Array class>>#with:with:with:

        Math

On Mar 4, 2007, at 10:47 PM, Thomas Fischer wrote:

>
> #(1 2 (1 + 3))      "unexpected result: #(1 2 #(1 #+ 3)) "
>
> Why squeak means, that "(1 + 3)" is an array and not 4?

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: array literal - a misunderstanding?

Ron Teitelbaum
In reply to this post by Thomas Fischer
Hi Thomas,

The #() syntax is for a regular array but for a literal array you want {}
(curly braces)

Try this: {1. 2. 1 + 3.}

Hope that helps,

Ron Teitelbaum

> From: Thomas Fischer
>
>
> Hello list,
>
> I'm starting for a couple of days with smalltalk/squeak - maybe it's not
> my
> last post  :)
>
> I like to construct a flat array, but get a nested array:
>
> #(1 2 (1 + 3))      "unexpected result: #(1 2 #(1 #+ 3)) "
>
> Why squeak means, that "(1 + 3)" is an array and not 4?
>
> The syntax for an array literal is defined via"#(" - isn't it?
>
> salute
> Thomas
> --
> View this message in context: http://www.nabble.com/array-literal---a-
> misunderstanding--tf3344098.html#a9300859
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: array literal - a misunderstanding?

Thomas Fischer
Hi Ron & Mathieu & list

> Try this: {1. 2. 1 + 3.}

Ah, thanks a lot, but this provokes my next question:
How can I use floats like 3.14 in an array literal?

{3.14 2.}      "{3.14  Period or right brace expected ->2.}"

PS: Is there anywhere in the net a *COMPLETE AND COMPACT* list
of all "cryptical" syntax characteristics for smalltalk/squeak?

salute
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: RE: array literal - a misunderstanding?

Mathieu SUEN
try this:

{3.14. 2}

        Math

On Mar 5, 2007, at 9:08 AM, Thomas Fischer wrote:

>
> {3.14 2.}      "{3.14  Period or right brace expected ->2.}"

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: RE: array literal - a misunderstanding?

Thomas Fischer
Hi Mathieu,

<quote author='Mathieu SUEN'>
> try this:
>{3.14. 2}

Thanks!
I recapitulate:
In {} Array literals I have to use a period sign between all items.
In #(..) array literal which build at compile time, I can never use expressions.
Right?

salute
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: array literal - a misunderstanding?

Zulq Alam-2
In reply to this post by Thomas Fischer
Hi Thomas,

The Terse guide to Squeak at http://wiki.squeak.org/squeak/5699 may help.

Zulq.

Thomas Fischer wrote:

> PS: Is there anywhere in the net a *COMPLETE AND COMPACT* list
> of all "cryptical" syntax characteristics for smalltalk/squeak?

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: RE: array literal - a misunderstanding?

Ron Teitelbaum
In reply to this post by Thomas Fischer
Hahah!  That's pretty funny.  I hadn't thought about {3.14 2.}  but I went
and tried it and guess what, it worked!  My guess is the space is
importation.

I know that there are a number of tutorials,
http://wiki.squeak.org/squeak/792 if you find something good feel free to
let us know.

Ron Teitelbaum

> -----Original Message-----
> From: [hidden email] [mailto:beginners-
> [hidden email]] On Behalf Of Thomas Fischer
> Sent: Monday, March 05, 2007 3:08 AM
> To: [hidden email]
> Subject: [Newbies] RE: array literal - a misunderstanding?
>
>
> Hi Ron & Mathieu & list
>
> > Try this: {1. 2. 1 + 3.}
>
> Ah, thanks a lot, but this provokes my next question:
> How can I use floats like 3.14 in an array literal?
>
> {3.14 2.}      "{3.14  Period or right brace expected ->2.}"
>
> PS: Is there anywhere in the net a *COMPLETE AND COMPACT* list
> of all "cryptical" syntax characteristics for smalltalk/squeak?
>
> salute
> Thomas
> --
> View this message in context: http://www.nabble.com/array-literal---a-
> misunderstanding--tf3344098.html#a9306975
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: array literal - a misunderstanding?

Thomas Fischer
In reply to this post by Zulq Alam-2
Hi,
<quote author='Zulq Alam-2'>
> The Terse guide to Squeak at http://wiki.squeak.org/squeak/5699 may help.

Thanks for this Link.

Arrrgh! There is no curly brace in the "Terse guide"

salute
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: array literal - a misunderstanding?

Bert Freudenberg

On Mar 5, 2007, at 18:48 , Thomas Fischer wrote:

>
> Hi,
>
>> The Terse guide to Squeak at http://wiki.squeak.org/squeak/5699 
>> may help.
>
> Thanks for this Link.
>
> Arrrgh! There is no curly brace in the "Terse guide"

It's a wiki. Add it.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: RE: array literal - a misunderstanding?

olivier mai
In reply to this post by Thomas Fischer
Mathieu,
No,
 With the brace syntax you separate STATEMENTS (hence the period) with a whitespace (tab newline etc... just as one
would with arrays). Expressions do not require a period.

 So, { (3.14 asFloat). 2.}  or { (3.14). 2. }
and just as well { (Stream on: ( String new:1204)).   'or whatever you  can get away with...'   .} (notice the periods
inside the literal string)

Olivier.

>
> Hi Mathieu,
>
>
> > try this:
> >{3.14. 2}
>
> Thanks!
> I recapitulate:
> In {} Array literals I have to use a period sign between all items.
> In #(..) array literal which build at compile time, I can never use
> expressions.
> Right?
>
> salute
> Thomas
>
> --
> View this message in context: http://www.nabble.com/array-literal---a-misunderstanding--tf3344098.html#a9307708
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners