greg
2019-4-4 18:28:28

@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?


greg
2019-4-4 18:29:44

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.


greg
2019-4-4 18:30:35

Anyway, it’s probably clear to you, but it’s not clear to me what code you want the macro to write.


greg
2019-4-4 18:31:06

needs to go AFK for a few minutes but will try to check back later…


mike.castillo.jr
2019-4-4 18:46:34

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.


mike.castillo.jr
2019-4-4 18:49:22

To clarify, I have a working line-2 function (for example), but recreating the name properly in my module-begin macro is the problem.


greg
2019-4-4 19:06:40

Are the code snippets above from a p-line macro, you mean?


greg
2019-4-4 19:07:07

Hmm, or some macro that tries to handle more than p-line?


mike.castillo.jr
2019-4-4 19:08:45

p-line comes straight from the parser. A have another macro that turns it into a line function with the rest of the contents


mike.castillo.jr
2019-4-4 19:10:33

I didn’t want to clog up the channel with a lot of code, but of course I can show you anything that helps


greg
2019-4-4 19:10:35

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.


greg
2019-4-4 19:11:02

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.


greg
2019-4-4 19:11:47

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.


mike.castillo.jr
2019-4-4 19:12:02

you mean like nested with-syntax?


greg
2019-4-4 19:12:38

I mean like write a macro handle-one-p-line, and then some other macro expands into reps of that.


greg
2019-4-4 19:13:29

Or, you could try to do something like (map syntax-line (syntax->list #'(LINE ...))).


greg
2019-4-4 19:13:41

If you want to keep trying to handle all lines in one macro pattern and template.


greg
2019-4-4 19:14:56

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.


mike.castillo.jr
2019-4-4 19:29:02

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.


greg
2019-4-4 19:40:46

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
2019-4-4 23:51:27

@hikazoh has joined the channel