mitranim/jisp

Atoms, prefixed with dot don't work as macros parameters

Closed this issue · 5 comments

I wanted to create a macros:

(mac http_call method url ...body
     `(do $http
         (,method ,url)                                                                                                                               (.success (fn data (do ,...body)))))

To be used like:

(http_call .get "/api/items/"
                      (= $scope.items data))

which should produce code like this:

(do $http
    (.get "/api/items/")
    (.success (fn data
                  (do (= $scope.items data)))))

But compiler says:

Error: unexpected .get in possible modes: emptyhash | hash | list | quote | unquote | spread | spread | atom

Tested against: (  :  )  (  isKey  :  (  `  ,  ...  …  isAtomString

Tokens: .get, "/api/permissions/", (, =, $scope.perms, data, ), ), (, http_get ...
    at Error (unknown source)
    at demand (/home/art/my-project/jisp/dev/jisp/lex.js:104:108)
    at lex (/home/art/my-project/jisp/dev/jisp/lex.js:170:22)
    at demand (/home/art/my-project/jisp/dev/jisp/lex.js:101:16)
    at lex (/home/art/my-project/jisp/dev/jisp/lex.js:170:22)
    at demand (/home/art/my-project/jisp/dev/jisp/lex.js:101:16)
    at lex (/home/art/my-project/jisp/dev/jisp/lex.js:161:21)
    at Object.compile (/home/art/my-project/jisp/dev/jisp/jisp.js:1571:20)
    at compileScript (/home/art/my-project/jisp/dev/jisp/command.js:170:25)
    at compilePath (/home/art/my-project/jisp/dev/jisp/command.js:127:15)

If i remove dot from get, then compilation succeed, but result is incorrect:

$http;
    ["/api/items/"]
      .success((function(data) {
        return ($scope.items = data);
      }));

Thanks for noting. Right now, the only place where the compiler expects a free-floating .dot or [bracket] notation is in the beginning of a list in a do:

(do str
  (.trim))

You can work around this by using (get get) instead of .get. I suppose the compiler needs to be more liberal in where it allows property notation. Yet another ToDo.

Thank you, (get $http get) works.

Think, nobody will work on this ever.

At some point, I'd like to write a blog post why. My opinion of Lisps was already low and went lower after some professional experience with Clojure.

It would be nice to read such post.