« first day (2643 days earlier)      last day (2193 days later) » 
00:00 - 15:0015:00 - 00:00

12:02 AM
kek'd
wait @Downgoat are you asking that rhetorically or
the answer kinda depends on how your closures work
And whether you need just generators or full coroutines
 
@quartata Like I was thinking I could do it with having a state struct and then jumping to correct part of code but I'm not sure if there is better way
 
That's what you would do for full coroutines
The "state struct" you are looking for is ucontext_t
But there are a few optimizations you can do for generators (semicoroutines)
the simplest being that you can inline them
Additionally if you already know what variables need to be captured at each point in the generator you can potentially get away with not having to have a separate stack, depending on the generator
Nim is very, very good at optimizing generators from what I've seen of it. Give it a look, it compiles to C so you should be able to read its emitted code
 
Does Nim itself do the optimizations or does it just generate code that is easily optimizable by GCC/Clang/LLVM
 
No it inlines the generators
scroll down a bit to "Inline iterators" vs "Closure iterators"
ignore the syntax, you'll hate it
 
12:19 AM
So for generators should we do let f: Generator<T> = f() or should we have like some designateed syntax (cc @ASCII-only)
I was thinking T* but that'll confuse everyone who uses C
 
I personally don't see a need to label functions that return generators
oh, wait. You're statically typed. Nevermind
OK then the former is probably OK
 
:( but so verbose and java-esque
 
If you look at the Nim closure iterators, you'll see that's what it is doing. It even has you explicitly return the iterators, which I like
One of the more confusing things about Python's generators and coroutines is that they don't start until you get the first value
 
Does the = at the end of the function decl. denote the body?
 
Common sense would dictate that you would get the generator back after the first yield
Since that's what the syntax looks like
@Downgoat yes
With this syntax, you're making it clear you return the iterator from the function. The iterator isn't invoked until you get the first value from it
 
12:23 AM
@Downgoat this.
C# has IEnumerable and no special syntax so yeah
 
Do you get what I mean? This is the difference:
 
things like this should be abstracted away IMO
 
@ASCII-only So how should we declare a generator function then?
 
@Downgoat returns an IEnumerable
or any generator sublclass of it
 
def f():
    doSomething()
    yield 1
    yield 2
f()  # returns a generator. Nothing in the function body has run though, looks weird
Versus
 
12:25 AM
@ASCII-only you are saying you want to do func myGenerator() -> IEnumerable<T> { ... }??
Do we just want to do generator func myGenerator() -> Int
and to generate we'll have you use a loop or you can call it to return an optional
e.g. let f = generator() (where generator returns int) let x: Int? = f()
 
def f():
    return iterator:
        doSomething()
        yield 1
        yield 2
f() # Good; we see that an iterator is returned. The first time we call it doSomething will run and yield
 
:| js way is weird
 
OR
 
@quartata hmmm that makes sense
 
def f():
    doSomething()
    return iterator:
        yield 1
        yield 2
f() # We can call things before the iterator is created and returned. Both behaviors are possible and unambiguous, unlike having yields in the function body proper
The closure iterators in Nim are exactly like this, just with different syntax
The inline iterators are more like templates or macros: the body of your for loop is substituted where the yields are
Two variations, with different performance consequences
But also different usages. You can't use an inline iterator like a coroutine:
 
12:30 AM
not a fan of having iterators as a seperate block though, I don't want to go the way with seperate inline generators/closure generators
 
If you want them to be fast you'll have both. It's simply a matter of transparency
I personally wish more languages were upfront about that sort of optimization, because it is a big difference
 
If you really want you can always add the @inline annotation, and we'll attempt to inline it anyways if we deem it better
 
Syntax is really up to you. Just supposed to illustrate the necessity
 
@user202729 :| didn't work I think? look at the second latest commit
 
I'll have to see how LLVM optimizes it, and if it doesn't very well we can have our own inline pass
 
12:32 AM
LLVM will be incapable of optimizing it
 
@Downgoat MD -> HTML build. idk why it's broken pls halp
 
All it's going to see is a bunch of weirdass jumps and setting/clearing flags. Practically unreadable
Keep in mind, the closure ones work using makecontext/swapcontext, or whatever your fastest equivalent is
 
ok let's try an example
 
oh. figured out the problem
 
Have you seen ucontext_t (or Boost::Context's fcontext_t) before? I recommend you read up on that and make a toy program first
Keep in mind that in the general case you'll need to have a separate stack
clever optimizations can bypass that, but emphasis on clever
I'm not sure how Nim's closure iterators work behind the scenes, should take a look at the code
 
12:42 AM
ok take this:
class GeneratorState {
    let state: Int
    let value: Int

    init(state: Int, value: Int) {
        self.state = state
        self.value = value
    }
}

func sideEffect(int: Int) external(sideEffect);

func generator(state: Int) -> GeneratorState {
    if state == 0 {
        return GeneratorState(state: 1, value: 1)
    } else if state == 1 {
        return GeneratorState(state: 2, value: 2)
    } else if state == 2 {
        return GeneratorState(state: 3, value: 3)
    } else {
        return GeneratorState(state: 999, value: 999)
that generates:
define i32 @main(i32, i8** nocapture readnone) local_unnamed_addr {
"generator$.0.exit10":
  tail call void @sideEffect(i32 1)
  tail call void @sideEffect(i32 2)
  tail call void @sideEffect(i32 3)
  ret i32 0
}
 
Reminds me of regenerator's implementation
 
and this is on default optimization level
Holy crap binary expressions are slow:
> TypeDeduct::IfStatement (3 calls): 0.50ms (0.17ms per)
 
The problem is that a. It's a semicoroutine, which means it only yields control back to the caller b. the only state is the program counter, there are no other variables
 
@moonheart08 I know this because of notyoff
 
$ vsl build test.vsl -S -o - --perf-breakdown
Assertion failed: ((i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"), function init, file /Users/vihan/Documents/Code/tests/llvm-cmake/llvm/lib/IR/Instructions.cpp, line 299.
[1]    44184 abort      vsl build test.vsl -S -o - --perf-breakdown
fck
 
12:52 AM
snort
 
I support segfaults are worse... but this is going to be fun to debug...
 
technically a compile time error which is much better
 
:| I have absolutely no idea what is causing this assert fail
 
@Downgoat the assert?
 
12:55 AM
assert caused assert
Asserts are the first cause
Deep
 
The generator$.0.0.0 is being generated correctly but for some reason the argument isn't passed correctly :/
oh crap this is using old mangling
 
how does that mangling work
All I see are numbers
 
@quartata it uses consistently unique numbers to identify any declaration within scopes
 
But
How do you interface with already compiled objects then
 
VSL compiles on a module-level
For example if you look at the new mangling: iFggTCTestNinit, we specify which module. In this case it's in a global class Test in the (generic) entry module
@quartata take a more complex case:
class GeneratorState {
    let state: Int
    let value: Int

    init(state: Int, value: Int) {
        self.state = state
        self.value = value
    }
}

func sideEffect(int: Int) external(sideEffect);

class Test {
    let value: Int = 0

    func generator(state: Int) -> GeneratorState {
        if state == 0 {
            self.value += 1
            return GeneratorState(state: 1, value: self.value)
        } else if state == 1 {
            self.value += 2
            return GeneratorState(state: 2, value: self.value)
LLVM normally doesn't optimize this but if you ask it to it can:
define i32 @main(i32, i8** nocapture readnone) local_unnamed_addr {
FggTCTestNgeneratorAstategNInt.exit:
  tail call void @sideEffect(i32 1)
  tail call void @sideEffect(i32 3)
  tail call void @sideEffect(i32 6)
  ret i32 0
}
 
1:12 AM
@Downgoat ok, that's better
although you're missing the types for overloading?
 
actually it also does it on O3
@quartata ? what do you mean?
 
if you have two inits
 
where?
 
If you overloaded it...
 
where is anything overloaded?
 
1:14 AM
in a theoretical example I'm too lazy to type up
I'm talking about your mangling
@Downgoat this definitely works, but here's the main issue with this:
 
@quartata AstategNInt
what do you mean? that's the type right there
 
It says Ninit
not NInt
 
oh over there, for that there's no arguments
which is why you don't see anything
 
oh
all right
ok anyways
yield 1
for (int i = 0; i < 10; i++)
    yield i
    yield doStuff()
I don't know what your IR looks like
But if you have this as a for loop by the time you create your generator object, you'll have trouble expressing the state in the middle of a loop
If you do it at a lower level, when it's already a jump, then you're saving more variables than you need to
all you need to save are registers, if you have the rest on a different stack
moving things off the stack to make way for the original context is gross imo
 
@quartata We have a function that lets us save a function's state (used for capture) but LLVM can optimize that if it is inlined
 
1:19 AM
although if you could guarantee that parts of the generator's state wouldn't be smashed when it resumes you could pull off some clever stuff
@Downgoat I don't know how your implementation works but that's probably where you need to start from
(by captures you mean for closures right?)
 
@quartata yeah
is there a case where that wouldn't work?
should the generators state object be stack allocated?
 
...huh
you know
I hadn't ever thought about it being heap allocated
 
2:28 AM
cuz if u return the generator from a function or something
 
 
2 hours later…
4:12 AM
This answer should probably be removed
-1
A: Brainf*** Golfer

bob--[----->+<]>-----.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+. abcdefghijklmnopqrstuvwxyz

 
4:58 AM
> null == 0
< false
> null >  0
< false
> null >= 0
< true
Guess the language...
 
@Dennis coffee letters?
(JavaScript)
 
ding ding ding ding ding
 
5:11 AM
maybe it's signed 0...?
that hurts my brain
 
@Dennis null is also <= 0 but not == 0 :P
 
Remind me again why anyone uses this language?
CMP: What function could map [0, 256) to the RGB colors with a good distribution of the rainbow?
 
because we have no choice
 
n -> [n, n, n] comes to mind, but that's obviously a bad choice since you will never get red (or green or blue or a bunch of others)
 
That's 3 bits encoding R, 3 bits encoding G, and 2 bits encoding B.
 
5:19 AM
Hmm. Is there a way to make the entire thing continuous?
 
@DJMcMayhem you never get any colour
all grayscale
 
@DJMcMayhem Continuous?
 
@Dennis I don't know how else to describe it, but one single row of that ^ is "continuous"
Can all of the rows line up, each one naturally shifting into the next?
Maybe I need to think of it in hues rather than RGB
 
@DJMcMayhem No
Because there are three colors
= 3d
to find the smoothest you need to minimize something like total distance of adjacent colors (r1, g1, b1) and (r2, g2, b2)
 
Hmm. I guess I could try generating all 256 and then sorting by that
 
5:26 AM
@DJMcMayhem (256, 0, 0) -> ... -> (128, 128, 0) -> (0, 256, 0) -> (0, 128, 128) -> (0, 0, 256) -> (128, 0, 128) -> (254, 0, 4) :P
 
@DJMcMayhem could you do something like the 3d version of the mapping from rationals to integers
the one that goes along diagonals
 
Cantor's diagonals?
 
@DJMcMayhem rainbow = 100 brightness?
if so then HSV where S and V are 100
 
@Potato44 I think that would shift back and forth between certain hues too much
 
@DJMcMayhem you'll have to shift back and forth between at least one of brightness, saturation, or hue (alternatively, red, green or blue)
 
5:31 AM
@DJMcMayhem true, but the shifts would be continuos if you use the zig-zagging variant of the bijection
 
@Dennis It should be two bits encoding G because our eyes are more sensitive to green. (or should it be four? :P)
@Potato44 of course, but it wouldn't look very nice
 
So basically, if I really want it to be smooth/continuous, I'll need to ignore hue (aka grayscale) or ignore brightness (aka color wheel with no black/white)
 
@DJMcMayhem yeah. (also no light/dark)
like you could fade to black and white on either end, but that doesn't solve anything
 
@ASCII-only Our eyes are least sensitive to blue, which is why it has only two bits.
 
@Dennis ah.
 
5:34 AM
@ASCII-only Or I could pick one color and go black -> that color -> white. That actually might look the best
 
@DJMcMayhem :| wouldn't that be no hue
@DJMcMayhem but yeah you can continuously vary all three of H, S and V
 
@ASCII-only Well, it would be one hue.
But it would give a nice smooth fade and include a good variety of brightness
 
@DJMcMayhem also why do you need this
 
Potential challenge that's been on my brain recently
I need to beat bork bork to 100
@ASCII-only Like you said, that's 3D. Makes it hard to smoothly iterate through
 
@DJMcMayhem no. vary all at the same time. brb jsfiddling
nvm. turns out it's HSL in CSS
 
5:38 AM
Oh, so like n -> [n, n, n] but with HSV instead of RGB
 
yep
 
Huh. I'll give both a shot
But for now I need sleep. o/
 
nvm.
it looks terrible
 
Can I see? I'm really curious
 
that's without saturation variance. with saturation variance it's even worse
@DJMcMayhem Personally I'd just vary hue because it's easier to see the difference
@DJMcMayhem added checkboxes
 
5:48 AM
@ASCII-only I think the brightness shift will look better
 
6:00 AM
.oO(Do people upvote things they don't understand on PPCG)
 
@ASCII-only I sometimes upvote things I only vaguely understand if they seem impressive, but never something I don't understand.
for example, I don't know Jelly, but if there are several Jelly answers I might upvote the shortest one, especially if it comes with an explanation.
 
6:48 AM
@Riker well technically he did create it
 
 
1 hour later…
8:16 AM
0
A: Sandbox for Proposed Challenges

xyz123Do other programming languages allow post-assignment, like R? Can you force it? In many programming languages assignment works like this, where a value such as 5 is assigned to x. int x = 5; // C++ x = 5 # etc ... // Python But in R, you can do this (and this is the first I've ever heard ...

 
8:28 AM
O_o
i wrote something in lisp and it worked
 
 
2 hours later…
10:51 AM
hi
is it ok if I ask random coding questions here?
as in arbitrary not actually random :)
 
@Anush Sure, as long as it doesn't disturb ongoing conversations about code golf and PPCG. But since the room is quiet, go ahead!
 
thanks :)
input: [0, 0, 0, 0, 0, 2, 0, 4, 0, 1, 1, 0, 1, 0, 1, 0] output: [5,5,7,7,7,7,9,10,12,14]
I have a list of counts of the number of times each index should occur.I want a list with those index numbers repeated the right number of times
is there a neat way of doing that?
 
@Anush In APL, that's just L/⍳⍴L.
 
wow!
how about in an ascii based language :)
 
@Anush In NARS APL, it is just .
 
ngn
10:57 AM
@Anush in k it's just &
 
@ngn really??
why :)
 
@Anush In J, it is just I.
 
why on earth do languages have this built in?
 
@Anush These are the indices where true.
 
and it does the repetition? As in you actually get [5,5,7,7,7,7,9,10,12,14]?
 
10:59 AM
@Anush Yes, click on his link!
 
that's pretty amazing
 
ngn
@Anush I don't know why :) It's called "where"
 
in python there is this obscure code [ idx for idx, item in enumerate(input) for unused in range(item) ]
I don't know if it can be any shorter in python
clearly the variable names can
 
@Anush It should be said that NARS and K and J are all APL dialects, and indexing is very important in APL. You often have a Boolean mask and need the indices where the mask has Trues. In APLs, Booleans are simply the numbers 0 and 1. Basically each index is replicated 0 or 1 times, and so it is natural to extend it to higher integers.
 
I am quite interested to know short ways in boring old languages too
e.g. python/C
if anyone still uses such old things :)
javascript!
 
11:03 AM
@Anush APL is older than C.
 
true! I just looked it up
maybe it's not boring though
 
@Anush No. I can highly recommend learning an APL. Personally, I prefer the flavour that's still called APL, but both J and K are excellent too.
 
@Adám why do you recommend it? I mean it's unreadable so just for fun?
not that fun should have the word just before it
 
ngn
@Anush in could be a little shorter in python: sum([x*[i]for i,x in enumerate(a)],[])
 
@Anush It isn't unreadable at all. It is just that on PPCG, most languages are used in the densest possible way, and some languages can become hard to read when you do that. Production quality APL is usually quite readable, especially if you take the time to learn the meaning of the most common symbols. They are very easy to memorise once someone explains them to you.
 
11:08 AM
@ngn that's a use of sum I didn't know about!
 
@Anush He's using sum in a very array oriented manner, which is usually only something an APLer would think of.
 
@ngn actually I don't really understand it. I see what [x*[i]for i,x in enumerate(a)] is
 
@Anush So even Python became "unreadable"? :-)
 
yes!
 
ngn
@Anush sum(a,b) is sum with initial value b, like this: b+a[0]+a[1]+...+a[-1]
 
11:11 AM
ok but you are adding [] ?
 
ngn
@Anush [] is the initial value
@Anush the default initial value is 0, so I must provide [] explicitly
@Anush otherwise 0+a[0] will raise an error because a[0] is a list
 
what does it mean to add [] to something numerically?
oh it just adds lists
I got it :)
 
ngn
@Anush yep, concatenation
 
that's very nice
 
@Anush Can I bother you with me explaining the age-old APL idiomatic expression a/⍳⍴a?
 
11:16 AM
@Adám I would love to learn but I have to do something else now so will read it a bit later
 
@Anush ⍴a gives the shape (i.e. length) of the list. is the index generator, so ⍳⍴a just gives the indices of an array of a's shape (e.g. a). / is called replicate as it takes a list of desired number of copies as left argument and the actual data on the right, so a/⍳⍴a uses the data itself to replicate its own indices, which is what you wanted.
 
@ngn how about converting the other way?
from [5,5,7,7,7,7,9,10,12,14] to [0, 0, 0, 0, 0, 2, 0, 4, 0, 1, 1, 0, 1, 0, 1, 0]
or even in APL :)
 
How would you know how many trailing 0s there are?
 
I guess look at the last number to get the length?
so we miss the trailing zeros
no trailing zeros
 
ngn
@Anush in python you could do something like: [a.count(x)for x in range(max(a)+1)]
@Anush or more elegantly: map(a.count,range(max(a)+1))
 
11:49 AM
@ngn true.. I should have specified my demand that it is linear time :)
 
ngn
that's also easy:
r=[0]*(max(a)+1)
for x in a:r[x]+=1
print(r)
 
max(a) = a[-1] right?
as it's sorted
 
ngn
@Anush right, I didn't think about that!
 
ok so.. next version.. [5,5,7,7,7,7,9,10,12,14] to [2,4,1,1,1,1]
please :)
 
@Anush That's lossy. You just what the length of each run?
 
ngn
11:53 AM
@Anush which language?
 
@Adám we are throwing that away
@ngn python please
although people who hate python can use their favorite of course
 
@Anush ≢¨⊆⍨ in Dyalog APL.
 
wow again!
 
ngn
sorry, this one turned out to be somewhat long:
x=-1;r=[]
for y in a:
if x<y:x=y;r+=[0]
r[-1]+=1
print(r)
 
@Anush cuts its right argument into pieces with a new piece beginning each time the corresponding left argument element is higher than its neighbour on the left. is a selfie, which makes the function use its single argument as both left and right argument. is "tally" (i.e. length), and ¨ is each so we count the length of each segment.
 
12:00 PM
@ngn nice! Let me try it out
@ngn I don't think it is right
you have 0s in your output
we are looking for [5,5,7,7,7,7,9,10,12,14] to [2,4,1,1,1,1]
oh maybe I am wrong
sorry
 
ngn
@Anush it might be due to wrong indentation
 
right!
where is the for loop?
r[-1]+=1 is in the for loop right?
 
ngn
@Anush yes
 
@Anush See what a difference it makes to have concise code with a clear concept for each symbol? Much easier to ensure that it does what you want.
 
:)
 
ngn
12:11 PM
@Anush the chat's markdown screws indentation sometimes
 
@ngn In such a case, you should post your initial pinging message and then a new msg with fixed width. That preserves indentation, and will still look like a single message.
 
@ngn right I got no indentation at all
 
ngn
@Adám nice tip, thanks
 
how about
x=-1;r=[]
for y in a:r+=(x>y-1and r.pop())+1,;x=y
print(r)

No indentation required!
 
ngn
also:
x=-1;r=[]
for y in a:r+=[0]*(x<y);x=y;r[-1]+=1
print(r)
 
12:24 PM
:)
those are cool
maybe I should ask only for no indentation solutions :)
 
Anonymous
@Anush You've inspired me to write a challenge based off of that idea
 
@Mego Do X without Y?
 
@Mego cool!
it's annoying python doesn't have a product function
 
Anonymous
@Adám X = "mention a challenge idea in TNB", Y = "getting criticized for possibly running afoul of Do X Without Y before anyone even knows what the challenge is about"
 
@Mego Yeah, 'tis tough. ;-)
 
12:35 PM
what is wrong with X without Y?
I mean I read ppcg doesn't like it
but it would be interesting, right?
 
@Anush it's usually hard to enforce
 
Also it usually indicates a problem with the challenge itself
 
@Anush I'm not even sure what idea Mego meant, but I was jokingly assuming he meant a challenge where one has to avoid indentation. However, "Do X without Y" challenges often fail to anticipate the nature of various programming languages, in this case whether a language uses indentation at all. Obviously, Mego realises that, so the whole thing is just a joke.
 
Anonymous
@Anush A lot of the time, it's used to make a boring challenge less boring, but actually makes it unnecessarily complicated
 
ah ok
 
Anonymous
12:39 PM
I like the challenges where you have to decide if the input meets some criteria, with a solution that must meet that same criteria. Those are usually pretty good
 
although less boring sounds positive :)
 
Anonymous
Which, incidentally, is what I'm writing right now
 
cool!
 
12:58 PM
0
A: Sandbox for Proposed Challenges

MegoDetect Rectangular Text code-golf restricted-source decision-problem Given a string of printable ASCII text (including newlines and spaces), output a truthy value if the string is rectangular, and a falsey value otherwise. Additionally, the source code for your solution must be rectangular. A s...

 
1:21 PM
0
Q: Getting the Vowel Square

Luis felipe De jesus MunozChallenge This time you will create a function which takes a matrix filled with letters from the alphabet and determine if a 2x2 square composed of vowels exists. If a 2x2 square of vowels is found your function should return the top-left position (row-column) of the square. If no 2x2 square ...

 
uh, what
wtf is going on? prntscr.com/j9yfbj
 
uh
is SO down for anyone
 
Is SO down?
I get nasty error
 
Not for me
 
I get an IIS page.... wtf
 
Anonymous
1:31 PM
Not for me. Probably depends on which server the load balancer sends you to
 
 
for all SE sites
@Blue ha looks like you hit one that's not even in production mode
 
Apparently not
 
@Poke yeah, mine's like that as well
 
well someone made quite the blunder
 
1:33 PM
I'm getting a 404 "Server Error".
 
mine is fine.
 
gotta love folks using the wrong http response codes
 
I'm getting either 404 or that error message
 
ooo back up for me
nice
 
Though it's back now
 
1:34 PM
Yup.
It was probably just long enough to fire the intern and fix the problem.
 
ahahahah
 
Or someone tripped over The Cloud's cord.
 
@Dennis probably an intern.
In my experience it's always the intern's fault.
 
@Dennis you could file an issue with SE about that ;) i doubt they'll care though :[
could probably also let them know about the server that isn't in production mode
 
2:29 PM
does anyone here know the concept of alternate reality games?
One i am participating in just gave out clues that look like they may be code from an esoteric language
Input 00
<1 == 100
>1 == 1001
<>010 == 1010001

Does that seem familiar to anybody?
 
2:51 PM
There's an additional issue, almost as severe as the outage itself. 404 is a client error, not a server error. — Dennis 10 secs ago
Done.
 
exit
……………tfw when you type in PPCG instead of your git console
 
cool :]
 
lol @Fatalize
 
@totallyhuman Are you going to re-bounty the challenge?
@Fatalize I've confused TNB with WhatsApp before and asked everyone if they wanted pizza.
Somehow, nobody asked for pizza.
 
I'm down for pizza
 
2:55 PM
Sorry, offer's expired. That was a year ago or something.
 
unlucky
the best thing on the lunch menu today seems to be a turkey burger
 
00:00 - 15:0015:00 - 00:00

« first day (2643 days earlier)      last day (2193 days later) »