#esoteric-python

1 messages · Page 61 of 1

frosty wyvern
#

I guess its aimed to people who already misuse them

#

I'm looking at it with the wrong mindset

fallen heath
#

He didn't show any hard to read convoluted lambdas

frosty wyvern
#

yeah cough cough @brisk zenith

#

jk thats just his shtick

fallen heath
#

like the rpn ones

frosty wyvern
#

:D

novel vine
#

Ty for merge based @frosty wyvern

frosty wyvern
#

You're welcome my child

sick hound
#
execute = lambda b,i=0,line='':(execute(b,b[i+1],line) if b[i]==1 else execute(b,i+2,line)if b[i]==2 else execute(b[128:],i+2,line)if b[i]==3 else(lambda l:execute(b[:b[i+1]]+l[0].encode()+b[b[i+1]+1:],i+2,l[1:]))(line if line else input()+'\n')if b[i]==4 else execute(b[:b[i+1]]+bytes([b[i+2]])+b[b[i+1]+1:],i+3,line)if b[i]==5 else 1/0 if b[i]else(print(chr(b[i+1]),end=''),execute(b,i+2,line))```
frosty wyvern
#

Hello my esoteric children

sick hound
#

an esoteric bytecode-ish language

#

b'\1\4\0\0\4\3\1\2' is a cat program

#

every operator has one operand except for 5 which has two

#

0 outputs the operand as an ascii character
1 jumps to the operand (starting from 0)
2 does nothing
3 deletes the first 128 bytes of the program and is the only way to jump to parts of the program more than 255 bytes
4 takes input (one character) and writes it to the program at the operand (starting from 0)
5 writes the second operand to the first (starting from 0)

#

the program's only memory is the program itself, with only 256 addressable bytes

#

the cat program writes its input to the operand of the output instruction and then executes the output instruction

stray needleBOT
sick hound
#

my first contribution on gitlab is an esoteric language :)

cunning wave
#

the current challenge is an esoteric language?

frosty wyvern
#

Yes

#

But it doesnt have to be esoteric

#

Just read the challenge : )

cunning wave
#

pft

#

reading

sick hound
#

Task: Create and(or) implement an esoteric language of your own!

frosty wyvern
#

But yeah, the task is about esoteric languages but some people like @vague gust actually created an almost real normal language

vague gust
#

I haven't added quite a few crucial things yet but hey it sorta works

#

and I will submit a MR soon

cunning wave
#
class KInterpreter:
    stack = []
    def eval(self, code):
        for char in code.split("k?")[1:]:
            if char == "+":
                self.stack.append(self.stack.pop() + self.stack.pop())
            elif char == "-":
                self.stack.append(self.stack.pop() - self.stack.pop())
            else:
                self.stack.append(ord(char))
        while len(self.stack) > 0:
            print(self.stack.pop())

interpreter = KInterpreter()
interpreter.eval("k?ak?bk?+")

good enough? @frosty wyvern

#

esoteric enough?

vague gust
#

huh nice

#

that is rancid

#

good esoteric

cunning wave
#

so i guess ill mr this

vague gust
#

I wrote 800 lines :^)

frosty wyvern
#

loool

cunning wave
#

lol to what

#

thanks eh gitlab

vague gust
#

NICE

cunning wave
#

ikr

vague gust
#

taking a trip back to web 2.0

cunning wave
#

oh no i gotta fork it

#

ew

frosty wyvern
#

let's fork the internet

#

Internet 2

cunning wave
#

ill add an increment with kk?

vague gust
#

hey nix

cunning wave
#

yeah

vague gust
#

how do you say hello world in your language

cunning wave
#

i dont

#

lol

vague gust
#

see with sef we can do

#
def main() do
    print("Hello world!")
end
cunning wave
#

i came up with this in like 2 minutes joseph

vague gust
#

😄

cunning wave
#
class KInterpreter:
    stack = []
    def eval(self, code):
        skip_next = False
        for char in code.split("k?")[1:]:
            if skip_next:
                skip_next = False
                continue
            if char == "+":
                self.stack.append(self.stack.pop() + self.stack.pop())
            elif char == "-":
                self.stack.append(self.stack.pop() - self.stack.pop())
            elif char == "k":
                self.stack.append(self.stack.pop() + 1)
                skip_next=True
            else:
                self.stack.append(ord(char))
        while len(self.stack) > 0:
            print(self.stack.pop())

interpreter = KInterpreter()
interpreter.eval("k?ak?bk?+k?ak?bk?+k?kk?k?a")
#

what a beauty

frosty wyvern
#

k

#

my language has the nicest syntax

pure dew
#

not quite so esoteric if you swap k? for spaces

#

@frosty wyvern nah tbh i think mine does

frosty wyvern
#

oh you have the weird lispy thing right

pure dew
#

lisp? its lambda calculus

#

it is pretty similar tho

frosty wyvern
#

oh its just pure lambda calculus

#

show

#

: )

pure dew
#

no its applied lambda calculus

frosty wyvern
#

so haskell

pure dew
#

uh

#

pure lc doesnt have numbers or any kind of operators

frosty wyvern
#

i didnt mean pure in any formal sense

pure dew
#

applied adds + - * /, numbers, logical operators, and the ability to bind abstractions to names

#

oh

#

yea, its just lambda calculus

frosty wyvern
#

sweet

#

did you submit it yet

pure dew
#

lolno

frosty wyvern
#

:(

pure dew
#

ill show an example when i fix the alpha reducer

#

i got beta reduction done and realized i didnt do alpha reduction correctly

#

i posted this earlier

#
py-lci> λabcdef.(a b) (c d) (e f)
(λa.(λb.(λc.(λd.(λe.(λf.(((a b) (c d)) (e f))))))))
fallen heath
#

Will not be able to complete it this weekend sadly

frosty wyvern
#

oh god

#

it's beautiful

fallen heath
#

I guess that makes sense tbh

#

It takes in garbage, randomises it and outputs garbage

frosty wyvern
#

LOOOL

pure dew
#

uh

frosty wyvern
pure dew
#

that is offensive

frosty wyvern
#

lmaooo

pure dew
#

its left associative

fallen heath
#

In my language all values go in a double ended queue that only accepts unique values and for execution of functions parameters are taken from alternating ends of the queue

frosty wyvern
#

I wanna make a new language already

#

Though if I ever do make another language

#

I'll write a formal grammar

#

and probably look into that python yacc binding or whatever

pure dew
#

nono

frosty wyvern
#

and also use proper ASTs or whatever

pure dew
#

use Lark

frosty wyvern
#

my interpreter is absolutely crap hacked together

pure dew
#

its fast

fallen heath
#

I really dislike yaccs style

#

You define variables in the files namespace and then yacc finds those and uses them

cunning wave
#

hmmm

#

i should do jumps

#

yeah

pure dew
#

Lark (using LALR) is the fastest and lightest on memory out of many common python grammar parser libraries

frosty wyvern
#

Perhaps next I should just work on implementing a very simple language "VM" runtime

#

with bytecode

#

instead of bothering writing grammars and parsing an actual language

#

frig it

#

people can write bytecode

cunning wave
#

should a language be able to edit its own opcodes at runtime?

#

it should?

#

right?

frosty wyvern
#

Uh

#

I mean

#

it doesnt have to

#

what do you mean exactly

cunning wave
#

well atm i have a list of opcodes

#

an now i can jump around that list

#

so in theory i could have an opcode deleting opcodes from the list

frosty wyvern
#

Yeah, I mean I guess that falls into like.. metaprogramming

#

where the program modifies itself

pure dew
#

metaprogramming is good

#

@cunning wave do it

cunning wave
#

k

#

bk?ak?-k?jk?

ITS AN ENDLESS LOOP

cunning wave
#

hk?>k?ek?>k?lk?>k?lk?>k?ok?>k?bk?lk?-k?>k?
@vague gust i taught it to say hello

vague gust
#

nice

arctic bridge
frosty wyvern
#

it interprets the jvm?

#

thats a dumb name

arctic bridge
#

python-jvm-interpreter is an implementation of the Java Virtual Machine in Python. It works by parsing and interpreting the Java Class files.

#

Yeah, should've been python-jvm or something

fallen heath
#

pvm

arctic bridge
#

:p

cunning wave
#

aight @pure dew self modifying code working whats next

pure dew
#

@cunning wave speculative self modification

cunning wave
#

huh?

pure dew
#

is easiest with bytecode

#

Speculative execution is the normal term

#

For every condional or jump, predict the result of the conditional or the location of the jump

fallen heath
#

Ah, introduce spectre into your language

cunning wave
#

there are no conditional jumps yet though

#

there are just jmps

pure dew
#

start executing (in a new thread maybe) the instructions as a result of that condtional or at that jump. If the actual cond/jump doesnt equal the predicted one, toss out the computed result or kill the thread

#

then add conditional jumps

#

@cunning wave or just randomly decide whether to execute a random instruction every cycle

cunning wave
#

that feels like it could break the program pretty easily

pure dew
#

it may execute the given one, or it'll pull an instruction outta its ass

#

it could

cunning wave
#

ok

#

skni can do conditional jumps now

pure dew
#

skni?

cunning wave
#

skip next if

pure dew
#

uh lol

cunning wave
#

it pops a value from the stack and if its not 0 skips the next instruction

pure dew
#

does that do what it sounds like it does?

#

nice

stray needleBOT
pure dew
#

@cunning wave split() splits by spaces, not individual characters

#

just fyi

cunning wave
#

hm?

pure dew
#

"asd".split() will yield "asd"

#

it splits on spaces

cunning wave
#

first
itll return ["asd"]
2nd if i pass a custom string to it itll split on that custom string

#

oh you mean that input split

#

its meant to do
a b c d e f g

pure dew
#

well, ye, it returns a list

cunning wave
#

so you can like

#

enter a new stack

#

yknow?

pure dew
#

but if they enter a b cd e f by mistake, itll crash

cunning wave
#

and if you do
kkk? itll crash too

#

¯_(ツ)_/¯

pure dew
#

cool

#

just making sure you know

frosty wyvern
#

oooo MRs

#

Seeing MRs gets me hot and bothered

stray needleBOT
frosty wyvern
#

Looks cool guys! Good job paste for actually adding instructions with your solution :) cough cough Nix

#

can't wait to have a closer look in a bit

pure dew
#

i wrote docs instead of code today

arctic bridge
#

Good man

vague gust
#

I might just MR in a Markdown file with links to my GitHub repository

fallen heath
#

split() splits on string.whitespace

stray needleBOT
vague gust
#

okay, i'm about to submit my MR

brisk zenith
#

for?

stray needleBOT
vague gust
#

that

brisk zenith
#

fancy

brisk zenith
#

@unborn frost simple calculator in one statement, with input validation and whatnot. ```py
calculator = (lambda:
print("Answer:", (lambda get_input:
(lambda left, op, right:
(lambda func: func(left, right))(
func = {
"+": int.add,
"-": int.sub,
"/": int.truediv,
"*": int.mul
}[op]
)
)(
left = int(get_input(
str.isdigit,
"Enter an integer: "
)),

        op = get_input(
            lambda char: char in list("+-/*"),
            "Enter an operator [+-/*]: "
        ),
        
        right = int(get_input(
            str.isdigit,
            "Enter one more integer: "
        ))
    )
)(
    get_input = (lambda predicate, prompt: 
        (lambda itertools: 
            next(itertools.dropwhile(
                lambda string: not predicate(string),
                (input(prompt) for _ in itertools.count())
            ))
        )(
            itertools = __import__("itertools")
        )
    )
))

)

unborn frost
#

huh that's pretty neat

#

also lmao I forgot I could have just used a list to find the operand

#

operator?

brisk zenith
#

operator, yes

frosty wyvern
#

ashiet, MRs

#

gonna look at em in a sec

brisk zenith
#

as you can see there, i actually call the unbound magic methods for int there (cause importing operator is too mainstream)

frosty wyvern
#

Is everyone done with their submissio s

brisk zenith
#

no

#

@unborn frost as one line: ```py
calculator = (lambda: print("Answer:", (lambda get_input: (lambda left, op, right: (lambda func: func(left, right))(func = {"+": int.add, "-": int.sub, "/": int.truediv, "": int.mul}[op]))(left = int(get_input(str.isdigit, "Enter an integer: ")), op = get_input(lambda char: char in list("+-/"), "Enter an operator [+-/*]: "), right = int(get_input(str.isdigit, "Enter one more integer: "))))(get_input = (lambda predicate, prompt: (lambda itertools: next(itertools.dropwhile(lambda string: not predicate(string), (input(prompt) for _ in itertools.count()))))(itertools = import("itertools"))))))

unborn frost
#

one liners

brisk zenith
#

one statement > one line :^)

#

you get silly plebs who use ; and say it's one line yert

unborn frost
#

true

#

😠

#

plebs

pure dew
#

@brisk zenith now turn it into an expression

brisk zenith
#

4

#

let's just hope the answer is always 4.

pure dew
#

a lambda is technically an expression, is it not? So remove the assignment and just call it directly

brisk zenith
#

expressions can contain expressions

#

and if you want to make it an expression, you can assign with globals().__setitem__("calculator", lambda ...)

#

or locals().__setitem__(...) might be more accurate

pure dew
#

oh lol yes

brisk zenith
#

and yes, lambdas are expressions

#

but they may only contain one expression (the return value)

vague gust
#

@frosty wyvern mergey wergey :^)

pure dew
#

().__class__.__base__.__globals__.__setitem__("calculate", lambda ...) path to globals may not be correct

stray needleBOT
brisk zenith
#

that was dunderful

pure dew
#

theres some dunderful way to access modules without importing anything

brisk zenith
#

yeah i know

pure dew
#

we discussed it earlier for the challenge

vague gust
#
joseph@wubalubadubdub:~% cat lang.py
if input() == "4":
    print("hello world")
joseph@wubalubadubdub:~% echo 4 | python3.6 lang.py
hello world
brisk zenith
#

joseph used it in his .. yeah

vague gust
#

one expression done

frosty wyvern
#

This is fully educational and is full of bugs, I have no real intention of developing this past the current state it is at

#

LOL

#

I love your attitude

vague gust
#

lmao

#

i love my attitude as well

pure dew
#

wait until you see my magnificent "its just a simple challenge, ill fix it later" code

brisk zenith
#

actually

#

my code is better than what it was

#

it's split into like 6 files so far

pure dew
#

lol

#

mines one and a repl wrapper

brisk zenith
#

i'm actually trying to make my language relatively usable

pure dew
#

im actually gonna polish this and upload it to pypi later

frosty wyvern
#

Are you saying there is no market for a language that supports nondeterministic flow of operations such as mine and with no flow control?

pure dew
#

uh ye

frosty wyvern
#

and no functions

vague gust
#

mine is like 4 files iirc

brisk zenith
#

yes it is jos-b

pure dew
#

no flow control isnt a huge deal

brisk zenith
#

mine has control flow

#

but it doesn't have iteration. just recursion.

vague gust
#

ty kingdom5500

#

or something like that

#

i forget the name

brisk zenith
#

yeah

#

also how well-known is the raise ... from None syntax?

vague gust
#

I've seen it before but never used it

#

pretty cool though

brisk zenith
#
>>> try:
...     1/0
... except ZeroDivisionError:
...     raise ValueError
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ValueError
>>> 
>>> try:
...     1/0
... except ZeroDivisionError:
...     raise ValueError from None
... 
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ValueError
>>> 
vague gust
#

would be cool to be able to chain them though :^)

brisk zenith
#

haha

vague gust
brisk zenith
#

raise ValueError from ImportError from ...

fallen heath
#

What does the from None do

brisk zenith
#

look at the example c:

vague gust
#

stops it from tracing back past the immediate error

brisk zenith
#

yup

fallen heath
#

Ah

vague gust
#

if you don't do that it will find the other error (ZeroDivisionError in the example) and show that as well

fallen heath
#

One thing about pythons syntax that is still weird to me is the for else loop

vague gust
#

yeah I guess it's kinda weird but it does make sense

brisk zenith
#

there's while/else

fallen heath
#

Idk why but it just looks wrong to me

brisk zenith
#

i actually really like it

vague gust
#

there is no real way to describe what it does though

#

else is somewhat fitting

brisk zenith
#

so, there's
if/elif/.../elif/else
try/except/.../except/else/finally
while/else
for/else
i can't think of any more things like that

#

i mean, else is everywhere

pure dew
#

@vague gust just nest try catch blocks, raising from in each one

vague gust
#

hmmm

brisk zenith
#

make a script that generates the nested try/excepts given a string, each exception with a word from str.split()

vague gust
#

oh my god it works @pure dew

pure dew
#

uh ye

vague gust
#

lovely

pure dew
#

err

#

not quite my idea

vague gust
pure dew
#
try:
    raise Exception("She")
    
except Exception as e:
    try:
       raise Exception("Took") from e

    except Exception as e:
        try:
            ...
``` you get the idea
vague gust
#

no need to do the from though since it's auto-inferred in try/except

brisk zenith
#

joseph as i said you should make a program to create the nested try/except blocks :^)

pure dew
#

@vague gust true

vague gust
#

@brisk zenith bro i can't be bothered

#

I like type type typing

brisk zenith
#

i also like type(type(typing))

vague gust
#

fuck he's good

brisk zenith
#

now i'm curious, how does type(type) is type work?

#

like, how can type subclass itself yert

vague gust
#

interesting

brisk zenith
#

type(type)(type(type)) is type

vague gust
#
>>> type.__subclasses__(type(type))
[<class 'abc.ABCMeta'>, <class 'enum.EnumMeta'>]
brisk zenith
#

🤔

#
>>> type.__mro__
(<class 'type'>, <class 'object'>)
>>>  
pure dew
#

py-lci now (messily) handles free names colliding with bound names

(λx.(λy.xy) x) x -> (λa.(λy.ay) a) x

#

I spoke too soon, it only works in the outmost scope lmao

pine edge
#

i started working on a biological programming language

#

where dna is the main computing element, e.g. the computations are just whether or not strands of dna bond because they have complimentary base pairs or not

#

and i was thinking about what dna could actually do, computationally

#

"well, strands of dna can pattern match"

#

"it'd be really awful to read and write just a whole bunch of 1d pattern matching strings"

#

"and the syntax would be godawful, using GCAT exclusively"

#

and then i realized it was literally regular expressions

#

regular expressions are 1 dimensional pattern matchers using terrible syntax

#

regular expressions match complexity with a language i was specifically trying to make hard to use

pure dew
#

You can make a BF interpreter with regex too

brisk zenith
#

progress on my esolang is almost completed, i just need to polish up a bit

pure dew
#

i have to rewrite mine lmao rip

frosty wyvern
#

I'm glad people are mostly done their entries. I'll be putting up a new challenge probably by tomorrow. Of course, feel free to keep working on this challenge even after the new one is up

#

I am as always open to suggestions/ideas for the next challenge <3 so speak up

pure dew
#

oof

#

rip me

brisk zenith
#

my esolang so far

#

it just needs polishing a bit

#

i also need to rewrite some stuff

#

but yeah, the idea is that it's all valid python syntax, you've just gotta import the esolang and it'll work

sick hound
#

right now that's not valid syntax

#

I think

brisk zenith
#

oh it is

sick hound
#

...wat

brisk zenith
#

tfw you even confuse pastebean

#
PROGRAM [
    # this is the start of a slice now
    : # colons are a feature of slices, yes?
]```
sick hound
#

yes but why does it have 5 slices

#

separated by commas

brisk zenith
#

that's a thing

#

numpy uses that, actually.

#
>>> thing [:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'thing' is not defined
>>> 

you can have as many as you want

sick hound
#

wat

pure dew
#

how does should work tho

#

i cant see how thats valid syntax

brisk zenith
#

() basically 'calls' SHOULD

sick hound
#
>>> type('',(),{'__getitem__':lambda s,i:i})()[:,:]
(slice(None, None, None), slice(None, None, None))```
#

It's a tuple of slices

brisk zenith
#

yes

sick hound
#

because that's so readable and pythonic

#

why is that a thing

brisk zenith
#

look up how numpy uses it

pure dew
#

oh oh

#

its an index

brisk zenith
#

yes

pure dew
#

i was thinking lua-style function call

brisk zenith
#
>>> def function(_):
...     return [1, 2, 3]
... 
>>> function (1 > 2) [ 1 ]
2
>>> 

this is how it's syntactically valid

pure dew
#

yea

brisk zenith
#

i'm gonna continue working on it now

brisk zenith
#

i should add some more stuff to the core module

#

any ideas? got print/input/int/str/float, can't think of anything else it would really need

#

there's also stuff like empty_stack

vague gust
#

None?

brisk zenith
#

hmm good idea, i'll do that at some point

#

i've already got null as a dummy identifier

#

as in, you can assign (well, pop) to null and it'll automatically discard the value

#

so basically /dev/null

brisk zenith
#

i'm going to make a module for my esolang for super basic file operations

pure dew
#

Ayy so it works now

((λx.(λy.(x y))) y) -> ((λx.(λa.(x a))) y)
(1 substitutions)
#

and it respects free variables in the function body
((λx.((λy.(x y)) y)) y) -> ((λx.((λa.(x a)) y)) y)

teal rune
#

I am starting to regret creating this language

vague gust
#

lol

fallen heath
#

Python doesn't allow for emoji variable name pepe

vague gust
#

Swift allows that

#

It's quite fun

fallen heath
#

JS aswell

vague gust
#

of course js allows that

fallen heath
pure dew
#

use haskell

vague gust
#

use Elixir

fallen heath
#

Don't use drugs, stay in school

stray needleBOT
pure dew
#

nice

stray needleBOT
frosty wyvern
#

sorry for spammerino friends

teal rune
#

I see you like emojis

#

get ready for 🤔lang

#

where 💥🤓🤚🌀🤝😅😅🤧🤚🌀🤒💥🤨🤐🌀🤢🌀 is valid syntax

cunning wave
#

the annoying guy inside me who learned about formal languages today wants to criticise that sentence

stray needleBOT
frosty wyvern
#

New challenge will be up tonight, I was a bit busy creating some scripts to help generate the challenge files/implement some simple test cases

teal rune
#

cool

stray needleBOT
frosty wyvern
#

dabward Challenge 04 is here! dabward

This challenge is straight forward: Code golf a maze solver. Details are available in the repository: https://gitlab.com/python-discord/esoteric-python-challenges/tree/master/challenges/04-maze-solver-golf

A couple of notes:

  1. This challenge introduces our new simple test-case system. Instructions on how to use it are available in the README in the root directory of the repository! This should help with ambiguous requirements.

  2. The entire repository (and the solutions submitted to it) is now licensed under GPLv3 (info: https://www.gnu.org/licenses/quick-guide-gplv3.html
    By submitting code you understand and agree to the licensing terms.

Happy Hacking ❤

fallen heath
#

so short instead of fast, will be interesting to see

sick hound
#

for these smaller mazes I wonder if it would be better to fill all white with dots, then remove any dots which aren't connected or have no use

pine edge
#

that sounds like an optimization

#

you don't want that

#

unless of course you want a stable and fast solution

frosty wyvern
#

I've never written any algorithms to solve mazes so I'm wondering myself what kind of solution will end up being more golfable, something more bruteforcy or an actual algorithm

#

and also whether writing an algorithm using the maze as a 2d list vs parsing the maze into a graph structure

#

shrugs

pine edge
#

oh man there's only one solution per maze

#

that's important

sick hound
#

well is a maze where all dots are filled in count as a valid path

stray needleBOT
teal rune
#

such a beautiful creation

frosty wyvern
#

@sick hound No, you can look at the test cases, though they're a bit hard to see in the format they're in in the json file

#

there's only one valid solution and its the direct path

#

the most direct path, that is

#
    🤔 lang should be pronounced "u+1F914 lang" or "colon thinking colon lang" on
    
    Discord, "please no thank you" also suffices.
#

HAHAHAHA

stray needleBOT
pine edge
#

@frosty wyvern i'm nearly done with my submission for challenge four but

#
Expected Output:
#####################
### ## ##...#########
##........#..########
##.#########. #     #
# . #.###....#### # #
##.##.###.## #### # #
#####.###.## ####   #
#    .....#### ### ##
## ######      ######
#####################

Actual Output:
#####################
### ## ##...#########
##........#..########
##.#########.       #
# . #.###....#### # #
##.##.###.## #### # #
#####.###.## ####   #
#    .....#### ### ##
## ######      ######
#####################
#

am i blind or is there no difference

#

this is test case 2

#

there's no extra trailing whitespace or anything

pure dew
#

diff time

pine edge
#

i'm messing with the test runner to get the actual variables out

frosty wyvern
#

oops

#

you deleted a wall >:(

#

lol

#

unless i fucked up the test cases

#

which is very likely actually.

pine edge
#

i mean it passed the first two tests so i'm very confused how it deleted wall here

pure dew
#

I hope to be submitting a small version of my project for #03 tonight or tomorrow

frosty wyvern
#

yea

#

the problem is in the test case @pine edge

#

sorry <3

pine edge
#

but yeah about the question of how golfable brute force maze functions are

#

mine is a depth first search

frosty wyvern
#

hold on trying to fix this dumb shit : )))

pine edge
#

and it's about 221 characters depending on if it passes the fixed tests or not

frosty wyvern
#

okay so

#

i fixed the test(I think)

#

HOWEVER

#

The thing I broke in the original test

#

meant that there was no test case where it was possible for a path to loop in circles

#

so lets see if it still passes haha

#

uhm

#

do you wanna just monkey patch your testcases.json file

pine edge
#

sure why not

frosty wyvern
#
[
    {
        "input": "###S###\n#     #\n## ## #\n## ## #\n##E####",
        "expected_output": "###.###\n# ..  #\n##.## #\n##.## #\n##.####"
    },
    {
        "input": "##########\nS      ###\n### ## ###\n### #### E\n#        #\n##########",
        "expected_output": "##########\n....   ###\n###.## ###\n###.####..\n#  ......#\n##########"
    },
    {
        "input": "#####################\n### ## ##   #########\n##        #  ########\n## #########        #\n#   #S###    #### # #\n##E## ### ## #### # #\n##### ### ## ####   #\n#         #### ### ##\n## ######      ######\n#####################",
        "expected_output": "#####################\n### ## ##...#########\n##........#..########\n##.#########.       #\n# . #.###....#### # #\n##.##.###.## #### # #\n#####.###.## ####   #\n#    .....#### ### ##\n## ######      ######\n#####################"
    }
]
pine edge
#

pfp pun intended

frosty wyvern
#

lemme know if this works

pine edge
#

all test cases passed

frosty wyvern
#

weee :D

pine edge
#

hold on lemme fix up my solution for any easy characters and then i'll push this version

stray needleBOT
pine edge
#

nm there we go

frosty wyvern
#

IMPORTANT NOTICE FOR THOSE WHO ALREADY PULLED CHALLENGE 04

There was a bug, I messed up one of the test cases. Please ensure that you pull the updated testcases.json file, sorry for any inconvenience and shout out to @pine edge for making me realize it dabward

stray needleBOT
pine edge
#

haha whoops that's a merge conflict

#

but yeah i wrote this function so it will always return the shortest path, but if there is a second, longer path, it will find it

#

and then because it's written to take advantage of the fact that only one path exists it will immediately crash

#

so if it returns, it is the shortest path

frosty wyvern
#

gah is there a way to resolve that on the site

#

if not can you just do a new commit and only include your solution file :DDD

pine edge
#

sure

#

i was hoping it would merge automatically because we both have the same file, but it's upset that we made the same file separately

dense spire
#

shit, that looks super fun

#

I wish I had time to do that maze challenge

#

maybe I'll do it later on

teal rune
#

maize

#

I wanted to implement 99bottles in 🤔lang but it's let's say sort of difficult

sick hound
#

I’m jizzing my pants

#

Props to @polar wolf for finding it!

polar wolf
#

stray needleBOT
pure dew
#

@frosty wyvern I got u fam. Its more or less done, arithmetic operators are gonna take some design rewrite i think, so i didnt add those in

teal rune
#

🤔 needs some more esothericalness

stray needleBOT
frosty wyvern
#

@pine edge please re-MR with only your solution file and not the modified testcases

stray needleBOT
pine edge
#

it's really a valuable skill to have

#

also if you just ping and ask me to fix it, any commits are automatically put into existing merge requests iirc

#

so no cancel/remake has to be done

frosty wyvern
#

lol was just trying to merge from my phone gimme a break :P

stray needleBOT
grave rover
#

@frosty wyvern isn't latest challenge just to write Dijkstra and making distances with walls a ridiculously high number?

pure dew
#

@grave rover hi

grave rover
#

Sup daps

frosty wyvern
#

@grave rover What? The challenge is code golf. The algorithm is irrelevant, it's whatever solution you can write the most succinctly

grave rover
#

But isn't that realistically the best method to do this other than trying everything and taking the shortest path?

teal rune
#

doesn't matter, golf it

frosty wyvern
#

@grave rover The goal is simple, write ANY code that solves the problem, it doesn't matter if it's efficient or not, as long as it solves the problem, and make it as short as possible

#

Perhaps Djikstras, perhaps a bruteforce solution. Depends how you implement it and who can implement it in the fewest characters

pine edge
#

what do i win if nobody else commits until next challenge

arctic bridge
#

What, we're already up to challenge 4?!

pine edge
#

don't say that too loudly

#

somebody else might do challenge 4

arctic bridge
#

Heck

#

Need a way to subscribe to these

arctic bridge
#

I'm not made for these challenges

#

Not great at algorithms, so my first thought goes to "what would be the most wacky solution that's still technically within the rules"

#

Well, ok, train a machine learning algorithm on the solutions, obviously

#

But, no imports!

#

Well, we use pip inline with:

from pip._internal import main; main('install tensorflow')
#

But that's an import!

#

Well, we put it in a different .py file that's on a GitHub gist, which is then linked to by a bit.ly link

#

To avoid imports of urllib, we determine the OS type by attempting to read OS-specific files

#

We then read the contents of urllib/request.py and exec:

exec(open('C:\\Program Files\\Python36\\Lib\\urllib\\request.py').read())
whole kiln
#

I like your line of thinking

#

causing chaos

arctic bridge
#

Now that we have urllib in our grubby not rule breaking technically probably please don't hurt me Shawn hands, we get the file:

urlretrieve('https://https://bit.ly/2E8iGuS', filename='evil.py')
exec(open('evil.py').read())
#

Then we simply call our solution, where i is the test input string:

f(i)
#

@frosty wyvern How's that

pure dew
#

name resolution fails for me. It's not compatible with pihole

arctic bridge
#

Well, that just adds complications, because now I have to change the DNS settings of the local system to not be pihole

#

Why ya gotta complicate thangs Drappar'?

mortal ingot
#

reminds me of this one xkcd

arctic bridge
#

Which one?

mortal ingot
#

the uh, the one where this old guy sends a youtube link in an extremely roundabout way

arctic bridge
#

This is how my mind works.
Elegant mathematical solution? Nah.
Glue available pieces together until I have something that does approximately the same thing? Yup.

#

Oh that rings a faint bell

mortal ingot
#

xkcd 763

#

that's the one

arctic bridge
#

Ah yes, that one

#
mortal ingot
#

yeah that's what your devilish thing reminded me of

mint quiver
#

hmm that is probably more efficient than my code at times

pine edge
#

the tests don't guarantee an ethernet cable is plugged in but it's too far to turn back now

#

i keep ending up writing recursive solutions for these

#

because loops are expensive but f(x) isn't

whole kiln
#

Pretty sure it's the opposite

#

recursion is expensive cause of call stack

pine edge
#

not in code golf

novel vine
#

maze solver:

return input.replace(" ",".")  # im really bad at mazes
brisk zenith
#

haha

teal rune
#

peak efficiency

frosty wyvern
#

that won't pass the test cases but ok :D

arctic bridge
#

Senpai Shawn, how did you like my answer?

frosty wyvern
#

Creative breaking of unwritten rules, I like it

arctic bridge
#

Thank you lemonblush

pine edge
#

just a couple more days until i win by default

pallid schooner
#

is there a language, where we have DNA sequences as syntax?

sick hound
#

there might be in an off topic channel

#

unless you're suggesting DNA sequences as an esoteric language for the challenge

#

or an esoteric implementation of DNA sequences as a language

cunning wave
#

(technically you can make a quaternary system out of DNA to represent instructions)

pallid schooner
#

based on this

frosty wyvern
#

Challenges Update

Greetings. Esoteric Python challenges will be on hiatus starting now and for the duration of the code jam. If you haven't signed up yet and would like to, hurry because the signups close this weekend!

https://pythondiscord.com/jams

As for the challenges and this channel in particular, do feel free to take a look at the various challenges if you haven't yet and try your hand at any of them! I welcome Merge Requests for solution submissions even for past challenges. If you have any challenge suggestions, comments, ideas on how we could make #esoteric-python events more exciting, etc. Feel free to DM me on Discord. We only have a small handful of people who regularly participate in the challenges which is fine, given that this is esoteric python and not everyone is interested in Golfing or various challenges but I would still love ideas on how we could get more people involved!

Our GitLab Repository for challenges: https://gitlab.com/python-discord/esoteric-python-challenges/

pine edge
#

@pallid schooner no but most of the operations dna based computing does is equivalent to regular expressions

#

actually mit made one but still regexes

frosty wyvern
#

Simple and useless Python unix-like Pipe implementation dabward

""" P I P E S    R    G O O  D"""


class PYEDPIPER:

    def __init__(self):
        self.tmp = None

    def __or__(self, other):
        args = []
        if type(other) is tuple:
            args = other[1:]
            other = other[0]
        if self.tmp:
            self.tmp = other(self.tmp, *args)
        else:
            if callable(other):
                self.tmp = other(*args)
            else:
                self.tmp = other
        return self


def ret2():
    return 2


def double_x(x):
    return x*2


def add_1(x):
    return x+1


P = PYEDPIPER()
import math

(P
 | 2
 | double_x
 | add_1
 | (math.pow, 2)
 | int
 | (int.__sub__, 73)
 | abs
 | print
 )
# >>> 48
tropic gulch
#

CAPS class names GWchadThinkeyes

frosty wyvern
#

oh hush

tropic gulch
frosty wyvern
#
""" Unix-like pipe syntax for chaining functions """
import math


class Piper:

    def __init__(self):
        self.tmp = None

    def __or__(self, other):
        args = []
        if type(other) is tuple:
            args = other[1:]
            other = other[0]
        if self.tmp:
            self.tmp = other(self.tmp, *args)
        else:
            if callable(other):
                self.tmp = other(*args)
            else:
                self.tmp = other
        return self

    def __call__(self, init):
        self.tmp = init
        return self


if __name__ == "__main__":

    """ Simple demo functions """
    def ret2():
        return 2

    def double_x(x):
        return x*2

    def add_1(x):
        return x+1

    P = Piper()

    (P(2)
     | double_x
     | add_1
     | (math.pow, 2)
     | int
     | (int.__sub__, 73)
     | abs
     | print
     )
    # >>> 48
#

Happy bytes?

#

;p

cunning wave
#

if you implement bashs subshell feature I'd like it

frosty wyvern
#

.<

cunning wave
#

:P

broken mesa
#

python one liner i made to encode a string using a variation of the caesar cipher, where every letter is shifted by its position in the string

print("".join([list(map(chr, range(97, 123)))[(list(map(chr, range(97, 123))).index(char)+i) % len(list(map(chr, range(97, 123))))] if char in list(map(chr, range(97, 123))) else char for i, char in enumerate(input("string to encode: "))]))```
cunning wave
#

thats not a variation of the caesar cipher, the caesar cipher has at least some kind of key

broken mesa
#

the caesar cipher shifts the letters by 3

#

normally

cunning wave
#

the caesar cipher shifts the letters by n

#

caesar just used to use 3 always

broken mesa
#

how does it makes this not a variation?

cunning wave
#

it is not even a cipher

#

a cipher would have a key

#

this has no key

mortal ingot
#

0/10 not enough list(map(chr, range(97, 123)))

broken mesa
#

lol

#

that just alpahabet

#

oh, and everyoen calls it a caesar cipher

#

the normal one

#

how is mine not?

cunning wave
#

if its not even a cipher

#

it cant be a variation of one

broken mesa
#

the original is a cipher

#

at least that how everyone calls it

cunning wave
#

yes

#

and caesar chose 3

#

but he had the option to chose n

#

here nobody has the option to choose anything

broken mesa
#

ah

#

okay i get it now

#

you need to be able to select a starting point

cunning wave
#

you need to be able to select a key

#

mathematically speaking a symmetric encryption function (which is what caesar cipher is) is a function taking the clear text and a key

#

what it does with that is up to the function

broken mesa
#

fixed it:

print("".join([list(map(chr, range(97, 123)))[(list(map(chr, range(97, 123))).index(char)+i) % len(list(map(chr, range(97, 123))))] if char in list(map(chr, range(97, 123))) else char for i, char in enumerate(input("string to encode: "), int(input("key: ")))]))
frosty wyvern
#

Caesar trash for not using PGP smh 😤

cunning wave
#

somebody should make a PGP Fork which relies on caesar cipher instead of modern symmetric ciphers

brisk zenith
#

ROT13

frosty wyvern
#

PGP Fork which relies on ROT13 and the whole key thing is just an honour system

#

okay time to improve my Pyed Piper module

#

I should add another o perator that creates a Thread

#

like..

#

hmm

#

i wanna add concurrency

#

im not sure how to model it though

#

I need an esoteric code guru like @brisk zenith

#

I guess I could just do like

brisk zenith
#

hello

frosty wyvern
#

hmmmmmm

#

ok Juan you need to help me figure this out

brisk zenith
#

okay

frosty wyvern
#

I want to add onto my Piping shitcode some concurrency like

#
 P
| a
| b
& a1
& a2
#

errr

#

this is gonna get complicated vvv quick

brisk zenith
#

hmm okay

frosty wyvern
#

cause what are the inputs where do the outputs even go

#

how does the P object handle waiting for threads

#

imma start cleaning the apt and think about it, help me brainstorm you little genius

brisk zenith
#

(btw why don't you use metaclasses to make it so you don't really need to initialise your class when you want to use it?)

frosty wyvern
#

(I don't know how to use metaclasses I've never used em)

#

can you convert my current code into a metaclass so I can learn from the sensei

brisk zenith
#

i'm thinking something like

(P ([1, 2, 3, 4, 5])
 | print  # prints the list
 & "my_thread", sum  # spawn a thread called "my_thread"
 | print  # still prints the list
 @ "my_thread"  # get (or wait for) the output of the thread
 | print  # now prints the result of the `sum`
)
#

wow thank you syntax

#

a metaclass is basically what creates class objects

#

cause everything is an object, even classes

#

the main metaclass is actually type (remember how i used that to define a class in my one-liners?)

#

so subclassing type allows you to make a metaclass

#

and i'm thinking that you could pass multiple arguments like ```py
(P (2)
| print, "my number =", ... # my number = 2
| print, ..., "is my number" # 2 is my number
)

#

cause that's valid syntax

#

it just creates a tuple of (func, *args)

#

and ... would be replaced with the pipe value

frosty wyvern
#

you're a pipe value

brisk zenith
#

wow thank you so much! :D

#

but you should also allow people to change this magic ... value in case they want to actually pass Ellipsis to a function

#

in which case you would make a different singleton so that you can check with is consistently

frosty wyvern
#

btw doing | fn, arg, arg doesnt seem to work without the ( )

brisk zenith
#

really?

frosty wyvern
#

unless its just my current code thats fucky

brisk zenith
#
>>> P(2) | 2, 3, 4 | "heck"
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    P(2) | 2, 3, 4 | "heck"
NameError: name 'P' is not defined
>>>

no syntaxerror here

frosty wyvern
#

in the middle of sweeping so cant rly debug rn

brisk zenith
#

or actually

#

hmm

frosty wyvern
#

i dont get invalid synta

#

it just

brisk zenith
#

when is , evaluated

frosty wyvern
#

doesnt create a tuple

brisk zenith
#

yeah okay

frosty wyvern
#

its no big deal

#

tho itd be cool

#

but eh

#

so

#

teach me meta class

#

: ))))

brisk zenith
#

i'm rethinking this and don't think a metaclass would be ideal if we want user-changeable values

#

i.e if they want to change the value of the ...

#

maybe you could have a bunch of singletons for different things

#

teeing would be interesting

#

like, ```py
(P(2)
| print T # prints the value of the pipe (2) but also replaces the return of print with the original pipe value of 2
)

#

well, however you want your syntax to work

frosty wyvern
#

oo cool

#

is that a thing or what

#

teeing

brisk zenith
#

teeing? well, you have tee in linux which sorta does something similar

frosty wyvern
#

oo cool

#

oo is the symbol like a T_ shaped pipe where the shit falls down into something but also keeps going in the same direction

brisk zenith
#

yup

frosty wyvern
#

hehe we plumbers now

brisk zenith
#

in linux

frosty wyvern
#

beautiful

brisk zenith
#

very

#

and good for pipes

#

cause the return value of None in print is annoying if you want to keep your original value, for example

frosty wyvern
#

Yep

#

ok well

#

heres the thing

#

how would I implement those other symbols

#

cause they not operators

#

I make em constants?

#

that get interpreted?

brisk zenith
#

i don't think they'd need to be operators

#

what syntax are you going with for arguments?

frosty wyvern
#

shrugs :)

#

the ellipsis is pretty dank

brisk zenith
#
(P(2)
 | (print, T)  # prints 2, passes 2 down the pipe
 | (print, ...)  # prints 2, consumes the value
 | print  # prints None, because the above `print` returned that
)

is what i'm thinking

frosty wyvern
#

yeeeeee

#

Agreed

#

hm

#

I feel like

#
(P(2)
 | (T, print)
 | (print, ...)
#

is a bit more visually appealing

#

cause the T is closer to the pipes

#

: )

brisk zenith
#

yeah, it makes more sense

#

but then, where does the value get passed to the print?

#

i suppose ... would have to be used there too

#

so py (P(2) | (T, print, ...) | (print, ...) )

frosty wyvern
#

well if it's just a function id say it gets implicitly passed

brisk zenith
#

yeah but what if the function takes multiple arguments

#

which one is given the pipe value?

frosty wyvern
#

whatchu mean

brisk zenith
#

as in,

#

(btw i think T should be a function/callable object, which executes the function and returns the value)

#
(P(2)
 | T(print, "shawn is", ..., "years old")
 | (print, ...)
)```
frosty wyvern
#

aw yeah cause thatll just evaluate to the original value and i can just keep chugging along

brisk zenith
#

yup

#

i don't think ... should be implicitly passed either, cause maybe there's a function that doesn't take any arguments at all

frosty wyvern
#

yeah if we're Tee-ing then it might make sense to call something that takes no argument

#

but like otherwise it kinda ruins the whole pipe thing

brisk zenith
#

yeah true

frosty wyvern
#

if ... isnt implicit in regular pipes then its like why bother cause its no longer like a unix pipe at all

#

at that point im just complicating calling functions LOL

brisk zenith
#

yeah that's a good point to be fair

#

i suppose if you have a function that needs to be called without any arguments, you could just do T(my_argless_func()) and that would work just as well

#

but then that requires a normal function call yert

frosty wyvern
#

Juan we need a stupid project to work on together

brisk zenith
#

we do

frosty wyvern
#

yes

#

Is there a way to create symbols in Python? Guess not eh, guess I can just make a plain object

brisk zenith
#

idea, dms

sick hound
#
b'e\0d\0\4\0\4\0d\1\x19\0\2\0d\2\x19\0\3\0\3\0d\3\x19\0\x83\3S\0'``` I just wrote some cpython bytecode manually
#

This indexes the 0th constant with the 1st, 2nd and 3rd constants, then calls the function with the first name with those arguments in that order without using * or **

vestal solstice
#

very hexing

pure dew
#

AHCKULALAYA, you're still writing regular python. You need to open a hex editor to write pure bytecode

sick hound
#

that is bytecode represented with python

pure dew
#

but its not bytecode, its python

#

:D

sick hound
#

it's cpython bytecode

#

@pure dew i'm using python as a way to represent the cpython bytecode I wrote...

pure dew
#

that's better lmao

arctic bridge
#

Dear lord pipes in Python

#

Deliciously evil

grave rover
#

Oh yeah pipes

#

I've done that before

#

list(range(10)).apply | (lambda x: x*x) # => [1, 4, 9, 16, ...]

#

Same with .filter and .first and stuff

fallen heath
#

map would be better there

grave rover
#

But muh piping

#

Maps are generally less readable imo

pine edge
#

actually useful pipes would do multithreaded generator to generator

#

that'd be neat as fuck

#

functions could just be automatically wrapped in a generator

ornate rivet
#

hey

#

does anyone know some relatively serious languages written in python?

green nymph
#

python

cunning wave
#

the python you use is not written in python, at least not the language part

#

cpython (the interpreter the majority of people uses) is written in C and the enormous stdlib is written in python

#

then there is the pypy interpreter (also interprets python) which is written in rpython

#

and then there are a few smaller languages such as hylang for example which is written in python and uses the python vm

fallen heath
#

jython, a java implementation

cunning wave
#

that is not written in python though

#

the question was for langs written in python

tropic gulch
#

what do you even mean by "language written in Python"? You can't write a language in another. That's like saying I write Spanish in French. And interpreters for languages can be (re)written in any language.

cunning wave
#

#javaisnotpython

fallen heath
#

you are just listing implementations

#

not languages

ornate rivet
#

^

cunning wave
#
class WhatAreYouDoingCPython:
    def __init__(self, x):
        self.x = x
    def __hash__(self):
        return self.x

print(hash(WhatAreYouDoingCPython(-1)))
brisk zenith
#

hash(-1) is -2 hm

#

@cunning wave relevent cpython source:

    switch(i) {
    case -1: return v->ob_digit[0]==1 ? -2 : -(sdigit)v->ob_digit[0];
    case 0: return 0;
    case 1: return v->ob_digit[0];
    }
#

v is the int object

cunning wave
#

yes i know why this happens

brisk zenith
#

why

cunning wave
#

-1 is an internal error code of cpython

#

so returning python one from the "user code" isnt ok

brisk zenith
#

huh, so it's like "fuck you this is reserved"

cunning wave
#

kinda

brisk zenith
#

wait so does cpython get upset if you return a C int of -1 like that?

cunning wave
#

¯_(ツ)_/¯

#

try

brisk zenith
#

uh how do you even

cunning wave
#

magic

pine edge
#

if you return -1 and you don't set an error string it raises some exception like "An exception was raised but no exception string was set!"

#

iirc

#

i never tried catching it because, like, why

cunning wave
#

i made an abdomination

pure dew
#

unreadable on mobile

tropic gulch
#

it's not your mobile's fault... GWchadThinkeyes

pure dew
#

no, but its at least legible on desktop

#

to say nothing of it being sensible

mortal ingot
#

reminds me of that one-line all lambda hello world

arctic bridge
#

Unreadable on desktop too @cunning wave is just bad at formatting

cunning wave
#

No

#

It's a one liner

#

What do you expect

arctic bridge
#

I expect perfection

cunning wave
#

It is perfect

sick hound
#
class Meta(type):
    @property
    def thing(cls):
        pass

    @thing.setter
    def thing(cls, value):
        print('setter was called')

# # # # # # # # # # # # # # # # #

class Blah(metaclass=Meta):
    thing = 1
    thing = 2```
is there a way to get this to "work" or is it just completely impossible because the class vars are handled before anything to do with the metaclass
#

(the assignments to thing don't trigger the setter func)

pine edge
#

@sick hound object.__setattr__(self, name, value)¶ Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value in the instance dictionary). name is the attribute name, value is the value to be assigned to it.

sick hound
#

?

grave rover
#

Override setattr instead, it'll make it less of a pain

fallen heath
#

or @property

sick hound
#

i'm not sure if i'm missing something but

  1. i know what __setattr__ does @ seinfeld :p and overriding it should in theory have the same effect as writing an @property so i wasn't sure why you posted that doc quote
  2. overriding __setattr__ doesn't work here, so i went on to try @property -- that's the codeblock i posted
#

it looks to me like class-var assignments (that are done within the body of the class itself) happen before anything from the metaclass happens, even if Blah.thing = 1 later on would behave appropriately
(so then I'm not sure if this problem in turn has anything to do with that the name of a class isn't bound within its own scope??)

pure dew
#

isnt it?

#

or is that only in instance methods?

sick hound
#

yeah just instance methods, i'm not sure how to describe the "non-method-inclusive scope of a class"

#

"top-level class statements" lol

pure dew
#
class Test:
    thing = Test

    def test(self):
        print(self.thing == Test)
sick hound
#

that works?

#

sec

#

right, NameError for me

#

at thing = Test

pure dew
#

i dont know if it works, i on my windows machine rn

#

i was asking

#

🤔 interesting

#

you can do this with Lua

#

local variable aboose

sick hound
#

ahh ok

pure dew
#
local test;
test = {
  test = test
}
#

gotta love lua syntax

pine edge
#

whoops sorry for not catching that extra bit of complexity

#

uhhhh

#

i checked by disassembling some python functions

#

and when you set a variable in a class definition like that the bytecode is doing a STORE_NAME

#

but the thing __setattr__ catches is STORE_ATTR

#

i can't think of any mechanism short of parsing the program yourself with something like ast to check to see if this happens

glacial rampart
#

TIL you can set __dict__

pure dew
#

what happens if you set __dict__ in __slots__

sick hound
#

oh shoot that's good seinfeld thank u (and dang 😔)

#

you can do that jack and it behaves like not setting __slots__ would

#

but i don't know how it fares performance-wise

cunning wave
#

the highlighted part is the IP the libraries would access

brisk zenith
#

lmao

cunning wave
#

like even stdlib fails to agree on one IP

#

I'm tempted to read the RFC which defines the URI grammar to find out which one is correct

brisk zenith
#

do it

#

tfw you want to monkeypatch a function written in C

#

PyEval_GetLocals in cpython/Python/ceval.c

#

you can access it via ctypes.pythonapi.PyEval_GetLocals but monkeypatching that doesn't work

cunning wave
#

i mean we are doing grammars in school atm..... so it counts as school work i guess

brisk zenith
#

lmao

#

my problem is something that @sick hound might know something about

cunning wave
brisk zenith
#

welp have fun :D

cunning wave
#

oh they do ABNF i only know BNF and EBNF 😦

brisk zenith
#

i can't imagine ABNF is much different

#

🤔

cunning wave
#

yeah

#

abnf is a lot cooler than EBNF

sick hound
#

@brisk zenith monkeypatching a function written in C is not easy

brisk zenith
#

yes

#

good

#

how do i do it? :D

sick hound
#

you might be able to cast the _FuncPtr from ctypes.pythonapi to a POINTER(c_char) and then write machine code to that

brisk zenith
#

yoinks

sick hound
#

but you'd need to make sure that area of memory is writable first

brisk zenith
#

who needs compatibility anyways yert

sick hound
#

or

#

cast a CFUNCTYPE/WINFUNCTYPE to a POINTER(c_char) and copy it over

#

you'd still need to make the C function code writable first though

pure dew
#

@cunning wave i dont think thats a valid url

cunning wave
#

that is a valid URI

#

after reading the grammar I'd say 1.1.1.1 would be the correct IP to access

pure dew
#

Whats the red box?

cunning wave
#

space

pure dew
#

Looking at the grammar, its a valid url

#

but wtf

#

the first ip would be the correct one

cunning wave
#

im not sure wether its a valid URL

#

but its a valid URI

pure dew
#

well ye

brisk zenith
#

it would be so convenient to be able to have a function called whenever a variable is accessed. i can achieve it easily with global variables, but not at all with local variables.

#

this is what the locals builtin does ```c
static PyObject *
builtin_locals_impl(PyObject *module)
{
PyObject *d;

d = PyEval_GetLocals();
Py_XINCREF(d);
return d;

}

#

that's all very simple

#

it just calls PyEval_GetLocals and assigns it to a python object

#

now, accessing a local variable doesn't actually use the locals builtin to look it up, it uses this PyEval_GetLocals function

#

which is why i want to somehow monkeypatch PyEval_GetLocals

#

oh no i just found a goto in cpython

#
#define GETLOCAL(i)     (fastlocals[i])```
#

getting closer to the root of it i suppose

pure dew
#

wew

brisk zenith
#
import ctypes

dummy = object()

ctypes.memmove(     # move some memory
    id(dummy),      # into `dummy`
    id(True),       # from `True`
    object.__sizeof__(dummy)
)

print(dummy)  # outputs `False` what
sick hound
#

try moving the size of True rather than the size of dummy?

brisk zenith
#

causes a segfault

sick hound
#

hmm...

brisk zenith
#

huh

sick hound
#

well I figured out how to monkey patch a function written in C in C

#

on windows

brisk zenith
#

fancy

sick hound
#

but you can't call the original function... yet

brisk zenith
#

i see

#

size_of = object.__sizeof__

print(size_of(True))
print(size_of(False))
#

prints 36 then 32

sick hound
#

False is smaller than True

brisk zenith
#

yeah

#

okay, sure.

pure dew
#

wut

frosty wyvern
#

loool

pine edge
#

1 and 0 are smaller than singletons

#

somehow

brisk zenith
#
Traceback (most recent call last):
  File "testing.py", line 32, in <module>
[1]    27418 segmentation fault (core dumped)  python3 testing.py

this is a new one haha

pine edge
#

that's real neat

#

not only did you throw an error

#

it segfaulted

#

after your program stopped

frosty wyvern
#

a work of art

pure dew
#

lolwat

grizzled epoch
#

how can i learn esoteric python

brisk zenith
#

you.. don't.

#

not as a beginner

#

esoteric python is almost never important

grizzled epoch
#

then why does it exits lol

brisk zenith
#

because it's fun

#

¯_(ツ)_/¯

pure dew
#

just how python works. we abuse it to do stupid stuff

grizzled epoch
#

o ok

#

so its like doing memes on the programming

brisk zenith
#

well

grizzled epoch
brisk zenith
#

for example, making 0 equal to 1

grizzled epoch
#

einstein rolls over in his grave

#

making 0 equal to 1 lol

brisk zenith
#

that's never something you'd ever need to do

#

but it's fun to mess with it

grizzled epoch
#

its impossible scientifically

brisk zenith
#

this isn't science

#

your computer doesn't give a fuck about science

pure dew
#

wait, so my production bot code is useless?

brisk zenith
#

lmao

pure dew
#

0 is just a symbol we assigned a value to

grizzled epoch
#

how is compuiter doesnt give a fuck about science

pure dew
#

in lambda calculus, 0 means fuckall

brisk zenith
#

computers are stupid

#

if you tell them that 0 is equal to 1

#

they'll believe it

grizzled epoch
#

ok im gona try

brisk zenith
#

don't.

grizzled epoch
#

ok sory

brisk zenith
#

lmao

#

it's fine

grizzled epoch
#

im just trying to get more understandings to make my brain like this brainmon

brisk zenith
#

this is not the place to be, if that's the case :D

grizzled epoch
#

haha small brain people here i guess brainmon

brisk zenith
#

anywhere else in the server is nifty.

grizzled epoch
#

ok bye dumb

brisk zenith
#

🤔

pure dew
#

cant get called dumb if you call them dumb and leave :weSmart:

brisk zenith
#

haha

#

!eval ```py
import ctypes

ctypes.memmove(
id(0),
id(1),
object.sizeof(1)
)

print(0 == 1)

night quarryBOT
#

@brisk zenith Your eval job has completed.

unknown error, code: 111
brisk zenith
#

heck

fallen heath
#

Socket error connection refused

grizzled epoch
#

u know what im sorry for the joke earlier it doesnt mean to be serious

#

this code looks like the opposite of dumb

#

cause i dont unders tand it yert

fallen heath
#

it's dumb becasue you should never do it

brisk zenith
#

haha that's fine, you don't need to understand it.

fallen heath
#

in a project

brisk zenith
#

yup

grizzled epoch
#

can i see example of cool estoic python code? yert

pure dew
fallen heath
#
reverse_polish = lambda expression: ((lambda PolishStack, split: ((lambda stack: tuple(stack.push(float(item)) if item.isdigit() else stack.operate(item) for item in split(expression)) and stack.pop())(stack=PolishStack())))(PolishStack = type("Stack", (), {"__init__": lambda self: (setattr(self, "_tuple", ())), "push": lambda self, item: (setattr(self, "_tuple", (item, *self._tuple))), "pop": lambda self: ((lambda tmp: tmp.add(self._tuple[0] if self._tuple else None) or setattr(self, "_tuple", self._tuple[1:]) or tmp.pop())(set())), "operate": lambda self, operator: ((lambda operation: self.push(operation(*(self.pop(), self.pop())[::-1])))(operation = {"+": float.__add__, "-": float.__sub__, "/": float.__truediv__, "*": float.__mul__, "^": float.__pow__}[operator]))}), split = lambda string: ((lambda spaces: (string[start:end - 1] for start, end in zip((0, *spaces), (*spaces, len(string) + 1))))(spaces = tuple(index + 1 for index, char in enumerate(string) if char.isspace())))))
brisk zenith
#

oh hey is that my code

fallen heath
#

yes it is

brisk zenith
#

👌

grizzled epoch
#

reverse_polish = lambda expression: ((lambda PolishStack, split: ((lambda stack: tuple(stack.push(float(item)) if item.isdigit() else stack.operate(item) for item in split(expression)) and stack.pop())(stack=PolishStack())))(PolishStack = type("Stack", (), {"init": lambda self: (setattr(self, "_tuple", ())), "push": lambda self, item: (setattr(self, "_tuple", (item, self._tuple))), "pop": lambda self: ((lambda tmp: tmp.add(self._tuple[0] if self._tuple else None) or setattr(self, "_tuple", self._tuple[1:]) or tmp.pop())(set())), "operate": lambda self, operator: ((lambda operation: self.push(operation((self.pop(), self.pop())[::-1])))(operation = {"+": float.add, "-": float.sub, "/": float.truediv, "*": float.mul, "^": float.pow}[operator]))}), split = lambda string: ((lambda spaces: (string[start:end - 1] for start, end in zip((0, *spaces), (*spaces, len(string) + 1))))(spaces = tuple(index + 1 for index, char in enumerate(string) if char.isspace())))))

"""
Annotated version

#

wow

#

oh

#

we look at the same yert

brisk zenith
#

haha

grizzled epoch
#

u write that sir spooky?

brisk zenith
#

i did.

grizzled epoch
#

wow

brisk zenith
#

i'd never write code like that in actual projects

grizzled epoch
#

now i know why you are spooky AND scary alpaca

brisk zenith
#

it's horrible

#

yes, spooky.

pure dew
#

also uh this

#
line_gen = ((t, r, st) ->((tran, text) ->(derot ->(lines ->(raw_lines ->(raw_words ->(words ->(shuf -> ((sli, sli_len) ->(raw_sent ->(sentences ->[sent[0].upper() + sent[1:] for sent in sentences])(derot[3].join(ss) + r.choice((derot[63], derot[63] * 2, derot[855], derot[477] + derot[475:477])) for ss in raw_sent))([sli[i:i + sli_len] for i in range(0, len(sli), sli_len)]))(shuf[:(len(shuf) |> r.randrange)], r.randrange(3, 15)))(r.sample(r.sample(words * 3, k=len(words) * 3), k=len(words) * 3)))(list(map(w -> w.lower(), filter(w -> w != str(), raw_words)))))(reduce((l, ll) -> (l, ll) |*> (+), raw_lines)))(map((raw -> [s.strip(st.punctuation + st.whitespace) for s in raw.lower().split()]), lines)))(filter(s -> s != str(), derot.splitlines())))(text.translate(tran)))(str.maketrans(t.d), t.s))((def -> sys = __import__("sys"); io = __import__("io"); old = sys.stdout; sys.stdout = io.StringIO(); __ = __import__("this"); sys.stdout = old; __)(), __import__("random"), __import__("string"))```
#

technically coconut, but its a python superset

grizzled epoch
#

very good

frosty wyvern
#

why is 0 smaller than all the other integer constants

#

.>

grizzled epoch
#

because it is the smallest number i think

pure dew
#

uhh

frosty wyvern
#

!e print(object.sizeof(0), object.sizeof(1), object.sizeof(2))

night quarryBOT
#

@frosty wyvern Your eval job has completed.

24 28 28
frosty wyvern
#

!e print(object.sizeof(-1))

night quarryBOT
#

@frosty wyvern Your eval job has completed.

type object 'object' has no attribute 'sizeof'
frosty wyvern
#

!e print(object.sizeof(-1))