43 questions
1
vote
1
answer
112
views
Scheme macro where I need an index number for each repeated element
I am trying to make a macro similar to register-groups-bind in the Common Lisp cl-ppcre library. The idea is that you make a regex with groups, and give it a list of variables, statements to execute. ...
0
votes
1
answer
935
views
Can you use #defines like method parameters in HLSL?
In HLSL, is there a way to make defines act like swap-able methods? My use case is creating a method that does fractal brownian noise with a sampling function(x, y). Ideally I would be able to have a ...
-1
votes
1
answer
51
views
Simulating C/C++ empty defines in Java
I know Java does not have pre-processor, but I struggle to find a way to do this.
I am looking to create macros to improve code readibility, to specify which of the functions or parameters are for ...
-1
votes
1
answer
57
views
Why #define variable in library is overridden from #define in calling application?
I am trying to a make plugin system which will have a header file for all plugins to include. In that header the version of the plugin system is defined in a #define like so:
PluginHeader.hpp:
#define ...
1
vote
1
answer
2k
views
For C/C++ syntax highlighting in vscode : how to tell vscode that a compile option "-Dxxxx" will be used?
When developing for micro controller, we use a lot of compile-time defines passed to the compiler with the "-Dxxxx" syntax.
I would like to configure vscode such that it knows that certain ...
2
votes
2
answers
165
views
Disallow C preprocessor from using a macro within another
I'm experimenting to see how far I can abuse the C preprocessor and I have stumbled across an interesting problem.
I have the following macro defines:
#define if(x) if (x)
#define do {
#define ...
2
votes
3
answers
280
views
C++: Simplifiying a #define
I have a #define with generates a enum class and a corresponding output operator the the generated enum class.(see below)
#define ENUM(N, T, N1, V1, N2, V2, N3, V3, N4, V4, N5, V5, N6, V6, N7, V7)\
...
1
vote
1
answer
1k
views
How to handle C char* defines in C++ [duplicate]
I am porting some C code to C++ right now. The C code is using multiple defines
like:
#define IPADDRESS "fd9e:21a7:a92c:2323::1"
The problem that i have is that when i am calling C functions ...
1
vote
1
answer
171
views
How to increment a Record Field using Scheme define-syntax macro
Given a Chez Scheme record with many numeric fields that are contantly being mutated by small increments and decrements, usually by one, is there a way to write a macro that can mutate a field value ...
-1
votes
1
answer
412
views
Custom pattern-matching facility for Chez Scheme
I am trying to make my own pattern-matching system in Scheme. To begin I am making a parser for s-expressions that divides them into tokens like this:
'(1 2 b (3 4)) => '(number number symbol (...
0
votes
1
answer
524
views
Token in macro definition was not declared in this scope
I am trying to make a logic system using defines macros for implementation of my logger that will expand into nothing when certain toggles are defined. The problem is that when I stack multiple of ...
1
vote
0
answers
357
views
Unsequenced function calls: error for a #define
A static code analysis tool shows me that I have an unsequenced function calls for a define. Want to get rid of the warning.
It complains that I use Logging() and get_id() (two functions, only one ...
0
votes
1
answer
48
views
Why there is only one method in the define-syntax my-class?
(define-syntax my-class
(syntax-rules ()
[(my-class <class-name> (<attr> ...)
(method (bigger-x other) (> x (other 'x))))
(define (<class-name> &...
0
votes
2
answers
150
views
Hygienic macro r7rs : Return second expression value
I'm currently learning some r7rs and I am trying to implement a macro 'begin' as following :
(begin0 expr0 expr1 ... expr2)
With expr being a regular expression (Like (set! x (+ x 1)))
And begin0 as ...
1
vote
1
answer
242
views
how to comment values under #ifdef in one place
let's imagine we have a C++ project that should work on several platforms (for example, arm/arm64) and we need to have target-specific values for each of them.
Right now we do:
#ifdef PLATFORM_ARM
#...
-1
votes
1
answer
5k
views
How to pass a variable to the define macro used for accessing the path in system verilog
I am using a define macro to set the path for a module,
ie,
`define DUT_PATH(CH) dut_top.u_channel_```CH``_mode
and using this define macro in a module where we are passing the channel number ,
...
1
vote
1
answer
227
views
Provide syntax-rule Racket
How do I provide syntax rules in racket?
I have code which is similar to this:
(define-syntax SELECT
(syntax-rules (FROM WHERE star)
[(SELECT colnames FROM relnames)
...]
[(SELECT ...
1
vote
2
answers
2k
views
Cannot resolve function-like macro inside conditional compilation block
Consider the following - I want to check with #if #endif whether a
token is defined somewhere in the code.
I am using a CONCAT(input) macro that should glue the constant and changing parts of the ...
0
votes
1
answer
38
views
How to tranpose pattern sequence in Scheme macro?
I wrote the following Scheme macro.
(define-syntax join
(syntax-rules ()
((join (var ...) (val ...) ...)
'(((var val) ...)
...))))
When I try it
(join (a b c)
(1 2 3)
(...
1
vote
1
answer
514
views
Make my own while loop using "define-syntax-rule"
I am trying to create my own while-loop in racket using the "define-syntax-rule".
I want it to be procedural based, so no helper functions (i.e. just using lambda, let, letrec, etc.).
I have this, ...
5
votes
2
answers
525
views
Racket macro that defines multiple top-level forms?
I found myself defining syntax parameters with identical definitions except for their name so I decided to write a macro to make this simpler:
(define-syntax (test-case-parameter stx)
(syntax-parse ...
2
votes
1
answer
661
views
How to call other macros from a Chicken Scheme macro?
I'm trying to move from Common Lisp to Chicken Scheme, and having plenty of problems.
My current problem is this: How can I write a macro (presumably using define-syntax?) that calls other macros?
...
4
votes
2
answers
99
views
Racket macro for expanding code
I want to be able to write:
(nota E2 82)
instead of:
(define E2
(network ()
[sunet <= sine-wave 82]
[out = (+ sunet)]))
I know I can do this using macros and tried to ...
0
votes
1
answer
120
views
Define-Syntax Arguments and Usage
I don't really understand the arguments and usage of define-syntax within Scheme. For what it's worth, I'm using Petite Chez Cheme. I've looked at a few sources:
define-syntax issue in scheme
Scheme ...
2
votes
1
answer
71
views
Is it possible to use user defined fuctions when expanding macro?
From chicken scheme manual:
define-syntax evaluates the procedure in a distinct expansion environment (initially having access to the exported identifiers of the scheme module)
Is it possible to ...
2
votes
2
answers
635
views
How to control order of Scheme macro expansion?
I'm working with the Racket macro extension syntax-id-rules, that some other Scheme implementations provide under the name identifier-syntax. These let you specify macro expansions that will happen ...
3
votes
1
answer
358
views
Writing a `define-let` macro, with hygiene
I'm trying to write a define-let macro in racket, which "saves" the header of a (let ((var value) ...) ...) , namely just the (var value) ... part, and allows re-using it later on.
The code below ...
2
votes
1
answer
2k
views
Defining a For Loop in Scheme
Note: This appears to be Gauche Scheme version 0.9.3.3.
I cannot seem to wrap my head around these Lisp languages :/.
I'm trying to define a for loop syntax in Scheme. I'm not sure if this is doable ...
0
votes
1
answer
914
views
How to use #define variable as method parameter in objective C
I'm pretty new to Objective-C and what I want to do is have define variables in the EntityNameConstants.h file where I store all the Entity Names.
And the I will use all the defines in repository for ...
7
votes
3
answers
1k
views
Capturing Macros in Scheme
What's the simplest way to define a capturing macro using define-syntax or define-syntax-rule in Racket?
As a concrete example, here's the trivial aif in a CL-style macro system.
(defmacro aif (...
6
votes
1
answer
430
views
Is there any way to define a compile-time (expansion-time) macro variable in Racket or any other Scheme?
To give a simple example:
(define-macro-variable _iota 0) ; define-macro-variable does not really exist
(define-syntax (iota stx)
(syntax-case stx ()
((iota)
(let ((i _iota))
(set! ...
1
vote
1
answer
880
views
how to create a macro in racket where a list becomes the args of said lambda?
How would I go about in doing a define-syntax-rule that accepts a list as arguments and a list (or a quote, in case it is a single element) as body of a lambda?
i would like to do something like:
...
5
votes
2
answers
947
views
Currying functions in Scheme using macros
I'm learning about the macro system in Scheme and I thought implementing curried functions would be a good start. This is what I cooked up:
(define-syntax function
(syntax-rules ()
((_ () ...
0
votes
2
answers
458
views
Error during expansion of macro in Chicken Scheme
I'm learning how the macro system in Scheme works and I'm trying to make my code look more JavaScript-y. So I thought I would start with the function macro. This is how I want a function definition to ...
3
votes
2
answers
486
views
Racket macros - making pairs
I've just started diving into Racket macros, and am trying to make a terse simple-macro-defining macro. I would like to expand an expression like this:
(macro id
(param) replacement1
(params ....
1
vote
1
answer
591
views
Scheme R5RS define-syntax ignored?
Just started learning Scheme.
I'm using Dr. Racket as my compiler/interpreter.
I need some String functions (string-replace to be exact), so I copied from SRFI 13.
When I test it, it shows..
...
1
vote
1
answer
1k
views
Scheme macro expansion: Nesting let-syntax inside define-syntax
I wish to expand
(foo x (f n) (f n) (arbitrary) (f n) ...)
into
(begin (x 'f n) (x 'f n) (arbitrary) (x 'f n) ...)
my attempt is:
(define-syntax foo
(syntax-rules ()
((_ l a ...)
(let-...
6
votes
2
answers
424
views
Can "if" be implemented using "call/cc"?
I've been told that "call/cc" can be used to implement arbitrary control flow constructs so I'm trying to implement all such constructs using "call/cc" but I'm having trouble. Assuming I didn't have "...
5
votes
1
answer
1k
views
what's wrong with this define-syntax macro in scheme?
I'm working though SICP and wanted to try out some of the examples in guile. I'm trying the stream examples and wanted an implementation for cons-stream, which I got from this StackOverflow question. ...
5
votes
4
answers
1k
views
What, if any, is wrong with this definition of letrec in Scheme?
R5RS gives proposed macro definitions for library forms of syntax:
http://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-10.html#%_sec_7.3
Which also defines letrec, in a very complicated way, ...
6
votes
1
answer
223
views
How are vector patterns used in syntax-rules?
I have been writing Common Lisp macros, so Scheme's R5Rs macros are a bit unnatural to me. I think I got the idea, except that I don't understand how one would use vector patterns in syntax-rules:
(...
5
votes
3
answers
774
views
Scheme Macro for nesting expressions
Can a macro be written in Scheme (with define-syntax, for example) which will take expressions like this:
(op a b c d e f g h i j)
And yield expressions like this as output?
(op (op (op (op (op (op (...
10
votes
4
answers
6k
views
Sources for learning about Scheme Macros: define-syntax and syntax-rules
I've read JRM's Syntax-rules Primer for the Merely Eccentric and it has helped me understand syntax-rules and how it's different from common-lisp's define-macro. syntax-rules is only one way of ...