Re: Generate function defintions at compile time

Neil Van Dyke <[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <[email protected]>
[email protected] wrote on 08/22/2017 05:29 PM:
> So far it looks good, but I am stuck on macros. There is a hash table 
> which serves as a specification for which functions to generate, it is 
> stored in the file 'nvim/api/specification.rkt'. This table has the 
> key" functions" which contains a vector of more hash tables.

You *can* go from hashes at syntax expansion time to syntax, but, in 
this case, I think there are ways that are more idiomatic and (once 
you're comfortable with syntax extension) easier...

If you define a kind of domain-specific language (DSL) syntax extension 
in Racket for your Neovim API, your specification might then look like 
this (with the "..." filled in):

(define-and-provide-neovim-api
   (version ...)
   (error-types ...)
   (types ...)
   (functions ...)
   (ui-events ...))

Or:

(define-and-provide-neovim-api
   #:version ...
   #:error-types ...
   #:types ...)
   #:functions ...
   #:ui-events ...)

Then you implement your `define-and-provide-neovim-api` syntax 
transformer using `syntax-case` or `syntax-parse`.  (When you're 
implementing this, it sometimes (not always) helps to type an example 
use of your syntax, then type an example of what syntax you would like 
that to expand to, and then rework those two examples into your 
`syntax-case` or `syntax-parse` form.)

Or, a somewhat different way is to have separate definition forms in 
Racket for each element of the API, such as:

(define neovim-foo (neovim-api-lambda ...))
(provide neovim-foo)

Or:

(define-and-provide-neovim-procedure neovim-foo ...)

BTW, consider making the `require` name be simply `neovim` or `nvim`, 
not `neovim/api` or `nvim/api`.  Or call the package `neovim-api`.

Also BTW, consider including the string "neovim" or "nvim" in the names 
of all provided identifiers of your API package, such as 
`neovim-command` instead of `command`.  (For example, I included 
"roomba" in every name in "http://www.neilvandyke.org/racket/roomba/".)  
This is not a rule, just something to consider.  Personally, I would 
probably make it `neovim-command` in the API library that can be used 
from `#lang racket`, and then, someday, I have the option of making a 
`#lang neovim` that (among doing other things) provides that procedure 
simply as `command` rather than `neovim-command`.

-- 
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.