Objects in Snap (without js...)

Snap! isn't supposed to be a GUI for Javascript. It's its own language.

Because JS is meant to support arbitrary web pages, it's pretty complicated, not in the core language, but in the libraries and object classes (which they confusingly call prototypes). We don't want to mirror all that complexity; we want Snap! to be easy for beginners. So we have a simplified graphics metaphor (stage and sprites) and all the JS hair is behind the scenes. To take your example, we don't want users to know that there's a Color class. We want them to be able to use a color picker to set the color, and learn more only if they really have to. (Crayons are an attempt to take a baby step toward more programmatic control of colors.)

If you need to do something that JS provides and we don't, feel free to use JS Function. If you think it'd be useful to others, submit a library for consideration. (I guess the right way to do this is in a PR?)

I'm not thinking about new types as much as I am variadic infix inputs.

i must be crazy for actually wanting to learn about these things

and its not about javascript specifically, that just happens to be what snap is programmed in my eyes but the actual structure of it, the "this should do that because of ... etc. etc..." is what snap is trying to do isnt it? i just know that level of complexity could be represented in such an intuitive way it would seem almost trivial,,

i would like my bigger projects to run smoothly. i cant do anything too complicated or else it will slow down too much. its quite disappointing

thats blocks, i mean if you just let multi inputs carry custom blocks then you can do any input you want. kinda like the idea behind a list of lists makes a table, of which could be contained in a cell holding a list of tables, which are tables of lists,, just more things should be able to fit together that way (imo. like legos. to the point where its hard to find peices that dont connect

What if you have variables sing, Ming, ding, ring, walking, talking, reading, etc.?

Right, but that would be an unusual coincidence, whereas foo1, foo2 is a commonplace.

No, not at all, I'm a programming languages person too; I just don't want to inflict my hobby on everyone.

I'm not sure what you mean by this. "What snap is trying to do" is a complicated question. Probably 90% of Snap! projects could run unchanged in Scratch, and indeed it's because of the ease of entry that we built and use Snap! instead of Scheme (as in Berkeley's previous non-major intro CS course). But another answer to what we're trying to do is recursion and higher order functions, the big CS ideas that we want to be more generally accessible. Your answer, provide an accessible entry point into how things worth below the surface, if I'm understanding you correctly, is a respectable answer but not at the top of our minds.

Interesting metaphor. What I thought of first was the multi-branch conditionals library, the poster child for variadic input groups.

What if you're making a dictionary (common sense of the word)? Then you'd have that kind of thing popping up all over the place!

Then you're going to end up with a lot of collisions no matter what hash function you use.

Homonyms? Just add an identifying number, like my dictionary. (the New Oxford American Dictionary)

No, I'm just thinking that with a huge collection of words, there will be lots of similar subsets of the words, same prefix or same suffix. And remember that the beginning of this subthread is a discussion of wjy you don't just hash on the first three or last three letters, but instead try to write a hash function in which every letter contributes equally to the result. (This is also why you pick a prime number as the size of the hash table, so the MOD operation doesn't push similar words into the same bucket by making every bit count equally.) (That's actually a lie, because if you're an English speaker then the first three bits of the Unicode value are the same for all letters, so you write a function that emphasizes the last five bits of each byte.)

"don't", "can't", etc. The apostrophe is 00100111.

Sure. But if you treat apostrophes as if they were G (the seventh letter of the alphabet) you just get collisions with the nonexistent words "dongt," "cangt," etc. Anyway I said "emphasizes," not "is limited to." (The actual algorithm I have in mind left rotates the total so far left by five bits before adding the new byte.)

More generally, you don't have to have a perfect hash algorithm. (That's a real thing; you can make one if you have a big enough table and do a lot of arithmetic.) You just have to have a pretty good one (not a technical term :~) ) so that you don't have a lot of collisions. You run your algorithm on some sample data, then look at the sizes of the buckets. If the largest size is pretty small, your hash function is okay.

I just made the Node from morphic.js in Snap! using my own version of this library.

https://snap.berkeley.edu/snap/snap.html#present:Username=wdstudios_llc121&ProjectName=OOP%202

I think you COULD translate JavaScript classes to Snap!.

nice work, a lot of effort for a case study! I like how you dive into trying to port ideas from other languages over to Snap, like dot-notation syntax and dictionaries.

thank you!!! and you as well (nice work),

are you familiar with logic gates? this is what im currently working on

screenshot(1)

just got basic camera movement and gate/wire creation via script but im shooting for a full ui and circuit simulation, maybe even integrated components, i just hope i can keep it running smoothly.

i picked up on your list => input technique (like representing x y coords as a single var untitled script pic(75)) i keep trying it on different blocks, i hope youre planning on expanding! i thought i was being pretty clever here,
untitled script pic(76)

...oh well. you could make it so the list inputs imitate the slot its in

menu(2)

1 last thing, please fix this:

Screen Shot 2022-05-19 at 9.57.36 PM

it replaces the entire script and the only way i know around it is setting the slot to one of the static types

Cool! Does it optimize gate placement (for planarness, short wires)?

(I looked at those gates on the right with mutual inputs to each other and thought "oh it's a flip-flop" but I'm too lazy to work out which flavor.)

(I wonder if you could write a program to take a Snap! predicate function and convert it to a gate diagram? I mean, I'm sure it's theoretically possible, but is it practical for more than two or three inputs? Conversely, can you convert that flip flop into a Snap! predicate? It'd have to be a recursive one, I guess. Or, no, it just needs names for each individual gate.

that's a feature we use to teach building your own recursive control structures, which is one of the powerful ideas Snap! aims to spread. Please don't use vocabulary like "fix" on me when referring to such features, just because your particular usage finds them inconvenient. Aside from heavy hinting that y'all can read and understand my JavaScript code ("setting the slot to static types") It's what makes hanging out in these forums particularly unpleasant for me.

i meant no disrespect. god. and you should take it as a compliment you know, I think it's incredibly impressive to have written such a wonderful app in the browser, and I just happen to know some javascript. it's only natural that I dig in a little to you (open source) source code. I could have spoke in all technical jargon but I at least had the decency to avoid it since I know you don't want to scare people off or whatever.

but really, please, tell me, why does it bother you? I honestly didn't mean to offend you but clearly ive struck a nerve.

ps. I said fix because I thought it was a bug that your entire script disappears when trying to put a reporter in one of the slots. I'm thinking about other users trying to do this and losing their work. (and the undo button is broken too but im starting to get tired of mentioning (supposed) bugs just to get snapped at.)

If I could offer some advice :slight_smile:

You've offended a few people in the short time you've been on the forum.

Obviously, you are a very talented programmer but equally obviously, your not the most tactful of people when in comes to the phrases you use in your posts.

Snap! is designed as an educational learning tool and there is a great preference for that to be the focus of discussions here and not what goes on in the engine room beneath :slight_smile:

Hopefully you'll take this as friendly advice going forward :slight_smile:

not as much as id like. what is planarness? ive never heard that.

if youre intersted

just the nor gates make an sr-latch, the and gates act as enable input, and tying together the set and reset inputs with one of them inverted (like I did above), makes it a d-latch. so you have a data input, and a write enable input.

for it to be a flip flop thered have to be a clock signal and rising/falling edge detection (which would be really cool!!!) thats called seqential logic but first i need to get combinational logic down first.

which, according to wikipedia,

combinational logic is a type of digital logic which is implemented by Boolean circuits, where the output is a pure function of the present input only.

seqential logic is a type of logic circuit whose output depends not only on the present value of its input signals but on the sequence of past inputs, the input history as well.

so until then i can call them functions :stuck_out_tongue:

I'm glad you recognized that though, I find this stuff fascinating, most people seem to think it's boring but oh well.

snap conversion would be tricky, ive tried before, but no dice. more wikipedia:

Consider, for example, a two-input AND gate fed with the following logic:

output = A ∧ A̅

A logic signal A on one input and its negation, ¬ A, on another input in theory never output a true value: A ∧ A̅ ≠ 1. If, however, changes in the value of A take longer to propagate to the second input than the first when A changes from false to true then a brief period will ensue during which both inputs are true, and so the gate's output will also be true.[2]

Interesting! (I almost wrote "Interessant" there.)