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

#5551 2012-07-08 04:14:51

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I was thinking you could hake a hat block that will do something, then reports a boolean value. The hat block will check the condition every step of the project (unless it has a

wait () secs
or
wait until <>
block is pending) and, if it evaluates to true, the script starts. For example, you could make a

when key [space v] released
script
block that only fires when you let go of the key, defined as

when key (letter = space) released
if <key (letter) pressed?>
  wait until <not <key (letter) pressed?>>
  report <true>
else
 report <false>
end

Last edited by joefarebrother (2012-07-08 04:15:32)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#5552 2012-07-08 04:17:40

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

I was thinking you could hake a hat block that will do something, then reports a boolean value. The hat block will check the condition every step of the project (unless it has a

wait () secs
or
wait until <>
block is pending) and, if it evaluates to true, the script starts. For example, you could make a

when key [space v] released
script
block that only fires when you let go of the key, defined as

when key (letter = space) released
if <key (letter) pressed?>
  wait until <not <key (letter) pressed?>>
  report <true>
else
 report <false>
end

That hat is already possible.

when gf clicked
forever
 wait until <key [space v] pressed?>
 wait until <not <key [space v] pressed?>>
 script
end


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#5553 2012-07-08 05:21:00

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hey bharvey, my Scheme interpreter is running wonderfully well! But I've run into a bit of a problem. When writing the Factorial function, the if n=0 should only evaluate the clause it needs to, right? Because if it evaluates both the if-true clause and the if-false clause (and then picks the appropriate result) it would fall into an infinite loop if one clause is recursive. So, my question is, is "if" the only special case like this, or do I need to consider each function I add to see if all arguments should be evaluated right away or only if needed? Thanks!  smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5554 2012-07-08 09:14:05

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

I was thinking you could hake a hat block that will do something, then reports a boolean value.

Sure.  You'd take the body of your script, starting with the "if key pressed," and make a predicate out of it, then put that predicate into the generic WHEN hat block.

EDIT:  Although there's a potential problem with this sort of thing regardless of notation:  You might miss a key-down-and-up cycle that happens so quickly that your script doesn't happen to be running at any time in the down part.  The built-in WHEN KEY PRESSED doesn't have that problem because system events are queued, so it's safer, I think to say

WHEN KEY PRESSED
WAIT UNTIL <NOT <KEY PRESSED>>
BROADCAST "key up"

Last edited by bharvey (2012-07-08 10:18:56)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5555 2012-07-08 09:19:33

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

So, my question is, is "if" the only special case like this, or do I need to consider each function I add to see if all arguments should be evaluated right away or only if needed?

IF is one of maybe a dozen special forms in Scheme:  COND, DEFINE, SET!, AND and OR for lazy evaluation, QUOTE, QUASIQUOTE, LAMBDA, LET, LET*, LETREC, and DEFINE-MACRO or DEFINE-SYNTAX or whatever you're using for macros.  And of course the user-defined macros are special forms; that's the whole point of macros.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5556 2012-07-08 10:53:44

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

So, my question is, is "if" the only special case like this, or do I need to consider each function I add to see if all arguments should be evaluated right away or only if needed?

IF is one of maybe a dozen special forms in Scheme:  COND, DEFINE, SET!, AND and OR for lazy evaluation, QUOTE, QUASIQUOTE, LAMBDA, LET, LET*, LETREC, and DEFINE-MACRO or DEFINE-SYNTAX or whatever you're using for macros.  And of course the user-defined macros are special forms; that's the whole point of macros.

I think macros should be in snap!!  (The punctuation is REALLY annoying!)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#5557 2012-07-08 11:15:30

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

I think macros should be in snap!!

Yes of course.  It's the only big missing piece of Scheme left, since we added call⁄cc.  I'm not promising hygienic macros, though; plain old FEXPR-style macros should do.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5558 2012-07-09 01:28:35

asampal
New Scratcher
Registered: 2011-08-26
Posts: 9

Re: BYOB 3 - Discussion Thread

In Snap!, is there a reason the built in answer variable can only be set by the ask block and not by the set block? I ran into a situation like the following:

<repeat until (answer) = "end">
   ask "Give me a subject"
   do something ...
<end>
<repeat until (answer) = "end">
   ask "Give me a verb"
   do something else ...
<end>

where the "end" value was used to break out of a particular loop asking for values.  Since answer couldn't be reset after the first loop, the second one wouldn't execute unless the code was changed so test was done on another variable that was a copy of answer.

Maybe I just couldn't find the block which could reset answer without asking. Is there one?

Thanks

Offline

 

#5559 2012-07-09 01:40:17

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hi asampal,

Snap follows Scratch's example in treating the ANSWER block as a sensor value, not as a user-settable variable (I've followed that thread on Scratch-Ed, btw). Since you never know what the last answer given previously actually was, I'd recommend you to not directly query the ANSWER value in any loops but to always assign it to a variable first (as you've found out yourself).

I was a little astonished by the corresponding thread on Scratch-Ed. OTOH I realize that Scratch does have a RESET TIMER block, so do you think a RESET ANSWER block would be important?


Jens Mönig

Offline

 

#5560 2012-07-09 06:29:20

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I'd say the best way for the ask block to work would be an (ask for ()) reporter which reported the value typed in by the user.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5561 2012-07-09 06:31:31

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

So, my question is, is "if" the only special case like this, or do I need to consider each function I add to see if all arguments should be evaluated right away or only if needed?

IF is one of maybe a dozen special forms in Scheme:  COND, DEFINE, SET!, AND and OR for lazy evaluation, QUOTE, QUASIQUOTE, LAMBDA, LET, LET*, LETREC, and DEFINE-MACRO or DEFINE-SYNTAX or whatever you're using for macros.  And of course the user-defined macros are special forms; that's the whole point of macros.

I'm not dealing with quoting and macros for now, I just want something that workssmile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5562 2012-07-09 06:58:41

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I'm not dealing with quoting and macros for now, I just want something that workssmile

You'd better be dealing with quoting, unless numbers are your only data.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5563 2012-07-09 06:59:52

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I'd say the best way for the ask block to work would be an (ask for ()) reporter which reported the value typed in by the user.

+1, I think.  I'd certainly do it that way if we were designing a language from scratch rather than from Scratch.  As it is, I'm not sure it's important enough to change.

Last edited by bharvey (2012-07-09 07:00:14)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5564 2012-07-09 07:37:24

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

I'm not dealing with quoting and macros for now, I just want something that workssmile

You'd better be dealing with quoting, unless numbers are your only data.

Just numbers, lists, and lambda for now.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5565 2012-07-09 12:44:26

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

joefarebrother wrote:

I think macros should be in snap!!

Yes of course.  It's the only big missing piece of Scheme left, since we added call⁄cc.  I'm not promising hygienic macros, though; plain old FEXPR-style macros should do.

I don't really understand those, I only understand the hygienic ones. Maybe it could be like logo macros?


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#5566 2012-07-09 17:53:01

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Just numbers, lists, and lambda for now.

And how do you get a data list into your program without quoting it?  I mean, how do you say the equivalent of

(car (quote (1 2 3) ) )

?  (You can use the ' notation, as in

(car '(1 2 3) )

but that's just an abbreviation for the QUOTE special form.)

Last edited by bharvey (2012-07-09 17:53:26)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5567 2012-07-09 18:04:49

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

I don't really understand those, I only understand the hygienic ones. Maybe it could be like logo macros?

You understand hygienic macros??  I'm impressed; you are a true KLC.

FEXPRs are just like (Berkeley) Logo macros: the macro returns a new expression that then gets EVALed in place of the macro call itself.  The only difference is that in a FEXPR none of the inputs are evaluated; the entire macro call is used as the sole input to the FEXPR.

The issue with macro in a block-based language is that there's (so far) no way to build a block with desired input expressions (as opposed to input values, which CALL and RUN allow).


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5568 2012-07-09 21:13:37

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

joefarebrother wrote:

I don't really understand those, I only understand the hygienic ones. Maybe it could be like logo macros?

You understand hygienic macros??

I don't. Mind giving me a non-Wikipedia link?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5569 2012-07-09 21:29:03

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Well... Wikipedia says, "Hygienic macros are macros whose expansion is guaranteed not to cause the accidental capture of identifiers."

In this case:

#define INCI(i) {int a=0; ++i;}
int main(void)
{
    int a = 0, b = 0;
    INCI(a);
    INCI(b);
    printf("a is now %d, b is now %d\n", a, b);
    return 0;
}

Running the above through the C preprocessor produces:

int main(void)
{
    int a = 0, b = 0;
    {int a=0; ++a;};
    {int a=0; ++b;};
    printf("a is now %d, b is now %d\n", a, b);
    return 0;
}

These are not hygienic macros because the variable 'a' is redefined in the macro causing it not to increment, unlike 'b'. A hygienic macro would not do this, it would change the macro to avoid conflict. If the variable 'a' were defined, the macro might internally change to "{int a1 = 0; ++a};" so that 'a1' and 'a' don't conflict.

Right Brian? Did I screw this up?  tongue

(credit to Wikipedia for the example lol)

Last edited by MathWizz (2012-07-09 21:34:46)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#5570 2012-07-09 21:29:37

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I don't. Mind giving me a non-Wikipedia link?

ftp://ftp.cs.indiana.edu/pub/scheme-rep … ros-01.txt

Also -02, -03, and -04.

Not easy.  I don't understand hygienic macros.  I'm not 100% convinced anyone does, since well-known Scheme experts keep posting "how do you do X in hygienic macros" questions on comp.lang.scheme.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5571 2012-07-09 21:35:05

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

MathWizz wrote:

These are not hygienic macros because the variable 'a' is redefined in the macro causing it not to increment, unlike 'b'. A hygienic macro would not do this, it would change the macro to avoid conflict. If the variable 'a' were defined, the macro might internally change to "{int a1 = 0; ++a};" so that 'a1' and 'a' don't conflict.

Right Brian? Did I screw this up?  tongue

Right, except you make it sound as if some C macros are hygienic and others aren't.  It's a language's whole macro system that is or isn't hygienic.  If a language uses hygienic macros, then the programmer doesn't have to worry about name captures.

It's the details that are complicated.  Sometimes a macro does want to refer to a particular variable in the caller, and that's the hairy part.  I think.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5572 2012-07-09 23:49:10

asampal
New Scratcher
Registered: 2011-08-26
Posts: 9

Re: BYOB 3 - Discussion Thread

I'd say that answer should be resettable just to make it symmetric with the timer. This would result in somewhat more concise code for the use case I described and it would make it even easier to follow for younger children (I was showing something to my son).

Jens wrote:

OTOH I realize that Scratch does have a RESET TIMER block, so do you think a RESET ANSWER block would be important?

Offline

 

#5573 2012-07-10 07:57:38

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

Just numbers, lists, and lambda for now.

And how do you get a data list into your program without quoting it?  I mean, how do you say the equivalent of

(car (quote (1 2 3) ) )

?  (You can use the ' notation, as in

(car '(1 2 3) )

but that's just an abbreviation for the QUOTE special form.)

What's the difference between "quote" and "list"? Or have I got the wrong LISP?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#5574 2012-07-10 11:32:45

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I'm not exactly sure. I thought (quote (1 2 3 (4 5))) was like an abbreviation of (list (1 2 3 (list 4 5)), where (quote +) became a new data type "symbol" '+.

Last edited by Hardmath123 (2012-07-10 11:32:58)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5575 2012-07-10 12:46:06

christian2000
Scratcher
Registered: 2010-11-01
Posts: 100+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Press the blue check mark button next to it.

I dont see any buttons next to it.  hmm


blerp......
http://obscureinternet.com/wp-content/uploads/Fail-at-Life-Funny-Cards.png

Offline

 

Board footer