Show newer

re: shouting 

@aescling @vaporeon_ the python syntax forces a new variable to be added to the current scope, something the javascript IIFEs do not do

there is no need to perfectly replicate javascript IIFE behavior because it is impossible

re: shouting 

@aescling @vaporeon_ what is wrong with having an iife that is a procedure can use again?

re: shouting 

@aescling @vaporeon_ personally what i would do is

def iife(func):
func()
return func

@iife
my_func():
print('my_func')

So that the original function still exists

re: shouting 

@aescling @vaporeon_ whatever the return value of the decorator is becomes the value of the function you decorated

re: shouting 

@aescling @vaporeon_ oh because it's calling _some_iffe

the pattern

my_func = decorator(my_func)

where you replace a function with a the return value of another function, is equivalent to

@decorator
def my_func():
print('my_func')

So we could define an decorator iife:

def iife(x):
x()

And use it like so:

@iife
def my_func():
print('my_func')

This is fully equivalent to the disgusting evil hack you just shared.

re: shouting 

@aescling @vaporeon_ why are there parenthesis after @lambda _:_()?

re: JavaScript 

@vaporeon_ the vaporeon will always have C brain (sea brain?)

@vaporeon_ also node, npm, eslint, typescript, the horrible tendency to recklessly add large numbers of tiny packages to projects instead of copy-pasting simple code, and transpilation

also eval, the Function constructor, var hoisting, function hoisting

re: JavaScript 

@vaporeon_ it's a neat little syntax that languages have been introducing lately to make string interpolation simpler.

Instead of String(x) + "-" + String(y) you do ${x}-{y} (I can't figure out how to add the surrounding backticks in markdown so just pretend they are there)

Python has a similar thing called "fstrings". In python it would look like f"{x}-{y}"

There are some interesting other features of the backtick strings in JavaScript that I don't use that I won't describe here.

every time i try to make :vaporeon:​ think c++ is bad and javascript is good the opposite happens lmao

re: shouting 

@vaporeon_ IT'S BEAUTIFUL 🥹

/**
* @param {character[][]} grid
* @return {number}
*/
var numIslands = function(grid) {
const seen = new Set;
const R = grid.length, C = grid[0].length;

let count = 0;
for (let x = 0; x < R; ++x)
for (let y = 0; y < C; ++y)
if (!seen.has(`${x}-${y}`) && grid[x][y] === '1')
(function crawl(grid, x, y, seen) {
if (x < 0 || x >= R || y < 0 || y >= C) return;

const key = `${x}-${y}`;
if (seen.has(key)) return;
seen.add(key);

if (grid[x][y] === '0') return;

crawl(grid, x + 1, y, seen);
crawl(grid, x, y + 1, seen);
crawl(grid, x - 1, y, seen);
crawl(grid, x, y - 1, seen);
})(grid, x, y, seen), count++;

return count;
};

re: shouting 

@vaporeon_ a special javascript syntax that lets you declare and execute a function simultaneously :DDDDD

shouting 

RECURSIVE IIFE SOLUTION :DDDDD

@vaporeon_ It suddenly occurs to me that I, too, do not understand how refrigerators work

Show older
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.