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 () secsor
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 scriptblock 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)
Offline
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 () secsorwait until <>block is pending) and, if it evaluates to true, the script starts. For example, you could make awhen key [space v] released scriptblock that only fires when you let go of the key, defined aswhen 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
Offline
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!
Offline
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)
Offline
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.
Offline
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!)
Offline
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.
Offline
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
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?
Offline
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.
Offline
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 works.
Offline
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)
Offline
bharvey wrote:
Hardmath123 wrote:
I'm not dealing with quoting and macros for now, I just want something that works.
You'd better be dealing with quoting, unless numbers are your only data.
Just numbers, lists, and lambda for now.
Offline
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?
Offline
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)
Offline
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).
Offline
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?
Offline
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?
(credit to Wikipedia for the example lol)
Last edited by MathWizz (2012-07-09 21:34:46)
Offline
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.
Offline
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?
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.
Offline
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
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?
Offline
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)
Offline
Hardmath123 wrote:
Press the blue check mark button next to it.
I dont see any buttons next to it.
Offline