View Issue Details

IDProjectCategoryView StatusLast Update
0000605LDMud 3.5LPC Compiler/Preprocessorpublic2010-11-20 19:00
Reportersinnvoll Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Summary0000605: Ideas for the preprocessor (start-end-tag-defines, foreach-loop)
DescriptionI often use a master-object to store data,
with many specialized set/query-functions, all with the same structure.
You could simplify that.

Some Ideas for that:
At first I need the ##-glue-operator for defines,
but this is part of an other idea in the database.
I want to show this idea in short form, to build onto it.
I hope it motivates to implement the ##-glue-operator.

The following code does not do, what you might think:

#define SET_QUERY(typ,name) \
type a; \
void set_name(type a) { name=a; } \
type query_name() { return name; }

The valid standard-c-syntax is:

#define SET_QUERY(typ,name) \
type a; \
void set_##name(type a) { name=a; } \
type query_##name() { return name; }

without glue-operator you could simplified the underlying structure,
but not so effective:

#define SET_QUERY(typ,name,setname,queryname) \
type a; \
void setname(type a) { name=a; } \
type queryname() { return name; }

The following new ideas I propose for the preprocessor:

For better readibility, to do multiline defines in an easy fashion:

#define_start SET_QUERY(typ,name)
type a;
void set_##name(type a) { name=a; }
type query_##name() { return name; }
#define_end

compared to now:

#define SET_QUERY(typ,name) \
type a; \
void set_##name(type a) { name=a; } \
type query_##name() { return name; }

now you have to look out for missing \ oder blanks following the \

on the other side to process a list of uniform data
a loop-construct seems useful

#foreach (a,b) ((string,name),(string,id),(int,plural)) SET_QUERY(a,b)

or:

#foreach (a,b) "%s %s\n" "filename" SET_QUERY(a,b)

with a file 'filename':
string name
string gender
int plural

You could store the shared structure of files with the same or related interface
i.e. the interfaces can differ in securing of the set-function
( private function, test of valid_caller)
or one object with only set-functions and the other only query_functions

a currently usable alternative is:

items.inc:
ITEM(string,name)
ITEM(string,gender)
ITEM(int,plural)

It is possible to utilize this include-file in the form:

#define ITEM(a,b) SET(a,b)
#include "items.inc"
#undef ITEM(a,b)
#define ITEM(a,b) QUERY(a,b)
#include "items.inc"
TagsNo tags attached.

Relationships

related to 0000174 new LDMud Preprocessor is not ISO-C compatible. 

Activities

zesstra

2009-02-08 09:05

administrator   ~0000947

Ok, as a first comment: I don't like precompiler magic like this very much and would definitely not accept it in domains I am responsible for. ;-) I tend to keep as many defines out of the code as possible with exceptions of constants. So personally I am not very interested in such features.

lynx

2009-05-22 01:57

reporter   ~0001131

The ##feature looks sweet, but I'm not sure if we need so much lex sugar.

Looking at the actual use for this being '#foreach (a,b) "%s %s\n" "filename" SET_QUERY(a,b)' why don't you just generate a file to be #included, which has all the necessary LPC code generated by a previous LPC program?

Gnomi

2009-05-25 15:18

manager   ~0001156

Programmatically generated LPC code is not the way I would like to go or encourage others to go. But I'm in favor of the ## operator.

Gnomi

2009-05-26 01:50

manager   ~0001157

But I think this should go to 3.5.

Sorcerer

2009-05-26 02:52

updater   ~0001158

Like zesstra, I am not a friend of too many precompiler directives in code I have to read (or even maintain). This being a personal taste, there is also one "non-personal" argument against those extensions:
LPC is a programming language that aims at a clientele that is not too familiar with programming (many start with LPC as their first "real" programming language). For those I think the extensive use of the precompiler will add one more burden when learning how to implement their ideas in LPC-code.

zesstra

2010-11-20 19:00

administrator   ~0001928

Sorcerers point is even more valid for new wizards who try to assume responsibility for a region/domain. So even if they don't use that stuff, they have to know it because somebody else might have used them.
I admit, I have a warped perception here because of too many wizards trying to obfuscate their code with precompiler stuff.

Issue History

Date Modified Username Field Change
2009-02-06 11:21 sinnvoll New Issue
2009-02-08 09:05 zesstra Note Added: 0000947
2009-05-22 01:57 lynx Note Added: 0001131
2009-05-25 15:18 Gnomi Note Added: 0001156
2009-05-26 01:50 Gnomi Note Added: 0001157
2009-05-26 01:51 Gnomi Project LDMud => LDMud 3.5
2009-05-26 02:52 Sorcerer Note Added: 0001158
2009-10-06 02:44 zesstra Relationship added related to 0000174
2010-11-20 19:00 zesstra Note Added: 0001928