dwitter icon indicating copy to clipboard operation
dwitter copied to clipboard

Inject more Math functions

Open naughton opened this issue 7 years ago • 9 comments

Would be more interesting if we had more Math functions injected...

var A = Math.abs;
var S = Math.sqrt;
var G = Math.sign;
var r = Math.random;

and maybe even:

var d = x.drawRect

and

var F = (s) => x.fillStyle = s;

naughton avatar Feb 20 '17 07:02 naughton

Seconding Math.random and fillRect especially.

bakkot avatar Feb 20 '17 08:02 bakkot

implemented this in PR #98 A = Math.abs G = Math.sign Q = Math.sqrt; D = (scale=1) => Math.random() * scale // D for "dice"? B = (x,y,w,h) => x.fillRect(x,y,w,h) // B for "box"? P = (x,y) => x.fillRect(x,y,1,1) // P for "point"? F = (s) => x.fillStyle = s

naughton avatar Feb 20 '17 10:02 naughton

Thanks a lot for the pull request! This has been discussed a few times, and it is quite tempting, but I'm a bit hesitant as it will diverge even more from normal js and it's effectively the same as increasing the character count. To be fair the "purity" is already broken by S, C etc. So I'm open to a discussion

lionleaf avatar Feb 20 '17 12:02 lionleaf

One of the ideas in the beginning was that it would force you to examine the docs to find seldom-used properties to exploit, so that it also doubled as a learning tool for the APIs.

sigvef avatar Feb 20 '17 17:02 sigvef

And in that case, maybe more math constants with single greek letter variable names, e.g.: π = Math.PI τ = Math.PI * 2

johanberonius avatar Feb 23 '17 20:02 johanberonius

Using 7 instead of Math.PI * 2 often works quite well :P Using Unicode letter names is cool though. Maybe a bit tricky to type?

sigvef avatar Feb 24 '17 00:02 sigvef

At first, I had many functions I would also like added. xx+yy, xx-yy, 2xy, etc.

But after consideration, I am against adding anything. The beauty is in the simplicity. Let it be simple. If people want complexity there is Processing and WebGL and three.js and many other find and wonderful complex systems.

The slippery slope is that you end up creating a code golfing 'esolang' like Jelly or V where programs are things like ":sil!î¬61énÀxVp" and "1;r2ị$¥/CỊ¡o”N" . http://codegolf.stackexchange.com/questions/111041/motorcycle-gear-checker .... nobody can read these programs so it makes 'remixes' more difficult. Imagine, if you will, a site like dwitter where you enter x86 machine code instead of javascript programs - does that sound more fun or less fun? To me it sounds less fun. Not many people can hop in and play around with x86 machine code, but even a high school kid can easily jump in and twiddle with the simple stuff like sine and cos and for loops. The accessibility is a feature that is lost by adding more complexity.

Also instead of working on the site, the admin will wind up being moderator on the never-ending debates about which programming functions are worthy of inclusion and which symbol should be used to represent them. The admin will wind up being a language maintainer instead of a site maintainer.

This is my opinion, thanks for reading. Didn't mean to hurt anyone's feelings.


I have one caveat.

If there could be a function OEIS() which will generate successive terms of any given Online Encyclopedia of Integer Sequence, from http://www.oeis.org , for example OEIS("A000045") could return successive items in the fibonacci sequence, each time it is called, then I would support that function.

donbright avatar Feb 24 '17 01:02 donbright

donbright hit the nail on the head here.

Current policy will be: No new shortcuts will be added to the "language" at this point

One can argue that this isn't consistent with the S,C,T etc shortcuts, and you'd be right. They were there from the start at arkt.is/t and by now they've become part of the "dwitter" language.

I would also agree that it would be fun to add more features to the language and see what people can make. A suggestion for how to potentially do this in the future would be to version the language into "core", "hardcore" and "pure" where "core" is the current language, "hardcore" is a more esoteric-looking language full of shortcuts, and "pure" removes even the S, C, T, R shortcuts. As long as the default landing site is one of the more readable ones I think that might work well. However, there is still a lot of innovation within the current limitations of a dweet and I'd like to focus efforts elsewhere.

lionleaf avatar Feb 25 '17 13:02 lionleaf

The only one I would suggest adding would be R.valueOf = Math.random :pizza:

qm3ster avatar Mar 05 '19 16:03 qm3ster