Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Snap! user discussion
- joefarebrother
- Scratcher
500+ posts
Snap! user discussion
I fixed my try/catch block!My example still fails.
Are you sure? I tried it and the sprite said “TypeError: list.at is not a function”.
On the other hand, I figured from reading your code that changing the name of the ERROR upvar would break it, but it doesn't.
That's because I set the variable from within the custom block, where it is always called “error”
Do you hate my proposed name change?
No, I'm just using what most progamming langauges call this construct. Feel free to change it to whatever you want if you want to add it to a library
(although be careful if you want to change the default upvar name, because you'd have to modify the JS too)
All you have to do is (define the-empty-stream '()) and test for it in MAP.
And also in stream-ref, if you wanted an error message that made sense
(Why do you capitalize function/variable names?)
- joefarebrother
- Scratcher
500+ posts
Snap! user discussion
Turned out I wasn't logged into the cloud, so m fixed version onl exists in my localstore.
Now it should have saved.
Now it should have saved.
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
So, you get that the first two items are 0 and 1, right? So make a table like this:
I still don't quite get how it works.
fib-stream: 0 1 ...
(stream-cdr fib-stream): 1 ...
fib-stream: 0 1 1 ...
(stream-cdr fib-stream): 1 1 ...
fib-stream: 0 1 1 2 ...
(stream-cdr fib-stream): 1 1 2 ...
Does that help?
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
Of course - it's failing.Are you sure? I tried it and the sprite said “TypeError: list.at is not a function”.I fixed my try/catch block!My example still fails.
202e-202e-202e-202e-202e UNI-CODE~~~~~
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
Okay, installed in library! Thanks!
PS I don't understand why there's a CALL in the LET block. Don't you want the value of RESET to be the js function itself?
PPS I capitalize words from code in text because it makes it easy for people to get that I'm talking about the code without me having to learn any fancy formatting.
PPPS I resigned from the R7RS-Small committee partly because they insisted on making identifiers case-sensitive, a massive gratuitous backward incompatibility.
PS I don't understand why there's a CALL in the LET block. Don't you want the value of RESET to be the js function itself?
PPS I capitalize words from code in text because it makes it easy for people to get that I'm talking about the code without me having to learn any fancy formatting.
PPPS I resigned from the R7RS-Small committee partly because they insisted on making identifiers case-sensitive, a massive gratuitous backward incompatibility.
Last edited by bharvey (May 23, 2016 19:15:13)
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
Yes, thanks!So, you get that the first two items are 0 and 1, right? So make a table like this:
I still don't quite get how it works.The remaining (infinitely many) items will be found by adding corresponding items of these two streams. Right now we only have one pair of corresponding items to add, so on the second call to stream-cdr we add 0+1 and get this:fib-stream: 0 1 ...
(stream-cdr fib-stream): 1 ...Now we have enough paired items to handle another stream-cdr, which does 1+1:fib-stream: 0 1 1 ...
(stream-cdr fib-stream): 1 1 ...And so on. The items of (stream-cdr fib-stream) appear just in time to allow the next call to stream-cdr.fib-stream: 0 1 1 2 ...
(stream-cdr fib-stream): 1 1 2 ...
Does that help?
who needs signatures
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
R7RS looks really complicated, for a “small” standard. PPPS I resigned from the R7RS-Small committee partly because they insisted on making identifiers case-sensitive, a massive gratuitous backward incompatibility.
who needs signatures
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
Yeah, exactly. Don't get me started on how wrong-headed R7RS is. (I think Scheme peaked somewhere around R3 or R4.) R7RS looks really complicated, for a “small” standard.
- joefarebrother
- Scratcher
500+ posts
Snap! user discussion
I don't understand why there's a CALL in the LET block. Don't you want the value of RESET to be the js function itself?
I want reset to be the function returned by the JS function, which is a closure over oldErrorHandler and oldCatchingErrors
Anyway, I think the best RnRS is either 4 or 5
I've never looked into R3RS, what are the differences between it and later versions?
R7RS is certainly better than R6RS, however
Last edited by joefarebrother (May 23, 2016 20:20:18)
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
OK, thanks. I want reset to be the function returned by the JS function, which is a closure over oldErrorHandler and oldCatchingErrors
I've never looked into R3RS, what are the differences between it and later versions?The biggest one I remember is that in R3 the empty list is still false, as in traditional Lisps.
R7RS is certainly better than R6RS, howeverThat's a lot like choosing between having an arm cut off or a leg cut off. R7 may have cleaned up some outright mistakes in R6, but it's a political disaster because it pretends to have accommodated the needs of the small-Scheme lovers.
- joefarebrother
- Scratcher
500+ posts
Snap! user discussion
I'd probably rather have a leg cut off then, because I could still use a wheelchair or a prosthetic leg, but losing an arm would mean I would lose a lot of dexterity that comes with having 2 arms.
So in this analogy, R7 is losing a leg, and R6 is losing an arm, right?
So in this analogy, R7 is losing a leg, and R6 is losing an arm, right?
- Jonathan50
- Scratcher
1000+ posts
Snap! user discussion
Nothing: What's wrong with imperative code?
No, but tail-recursion doesn't need state to change. I could have said “And tail recursion is better than looping because for a while loop to terminate there needs to be state.”
If you're talking about EDIT: @jonathan50, your recursive solution is NOT tail recursive, it's tree recursive.
it is. I didn't say the fib(n) = fib(n - 1) + fib(n - 2) one is?is still much nicer than the looping one imo. (I know JS isn't tail call optimized but pretend it was)function fib(n) { function fib_aux(n, a, b) { return n <= 1 ? a : fib_aux(n - 1, a + b, a); } return fib_aux(n, 1, 0); }
Last edited by Jonathan50 (May 23, 2016 20:50:01)
Not yet a Knight of the Mu Calculus.
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
@Jonathan50, than why are you saying that recursion is better than looping? It can't be state because you have to maintain state in both versions, the difference is that in the recursive version you use arguments and in the looping version you use parameters.
It appeared to me that you were saying that fib(n) = fib(n - 1) + fib(n - 2) is tail recursive. Sorry for misunderstanding you.
It appeared to me that you were saying that fib(n) = fib(n - 1) + fib(n - 2) is tail recursive. Sorry for misunderstanding you.
who needs signatures
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
I think you guys just like arguing. (Said Brian, who never argues.)
jfb: No need to lose any limbs at all. I have an R4RS running on my computer. So I don't have to have an opinion as to which is which.
jfb: No need to lose any limbs at all. I have an R4RS running on my computer. So I don't have to have an opinion as to which is which.
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
Arguing is good! It's fighting that isn't. I think you guys just like arguing. (Said Brian, who never argues.)
jfb: No need to lose any limbs at all. I have an R4RS running on my computer. So I don't have to have an opinion as to which is which.
I use chicken scheme, which is R5RS.
who needs signatures
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
The codification example has several bugs in the map to Python block.
who needs signatures
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
really needs to be made async. Every time I try to load a block library or project, my web browser says that snap! is locked up, and if I let it continue, it locks up my whole browser for one or two minutes, depending on how big the project is.Please jens? For me and my ancient laptop? Project loading
who needs signatures
- Jonathan50
- Scratcher
1000+ posts
Snap! user discussion
really needs to be made async. Every time I try to load a block library or project, my web browser says that snap! is locked up, and if I let it continue, it locks up my whole browser for one or two minutes, depending on how big the project is.It makes my browser freeze, usually. Will making it run in not the main thread help? Project loading
Not yet a Knight of the Mu Calculus.
- Jonathan50
- Scratcher
1000+ posts
Snap! user discussion
For a while loop to end then state needs to change. @Jonathan50, than why are you saying that recursion is better than looping? It can't be state because you have to maintain state in both versions, the difference is that in the recursive version you use arguments and in the looping version you use parameters.
It appeared to me that you were saying that fib(n) = fib(n - 1) + fib(n - 2) is tail recursive. Sorry for misunderstanding you.
Not yet a Knight of the Mu Calculus.
- BookOwl
- Scratcher
1000+ posts
Snap! user discussion
It should.really needs to be made async. Every time I try to load a block library or project, my web browser says that snap! is locked up, and if I let it continue, it locks up my whole browser for one or two minutes, depending on how big the project is.It makes my browser freeze, usually. Will making it run in not the main thread help? Project loading
who needs signatures