Questions tagged [generative-programming]

Generative programming identifies a type of computer programming in which some mechanism generates a computer program to allow human programmers to write the code at a higher abstraction level.

It's also known as automatic programming.

17 questions
19
votes
3 answers

Implementing variadic type traits

Intro I'm looking for a pattern to convert C++ type traits into their variadic counterparts. A methodology to approach the problem would be appreciated and generative programming patterns to automate the task would be ideal. Example Take the…
18
votes
7 answers

Are there any Parsing Expression Grammar (PEG) libraries for Javascript or PHP?

I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared…
17
votes
1 answer

Visual Studio T4 vs CodeSmith

I've been using CodeSmith for the past 2 years and love what it does for me. However, I also know about T4 which is built in to Visual Studio and can do some pretty cool stuff too. Based on conversations with friends T4 in VS2010 T4 is going to be…
Jake
  • 906
  • 10
  • 23
7
votes
2 answers

Generative regular expressions

Typically in our work we use regular expressions in capture or match operations. However, regular expressions can be used - manually at least - to generate legal sentences that match the regular expression. Of course, some regular expressions can…
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
7
votes
2 answers

Write an anonymous sub in Perl to a file for later use

I have a Perl program that generates parsing rules as subs from an input file. The subs are anonymously defined an put into a hash. Now, I want to export that hash, with all the subs and then load them again later to use with a different…
Ritwik Bose
  • 5,889
  • 8
  • 32
  • 43
4
votes
2 answers

How to keep template whitespace (tabs) formatting using Apache Velocity 1.7?

I am using Velocity to generate different artifacts in my project, including Java Hibernate Entities. Here is an example of my template: #foreach( $column in $columns ) #if ($column.columnID != "id") #if…
Daniel
  • 53
  • 1
  • 4
1
vote
1 answer

Auto-generate methods for subclasses

I have a few dozen classes. Here are two of them: class Class_A(ClassABC): def __init__(self): super().__init__() def from_B(self, b): #do stuff def from_C(self, c): #do stuff #... def to_B(self): …
Arlen
  • 6,641
  • 4
  • 29
  • 61
1
vote
1 answer

Javascript P5, drawing a grid on a canvas

I'm carrying out a P5 assignment for college and struggling to understand some code I found online. I've included a screenshot of the output of the code and the actual code below. I understand the logic of creating the basic grid, but I was…
0
votes
0 answers

How to prompt engineer/ context for llm (Code Generation)

I am building a natural language to sql application and for that im using: https://teknium-replit-v2-codeinstruct-3b.hf.space/ using its api, im generating sql code but I dont know how to provide context or how to style the prompt template so that…
0
votes
0 answers

How can I make GCC Assert a Compile Time Error when an array of constant structs has a single uninitialized element?

I want to generate asserts at compile time, checking whether each element within a struct is initialized or not. I was wondering how I could generate a for loop of such static assert statements at compile time given that the assert is not a…
0
votes
1 answer

JavaScript Counter Variable Fluctuate Between Two Values

I'm trying to fluctuate the variable "z" by 0.1 between the two ranges of 0 and 2 continuously. When it hits the max of 2, I want the variable "z" to decrement. And when it hits the min of 0, I want the variable "z" to increment. So far, all my code…
0
votes
2 answers

How to write CPP template functions that is recursive on argument array length

Say I want to write a function arrfill that fills an array of length N. Below is the template implementation I tried. template bool arrfill(T arr[0], T v){;} template void arrfill(T arr[N], T v){ arr[0] =…
Yangcy
  • 167
  • 1
  • 6
0
votes
2 answers

Templated member variables in C++

Often when writing templated code, I find myself needing to store an instance of the template type in a member variable. For example, I might need to cache a value to be used later on. I would like to be able to write my code as: struct Foo { …
pooya13
  • 2,060
  • 2
  • 23
  • 29
0
votes
2 answers

Gen: How to combine multiple generative function traces in a higher-order generative function?

I'm going through the "Introduction to Modeling in Gen" Notebook at https://github.com/probcomp/gen-quickstart Section 5 (Calling other generative functions) asks to "Construct a data set for which it is ambiguous whether the line or sine wave…
0
votes
0 answers

How to start a generative portrait in p5.js

I need help with a code I'm working on for a project. What I need it to do is show the users the picture one by one and memorize the time spent on each. At the end it should open the webcam and start drawing a portrait of the user with particles…
Silsil
  • 1
  • 1
1
2