Live data from Hacker News

Designing a programming language to speedrun Advent of Code

blog.vero.site

91–100 of 101 posts

Re: Designing a programming language to speedrun Advent of Code

#91
post #90
post #89

Earlier quoted context omitted.

My interpretation of sgarland's question was that he meant `<file` being the entirety of the statement, i.e. typing only that at a shell prompt and pressing return.

Ah. Now I understand where the misunderstanding was. It confused me that we were talking about redirection as a replacement for useless use of cat.

Yep I can appreciate the misunderstanding. For completeness of the discussion, I think where sgarland mentioned a sub-shell, he was possibly referencing the Bashism `$(https://www.gnu.org/software/bash/manual/html_node/Command-S... in addition to what I called a "statement" above.

Re: Designing a programming language to speedrun Advent of Code

#92
post #91
post #90

Earlier quoted context omitted.

Ah. Now I understand where the misunderstanding was. It confused me that we were talking about redirection as a replacement for useless use of cat.

Yep I can appreciate the misunderstanding. For completeness of the discussion, I think where sgarland mentioned a sub-shell, he was possibly referencing the Bashism `$( https://www.gnu.org/software/bash/manual/html_node/Command-S... in addition to what I called a "statement" above.

Correct, that’s what I had in mind.

Re: Designing a programming language to speedrun Advent of Code

#93
post #83

Earlier quoted context omitted.

Is `<file` shorthand for `cat file`, or is that only true when used in a sub-shell?

In that fun way that shells are, for bare redirection it depends. In bash/ksh, it matches frou_dh's explanation. In zsh, it depends on how you've set the various *NULLCMD options and parameters. In csh, it is an error. Even in zsh, when configured to behave like `cat file` it still doesn't quite do that as it won't con cat enate files as it only passes the first shell word following the `<` to `cat`(or whatever you'v…

Because I hate myself I guess, I use zsh as my interactive shell, but generally write scripts for bash. The latter is mostly for portability (although with Macs stuck on 3.2 unless updated manually, that’s less true over time), and also because shellcheck doesn’t work on zsh.

This means I get to remember an increasingly unfortunate amount of differences. I’ll add this one to the pile, thanks.

Re: Designing a programming language to speedrun Advent of Code

#94
post #83

Earlier quoted context omitted.

In that fun way that shells are, for bare redirection it depends. In bash/ksh, it matches frou_dh's explanation. In zsh, it depends on how you've set the various *NULLCMD options and parameters. In csh, it is an error. Even in zsh, when configured to behave like `cat file` it still doesn't quite do that as it won't con cat enate files as it only passes the first shell word following the `<` to `cat`(or whatever you'v…

Because I hate myself I guess, I use zsh as my interactive shell, but generally write scripts for bash. The latter is mostly for portability (although with Macs stuck on 3.2 unless updated manually, that’s less true over time), and also because shellcheck doesn’t work on zsh. This means I get to remember an increasingly unfortunate amount of differences. I’ll add this one to the pile, thanks.

[deleted]

Re: Designing a programming language to speedrun Advent of Code

#95
post #83

Earlier quoted context omitted.

In that fun way that shells are, for bare redirection it depends. In bash/ksh, it matches frou_dh's explanation. In zsh, it depends on how you've set the various *NULLCMD options and parameters. In csh, it is an error. Even in zsh, when configured to behave like `cat file` it still doesn't quite do that as it won't con cat enate files as it only passes the first shell word following the `<` to `cat`(or whatever you'v…

Because I hate myself I guess, I use zsh as my interactive shell, but generally write scripts for bash. The latter is mostly for portability (although with Macs stuck on 3.2 unless updated manually, that’s less true over time), and also because shellcheck doesn’t work on zsh. This means I get to remember an increasingly unfortunate amount of differences. I’ll add this one to the pile, thanks.

I've mentioned this in previous posts here, but I write zsh scripts utilising all the extras that zsh gives(alternate form syntax, extensive extended globbing, zsh module support for extra functionality). It sounds stupid but it makes it really obvious that what you're writing isn't a generic shell script, and you can forgo having to think too much about whether something will work in modern bash, or MacOS pre-GPL3 bash, or {b,d,k,z}ash as /bin/sh symlink.

I definitely get the argument about shellcheck though, it would be nice if it supported zsh.

Re: Designing a programming language to speedrun Advent of Code

#96
post #95

Earlier quoted context omitted.

Because I hate myself I guess, I use zsh as my interactive shell, but generally write scripts for bash. The latter is mostly for portability (although with Macs stuck on 3.2 unless updated manually, that’s less true over time), and also because shellcheck doesn’t work on zsh. This means I get to remember an increasingly unfortunate amount of differences. I’ll add this one to the pile, thanks.

I've mentioned this in previous posts here, but I write zsh scripts utilising all the extras that zsh gives(alternate form syntax, extensive extended globbing, zsh module support for extra functionality). It sounds stupid but it makes it really obvious that what you're writing isn't a generic shell script, and you can forgo having to think too much about whether something will work in modern bash, or MacOS pre-GPL3 b…

That’s fair. I wrote a script at work recently for zsh that relied on some of its niceties, like glob qualifiers. The reason for using zsh was we only use Macs, so it was reasonable to assume everyone would have a decently modern version of zsh available.

It definitely looks foreign, but then, so does parameter substitution in bash or zsh. There are shell scripts, and then there are those that make you break out the man pages to figure out what they’re doing.

Re: Designing a programming language to speedrun Advent of Code

#97
Why are people so insistent on having unary minus? In my experience, "0-whatever" is just as good as "-whatever" except in a single case where you're trying to write an INT_MIN but then again, unary minus doesn't help you in this case either — unless you, as e.g. SML does, make the unary minus the lexical part of the number itself. However, SML has to actually use the tilde "~" instead of the minus for the negation because otherwise "1 -2" would be ambiguous.

IIRC Elm didn't have unary minus for quite some time just fine unless its author decided he really would like to have specifically unary minues but, weirdly, not any other unary operator. So, what's the deal with unary minus, why do people want it so much?

Re: Designing a programming language to speedrun Advent of Code

#98
post #70

Earlier quoted context omitted.

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

I really wish python would steal 'let' from JS, specifically in a block scoped form - coming from perl's 'my' as a way of life, python's (and ruby's) function level scoping and "surprise! variable just popped into existence on assignment!" behaviour really messed me up.

Can you tell me more about the usefulness of 'let'? I'm an intermediate(?) programmer but I've worked mostly in Python, C and C++. I did one JS project and everything I saw about 'let' seemed redundant.

Re: Designing a programming language to speedrun Advent of Code

#99
post #98
post #70

Earlier quoted context omitted.

I really wish python would steal 'let' from JS, specifically in a block scoped form - coming from perl's 'my' as a way of life, python's (and ruby's) function level scoping and "surprise! variable just popped into existence on assignment!" behaviour really messed me up.

Can you tell me more about the usefulness of 'let'? I'm an intermediate(?) programmer but I've worked mostly in Python, C and C++. I did one JS project and everything I saw about 'let' seemed redundant.

Firstly (compared to python at least) there's the obvious 'typo in variable name barfs early' advantage, which honestly is not to be sniffed at on its own.

But my big thing is about being able to scope values to the specific block where they belong:

    ...
    let foo;
    {
        let x = blah();
        let y = frob(x);
        foo = munge(y);
    }
and the temporaries 'x' and 'y' have gone away as soon as the } happens.

also, if you've ever had "fun" trying to capture a loop variable,

    for (let val of things) {
      callbacks.push(() => val.finish());
    }
has a different 'val' for each iteration of the loop so you can do that safely without requiring some sort of copying or an intermediate function invocation to create an extra scope.

Oh, and it also renders impossible certain weird constructs like

    if :
        some_name = ...
where now whether the some_name variable even -exists- after that if block is indeterminate without knowing which way the went.

I also like being able to do e.g.

    for (let thing of things) {
        let blah = thing.blah;
        callbacks.push(() => blah.doThing());
    }
Without 'let' you'd have to write (for the first 'for' example)

    for (var val of things) {
      callbacks.push(((val) => {
        return () => { val.finish() }
      })(val));
    }
to perpetrate let-over-lambda to get a separate scope for the callback function.

This is not my favourite thing to write, and -very- far from my favourite thing to read later.

Hopefully that gives you a better idea of why I, at least, prefer having 'let' available.

Re: Designing a programming language to speedrun Advent of Code

#100
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?

words←⊃⎕nget 'wordlist.txt' 1 ⍝ read lines tenK←'^........k.$' ⎕S '&' ⊢ words ⍝ regex filter ↑tenK/⍨{∧/1='abc'(+/∘.∊)⍵}¨tenK ⍝ count abc and filter Dyalog APL, but it's still kinda ... heavy.

> tenK←'^........k.$' ⎕S '&' ⊢ words ⍝ regex filter

Is tenK←{(10=≢⍵)∧⍵[9]='k'}¨words better?

Feel that better matches the problem spec, although requires the each

Post reply on HN