1. 27
    1. 18

      Python can do a similar trick with JSON syntax. It’s useful if you are working at a repl and just want to paste some JSON directly into your python code without parsing it. You just need these definitions:

      true = True
      false = False
      null = None
      
      lobster = {
        "name": "agent281",
        "account_age": 7,
        "banned": false,
        "hat": null,
        "comments": ["shitpost", "shitpost", "uninteresting"] 
      }
      
      1. 12

        That “report abuse” link is quite tempting.

        Bravo. No notes. I might use this if I had the right kinda crazy on the right day.

        1. 6

          I always wondered what a superset programming language to YAML would look like. I had no idea we already had one in Scala. :D

          1. 3

            C… can a Scala person explain what the hell is going on here? I’m scared.

            1. 10

              Scala 3 introduced an optional Pythonic syntax, swapping out curly brackets for whitespace. You can define some keywords as methods and nest methods inside of objects in order to get dot syntax. Defining methods like / and unary_- enable some syntactic sugar to take over. Unit type is basically void in Scala (adequate for purposes of this example) and lets anything pass through (but it’s not Any; read more here). The method bodies being just ??? is a Scala version of marking something unimplemented; it’s just a shortcut for throw NotImplementedException IIRC.

              Scala is really powerful in the creation of DSLs. One Scala scholar who taught me a lot about it years ago essentially said that the mark of a good Scala developer is building DSLs as your application’s framework.

              1. 4

                Yes Scala is quite powerful syntactically but the widespread community opinion about DSLs has changed quite a lot since the heydays of DSLs, nowadays people widely agree that the mark of a good Scala developer is building a tasteful API that is easy to read in practice and doesn’t go overboard with the operators.

                1. 1

                  I agree. There was a time there in the 2010s I felt people were really getting carried away with operator stuff.

                2. 2

                  One Scala scholar who taught me a lot about it years ago essentially said that the mark of a good Scala developer is building DSLs as your application’s framework.

                  I’m having flashbacks to early Liftweb.

              2. 1

                I really want to use this to out-Helm Helm.

                I see your Go templating and I raise you.

                1. 2

                  This would be super hard to deploy. You’re probably better off using a targeted next-generation config language like Pkl: https://pkl-lang.org/

                  1. 2

                    That’s really cool!