« first day (4412 days earlier)      last day (436 days later) » 
00:00 - 04:0004:00 - 00:00

4:03 AM
What Thunn claims is a "sum of squares" program actually generates OEIS sequence A098152
 
errr this sort of stuff is outta my league, i was only helping cuz i knew python
 
It's not, the mistake is actually pretty simple
 
Sounds like the page expected the 2nd quotation to take [prev_result cur_num] but they're flipped in the impl
 
And it's just a stack-based language, where dup is duplicate
So 3 dup * + does in fact, duplicate the 3, multiply it by itself, and then add it to whatever comes before it
and then the [0] primrec just says to recursively do that from n..0
 
reading the tutorial, the explanation of primrec feels... weirdly backwards
 
4:08 AM
@Bubbler That's what I thought at first, too, lemme check that again though rq
@Bubbler Yeah, no, I haven't gotten that to work. Were you able to make a step-by-step where you make that work?
Here's what I think happened, because it's the same thing I did with my implementation:
So, with a program like 5 [1] [*] primrec which computes 5!, you can have the interpreter expand out, and then reduce.
5
5 4
5 4 3
...
5 4 3 2 1 1
5 4 3 2 1
5 4 3 2
...
But if you do that technique with [dup * +] you recover the sequence that TIO is spitting out:
5 4 3 2 1 0
5 4 3 2 1
5 4 3 3
5 4 12
5 148
21909
So it's squaring the top element, then adding it to the element below. Then squaring the top element, then adding it to the element below...
5 4 3 3  # 3^2 + 3 = 12
5 4 12   # 12^2 + 4 = 148
5 148    # 148^2 + 5 = 21909
 
Yes, either the tutorial or the impl is wrong, but we don't know which
 
That's what I believe it's doing. Instead of squaring each element individually, and then adding them up.
 
I agree with what the impl is doing.
 
@Bubbler Can the tutorial really be wrong? It's stated so clearly.
The following compute... the sum of their squares.
And that interpretation of the program is much purer and more mathematical. Far more in line with the nature of the language.
There is a way to implement primrec where that program does, in fact, give you the sum of squares. (At least according to the quick recursive sketch I did in my head.)
 
> On the way back from the recursion it uses the other quotation, [*], to multiply what is now a factorial on top of the stack by the second element on the stack.
This line matches what the impl is doing.
 
4:19 AM
@Bubbler Right, yeah. That's why I implemented it the way I did. With the 21909. I based it on that sentence.
 
But the sum-of-squares thing doesn't, so it's probably the tutorial that's wrong
 
But I think there's another way to interpret that sentence.
I believe it might be applying each program to an element, and only recursively drawing on the next one when it's needed.
So, when the quoted program is +, it has arity 2, and so it immediately needs to make another recursive call.
Whereas [dup * +] can start operating on the top element, 0. It duplicates 0. It multiplies it by itself. And now there is only one element left on the stack, so when it reaches the +, it makes a recursive call to the next element.
What do you think?
heyo @m90!
 
@AviFS I don't think it's how it works
 
@Bubbler I'll be terribly sad if not! Why?
 
It certainly doesn't recurse when there isn't enough element on the stack. It just recurses while the current counter is not zero.
def primrec(cnt, f, g):
    if cnt == 0: return f()
    else: return g(cnt, primrec(cnt-1, f, g))
 
4:26 AM
As far as I can see, it's perfectly in line with everything else. Plus, it feels more truly recursive. Expanding out a range from n..0, and then reducing back over it doesn't feel like a true recursive call. Making recursive calls throughout the evaluation process is much truer to how recursive programs work. And this is supposed to be a seriously functional language.
 
This is my interpretation of primrec
 
Plus there's already a way to generate a range from n..0, and reduce over it, in Joy.
 
Someone remind me tomorrow to do a bounty for a new language
@RydwolfPrograms Self-ping to remind me
 
> ... primrec tests whether the top element on the stack (initially the 5) is equal to zero. If it is, it pops it off and executes one of the quotations, the [1] which leaves 1 on the stack as the result. Otherwise it pushes a decremented copy of the top element and recurses.
This is the definition of primrec
 
@Bubbler Right, I understood that. But I feel like applying the function until you have to make a recursive call, is still in line with that.
@Bubbler I did say it backwards, it should start with 5, duplicate 5, and then when it hits the add function, do a recursive call to 4.
Before we say it's not correct, do you get the idea I'm proposing to make the sum of squares program work?
 
4:31 AM
@AviFS What would the result be for 1 2 3 4 5 [0] [+] primrec?
I'd expect 1 2 3 4 15 by the definition.
 
@Bubbler Yeah, it is how I did it. It's just painfully bland. In order to implement it, you literally generates a range from n to 0, and then just reduce it back up.
@Bubbler That should be right, yeah.
 
@AviFS But your interpretation would call [+] more than five times, consuming lower elements in the stack and producing 25.
 
No, it would still only operate on the 5.
It would try to apply the + to 5, but insodoing it would need a second parameter, so it would recurse one step, check for equality to 0, then fill in a 4.
 
@AviFS I'm trying to say "It would try to apply the + to 5" is not what happens in the first place.
 
But it does allow each independent item to be squared, before they are added, in the sum of squares example.
 
4:38 AM
That breaks the expectation of [dup * +] being one unit of execution.
 
@Bubbler I do understand that interpretation though, given that that's how I implemented it. The reason I discovered this bug is because I was checking my own primrec implementation, and so tried the sum of squares program with 5, and got 21909, which was radically wrong.
It's only then, that I started piecing it together, found the OEIS sequence, figured out what went wrong, and my very final step was to check the reference implementation, which acted just like mine had.
@Bubbler I don't believe so? I mean, it's possible that what I'm suggesting doesn't actually work. That it breaks down in practice in a way that I'm not yet seeing. That's very possible.
But, at least in theory, I can imagine a way to interpret that as one unit of execution, which works the way I'd like it to.
I mean, if you have a:
DEFINE square == dup *.
@Bubbler Then you can express the quoted program as [square +].
And maybe that makes it clearer how it's one unit of execution, which is squaring the top element, then adding it to the one below?
@AviFS (This is a perfectly valid definition that Thun makes in the tutorial.)
 
A quotation corresponds to a lambda in other languages. What you're trying to do is to arbitrarily insert a try-catch inside a lambda, which you normally can't in other languages.
That's what I mean by one unit of execution.
 
@Bubbler Maybe it would help me to see what an implementation of what I'm saying would look like? Because I'm not seeing the try-catch in my head, but then again, I'm not seeing any concrete piece of code yet.
@Bubbler Part of my hesitancy is that I understood the desired design was to have stack-based to be an implementation detail in Joy.
I thought it proposed itself as a concatenative language (a new class of functional languages, contrasted with the usual applicative languages).
Ie, in most functional languages, the default operation is function application, whereas in Joy, it's function composition.
 
@AviFS You basically want to push the next number when it hits + because there are not enough elements on the stack. By this, you just transformed [dup * +] into [dup * try: + except: (push another number) (recurse) +]
 
Eg. f a in Haskell means apply f to the argument a.
Whereas f a in Joy is first applying f, then applying a. And if you think of all keywords as pure functions which take a stack as input, and return a stack as output, then all Joy programs are just one long composition of mathematically pure functions.
 
4:48 AM
I know what concatenative languages are. I'm the one who advocated Factor the other day.
 
@Bubbler I'm sorry, I'm not trying to imply you don't!
Just going through my understanding, and why I'm interpreting it the way I am. I don't know how much you guys have looked at such langs.
 
@AviFS "in Joy, it's functional composition". And you're transforming [dup * +] as something that is NOT a composition of dup, *, and +. That's the point.
 
Alright, I'll pause and go read.
@Bubbler So did I misunderstand the idea that Joy wasn't trying to promote stack-based thinking?
I thought Joy programs were supposed to be able to be reasoned about without thinking about stacks.
I'm also wondering: If someone read a bunch more of those essays, would there be some clarification on this? Like some more code including primrec, that further validated one of the two ideas?
@Bubbler I do see what you're saying, but I can't help feeling it can work as composition, and without any try except blocks. Again, I might have to see an implementation, or try making one myself-- which I think I may as an exercise-- to see what what I'm proposing would actually look like, and how right/wrong/impossible/try-catch-filled it really is. Right now it's just an idea in my head.
Do you see no way to interpret [0] [square +] primrec as sum of squares without breaking something, no matter how badly you want to, and how leading it looks?
 
There is one way, that is to implicitly swap before calling the 2nd quotation, but it doesn't match the text I quoted before.
 
Just realizing, what I'm proposing is akin to expand ... [square] map ... [+] reduce
@Bubbler I see, yeah I agree-- that doesn't make sense to me.
Alright, well I'll read a bit, and see if I can find anything else to help clarify.
On the bright side, according to @Bubbler, my implementation is correct :p
 
5:02 AM
Yes, I think so.
 
@Bubbler By the by, have you ever been able to get the official implementation in C running on your computer?
I've never been able to on my mac.
 
Do you have a link?
 
And this is always the one that comes up on Github: github.com/Wodan58/Joy
But that's not the original author.
By the way, if anyone wants to parse this stuff on combinators, this should concretify it:
For linear recursion over numeric types the if-part often is [null] and the first recursion part is [dup pred]. The primrec combinator has this built in. For integers the rewrite rules are:

        0  [T]  [R2]  primrec   =>   pop  T.
        i  [T]  [R2]  primrec   =>   i  dup pred  [T]  [R2]  primrec  R2.
 
That seems to confirm our interpretation
 
FWIW The joy implementation in Dyalog's dfns also agrees that 5 sumofsquares is 21909
@Bubbler Wait really? You were able to read that?!
 
5:20 AM
Also apparently primrec is more than that, it can take a list (or string?) instead of a number and it will reduce over its "elements"
@AviFS github.com/Wodan58/joy0 - "This is the original version of Joy, created by Manfred von Thun."
with minimal changes to be compiled with gcc I guess
 
Sorry, I lost connection.
@Bubbler Right, I often try with that one.
How did it go for you?
 
make worked for me
 
@Bubbler Yeah, I saw that! I haven't seen that mentioned anywhere in the tutorial.
@Bubbler Are you...
Damn. Linux?
 
yes
 
Hmm, containerize maybe. This was before I knew about containers, haha. La Trobe or Wodan?
 
5:25 AM
Wodan's joy0
 
Oh, why joy0?
 
> This is the original version of Joy, created by Manfred von Thun.
 
Oh, minimal changes.
@Bubbler I didn't get that you were referring to joy0. Got it. I'll give it a shot.
@Bubbler You were familiar with these combinators?
 
@AviFS Not exactly, but Factor's combinators work like that in general principle
 
I've got Joy working now! Are you able to make sense of the REPL?
I'm not able to run anything so far.
 
5:33 AM
I haven't got the REPL part to work either, but just ./joy < file.joy seems to work
 
lmao, half of the stuff in my git repository are failed joy interpreters that i could never get to work
and i've had this computer for over a year, lolol
 
lmao
nice
 
i'd forgotten about that
i'm counting 8 😂
@Bubbler I always forget about that and do cat file.joy | ./joy
@Bubbler I don't know. The fibonacci program is taking forever. The joy tutorial is not waiting for input, like it's supposed to. And I haven't figured out the REPL yet, either.
But the joy tutorial is definitely not working.
 
@AviFS It takes more than a few seconds to finish
 
@Bubbler Yeah, that finished. But joytut.joy isn't waiting for input. (Different from tutorial.joy)
No flags, either. This is rough.
 
5:58 AM
@AviFS I think I found how to run it. Delete all the lines after joytut quit. and run with cat joytut.joy - | ./joy
 
@Bubbler On it!
@Bubbler Bash wizardry!!
Thank you very much.
Ooh, and I got the repl, too!
You just have to end a line with period, in order to get it to run.
That seems very un-REPL-y. But it means the stack continues over multiple lines until you hit ., which resets the stack.
> 1
> 2
> 3
> +
> +.
6
 
The dot seems to print the top element to me actually
Try 1 2 3 + . and then .
 
Oh, you're right.
So, it doesn't reset the stack then.
Nothing happens if you do period on an empty stack.
Interesting, alright, got it.
Thank you so much for your help, Bubbler. Will see if there's an easy way to add an automatic period in rlwrap.
 
So it only executes when a dot is entered, AND pops and prints the top value
What a weird kind of repl.
 
@Bubbler By the way, that also fixes piping input. So echo "1 3 +." | ./joy now works.
@Bubbler It does? I thought it was still executing immediately.
Eg.
> 2 3 +
> .
5
You think it's waiting?
@Bubbler But yes, I'm so glad you agree!
 
6:09 AM
help is a nullary function but it doesn't print until you hit .
and help dup errors on dup only after .
 
@Bubbler Interesting. Is that not comparable to ending a line with a semicolon, though?
Or it is comparable, but you're just emphasizing how weird that is for a repl?
I mean, maybe there is an actual repl, but we'll never find it, haha
 
lol yeah
 
some mystery flag or something, lol
 
and there's helpdetail which you can use like [binrec] helpdetail . to get more info on builtins
 
quick repl in bash?
@Bubbler oh, neat
Ooh, even a type signature. That's nice.
If we did try to make a repl, either as a bash script or a joy program, how do you think it should behave?
Print out the whole stack after every line, and then just reset?
 
6:15 AM
Probably like what Factor listener does. Print out whole stack after each line, keeping it
 
Oh, right, much better idea.
 
So you can actually observe what happens after 1 2 3 and then +
for example
2 [1 2 3 4] [+ +] primrec .
11
.
2
.
5 [1 2 3 4] [+ +] primrec .
run time error: two parameters needed for +
.
25
.
Fun with wrong types
 
Huh.
I was hoping to modify joytut.joy to make a repl in Joy, but I'm thoroughly confused.
The entire program is one huge DEFINE block.
I don't see any command to do anything!
 
It's not designed as a repl, it's just a set of quizzes with a list of expected answers
 
Right, but it has user input, so I was hoping to take those functions, and make a repl. (Preferential to trying to find docs on how to get user input.)
Thanks again for all your help, Bubbler.
 
 
5 hours later…
11:06 AM
0
Q: Shortest code to generate any Galaxy

Aira ThunbergWhat kept the interest of the physicist interested was... Astrophysics for large mind. Geniuses like Hawking and Einstein need your help This challenge is a code golf challenge hosted on Code Golf Stack Exchange. The task is to generate a random image of a galaxy using any golf language, and the ...

 
11:35 AM
0
Q: Shortest code to generate all Pythagorean triples up to a given limit

Aira ThunbergGenerate the shortest possible code in any programming language that can generate all Pythagorean triples with all values not exceeding a given integer limit. A Pythagorean triple is a set of three integers $(a, b, c)$ that satisfy the equation $a^2 + b^2 = c^2$. The program should output the tri...

 
11:53 AM
@user wait, why do I want my file extension to be hard to type again?
 
because funny
 
nah
 
 
1 hour later…
1:20 PM
alright, so: how should Rabbit do error handling?
LDQ: ^
 
 
2 hours later…
2:53 PM
0
A: Number to Binary

Parcly TaxelPiet, 151 bytes Try it online!

How many Piet answers do we have?
 
@Ginger Something akin to Result but with a more restricted Err field
@Ginger user's saying that rbt is hard to type, not pk
Your finger has to go from r to b to t if you type like a spider
But IMO we as non-spiders should try to troll people who type all fancy and elitist by doing things like that :p
 
3:36 PM
I can type rbt fine, pk is harder :b
 
3:47 PM
slightly better Piet
 
@ParclyTaxel so that's what sbt stands for! q:
 
what sbt?
 
it's a joke we have in a certain chatroom
@RydwolfPrograms wdym "more restricted"?
 
As in, don't allow any type for Err
Since in Rust, you quickly run into really annoying situations where things return a dyn Error
You don't know what type of error it can return, and it's not even documented anywhere, since dyn Error can be literally any error
And if you want to use the convenient ? syntax you need to return dyn Error too
It's just gross
 
blech
what should be allowed then?
 
3:56 PM
One option I've thought of is a sort of...global namespaced error type enum
Actually that's not even necessary
Just have a Result<T> type that can contain either a type T or one of a list of possible error types
 
@RydwolfPrograms remind me what dyn means in Rust?
 
It's a dynamically dispatched trait type. So a dyn Foo can be any type that implements the trait Foo
But you can only interact with it in ways that Foo (or one of the traits it inherits from) defines
 
ah, makes sense
 
@RydwolfPrograms So the compiler/interpreter always knows which error types can be in a particular Result
 
in Rabbit that'd be T with Err
or maybe T impl Err
 
4:00 PM
There's a difference
Rust has impl Err for any type that's Err, but it has to be a type known at compile time
Whereas a dyn Err can be determined at runtime
impl Err is more like a generic
 
then I guess it wouldn't matter in Rabbit, what with it being interpreted and all
 
I think it still would
Say a function takes an impl Xyz and returns its input as the same type
If I call that function with a String that implements Xyz, I know I have a String
But if it takes a dyn, I now cannot assume it's a String
 
hmmm
I still don't get it
 
@ParclyTaxel this
 
4:19 PM
0
Q: Generate a permutation from the high-water marks

Command MasterGiven a permutation, we can define its high-water marks as the indices in which its cumulative maximum increases, or, equivalently, indices with values bigger than all previous values. For example, the permutation \$ 4, 2, 3, 7, 8, 5, 6, 1 \$, with a cumulative maximum of \$ 4, 4, 4, 7, 8, 8, 8, ...

 
4:30 PM
guys.... how do i deal with this answer? codegolf.stackexchange.com/a/258463/96039
it says its non competing... is that even allowed???
whats the consensus on these types of answers, doesnt there need to be some effort in golfing?
 
4:48 PM
@Bubbler try optimising this? codegolf.stackexchange.com/a/258456/110698
and in other news…
Yes, 100K at last on MathsSE
 
waow
 
@ParclyTaxel damn
 
noice
 
@ParclyTaxel sheesh thats a lot of black codels, my gut feeling says thats definitely not the optimal structure
 
yeah I've only done one other non-trivial Piet program here
 
5:01 PM
@RydwolfPrograms wait, so like what if I want to return an error with certain data fields with more info (like an HTTP request error code)?
can I just... not do that?
 
@AidenChow No
@Ginger You could store that in the enum's data
 
> The current winner is user1502040's Python 3 + Google OR-Tools answer at 3 bytes
 
So it would be a Result::Error::std::http::NetworkAccessError(ip, port)
 
@ParclyTaxel well im not much better, i have a few piet answers here but they are mostly trivial lol
 
If anyone's designing a 2d language here and looking for an interesting way to compactly encode it...
Sep 28, 2021 at 17:36, by Redwolf Programs
I have an idea for a golfy way to represent programs in 2d languages
See the transcript for details
 
5:07 PM
@RydwolfPrograms ok so like how should i respond to this guy
 
Mod flag, and comment telling them answers must make a serious effort to be golfy
Do the comment first
I kinda want to make that extremely dumb 2d language I came up with
Where every square costs 8 bytes
(for someone who doesn't like 2d languages I sure come up with a lot of them)
 
@ParclyTaxel ill probably try a piet answer myself later and see how many bytes i get, 121 bytes definitely seems a bit too much
@RydwolfPrograms u do it lol, im not good at this formal moderation language so idk how to make the comment
 
Done
I kinda want to finally do the KotH I planned like five years ago
Where you buy weapons at an auction and then fight
 
5:32 PM
Can anyone golf this python code?
def find_closest_number(numbers, query):
    index = bisect_left(numbers, query)
    if index == 0:
        return numbers[0]
    if index == len(numbers):
        return numbers[-1]
    before = numbers[index - 1]
    after = numbers[index]
    if after - query < query - before:
        return after
    else:
        return before
it assumes numbers is sorted
 
Do we need to do it efficiently
You're doing a binary search sorta thing but the golfy approach would probably not do that
 
@RydwolfPrograms I don't get it
 
@RydwolfPrograms log time please
you can use any builtin you like
 
5:57 PM
@Simd Yes, I'm sure anyone can :P
Starting by replacing the variables with shorter ones
 
6:25 PM
@DLosc is there anything else one can do?
It seems such a basic function
Find the nearest point
 
(What I'm getting at is: before asking for golfing help, it's considered good form to golf the code as much as you can yourself.)
 
6:42 PM
here's a thing: Rabbit if while, an alternate syntax for while loops
(this also works for case)
main function truthMachine():
	num = int(input())
	if num == 1 while:
		print(1)
	else if num == 0:
		print(0)
	else:
		print("What?")
that's not a very good example (because num will never not equal 1), so here's a better one:
main function countDown():
	num = int(input())
	if num > 0 while:
		print(num)
		num--
	else:
		print("Can't count from that!")
 
7:18 PM
@DLosc that's reasonable
I meant it more as a fun challenge
I don't really need it golfed
 
Sure. Just speaking for myself, though, I would have more fun with it if I didn't have to start by doing all the obvious golfs. :)
 
 
1 hour later…
8:25 PM
@RydwolfPrograms why the extra keyword. why not just Foo like tradoop
 
8:36 PM
The slickest Pyth program I've written in years: codegolf.stackexchange.com/a/258492/20080
 
@Seggan Because it's a trait, not a normal struct/enum/typealias
 
yeah but its like using -> for pointers but . for normal stuff
useless
 
I guess you could allow that, but it lets people know they're using a trait there
Otherwise they might go hunting for a struct Foo
Actually, that wouldn't be a problem
Still, good to be explicit. Looks like the Rust devs weren't too bothered by verbosity
@DLosc It might be easier to golf something starting from an ungolfed version, so you can take an entirely new approach if needed, but yeah, an accompanying golfed version would've been nice (along with an explanation of what exactly that function did)
 
@user well they explicitly stated that they decided to drop ->
@user ides go brrr
 
8:55 PM
more Rabbit syntax, and a fizzbuzz program:
main function fizzbuzz() -> never:
    match i from [1...]:
        case i % 3 == 0:
            print("Fizz", end = "")
            proceed
        case i % 5 == 0:
            print("Buzz", end = "")
            proceed
        any case:
            print("\n")
 
why does it return never
 
@Seggan ...you literally just said why :p
 
but it does return
nvm
 
lol
 
9:48 PM
@Ginger Is that really right? Where does it print i?
 
@Adám hm?
what do you mean?
 
FB needs to print 1 2 Fizz 3 4 Buzz…
 
I may be stupid :p
@Adám fixed it:
main function fizzbuzz() -> never:
    match i from [1...]:
        case i % 3 == 0:
            print("Fizz", end = "")
            proceed
        case i % 5 == 0:
            print("Buzz", end = "")
            proceed
        any case:
            print("\n")
        else:
            print(i)
(any case runs if any of the case blocks are matched, else runs if none are)
 
Now, that looks more right.
 
10:06 PM
@Ginger Is the any case construct really necessary?
 
probably not, but I like it, so it's staying
 
lol fair enough
 
@Seggan There would be ambiguity between impl Foo and dyn Foo, for one
Also, you can do things like dyn Foo + Bar, and Foo + Bar on its own might be a slightly confusing type signature
And also super importantly: dyn Foo on its own isn't sized
Which means you need to Box it pretty often
And as user said, being able to tell whether something's an actual type or a trait with dyn/impl is super important because those behave very differently
 
10:23 PM
@RydwolfPrograms wait whats the difference
 
A dyn Foo is dynamically dispatched
 
impl is sugar
 
E.g., a dyn Iterator could be any type of Iterator, determined at runtime
 
fn foo(a: impl A) is like fn foo<T: A>(a: T), I think
 
An impl Foo is just any object which is Foo determined at compile time, like a generic
 
10:25 PM
mhm
 
 
1 hour later…
11:37 PM
is there a shorter way to write sequence in Haskell than mapM id?
my context: i have a function

```
f=print=<<(mapM g.zip[1..].undefined)
g(x,y)=undefined
```

which i want to make infix. i also have a short alias `z=zipWith` i'm already using.

```
f=print=<<(mapM id.z(~)[1..].undefined)
x~y=undefined
```

looking for getting the second 1 byte shorter ideally

edit: i don't know how to code blocks ;_;
 
multiline code blocks dont work in chat
unless the code is the only thing in the message, then you can press "fixed font"
like
this
 
example tio for the above
@Seggan thanks, i'll have to remember that for future code blocks (seems I can't edit my message anymore)
i'm quite upset by the parens around print=<<(...) too, but i want the print to happen last. (~)/g are effectful.
 
11:53 PM
Only thing I can find in the Haskell tips mentioning sequence is this but you're already using mapM
 
00:00 - 04:0004:00 - 00:00

« first day (4412 days earlier)      last day (436 days later) »