Discuss Scratch
- Discussion Forums
- » Suggestions
- » A little sugar for Recursion,hashmaps Maybe?
- fanofcena
-
12 posts
A little sugar for Recursion,hashmaps Maybe?
I was trying to build a recursive noise today… The first thing i stuck upon was recursion, usually i would just called a seed function recursively on the dataset to compute the output, which isn't looking as a case so far since there is no block level scope of variables except for those which are initialized with the block call, can we change them ? :-( , so am i missing something , is there any way to implement function level scope // i really dont see a point in emulating a callstack… which would be fun but …. seriously there is no point!
Other then that since we have had 1d Arrays forever, why cant we have “hashmaps” ? Basic keyvalue pairs , those who are familiar with other langauges will get this. And hashmaps are usually simple to understand aswell :-)
Other then that since we have had 1d Arrays forever, why cant we have “hashmaps” ? Basic keyvalue pairs , those who are familiar with other langauges will get this. And hashmaps are usually simple to understand aswell :-)

- SuperJedi224
-
100+ posts
A little sugar for Recursion,hashmaps Maybe?
I understand what you mean, but JS calls them objects.
- fanofcena
-
12 posts
A little sugar for Recursion,hashmaps Maybe?
All objects in javascript are mere hashmaps ^^, // read the v8 source code and the specs and this hashmap possiblity allows javascript to have a kind of polymorphic behavior using the this pointer, for example I understand what you mean, but JS calls them objects.
ob1 = {
a:10,
val:2
};
obj2 = {
b:20,
c:4
};
function addAllNumericalValues(){
sum = 0;
for( x in this ){
if( typeof(this) === "number" ){
sum += this;
}
}
return sum;
}
ob1.add = addAllNumericalValues;
obj2.add = addAllNumericalValues;
console.log(ob1.add(),obj2.add()); //12 , 24
but thats a different story, hashmaps can actually allow a lot more then current lists, efficiently and could be a help for creating dynamic programs on scratch

Last edited by fanofcena (June 17, 2013 04:18:51)
- quadrupleslap
-
26 posts
A little sugar for Recursion,hashmaps Maybe?
Support, although how would they implement the syntax without making Scratch ultra scary for newcomers? And, at least to me, hashmaps in Scratch would seem as unwieldy as hashmaps in LISP-2.
<rant>
P.S. @SuperJedi224
For maps, ES6 actually plans to introduce Maps, which are actual hashmaps. So far, the object is inferior in the following ways:
- They can only accept string keys.
- They have prototypes and thus, using the literal syntax, at least the Object.prototype as a fallback. This can cause a lot of stupid mistakes.
- In an object it's really annoying to check the length. In a Map you can just use the length member.
- More reliable performance across browsers.
- For what it's worth, the insertion order is preserved when iterating a Map.
So yeah, the JS equivalent of a hashmap is a Map, not an Object. The only problem is that lots of browsers heven't implemented Maps yet, and everyone has been using Objects in the meantime. xD
</rant>
<rant>
P.S. @SuperJedi224
For maps, ES6 actually plans to introduce Maps, which are actual hashmaps. So far, the object is inferior in the following ways:
- They can only accept string keys.
- They have prototypes and thus, using the literal syntax, at least the Object.prototype as a fallback. This can cause a lot of stupid mistakes.
- In an object it's really annoying to check the length. In a Map you can just use the length member.
- More reliable performance across browsers.
- For what it's worth, the insertion order is preserved when iterating a Map.
So yeah, the JS equivalent of a hashmap is a Map, not an Object. The only problem is that lots of browsers heven't implemented Maps yet, and everyone has been using Objects in the meantime. xD
</rant>
- Discussion Forums
- » Suggestions
-
» A little sugar for Recursion,hashmaps Maybe?