logoalt Hacker News

dev_l1x_belast Wednesday at 1:06 PM12 repliesview on HN

I would love to have a scripting language has typed features and you can replace bash with.

What comes close is:

    #! /usr/bin/env elixir

    Mix.install([:jason])

    defmodule JsonPrettyPrinter do
      def get_stdin_data do
        :stdio
        |> IO.read(:all)
        |> Jason.decode()
        |> case do
          {:ok, json_data} -> json_data
          _ -> raise "Invalid JSON payload was provided"
       end
     end
    end

    JsonPrettyPrinter.get_stdin_data()
    |> JsonPrettyPrinter.pretty_print_json()
    |> IO.puts()

Replies

jakkoslast Wednesday at 1:36 PM

Have you seen nushell? It lets me one-liner so many things that would have previously taken breaking out a "real" language to do

Contrived example:

  ls | where type == 'file' | sort-by size | take 4  | each {|f| {n: $f.name, s: ($f.size | format filesize MB) }} | to json
outputs

  {
    "n": "clippy.toml",
    "s": "0.000001 MB"
  },
  {
    "n": "README.md",
    "s": "0.000009 MB"
  },
  {
    "n": "rustfmt.toml",
    "s": "0.000052 MB"
  },
  {
    "n": "typos.toml",
    "s": "0.00009 MB"
  }
show 7 replies
frou_dhlast Wednesday at 2:20 PM

OCaml is a scripting language in this sense. No need to compile an executable ahead of time, just have a `#!/usr/bin/env ocaml` shebang (or more realistically: `#!/usr/bin/env -S ocaml -I +unix unix.cma`) at the top of a source file.

Though, I don't think it has the capability for single-file scripts to declare 3rd-party dependencies to be automatically installed.

show 1 reply
leonidasvlast Wednesday at 1:50 PM

There's a trick shared here days ago to add a kind of shebang to Go that may interest you: https://lorentz.app/blog-item.html?id=go-shebang

Discussion: https://news.ycombinator.com/item?id=46431028

PaulHoulelast Wednesday at 1:16 PM

Two interesting options for everyday scripting are Python and Powershell.

show 4 replies
Pet_Antlast Wednesday at 3:09 PM

Have you considered PowerShell? It's open-source, and typed, and definitely usable from the command line with lots of resources for.

https://github.com/PowerShell/PowerShell

show 1 reply
ashton314last Wednesday at 2:05 PM

If you just wait a few months, then that program will be written in a typed language. The type checker for Elixir is coming along nicely and every release brings more checks.

librastevelast Wednesday at 1:23 PM

Suggest you take a look at https://raku.org for a strongly (but gradual) typed scripting language.

show 1 reply
unpiggedlast Wednesday at 2:20 PM

Babashka (https://babashka.org/) is an interesting tool for scripting. It's Clojure, so dynamic typing, but it's data orientation makes it a great fit for something like your example.

qrobitlast Wednesday at 1:22 PM

I wanted to say Haskell with shh[^1] and stack's or nix's shebangs[^2][^3], but interpreted haskell is not particularly fast.

Also I think a Python script is reasonable if you use a type-checker with full type annotations, although they are not a silver bullet. For most scripts I use fish, which is my preferred interactive shell too.

[1]: https://hackage.haskell.org/package/shh

[2]: https://docs.haskellstack.org/en/v3.9.1/topics/scripts/

[3]: https://wiki.nixos.org/wiki/Nix-shell_shebang. On a side note, if you were to use nix's shebang for haskell scripts with dependencies, you should be using https://github.com/tomberek/- instead of impure inputs, because it allows for cached evaluation. I personally cloned the repo to my personal gitlab account, since it's small and should never change

melagonsterlast Thursday at 9:06 AM

It probably is perl or Python.

DonHopkinslast Wednesday at 2:53 PM

@dev_l1x_be: The answer isn't a new typed scripting language. It's recognizing what the interpreter already is.

LLMs are eval(). Skills are programs. YAML is the motherboard.

@unkulunkulu nails it -- "library as the final language", languages all the way down. Exactly. Skills ARE languages. They teach the interpreter what to understand. When the interpreter understands intent, the distinction dissolves.

@conartist6: "DSL is fuzzy... languages and libraries don't have to be opposing" -- yes. Traditional DSL: parse -> AST -> evaluate. LLM "DSL": read intent -> understand -> act. All one step. You can code-switch mid-sentence and it doesn't care.

The problem with opinionated frameworks like ROR and their BDFLs like DHH is that one opinion is the WRONG number!

The key insight nobody's mentioned: SPEED OF LIGHT vs CARRIER PIGEON.

Carrier pigeon: call LLM, get response, parse it, call LLM again, repeat. Slow. Noisy. Every round-trip destroys precision through tokenization.

Speed of light: ONE call. I ran 33 turns of Stoner Fluxx -- 10 characters, many opinions, game state, hands, rules, dialogue, jokes -- in a single LLM invocation. The LLM simulates internally at the speed of thought. No serialization overhead. No context-destroying round trips.

@jakkos, @PaulHoule: nushell and Python are fine. But you're still writing syntax for a parser. What if you wrote intent for an understander?

Bash is a tragedy -- quoting footguns, jq gymnastics, write-only syntax. Our pattern: write intent in YAML, let the LLM "uplift" to clean Python when you need real code.

Postel's Law as type system: liberal in what you accept. Semantic understanding catches nonsense because it knows what you MEANT, not just what you TYPED.

Proof and philosophy: https://github.com/SimHacker/moollm/blob/main/designs/stanza...

show 1 reply