Live data from Hacker News

Designing a programming language to speedrun Advent of Code

blog.vero.site

21–30 of 101 posts

Re: Designing a programming language to speedrun Advent of Code

#21
post #7

> I solve and write a lot of puzzlehunts, and I wanted a better programming language to use to search word lists for words satisfying unusual constraints, such as, “Find all ten-letter words that contain each of the letters A, B, and C exactly once and that have the ninth letter K.” So... Perl?

    grep { len($_) == 10 && /^[^a]*a[^a]*$/i && /^[^b]*b[^b]*$/i && /^[^c]*c[^c]*$/i && /k.$/i } @words;
Is there a simpler way?

Re: Designing a programming language to speedrun Advent of Code

#22
post #20

Earlier quoted context omitted.

I'm surprised that file> command isn't the preferred idiom. Does that mean something else?

That would execute the command `file` and put the output into the file `command`.

Oh, now I re-read it - of course! Hah.

Re: Designing a programming language to speedrun Advent of Code

#23
post #3

> Before we move on, I want to point out that “being able to write code from left to right without backtracking” is a completely bonkers thing to optimize a programming language for. This should not be anywhere in the top hundred priorities for any “serious programming language”! There are plenty of serious languages that are written this way. Most noticeably are shell scripting languages but I’ve seen stack based an…

Yeah, Smalltalk also works this way...mostly.

  3 negated + 2 negated.
Alas, as with the post, this also breaks down when you have more than 2 arguments (or in Smalltalk parlance, 1 argument in addition to the message receiver), as those are handled by keyword arguments and you can't tell where the keywords for one message stop and the ones for the next one start. Let's say we have some nested arrays, which are accessed with at: in Smalltalk:

   array at:4 at:2 at:1.
Alas, that doesn't get interpreted as 3 messages, but as the single message at:at:at:. As it kind of has to be as there is no way to disambiguate. Surprisingly, Smalltalk does have a way to chain messages and thus separate the keywords, the semicolon:

   array at:4;
         at:2;
         at:1.
Alas, this sends the subsequent messages to the original receiver, so it is equivalent to:

   array at:4.
   array at:2.
   array at:1.
(And so this example doesn't actually make sense, it's just a syntax example). So what you have to do is add parens:

   ((array at:4) at:2) at:1.
Hmm, not nice. For Objective-S (https://objective.st), I introduced the pipe for message chaining:

   array at:4 | at:2 | at:1.
One way of looking at this is as a syntactic device that allows left-to-right typing without backtracking, which it is. And that is both nice to write and quite readable, IMNSHO.

A second way of looking at it is as a version of the pipe/filter architectural style, with each message expression being a filter, the results from the filter on the left piped into the filter on the right as the receiver. This is a little bit like |> in some FP languages. But really only a little bit, because in Objective-S this is not the whole story, but just a way of integrating messaging into the way the pipe/filter architectural style is supported at the language level.

Re: Designing a programming language to speedrun Advent of Code

#24
I think it’s interesting how similar a lot of this stuff is to what I do, except I’m not very good at Advent of Code and also I decided to hack Python to do this instead of writing my own language. For example:

* I couldn’t really make operators first class functions, but I just autoimported operator which has this but in words

* I wanted partial application and hated lambda syntax, so I hacked it together with some magic. “_0 + 1” is basically equivalent to lambda x: x + 1

* Python really likes to make everything a free function, which messes with the whole left-to-right thing. So I monkey-patched functional methods onto all the collections

Together this means that if I have like a comma separated list of numbers in str and I want to, idk, count how many are above five I’d do something like

  str.split(",").map(int).filter(_0 > 5).len
which matches how my brain things about it far better than how Python would like me to write it. It uses some tricks but it’s not actually that bad of a hack IMO: https://github.com/saagarjha/advent-of-code/blob/main/aoc.py

Re: Designing a programming language to speedrun Advent of Code

#25
post #11

Earlier quoted context omitted.

Isn't that a whole lot more "being able to write code without making a lot of dumb mistakes", which is a feature of the programer. So it boils down to getting gud and practice?

No, what the author is discussing is a syntax thing. Lets take a hypothetical C-like language: result = C(B(A())) In this your result is on the left hand side. The first function to be executed is A and then B and lastly C, which also reads right to left. This is a pretty common way to write code, it's by no means unique to C-like languages. So you'd have gotten so good at reading code like this that you probably don…

Or with uniform function call syntax

result = A().B().C()

Re: Designing a programming language to speedrun Advent of Code

#26
post #7

> I solve and write a lot of puzzlehunts, and I wanted a better programming language to use to search word lists for words satisfying unusual constraints, such as, “Find all ten-letter words that contain each of the letters A, B, and C exactly once and that have the ninth letter K.” So... Perl?

grep { len($_) == 10 && /^[^a]*a[^a]*$/i && /^[^b]*b[^b]*$/i && /^[^c]*c[^c]*$/i && /k.$/i } @words; Is there a simpler way?

Perl has `length`, not `len` :) Also I can't resist a bit of TIMTOWTDI:

    my @found = grep {
        local $_ = lc;
        length         == 10  &&
        substr($_,8,1) eq "k" &&
        join("",sort [/([abc])/g]->@*) eq "abc"
    } @words;

Re: Designing a programming language to speedrun Advent of Code

#27
post #7

> I solve and write a lot of puzzlehunts, and I wanted a better programming language to use to search word lists for words satisfying unusual constraints, such as, “Find all ten-letter words that contain each of the letters A, B, and C exactly once and that have the ninth letter K.” So... Perl?

grep { len($_) == 10 && /^[^a]*a[^a]*$/i && /^[^b]*b[^b]*$/i && /^[^c]*c[^c]*$/i && /k.$/i } @words; Is there a simpler way?

Might as well do it on the command line at that point:

    $ grep '^........k.$' /usr/share/dict/words | grep a | grep b | grep c | grep -v 'a.*a' | grep -v 'b.*b' | grep -v 'c.*c'
    backstroke
    bailiwicks
    benchmarks
    branchlike
    bushwhacks
    greenbacks
    matchbooks
    piggybacks
    roadblocks
    scrapbooks
    slingbacks
    throwbacks
    thumbtacks

Re: Designing a programming language to speedrun Advent of Code

#28

I think it’s interesting how similar a lot of this stuff is to what I do, except I’m not very good at Advent of Code and also I decided to hack Python to do this instead of writing my own language. For example: * I couldn’t really make operators first class functions, but I just autoimported operator which has this but in words * I wanted partial application and hated lambda syntax, so I hacked it together with some…

reads a bit like javascript now. You might want to consider switching languages

Re: Designing a programming language to speedrun Advent of Code

#29

I think it’s interesting how similar a lot of this stuff is to what I do, except I’m not very good at Advent of Code and also I decided to hack Python to do this instead of writing my own language. For example: * I couldn’t really make operators first class functions, but I just autoimported operator which has this but in words * I wanted partial application and hated lambda syntax, so I hacked it together with some…

reads a bit like javascript now. You might want to consider switching languages

Oh it definitely does. The reason I stick with Python is that it has a somewhat decent standard library, and IMO fewer surprises (I don’t know Python or JavaScript all that well, since I basically never use it professionally, so I need to reduce footguns for myself).

Re: Designing a programming language to speedrun Advent of Code

#30

I think it’s interesting how similar a lot of this stuff is to what I do, except I’m not very good at Advent of Code and also I decided to hack Python to do this instead of writing my own language. For example: * I couldn’t really make operators first class functions, but I just autoimported operator which has this but in words * I wanted partial application and hated lambda syntax, so I hacked it together with some…

reads a bit like javascript now. You might want to consider switching languages

Honestly I'm jealous of JavaScript's arrow syntax. I don't really need anything else but the arrows are nice (and Turing complete).
Post reply on HN