News for hackers. Stuff that matters.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by michaelmrose on Tuesday January 07, 2020 @03:05PM (#21984188)
If this was lispy then (elem "countries" (elem 0)

Would be an error.

Expression evaluation ought to be inside out.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by cube2222 on Tuesday January 07, 2020 @03:15PM (#21984293)
Why?

It is, it's just that everything returns a function! The topmost function will in the end be called with the json as an argument.

Check out these parts of the README: https://github.com/cube2222/jql#attention https://github.com/cube2222/jql#type-cheatsheet

(elem 0) returns a function which takes a JSON array as input and returns its first element.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by michaelmrose on Tuesday January 07, 2020 @05:43PM (#21985970)
Can you find many lisps or even any lisps that evaluate like that? A familiar syntax that actually works different from any lisp in existence may be more hindrance than help.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by cube2222 on Wednesday January 08, 2020 @02:53AM (#21989295)
It’s first class functions. Clojure has them.

It's just that the query ends up having a type JSON -> JSON, not just JSON.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by michaelmrose on Wednesday January 08, 2020 @03:16AM (#21989417)
Take

   (elem "countries" (elem 0))
Inside out elem 0 has to return a function since it doesn't have enough to do anything. I'm not sure why 0 couldn't be a key necessitating a different function to differentiate but whatever.

Elem countries has to return json and one can imagine using the json in the first position like a map in clojure and taking a fn in following position. This would mean that on net it would be exactly the same as.

    (elem 0 (elem countries))
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by cube2222 on Wednesday January 08, 2020 @03:22AM (#21989467)
It really ends up being called like this: ((elem "countries" (elem 0)) JSON)

Yours is more akin to (elem 0 (elem "countries" json))

and you can see that the hierarchy of the query is now inverted in respect to the json. This is what I like about the continuation based approach, a big query will be readable because it fits the data very well.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by michaelmrose on Wednesday January 08, 2020 @02:12PM (#21994686)
Is it more readable than

    (->> JSON 
        (elem "countries")
        first)
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by cube2222 on Wednesday January 08, 2020 @02:57PM (#21995110)
This looks very readable and matches the structure of the json too.

To me it's basically the same readability wise with proper indentation.

Though with deeply nested data and a lot of map functions I think you'd have a lot of unnecessary (->> JSON ...). But those can probably be eliminated with another macro.

Also, there's the pipe function in jql which basically lets you do this.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by kazinator on Tuesday January 07, 2020 @10:15PM (#21987940)
You can find Lisp macros which evaluate like that, more or less.

Programming with combinators over functions is a thing also.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by scarejunba on Tuesday January 07, 2020 @06:57PM (#21986641)
It's continuation-passing style.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by zeroimpl on Tuesday January 07, 2020 @11:57PM (#21988496)
To me it also seems like it should be:

    (elem (elem input "countries") 0)