Monadic minus vs. NEG OF

if you make some code using that option as the negation function, and someone uses MAPs your code on a list, it will not work correctly.

That’s their problem. Plus, if they understood how empty slots are treated in map, then they would know to fix the code.

now you’re being a bit rude. a beginner may need help, it shouldnt be their problem. bh has a point I think about trying to make your code so readable that you don’t even need to comment it. Adding the number “0” is not that hard, and it may just help someone who needs it.

All y’all are answering the question “how should a Snap! user work around the empty-slot ambiguity?”

I’m asking a different question: “How should the Snap! developers (which really means just Jens for something like this) fix the ambiguity altogether?”

It’s easy! Just make :snap: automatically put zeros are defaults in these blocks!

for () * () , () ÷ () , and () Λ () ::operators reporter, the default should be 1.

It is always a bit of a mouthful for my brain, so I often use [neg V] of () or just don’t say what I’m doing out loud in my head.

Better yet, make it use each function’s identity (of course, the dyadic operators only have an identity for their second slot, their first slot’s default is kind of arbitrary):

When a beginner learns about hofs, they’ll learn how snap fills in empty slots. They also will know that if you do 0-5, you get -5 (it’s basic math that you learn very early). Yes, it’s not hard, but it’s not necessary unless you’re using hofs (which is what owless said). If you’re not writing code that’s meant to be in an hof, why put in a 0?

The way I see empty slots, is the absence of a value, which in math, is 0.

untitled script pic

I think I might be crazy. I’ve always been doing this.

no, that’s perfectly good.

which in math, is 0

Zero is a perfectly good value! In arithmetic the idea of “the absence of a value” doesn’t really come up, except in the context of 0/0, which is emphatically different from 0. So in computer programming we represent that as NaN. And, as several people have remarked, it’s only addition that has 0 as the identity element, which is another sense of “no value”; for multiplication it’s 1. In more advanced math topics, such as formal language theory, when they need a representation for “no value” they use something like 𝜑, not 0.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.