technoblogy / ulisp

A version of the Lisp programming language for ATmega-based Arduino boards.

Home Page:http://www.ulisp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simplify code by using macros

dragoncoder047 opened this issue · comments

The whole pile of const char stringNNN[] PROGMEM = "NNN" annoys me for some reason. I don't know how to get rid of it, but I can simplify it with a macro.

#define STRINGER(x, s) const char string##x[] PROGMEM = s;
STRINGER(123, "foo")
// expands to: const char string123[] PROGMEM = "foo";

Could also use macros for docstrings:

#define DOCSTRINGER(x, d) const char doc##x[] PROGMEM = d;

I don't know how to get the entry for the table, however, because the paste operator (##) requires there to be a prefix on the token.
Perhaps multiple macros?

#define SPENTRY(s, f, a, d) { string##s, sp_##f, a, doc##d }
#define TFENTRY(s, f, a, d) { string##s, tf_##f, a, doc##d }
#define FNENTRY(s, f, a, d) { string##s, fn_##f, a, doc##d }
SPENTRY(123, foobar, 0x12, 456), // expands to { string123, sp_foobar, 0x12, doc456 },

That would definitely be neater, but I think there's some advantage in keeping it simple.

Also, it doesn't annoy me because I don't have to type them in - they are generated automatically by my uLisp Builder; see:

https://github.com/technoblogy/ulisp-builder

uLisp 4.4 looks like it would be easy to add user extensions without resorting to macro hacks, so I'll close this.