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

#6351 2012-11-29 12:08:24

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

wouldn't that be only if the circularity is on a cdr?

Yes, that's true.  If the circularity is on a car, then it's a depth that the list doesn't have.


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

Offline

 

#6352 2012-11-29 12:36:27

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

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

Okay, this is getting complicated. Are you thinking something like "set x to (1 in front of (2 in front of x))"?

No, in that case the circular part reaches all the way back to the head of the list.  You can't set up the thing I mean in one step.  It has to be

set X to (1 in front of (2 in front of X))
set Y to (a in front of (b in front of X))

Then Y is the list (a, b, 1, 2, 1, 2, ...)

Actually even that might not really work -- the SET X will fail because X doesn't already have a value.  Certainly it doesn't already have the right value.

Jens, we need a set-cdr! block.   smile

Or find whether a list is circular in time linear in the number of unique elements.  smile

I don't understand this one. (Which is probably ironic...  tongue ) If it's not nested, you can just do:

    for item in list:
        if item is list:
            return item

Again, you are assuming that the circularity is at the head of the list.  For each item in the list, you have to check whether that item is either the list or any tail of the list.

It's not hard to solve this problem in quadratic time.  (But you have to be careful not to take infinite time if the list is, in fact, circular.  We want an answer either way, in finite time.)  Making it linear time (oh, and, btw, constant space) is one of those problems that hardly anyone gets -- someone has to show you, as part of your initiation into the mysteries.


I thought the same — I've been reading the first chapter of SICP over the past few days. (The new Kindles have this awful feature that predicts how long it will take you to finish, and for SICP it claims about 16 hours...) Maybe I should try some of the other exercises from that? Though I thought it was more about language theory...

SICP is about the deepest mysteries of the universe.  It explains the meaning of life.  Those who haven't read SICP are ignorant of computer science.  (Yes, ignoramuses are legion in highly paid jobs in the computer industry.)  (Ignorami?  Ignorames?)  They are callow youth, gambolling in the fields.

Do the exercises.  All of them.  It's not like your high school algebra book, with 50 identical-except-for-the-numbers equations to solve in the same way.  Every exercise teaches a specific new idea or skill.

Last edited by bharvey (2012-11-29 13:15:11)


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

Offline

 

#6353 2012-11-29 14:52:40

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

Re: BYOB 3 - Discussion Thread

Okay, okay! I'll read SICP...  big_smile  *serious face*

bharvey wrote:

blob8108 wrote:

Okay, this is getting complicated. Are you thinking something like "set x to (1 in front of (2 in front of x))"?

No, in that case the circular part reaches all the way back to the head of the list.  You can't set up the thing I mean in one step.  It has to be

set X to (1 in front of (2 in front of X))
set Y to (a in front of (b in front of X))

Then Y is the list (a, b, 1, 2, 1, 2, ...)

Actually even that might not really work -- the SET X will fail because X doesn't already have a value.  Certainly it doesn't already have the right value.

Jens, we need a set-cdr! block.   smile

Okay, this is definitely making my brain hurt now.  tongue

I think I understand Snap! lists a bit more. They're, so they either take the form of a "cons", having attributes:

    first -> first item
    rest -> a list containing the remaining items

Or a normal JS array, where all the items are found on the "contents" attribute.

Right? (Sorry, I'm being slow here.)

So what I think you're trying to do is set up a list "list" where "rest" = "list". Am I right?


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

Offline

 

#6354 2012-11-29 15:43:56

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

SICP is about the deepest mysteries of the universe.  It explains the meaning of life.

Where? On page 42? I didn't see it...


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

 

#6355 2012-11-29 15:51:41

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

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

bharvey wrote:

blob8108 wrote:

Okay, this is getting complicated. Are you thinking something like "set x to (1 in front of (2 in front of x))"?

No, in that case the circular part reaches all the way back to the head of the list.  You can't set up the thing I mean in one step.  It has to be

set X to (1 in front of (2 in front of X))
set Y to (a in front of (b in front of X))

Then Y is the list (a, b, 1, 2, 1, 2, ...)

Actually even that might not really work -- the SET X will fail because X doesn't already have a value.  Certainly it doesn't already have the right value.

Jens, we need a set-cdr! block.   smile

Okay, this is definitely making my brain hurt now.  tongue

I think I understand Snap! lists a bit more. They're, so they either take the form of a "cons", having attributes:

    first -> first item
    rest -> a list containing the remaining items

Or a normal JS array, where all the items are found on the "contents" attribute.

Right? (Sorry, I'm being slow here.)

So what I think you're trying to do is set up a list "list" where "rest" = "list". Am I right?

He's trying to make a list like this:

Code:

{ // 1
    first: 'a',
    rest: { // 2
        first: 'b',
        rest: { // 3
            first: '1',
            rest: { // 4
                first: '2',
                rest: … // 3
            }
        }
    }
}

nXIII

Offline

 

#6356 2012-11-29 16:00:34

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

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

Okay, this is definitely making my brain hurt now.  tongue

Always a good sign.

I think I understand Snap! lists a bit more. They're, so they either take the form of a "cons", having attributes:

    first -> first item
    rest -> a list containing the remaining items

Or a normal JS array, where all the items are found on the "contents" attribute.

Right? (Sorry, I'm being slow here.)

So what I think you're trying to do is set up a list "list" where "rest" = "list". Am I right?

You're not being slow.  I'm being slow, for not remembering that REPLACE ITEM (n) OF (list) WITH (value) converts the list into array format.  (Jens just emailed to remind me that I wrote this code.)  That's a misfeature, I now think.  I'll work on it.

The goal of the complexity of list implementation is that Scratch-style iterative list processing should continue to work efficiently (constant time, not linear time, for ITEM, INSERT, etc.), but also Scheme-style recursive functional list processing should work efficiently (constant time IN FRONT OF and ALL BUT FIRST OF).

The only thing that's inefficient is mixing styles with the same list, first doing ALL BUT FIRST OF and then doing INSERT etc, because then the list gets converted from one form to the other repeatedly.

What's confusing you is that when we agreed on this design, I had in mind that the use of car/cdr lists would always be purely functional.   So we didn't provide for SET-CAR! or SET-CDR! equivalents.  I'll work on that...  as soon as I get out from under writing grad school recommendation letters for Berkeley students.  It's that season, as you know.

So, don't feel bad, you're doing as well as possible, given the current limitations of Snap! list processing.


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

Offline

 

#6357 2012-11-29 16:02:57

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

Where? On page 42? I didn't see it...

Ah, my son, that was a comic novel.  The meaning of life isn't a sound bite; you have to study the entire book to understand it fully.

And bring me a towel, a piece of fresh fruit, and $100.


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

Offline

 

#6358 2012-11-30 07:21:56

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Or find whether a list is circular in time linear in the number of unique elements.  smile

I don't understand this one. (Which is probably ironic...  tongue ) If it's not nested, you can just do:

    for item in list:
        if item is list:
            return item

Again, you are assuming that the circularity is at the head of the list.  For each item in the list, you have to check whether that item is either the list or any tail of the list.

It's not hard to solve this problem in quadratic time.  (But you have to be careful not to take infinite time if the list is, in fact, circular.  We want an answer either way, in finite time.)  Making it linear time (oh, and, btw, constant space) is one of those problems that hardly anyone gets -- someone has to show you, as part of your initiation into the mysteries.

I did it in linear time and linear space (and JavaScript  tongue ).

Code:

function isCircular(list) {
    var flag = {}; // any unique value
    !function f(list) {
        if (isEmpty(list) || isList(car(list)) && car(car(list)) === flag) return;
        setCar(list, cons(flag, car(list)));
        f(cdr(list));
    }(list);
    return function f(list) {
        if (isEmpty(list)) return false;
        if (!isList(car(list)) || car(car(list)) !== flag) return true;
        setCar(list, cdr(car(list)));
        return f(cdr(list));
    }(list);
}

I'm still working on constant space.

Last edited by nXIII (2012-11-30 07:26:36)


nXIII

Offline

 

#6359 2012-11-30 17:25:47

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Those who haven't read SICP are ignorant of computer science.  (Yes, ignoramuses are legion in highly paid jobs in the computer industry.)  (Ignorami?  Ignorames?)  They are callow youth, gambolling in the fields.

This made me laugh. I've been trying a bit of Android development lately and the lack of first-class procedures is driving me nuts!


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#6360 2012-11-30 20:40:48

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

Re: BYOB 3 - Discussion Thread

fullmoon wrote:

and the lack of first-class procedures is driving me nuts!

tongue

But of course lambda isn't all of SICP; it's in Chapter 1 (of 5).  Really understanding OOP, for example, comes in Chapter 3.  Understanding compilers in Chapter 5.  Declarative (logic) programming, Chapter 4.
And so on.


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

Offline

 

#6361 2012-11-30 20:41:51

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

Re: BYOB 3 - Discussion Thread

nXIII wrote:

I'm still working on constant space.

Bwahahaha!  big_smile


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

Offline

 

#6362 2012-12-06 16:30:24

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

Re: BYOB 3 - Discussion Thread

Found a linear time, constant space, tail recursive test for circularity written in scheme.

Code:

(define (circular? x) 
 (let race ((hare x) (tortoise x)) ;;hare and tortoise algorithm
     (if (pair? hare)
         (let ((hare (cdr hare))) 
            (if (pair? hare) 
                 (or (eq? hare tortoise)       
                     (race (cdr hare) (cdr tortoise)))
                 (circular-on-cars? x)) 
     (circular-on-cars? x))))

It's linear time because as it traverses the list the hare is one more ahead of the tortoise each time, so if it is circular it will go round the list once before it catches up, otherwise it will hit the end of the list.

My circular on cars procedure is linear space  sad  (it probably has too many opening or closing parenthesis too but i can't be bothered to check)

Code:

(define (circular-on-cars? x)
 (let ((unique-value (cons '() '())))
       (let helper ((x x) (callback (lambda () #t)))
             (cond ((not (pair? x)) (callback) #f) ;;just call for the side effect of putting all the cars back and report false instead of true
                   ((eq? (car x) unique-value) (callback))
                   (else (let ((old-car (car x))) 
                               (set-car! x unique-value)
                               (helper (cdr x) (lambda () 
                                                    (set-car! x old-car)
                                                    (callback)))))))))

Last edited by joefarebrother (2012-12-07 17:13:39)


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

 

#6363 2012-12-06 17:36:43

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

(let race ((hare x) (tortoise x)) ;;hare and tortoise algorithm

Great!  Does "found" mean, like, "found in Google," or did you independently invent this?


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

Offline

 

#6364 2012-12-07 17:12:46

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

joefarebrother wrote:

(let race ((hare x) (tortoise x)) ;;hare and tortoise algorithm

Great!  Does "found" mean, like, "found in Google," or did you independently invent this?

I found it when reading through a few CS textbooks but I changed a letrec for a named let and added circular-on-cars?

Last edited by joefarebrother (2012-12-07 17:15:33)


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

 

#6365 2012-12-09 09:34:52

technoboy10
Scratcher
Registered: 2007-08-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

technoboy10 wrote:

Hey all! I've been playing with Snap! on the iPad mini, and it works pretty well except for a few things. The text inputs default to caps lock, and the iOS touch-and-hold to move the text cursor doesn't work. Any way to fix this?


So long, 1.4.
http://goo.gl/3JEV9

Offline

 

#6366 2012-12-09 13:06:25

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

Re: BYOB 3 - Discussion Thread

What would the cloud thing on snap eventually do when it works? Will it be saving projects in the cloud, or something like cloud variables in 2.0, or some way to connect projects like mesh via the cloud, or is it something else?


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

 

#6367 2012-12-09 15:17:28

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

What would the cloud thing on snap eventually do when it works? Will it be saving projects in the cloud, or something like cloud variables in 2.0, or some way to connect projects like mesh via the cloud, or is it something else?

Aargh I just wrote a long reply to this and the stupid forum software logged me out before I hit "submit"!  sad

Trying again...  The initial impementation will do two things: (1) Allow you to save your projects (and block libraries, costumes, anything exportable) privately.  (2) Allow us to provide "public" block libraries and media that anyone can access easily.

(Backstory:  The ability to save projects reliably and conveniently is the biggest thing standing in the way of us declaring beta status.  So we want that now rather than waiting for a super-featureful back end.)

Later, of course we want people to be able to publish projects, block libraries, etc. to the world, even though I'm still terrified about having to police the site.

In a certain sense, cloud variables are just a special case of block libraries, since a variable is a kind of block.  For example, I imagine one of the libraries we'd provide would be called "constants" and would have blocks such as PI, E, and PHI.  But thinking of cloud variables that way would require projects to save the variable after every change of value.  So, Scratch-2.0-style cloud variables are something for us to think about later.

Worldwide mesh would be super cool, of course, but also a security hassle.  You don't want strangers hijacking your collaborative project.  Keeping the mesh behind a local firewall implicitly solves that problem; once we make it global, we'd have to invent a login mechanism for local virtual meshes.  Another thing for us to think about after 4.0 is out the door.

Of course, once people can publish projects, we'd want to do all the Scratch-front-page sorts of things, and fora, and person-to-person messaging so I can argue with Shadow about politics  smile  -- if Club Penguin can do it, so can we, imho.


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

Offline

 

#6368 2012-12-09 16:14:08

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

So I can argue with Shadow about politics  smile

Looking forward to it.  big_smile

Offline

 

#6369 2012-12-10 00:58:30

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

Re: BYOB 3 - Discussion Thread

Hi technoboy10, I've just gotten a new iPad mini myself and I'm delighted how well Snap! works on it! I'll look into improving text input gradually, right mow you have to explicitly turn caps on and off, and tap on the character where you want the caret to be. If you zoom the entire window make sure to use two fingers for scrolling. Cheers!


Jens Mönig

Offline

 

#6370 2012-12-10 06:11:25

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

Re: BYOB 3 - Discussion Thread

On my iPad (2 running iOS 6) Snap! works brilliantly (for a web app!), but it's dreadfully slow. Maybe I'm spoiled with Apple's fluid scrolling, but I would really like some speed optimizations.


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

Offline

 

#6371 2012-12-10 08:05:03

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

Re: BYOB 3 - Discussion Thread

Ah, which generation of the iPad 2 are your running Snap on? It's quite fast (I'd even say surprisingly fast) on the iPad mini. So I'm inclined - as I did with Smalltalk and Squeak - to just wait for computers to become faster. But hey, I'm open to any suggestions about speed optimizations you might have or come up with! Is there anything in particular that you can point me to?


Jens Mönig

Offline

 

#6372 2012-12-10 09:31:40

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

Re: BYOB 3 - Discussion Thread

You can now "snap" comments to blocks in http://snap.berkeley.edu/run, in the main scripting area. Then if you move the block the comment follows.
Enjoy!


Jens Mönig

Offline

 

#6373 2012-12-10 10:30:05

technoboy10
Scratcher
Registered: 2007-08-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens wrote:

Hi technoboy10, I've just gotten a new iPad mini myself and I'm delighted how well Snap! works on it! I'll look into improving text input gradually, right mow you have to explicitly turn caps on and off, and tap on the character where you want the caret to be. If you zoom the entire window make sure to use two fingers for scrolling. Cheers!

Ok, thanks.  smile


So long, 1.4.
http://goo.gl/3JEV9

Offline

 

#6374 2012-12-11 16:49:08

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

I don't know if that is worth of interest or not ? I've installed on a Windows XP PC a server , xampp, which allows to use Snap! locally. It works pretty well, better with Firefox than Chrome. Snap! projects can be loaded and saved as usual.

Offline

 

#6375 2012-12-11 19:25:37

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

Re: BYOB 3 - Discussion Thread

xly wrote:

I don't know if that is worth of interest or not ? I've installed on a Windows XP PC a server , xampp, which allows to use Snap! locally. It works pretty well, better with Firefox than Chrome. Snap! projects can be loaded and saved as usual.

Yes, that's awesome!  Does that mean you keep a local copy of the Snap! source code, or does it automatically download the latest version when you have net access?

(It's especially awesome because it's platform-independent!)


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

Offline

 

Board footer