alright have the world's worst static site generator

here's the finished version. i ended up making it work slightly differently than in this screenshot

Show thread

@jordyd @djsumdog i guess if you have a really broad definition of a lisp

@djsumdog arrays *and subscripts*!

(it doesn't actually matter what they are, the code just has to compile without syntax errors and then i can replace the code in the method on class construction)

@djsumdog @xnx38h omg I just realized what you're doing, those arrays are just indexing further and further down into a virtual tree!

Evil. I like it.

@clacke @djsumdog so

- the ellipsis doesn't mean anything. it's a python object that has some purpose in math libraries i think. it's here just for the purpose of marking code to parse and turn into HTML

- those aren't lists (well actually one of them is - the [html] one) the rest are subscripts, like what you would use when you want to get the item of a list at a certain index.

@clacke @djsumdog

- of course, python lists of nonexistent objects don't let you subscript them with random objects 10 times in a row, so if you ran this normally it wouldn't run. but in PageMeta i am replacing the render method with a version that converts the weird syntax into a string filled with HTML.

@clacke @djsumdog

this happens on class construction (not initialization!) and before the method even runs. this works as long as the code runs long enough to get to the point where the code is replaced, which it does because the method hasn't run yet when the object is being constructed. all that needs to happen is for the code in the method to not have any syntax errors, otherwise none of the program will run.

@xnx38h @djsumdog Wait, so the metaclass can transform the AST of the method? When the code runs it doesn't actually look like that?

I need to learn more about metaclasses, clearly.

But I guess as long as something in the metaclass runs after class definition, it can always transform the class any way it likes, it's just data. As you said, as long as it compiles, but that's true of any Python code.

@clacke @djsumdog yeah so if you override the __new__ method in the metaclass it will give you the class name, superclasses, and dict (dict being a dictionary of all class bars including methods). you can then find the method in the dict and then replace it before sending it to the metaclass's superclass (usually `type`)

@xnx38h @djsumdog Yeah, I should have said "array-looking things" to be clear.

@LogicalDash huh, never heard of that before. but nah this is worse

@xnx38h This reminds me of really old stuff in Perl, you could nest formatting functions:

print p( ul( "one", "two", p("three is a paragraph") ) ); # etc

Code-soup hell, but it made writing stuff from the DB into a web 1.0 looking page simple.

@unlofl that's pretty similar to the actual way you write layouts in Flutter

@xnx38h Huh, never used Flutter, is it just for layout/UI elements?

The Perl thing was a decent idea compared, it's just not better than using a templating language/markup, and backend devs love to yeet that stuff out of their codebase. Ah, the old times, when we double escaped html being written by javascript that was generated by CGI... *gag*

@unlofl flutter is a mobile app development package. you write the layouts in with the rest of the code though. think android XML tags but they're all Dart object constructor calls

@xnx38h Fortunately/unfortunately, I've never done mobile development. But I think I get the idea, I've seen other systems for "E-Z layout design, then just attach your event handlers."

@xnx38h Yeah, curious, and that certainly seems readable.

But I've just gone from Perl to Python, so white-space sensitive and still using semi-colons is blowing my mind.

@unlofl it's not whitespace sensitive, that's just the C-style single line block thingy

@unlofl also semicolons might actually be optional i don't remember

@xnx38h I hate it so much I'd actually like to use it so bad!

@xnx38h the worst static site generator: just writing html

html is a great language to write websites in because it compiles seamlessly to web native code

@xnx38h way to include a floating point error in there, any particular reason?

@bulkington i wanted to show off the fact that it was running python without having to access any local variables (because with the lazy way i'm doing it, i am evaluating everything surrounded by brackets in an empty namespace (there's no way to access the actual method namespace i think) and if it errors i convert it into an html tag)

@xnx38h if you get nasty with dunder variables, python functions can access the namespace of the calling context, but unless you’re writing a debugger, it is probably best not to.

@bulkington oh really? didn't know that, but it still wouldn't be able to access the variables that require parts of the function executing first

@bulkington i could interpolate the expressions into string literals, which would be the rational way of doing it, but then there would be no way of telling the HTML tags from the rest and i would have to come up with a less stupid syntax

@xnx38h thanks! sorry i hadn't seen that. tbh my head is spinning a bit, that's pretty incredible

@xnx38h You just reinvented the Elm's Html package! In python!!!!

Sign in to participate in the conversation

cybrespace: the social hub of the information superhighway jack in to the mastodon fediverse today and surf the dataflow through our cybrepunk, slightly glitchy web portal support us on patreon or liberapay!