This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2010-08-07 18:12:48

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Squeak (Source Code) Guide

markyparky56 wrote:

nXIII wrote:

johnnydean1 wrote:

yep

I'm not really sure what you meant here. I'll explain.

markyparky56 wrote:


As in places to put code?

As in unevaluated code. For example,

Code:

sandwich := [:bread :toppings | {'Bread: ', bread asString. 'Toppings: ', toppings asArray asString}].

This tells me how to make a sandwich (array with two strings, "Bread: bread_type" and "Toppings: toppings") with just the toppings and bread given. I can do this as many times as I want with whatever things I want by simply typing

Code:

sandwich value: 'bread' value: #(topping topping topping).
"or even"
sandwich value: self basicsize asString, ' different kinds!' value: {self. self class}.

However, to simply put

Code:

bread := 'Wheat'.
toppings := #(cheese lettuce tomato).
sandwich := {'Bread: ', bread. 'Toppings: ', toppings}.

would only give me one sandwich, and I wouldn't know how to make another one of a different type without doing all that again manually.

So its making a class?

No... it's like a BYOB lambda


nXIII

Offline

 

#27 2011-05-14 05:28:58

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Squeak (Source Code) Guide

bbbeb wrote:

How do you stop it if its false? doReturn or something like that?

Code:

[variable to test] ifTrue: [ extra scripts, include brackets ]
^ self

Offline

 

Board footer