Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backquote macro in LFE #16

Closed
oubiwann opened this issue May 22, 2014 · 2 comments
Closed

Backquote macro in LFE #16

oubiwann opened this issue May 22, 2014 · 2 comments

Comments

@oubiwann
Copy link
Member

This is from an email that Robert sent, and it's a great idea:

I was looking through some of the examples you refer to in the LFE page when I remembered that LFEs backquote macro even works with tuples . So you can use a tuple "pattern" which expands into code to build a tuple. For example:

`#(ok ,reply) ==> (tuple 'ok reply))

With that you could write the callbacks to the ping_pong server as:

(defun init (args)
  `#(ok ,(make-state pings 0)))

(defun handle_call (req from state)
  (let* ((new-count (+ (state-pings state) 1))
         (new-state (set-state-pings state new-count)))
    `#(reply #(pong ,new-count) ,new-state)))

It of course also works in patterns. This is clearer and more concise for those who know about it but I don't think that this is something to drop on the poor unsuspecting reader from the beginning, but a section on the backquote macro would be good to have somewhere.

@oubiwann
Copy link
Member Author

There was a recent email that went out to the list that ended up being a bit of a tutorial along these lines:

That might make a good starting point...

@oubiwann
Copy link
Member Author

oubiwann commented Mar 1, 2016

@rvirding has done some good work on this for the "official LFE tutorial" here:

The published tutorial is currently available here:

The section on macros with info on the backquote is here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant