@mike.castillo.jr I’m not sure I understand, but if I give you bad advice, then someone will correct me, so you will get helped. :smile: I understand you want identifiers like line-1
, line-2
. I don’t understand what you want to do with them. Do you want your macro to emit a bunch of (define line-1 <some-value>)
? And if so, what do you want <value>
to be?
Sometimes with macros, it helps to go “backwards”. What code do I want the macro to write for me? Write it. Make sure it works. Then figure out how to make a macro that will write that code.
Anyway, it’s probably clear to you, but it’s not clear to me what code you want the macro to write.
needs to go AFK for a few minutes but will try to check back later…
Thanks. Here’s an example. I have this line of code 10 x = 1; y = 3; z = 5
It gets turned into (p-line 10 (p-assign x ...))
by the parser. Now I create a line function line-10
using a macro and insert it into an instruction table as (10 line-10)
using (make-immutable-hasheqv (map cons '(LINE-NUM ...) '(LINE-ID ...)))
or something similar. I can do this just fine when I use the manually-inserted line number, and my program works. But when I generate them based on the actual source line instead, so far I can only get a symbol or syntax object into the table, which I haven’t gotten to run correctly.
To clarify, I have a working line-2
function (for example), but recreating the name properly in my module-begin macro is the problem.
Are the code snippets above from a p-line
macro, you mean?
Hmm, or some macro that tries to handle more than p-line
?
p-line
comes straight from the parser. A have another macro that turns it into a line function with the rest of the contents
I didn’t want to clog up the channel with a lot of code, but of course I can show you anything that helps
The with-syntax
above has [((_ LINE-NUM _ ...) ...) #'(LINE ...)]
which feels like you’re trying to do all of them at once. I think this sets up the problem that (syntax-line #'(LINE ...))
is giving you the line of the template syntax.
Whereas if you did them one at a time, and you had a bit of syntax from the original program, then giving it to syntax-line
would do what you want.
So I think it might help if you focused on doing just one at a time. And then have some other macro invoke that macro ...
times. If that makes any sense? Not sure if I’m explaining that well.
you mean like nested with-syntax
?
I mean like write a macro handle-one-p-line
, and then some other macro expands into reps of that.
Or, you could try to do something like (map syntax-line (syntax->list #'(LINE ...)))
.
If you want to keep trying to handle all lines in one macro pattern and template.
That will give you a list of line numbers, one for each bit of syntax in #'(LINE ...)
. A list of numbers, not a list of syntaxes.
I think (map syntax-line (syntax->list #'(LINE ...)))
works, since I get an error line-2: unbound identifier in: line-2
(apparently unrelated?). Thanks, I had tried just (map syntax-line (list #'(LINE ...)))
before which didn’t work.
Good! It can be confusing when you’re using ellipses, keeping straight what is a list of syntax objects, vs. one syntax object that contains a list.
@hikazoh has joined the channel